meedshit

s7_p2_optilab

Jul 4th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. clear; close all; clc;
  2.  
  3. load data_l1_trend_filtering.mat;
  4.  
  5. N = length(yti);
  6.  
  7. % your solution here %
  8. figure();
  9. plot(yti); hold on
  10. %% variables
  11.  
  12. % Creating A
  13. A= zeros(N-1, N);
  14.  
  15. for i = 1:N-1
  16. A(i, i)=-1;
  17. A(i, i+1) = 1;
  18. end
  19.  
  20. %creating gamma
  21. gamma = 5;
  22. gammas = linspace(1, 40, 20);
  23.  
  24. trade_off = zeros(2, 20);
  25.  
  26. %% CVX
  27.  
  28. for gamma = 1 : size(gammas, 2)
  29. cvx_begin
  30. variable x_head(N);
  31. %minimize( sqrt( (yti - x_head)'*(yti - x_head) ) + gamma * sqrt( (A*x_head)'*(A*x_head) ) );
  32. %minimize( (yti - x_head)'*(yti - x_head) + gamma * (A*x_head)'*(A*x_head) );
  33. minimize( norm( (yti - x_head) ) + gamma * norm( (A*x_head) ) );
  34.  
  35. cvx_end
  36.  
  37. trade_off(1, gamma) = norm( (A*x_head) );
  38. trade_off(2, gamma) = norm( (yti - x_head) );
  39.  
  40. end
  41. figure();
  42. plot(trade_off(2, :),trade_off(1, :) );
Add Comment
Please, Sign In to add comment