Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. wine_quality.m:
  2.  
  3. function [white_indicators, red_indicators]=wine_quality()
  4. dwhite=dlmread('../data/winequality-white.csv', ';', 1, 0);
  5. white_indicators=do_wine_quality(dwhite, 0.0003, 1000)
  6. dred=dlmread('../data/winequality-red.csv', ';', 1, 0);
  7. red_indicators=do_wine_quality(dred, 0.005, 1000)
  8. end
  9.  
  10. function x=do_wine_quality(data, lambda, iters)
  11. A=data(:, 1:11);
  12. b=data(:, 12);
  13. x0=zeros(11, 1);
  14. % L=norm(A)^2 is the factor of smoothness of g(x)=|Ax-b|^2
  15. % This sets tau*L=0.9<=1.
  16. tau=0.9/norm(A)^2;
  17. x=lasso_fb(A, b, lambda, x0, tau, iters);
  18. end
  19.  
  20.  
  21. lasso_fb.m:
  22.  
  23. function x=lasso_fb(A, b, lambda, x0, tau, iters)
  24. x=x0;
  25. for i=1:iters
  26. % z = x-tau grad g(x)
  27. x = prox_l1(tau, lambda, x - tau*A'*(A*x-b));
  28. end
  29. end
  30.  
  31.  
  32. prox_l1.m:
  33.  
  34. function xnext=prox_l1(tau, lambda, z)
  35. % Soft thresholding
  36. idx=abs(z)<=lambda;
  37. xnext=z-lambda*z./abs(z);
  38. xnext(idx)=0;
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement