-
Notifications
You must be signed in to change notification settings - Fork 6
/
costCalculation.m
33 lines (23 loc) · 899 Bytes
/
costCalculation.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
29
30
31
32
33
%% Calculate Cost of currentIndividual and Update Its W
s = zeros(nStates,1);
s(1) = 1;
RS_Big = zeros(nData, nRules_Output*nStates);
for t=1:nData
%% Find Output
% Compute Cartesian Product R x S
[R, S] = meshgrid(rbarOutput(:,t),s);
RS = R(:) .* S(:);
RS_Big(t,:) = RS;
%% Find Next State
[R2, S2] = meshgrid(rbarState(:,t),s);
RS2 = R2(:) .* S2(:);
nextState = RS2' * currentIndividual.V(:);
nextState = (nextState*(nStates-1)) + 1;
% This Script Calculate S
evaluateMFForStateNetworkOutput;
end
lastState = nextState;
W = lsqminnorm(RS_Big, targetOutput);
currentIndividual.W = reshape(W,nStates,nRules_Output);
predictedOutput = RS_Big * currentIndividual.W(:);
currentIndividual.Cost = sqrt(immse(predictedOutput,targetOutput));