forked from ManosijGhosh/Scene-Text-Recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGA.m
68 lines (58 loc) · 1.83 KB
/
GA.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
% GA runs to find the bins
function [st_ga]=GA()
% clear all
% clc
mkdir('output');
tic
rng('shuffle');
global lowerBound upperBound;
upperBound = 60;
lowerBound = 10;
c=upperBound - lowerBound + 1;
%n=int16(input('Enter the number of chromosomes to work on :'));
n=5; % To change population Size
iter = 5;
population=datacreate(n,c); % Feature Length
fprintf('data created\n');
%[r,c]=size(population);
rank=zeros(1,n);
rankcs=zeros(1,n);
[population,rank]=chromosomeRank(population,rank,0);
fprintf('Chromosomes ranked\n');
count = 1;
while (count<=iter) % To Change if reqd..count - number of iterations
%crossover starts
fprintf('\nCrossover done for %d th time\n',count);
for i=1:uint16(n/2)
%cumulative sum for crossover
rankcs(1:n)=rank(1:n);%copying the values of rank to rankcs
for j= 2:n% size of weights = no. of features in popaulation=c
rankcs(j)=rankcs(j)+rankcs(j-1);
end
maxcs=rankcs(n);
for j= 1:n
rankcs(j)=rankcs(j)/maxcs;
end
a=find(rankcs>rand(1),1,'first');
b=find(rankcs>rand(1),1,'first');
%roulette wheel ends
[population,rank]=crossover(population,rank,a,b,0.5,0.001);
%[population,rank]=crossover(x,t,population,randi(n,1),randi(n,1),rand(1),rank);
clear a b j rankcs;
end
%crossover ends
count=count+1;
[population,rank]=chromosomeRank(population,rank,1);
fprintf('Accuracy of population - ');
disp(rank);
disp('Results saved');
save('output/result.mat','population','rank');
%end
end
fprintf('The number of bins is : %d\n',sum(population(1,:)));
fprintf('The best accuracy is : %d\n',rank(1));
save('output/result.mat','population','rank');
disp('Final results stored');
st_ga=[sum(population(1,:)==1) rank(1)];
toc
end