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