-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPredictor.m
28 lines (22 loc) · 966 Bytes
/
Predictor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function [optTheta1,optTheta2,FP] = Predictor(X,iniTheta1,iniTheta2,lambda)
nof = size(X,1);
M = size(X,2);
m = 365;
e = M-m;
x = X(:,1);
y = X(:,366);
for i = 367:M
x = [x,X(:,i-m)];
y = [y,X(:,i)];
endfor
# Unrolling into Theta Vector
thetaVec = [ iniTheta1(:); iniTheta2(:) ];
# Minimize Cost Function to get OptTheta Vector
options = optimset( 'GradObj', 'on', 'MaxIter', 1000000 );
[optThetaVec, jMin, exitFlag ] = fminunc( @(thetaVec)(predictionCostFunction(thetaVec,nof,x,y,e,lambda)), thetaVec, options );
# Reshaping Optimal Theta Vector into Matrices for Layer 1 and Layer 2
optTheta1 = reshape( optThetaVec( 1:(nof-1)*nof ), nof-1, nof );
optTheta2 = reshape( optThetaVec( ( (nof-1)*nof )+1:(nof-1)*nof*2), nof-1, nof );
# Apply Forward Propogation to make final Predictions in Nueral Network
[a1,a2,FP] = forwardPropPredictor(x,optTheta1,optTheta2);
endfunction