-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFitness.m
38 lines (38 loc) · 824 Bytes
/
Fitness.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
function MSE=Fitness(Input,Model,Degree)
x=Model.x;
y=Model.y;
%%
Error=0;
if(Degree ==1)
for i=1:length(x)
a=Input(1);
b=Input(2);
c=Input(3);
OutY=(a*x(i)+c)/-b;
Distance=OutY-y(i);
Error=Error+(Distance)^2;
end
elseif(Degree==2)
for i=1:length(x)
a=Input(1);
b=Input(2);
c=Input(3);
d=Input(4);
OutY=(a*(x(i)^2)+b*x(i)+d)/-c;
Distance=OutY-y(i);
Error=Error+(Distance)^2;
end
elseif(Degree==3)
for i=1:length(x)
a=Input(1);
b=Input(2);
c=Input(3);
d=Input(4);
e=Input(5);
OutY=(a*(x(i)^3)+b*(x(i)^2)+c*x(i)+e)/-d;
Distance=OutY-y(i);
Error=Error+(Distance)^2;
end
end
MSE=Error/length(x);
end