In [1]:
from stack import *
my_stack = load('io_files/saved_stack_200_alt.txt')
my_pump = incident_wp(my_stack)
#my_pump.add_packet(100,[1550.0,1600.0])
#my_pump.add_packet(100,[1600.5,1650.5])
my_pump.add_packet(200,[1625.5,1675.5])
my_pump.add_packet(200,[1575.25,1625.25],type='uniform',height=0.0001)
my_pump.add_packet(200,[1525,1575])
my_pump.apply_shaping(focus_mask(my_pump,0,component=0))
Nmodes=600
In [4]:
jtar = 190
pplsize = 50
elitesize = 10
ztar = my_stack.get_location(jtar) + my_stack.get_layerlength(jtar)/2.0
search = genetic_search(my_pump,jtar,resolution=12,pplsize=pplsize,elitesize=elitesize)
In [5]:
print('fitness_score() runtime for one individual:')
%timeit search.fitness_score(search.new_indv())
print('')
print('focus-outside score:',np.sum(my_pump.get_2PS(ztar)[:,1][Nmodes/3:2*Nmodes/3]))
seed = map(cmath.phase,focus_mask(my_pump,jtar,component=0))
my_pump.apply_shaping(focus_mask(my_pump,jtar,component=0))
print('best score with best resolution:',np.sum(my_pump.get_2PS(ztar)[:,1][Nmodes/3:2*Nmodes/3]))
my_pump.apply_shaping(focus_mask(my_pump,0,component=0))
In [5]:
search.pplinit(seed=seed)
In [6]:
data = DataFrame(columns=range(pplsize))
Ngen = 40
for j in range(1,Ngen+1):
data.loc[j] = search.generation_scores()
search.evolve([0.1,0.2,0.9],[0.5,0.1,0.9])#[0.8,0.5,0.2]
print(j,end='-')
In [7]:
print('final top score:',search.fitness_score(search.topbreed()))
pyplot.figure(figsize=(18,5))
for j in range(1,len(data.index)+1): pyplot.plot(data.loc[j],'-o')
pyplot.show()
.
.
.
In [15]:
"""
gmask = genetic_mask(my_pump,jtar,resolution=20,pplsize=100,elitesize=20,Ngen=50)
my_pump.apply_shaping(gmask)
print(np.sum(my_pump.get_2PS(ztar)[:,1][Nmodes/3:2*Nmodes/3]))
my_pump.apply_shaping(conjugate(gmask))
"""
Out[15]:
In [7]:
#np.save('io_files/gmask@10-05nm.npy',gmask)
.
.
.
In [23]:
"""
# testing mutation
indv0 = search.new_indv()
indv1 = deepcopy(indv0)
search.mutate(indv0,[0.25,0.2,0.8])
pyplot.figure(figsize=(18,5))
pyplot.plot(indv0,'-bo');pyplot.plot(indv1,'-ro');pyplot.show()
"""
Out[23]:
In [22]:
"""
# testing reproduction
indv0 = search.new_indv()
indv1 = search.new_indv()
child1,child2= search.reproduce('a',[indv0,indv1])
pyplot.figure(figsize=(18,5))
pyplot.plot(indv0,'-b');pyplot.plot(indv1,'-r');pyplot.plot(child2,'-go')
pyplot.axis([20,40,0,1]);pyplot.show()
"""
Out[22]:
In [20]:
"""
import pandas; from pandas import *
df = pandas.read_csv('io_files/genetics-mutant-A.txt',index_col=0)
pyplot.figure(figsize=(18,5))
#for j in range(len(df.index)):pyplot.plot(df.loc[j],'-o')
pyplot.plot(df.loc[0],'-o')
pyplot.plot(df.loc[len(df.index)-1],'-o')
pyplot.plot(df.loc[len(df.index)-20],'-o')
#pyplot.plot(df['39'])
pyplot.show()
"""
Out[20]:
In [ ]: