submit.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. function submit()
  2. addpath('./lib');
  3. conf.assignmentSlug = 'anomaly-detection-and-recommender-systems';
  4. conf.itemName = 'Anomaly Detection and Recommender Systems';
  5. conf.partArrays = { ...
  6. { ...
  7. '1', ...
  8. { 'estimateGaussian.m' }, ...
  9. 'Estimate Gaussian Parameters', ...
  10. }, ...
  11. { ...
  12. '2', ...
  13. { 'selectThreshold.m' }, ...
  14. 'Select Threshold', ...
  15. }, ...
  16. { ...
  17. '3', ...
  18. { 'cofiCostFunc.m' }, ...
  19. 'Collaborative Filtering Cost', ...
  20. }, ...
  21. { ...
  22. '4', ...
  23. { 'cofiCostFunc.m' }, ...
  24. 'Collaborative Filtering Gradient', ...
  25. }, ...
  26. { ...
  27. '5', ...
  28. { 'cofiCostFunc.m' }, ...
  29. 'Regularized Cost', ...
  30. }, ...
  31. { ...
  32. '6', ...
  33. { 'cofiCostFunc.m' }, ...
  34. 'Regularized Gradient', ...
  35. }, ...
  36. };
  37. conf.output = @output;
  38. submitWithConfiguration(conf);
  39. end
  40. function out = output(partId, auxstring)
  41. % Random Test Cases
  42. n_u = 3; n_m = 4; n = 5;
  43. X = reshape(sin(1:n_m*n), n_m, n);
  44. Theta = reshape(cos(1:n_u*n), n_u, n);
  45. Y = reshape(sin(1:2:2*n_m*n_u), n_m, n_u);
  46. R = Y > 0.5;
  47. pval = [abs(Y(:)) ; 0.001; 1];
  48. Y = (Y .* double(R)); % set 'Y' values to 0 for movies not reviewed
  49. yval = [R(:) ; 1; 0];
  50. params = [X(:); Theta(:)];
  51. if partId == '1'
  52. [mu sigma2] = estimateGaussian(X);
  53. out = sprintf('%0.5f ', [mu(:); sigma2(:)]);
  54. elseif partId == '2'
  55. [bestEpsilon bestF1] = selectThreshold(yval, pval);
  56. out = sprintf('%0.5f ', [bestEpsilon(:); bestF1(:)]);
  57. elseif partId == '3'
  58. [J] = cofiCostFunc(params, Y, R, n_u, n_m, ...
  59. n, 0);
  60. out = sprintf('%0.5f ', J(:));
  61. elseif partId == '4'
  62. [J, grad] = cofiCostFunc(params, Y, R, n_u, n_m, ...
  63. n, 0);
  64. out = sprintf('%0.5f ', grad(:));
  65. elseif partId == '5'
  66. [J] = cofiCostFunc(params, Y, R, n_u, n_m, ...
  67. n, 1.5);
  68. out = sprintf('%0.5f ', J(:));
  69. elseif partId == '6'
  70. [J, grad] = cofiCostFunc(params, Y, R, n_u, n_m, ...
  71. n, 1.5);
  72. out = sprintf('%0.5f ', grad(:));
  73. end
  74. end