Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wine_quality.m:
- function [white_indicators, red_indicators]=wine_quality()
- dwhite=dlmread('../data/winequality-white.csv', ';', 1, 0);
- white_indicators=do_wine_quality(dwhite, 0.0003, 1000)
- dred=dlmread('../data/winequality-red.csv', ';', 1, 0);
- red_indicators=do_wine_quality(dred, 0.005, 1000)
- end
- function x=do_wine_quality(data, lambda, iters)
- A=data(:, 1:11);
- b=data(:, 12);
- x0=zeros(11, 1);
- % L=norm(A)^2 is the factor of smoothness of g(x)=|Ax-b|^2
- % This sets tau*L=0.9<=1.
- tau=0.9/norm(A)^2;
- x=lasso_fb(A, b, lambda, x0, tau, iters);
- end
- lasso_fb.m:
- function x=lasso_fb(A, b, lambda, x0, tau, iters)
- x=x0;
- for i=1:iters
- % z = x-tau grad g(x)
- x = prox_l1(tau, lambda, x - tau*A'*(A*x-b));
- end
- end
- prox_l1.m:
- function xnext=prox_l1(tau, lambda, z)
- % Soft thresholding
- idx=abs(z)<=lambda;
- xnext=z-lambda*z./abs(z);
- xnext(idx)=0;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement