submit.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function submit()
  2. addpath('./lib');
  3. conf.assignmentSlug = 'k-means-clustering-and-pca';
  4. conf.itemName = 'K-Means Clustering and PCA';
  5. conf.partArrays = { ...
  6. { ...
  7. '1', ...
  8. { 'findClosestCentroids.m' }, ...
  9. 'Find Closest Centroids (k-Means)', ...
  10. }, ...
  11. { ...
  12. '2', ...
  13. { 'computeCentroids.m' }, ...
  14. 'Compute Centroid Means (k-Means)', ...
  15. }, ...
  16. { ...
  17. '3', ...
  18. { 'pca.m' }, ...
  19. 'PCA', ...
  20. }, ...
  21. { ...
  22. '4', ...
  23. { 'projectData.m' }, ...
  24. 'Project Data (PCA)', ...
  25. }, ...
  26. { ...
  27. '5', ...
  28. { 'recoverData.m' }, ...
  29. 'Recover Data (PCA)', ...
  30. }, ...
  31. };
  32. conf.output = @output;
  33. submitWithConfiguration(conf);
  34. end
  35. function out = output(partId, auxstring)
  36. % Random Test Cases
  37. X = reshape(sin(1:165), 15, 11);
  38. Z = reshape(cos(1:121), 11, 11);
  39. C = Z(1:5, :);
  40. idx = (1 + mod(1:15, 3))';
  41. if partId == '1'
  42. idx = findClosestCentroids(X, C);
  43. out = sprintf('%0.5f ', idx(:));
  44. elseif partId == '2'
  45. centroids = computeCentroids(X, idx, 3);
  46. out = sprintf('%0.5f ', centroids(:));
  47. elseif partId == '3'
  48. [U, S] = pca(X);
  49. out = sprintf('%0.5f ', abs([U(:); S(:)]));
  50. elseif partId == '4'
  51. X_proj = projectData(X, Z, 5);
  52. out = sprintf('%0.5f ', X_proj(:));
  53. elseif partId == '5'
  54. X_rec = recoverData(X(:,1:5), Z, 5);
  55. out = sprintf('%0.5f ', X_rec(:));
  56. end
  57. end