def Calc_initialPopulatin(Error_initial_population):
for it in range(soln_per_population):
Error_initial_population.append(server.get_errors(key,initial_population[i t].tolist()))
Error_initial_population[it].append(it)
Error_initial_population[it].append(Error_initial_population[it][ 0 ]*3.5+Er ror_initial_population[it][ 1 ]*6.5)
Error_initial_population=np.array(Error_initial_population)
return Error_initial_population
def Crossover(parents_from_initial_population):
first_generation=[]
for i in range(int(soln_per_population/ 2 )):
temp=[]
for j in range(num_coefficientWeights):
temp.append(initial_population[int(parents_from_initial_population[i][ 2 ])] [j])
first_generation.append(temp)
for i in range(int(soln_per_population/ 2 )):
temp=[]
temp.append(- 10 )
for j in range( 2 ):
temp.append(first_generation[i][j+ 1 ])
for j in range( 2 ):
temp.append(first_generation[(i+ 1 )% 5 ][j+ 3 ])
for j in range( 2 ):
temp.append(first_generation[(i+ 2 )% 5 ][j+ 5 ])
for j in range( 2 ):
temp.append(first_generation[(i+ 3 )% 5 ][j+ 7 ])
for j in range( 2 ):
temp.append(first_generation[(i+ 4 )% 5 ][j+ 9 ])
first_generation.append(temp)
return first_generation
def Mutation(initial_population):
num=random.randint( 4 , 6 )
i= 0
for i in range(num):
a=random.randint( 1 , 9 )
b=random.randint( 1 , 10 )
initial_population[a][b]=(initial_population[a][b]+(initial_population[a][ b]*random.randint(-0.3,0.3)))% 10
return initial_population
return initial_population
First we analyzed the given overfit vector making some changes in each weight. Then we
considered the best out of them as our initial population.So my First generated initial population
consists of 10 vectors where each vector has a slight difference with one of the weights of given
overfit vector.(The weight of first coefficient remains same as of overfit vector since we didn’t observed much changes on changing it)
After generating our initial population ,we started on calculating fitness function . Our first fitness function was addition of the two errors. (i.e Train_Error+Validation_Error). We observed
that errors were decreasing to some extent but not much.
We noticed that the train errors are considerably low, but validation errors are huge..
The crossovers we tried are uniform crossover and diagonal multi-parent crossover considering
we get a wide range of results.
We randomly selected some positions in the array and replace it with a random number%
Then we started updating our fitness functions in such a way that we decrease our validation
error. Then we tried different variants but best one was:
(Train_Error*(X) + Validation_Error*(Y))
We tried different values of X and Y and noticed that the best results are obtained when
X<=4 and Y>=6 and X+Y=
Then we observed some good results where both train and validation are almost equal and are
in a range of (10^7).
Then I manually crossovered these best results and mutated them, and the errors are decreased to a range of (7* 10^6)
mutation was updating the value, now we thought of just updating the power (or) exponential
part.So we tried and analyzed different values as exponents and decided some ranges for each
weight.
def Updating_exponents(entered):
i= 0
for i in range( 7 ):
exp = random.randint(min(-(i*(i- 1 )), -( 4 *(i+ 1 ))),max(-(i*(i- 1 )), -( 4 *(i+ 1 ))))
if(exp<- 13 ):
exp=random.randint(- 15 ,- 12 )
entered[i+ 4 ]=(entered[i+ 4 ]*( 10 **exp))
return entered
Here we didn’t performed any crossover but just tried updating the best results we had, and we
resulted with even better arrays, and were able to reduce the train and validation errors to the
range of (3*10^6).Then on manual changes we were able to reduce it a little.
1)On an average our vectors converge on 25~35 iterations based on mutations and crossover applied.
We hope that our current best vector is almost near to this:
[-10, 3.6732405419386582, -0.09, 0.054, -3.86000157715883e-07, 2.901944449494161e-07, -6.93409e-09, -6.00985565299179e-10, 3.488006383229681e-12,
4.551492499340711e-14, -3.430100176902565e-15]
Because of the errors we got, Train error:259295.9197084011 and Validation error:262101.
Here the two errors are almost equal which ensures that I am not overfitting the dataset and
also we need is the best fit out of given overfit.As given is overfit it performs well on the training data but not on the validation data so we need to give importance for reducing the validation
error compromising training error upto an extent as already it's a better one.And here we
reduced validation error from 10^8 to 10^6 compromising training error to some extent.
“IterationDiagrams.pdf” and we have 2 trace outputs “trace1.txt” contains our intermediate best initial population and “trace2.txt” contains our final best initial population.