Skip to content

Commit 6c92b89

Browse files
committed
Add softmaxPredict
1 parent c47e800 commit 6c92b89

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

cnn_exercise/softmaxPredict.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function [pred] = softmaxPredict(softmaxModel, data)
2+
3+
% softmaxModel - model trained using softmaxTrain
4+
% data - the N x M input matrix, where each column data(:, i) corresponds to
5+
% a single test set
6+
%
7+
% Your code should produce the prediction matrix
8+
% pred, where pred(i) is argmax_c P(y(c) | x(i)).
9+
10+
% Unroll the parameters from theta
11+
theta = softmaxModel.optTheta; % this provides a numClasses x inputSize matrix
12+
pred = zeros(1, size(data, 2));
13+
14+
%% ---------- YOUR CODE HERE --------------------------------------
15+
% Instructions: Compute pred using theta assuming that the labels start
16+
% from 1.
17+
18+
19+
20+
size(pred) % 1 10000
21+
size(data) % 784 10000
22+
size(theta)% 10 8
23+
24+
p = theta*data;
25+
[junk, idx] = max(p, [], 1);
26+
27+
pred = idx
28+
29+
% ---------------------------------------------------------------------
30+
31+
end
32+

0 commit comments

Comments
 (0)