-
Notifications
You must be signed in to change notification settings - Fork 5
/
costCalculation03.m
41 lines (31 loc) · 1.11 KB
/
costCalculation03.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
34
35
36
37
38
39
40
41
function out = costCalculation03 (V)
global nStates;
global nData;
global nRules_Output;
global rbarOutput;
global rbarState;
global currentIndividual;
global targetOutput;
currentIndividual.V = V;
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;
evaluateMFForStateNetworkOutput
end
W = lsqminnorm(RS_Big, targetOutput);
currentIndividual.W = reshape(W,nStates,nRules_Output);
predictedOutput = RS_Big * currentIndividual.W(:);
currentIndividual.Cost = sqrt(immse(predictedOutput,targetOutput));
out = currentIndividual.Cost;
end