submit.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. function submit()
  2. addpath('./lib');
  3. conf.assignmentSlug = 'multi-class-classification-and-neural-networks';
  4. conf.itemName = 'Multi-class Classification and Neural Networks';
  5. conf.partArrays = { ...
  6. { ...
  7. '1', ...
  8. { 'lrCostFunction.m' }, ...
  9. 'Regularized Logistic Regression', ...
  10. }, ...
  11. { ...
  12. '2', ...
  13. { 'oneVsAll.m' }, ...
  14. 'One-vs-All Classifier Training', ...
  15. }, ...
  16. { ...
  17. '3', ...
  18. { 'predictOneVsAll.m' }, ...
  19. 'One-vs-All Classifier Prediction', ...
  20. }, ...
  21. { ...
  22. '4', ...
  23. { 'predict.m' }, ...
  24. 'Neural Network Prediction Function' ...
  25. }, ...
  26. };
  27. conf.output = @output;
  28. submitWithConfiguration(conf);
  29. end
  30. function out = output(partId, auxdata)
  31. % Random Test Cases
  32. X = [ones(20,1) (exp(1) * sin(1:1:20))' (exp(0.5) * cos(1:1:20))'];
  33. y = sin(X(:,1) + X(:,2)) > 0;
  34. Xm = [ -1 -1 ; -1 -2 ; -2 -1 ; -2 -2 ; ...
  35. 1 1 ; 1 2 ; 2 1 ; 2 2 ; ...
  36. -1 1 ; -1 2 ; -2 1 ; -2 2 ; ...
  37. 1 -1 ; 1 -2 ; -2 -1 ; -2 -2 ];
  38. ym = [ 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 ]';
  39. t1 = sin(reshape(1:2:24, 4, 3));
  40. t2 = cos(reshape(1:2:40, 4, 5));
  41. if partId == '1'
  42. [J, grad] = lrCostFunction([0.25 0.5 -0.5]', X, y, 0.1);
  43. out = sprintf('%0.5f ', J);
  44. out = [out sprintf('%0.5f ', grad)];
  45. elseif partId == '2'
  46. out = sprintf('%0.5f ', oneVsAll(Xm, ym, 4, 0.1));
  47. elseif partId == '3'
  48. out = sprintf('%0.5f ', predictOneVsAll(t1, Xm));
  49. elseif partId == '4'
  50. out = sprintf('%0.5f ', predict(t1, t2, Xm));
  51. end
  52. end