/3rd_party_code/minFunc/lbfgsUpdate.m

http://github.com/Sohl-Dickstein/Minimum-Probability-Flow-Learning · Objective C · 21 lines · 20 code · 1 blank · 0 comment · 3 complexity · 71f62353ce9ae32bb70f752844f9d0d3 MD5 · raw file

  1. function [old_dirs,old_stps,Hdiag] = lbfgsUpdate(y,s,corrections,debug,old_dirs,old_stps,Hdiag)
  2. ys = y'*s;
  3. if ys > 1e-10
  4. numCorrections = size(old_dirs,2);
  5. if numCorrections < corrections
  6. % Full Update
  7. old_dirs(:,numCorrections+1) = s;
  8. old_stps(:,numCorrections+1) = y;
  9. else
  10. % Limited-Memory Update
  11. old_dirs = [old_dirs(:,2:corrections) s];
  12. old_stps = [old_stps(:,2:corrections) y];
  13. end
  14. % Update scale of initial Hessian approximation
  15. Hdiag = ys/(y'*y);
  16. else
  17. if debug
  18. fprintf('Skipping Update\n');
  19. end
  20. end