コード例 #1
0
print(str(socket.gethostname()) + ': Starting calculation at: ' + time.ctime())

print('Testing proposal is: ' + str(allparameters_proposal))
time_start_single = time.time()
print('Likelihood for the testing proposal is: ' +
      str(model(allparameters_proposal)))
time_end_single = time.time()
print('Time for single calculation is ' +
      str(time_end_single - time_start_single))

sys.stdout.flush()
#####################################################################################################################
# First swarm

parInit1 = create_parInit(allparameters_proposal, None, pupil_parameters)
while len(parInit1) < options[0]:
    parInit1_2 = create_parInit(allparameters_proposal, None, pupil_parameters)
    parInit1 = np.vstack((parInit1, parInit1_2))

chain = cosmoHammer.LikelihoodComputationChain()
chain.addLikelihoodModule(PFSLikelihoodModule(model))

pso = cosmoHammer.ParticleSwarmOptimizer(chain,
                                         low=lower_limits,
                                         high=higher_limits,
                                         particleCount=options[0],
                                         pool=pool)

for i in range(len(pso.swarm)):
    pso.swarm[i].position = parInit1[i]
コード例 #2
0
print(str(socket.gethostname()) + ': Starting calculation at: ' + time.ctime())

print('Testing proposal is: ' + str(allparameters_proposal))
time_start_single = time.time()
print('Likelihood for the testing proposal is: ' +
      str(model(allparameters_proposal)))
time_end_single = time.time()
print('Time for single calculation is ' +
      str(time_end_single - time_start_single))

sys.stdout.flush()
#####################################################################################################################
# First swarm

parInit1 = create_parInit(allparameters_proposal, None, None, None, None, 1)
while len(parInit1) < options[0]:
    parInit1_2 = create_parInit(allparameters_proposal, None, None, None, None,
                                1)
    parInit1 = np.vstack((parInit1, parInit1_2))

chain = cosmoHammer.LikelihoodComputationChain()
chain.addLikelihoodModule(PFSLikelihoodModule(model))

pso = cosmoHammer.ParticleSwarmOptimizer(chain,
                                         low=lower_limits,
                                         high=higher_limits,
                                         particleCount=options[0],
                                         pool=pool)

for i in range(len(pso.swarm)):
コード例 #3
0
                      'grating_lines','scattering_radius','scattering_slope','scattering_amplitude',
                      'pixel_effect','fiber_r','flux']  

allparameters_proposal=np.array([-7,0.00,0.00,-0.0,0.0,0.0,0.00,0.0,0,0.00,0.00,-0.0,0.0,0.0,0.00,0.0,
                                 0.65,0.1,0.0,0.0,0.08,0.0,
                                 0.7,2,-0.2,0.00,
                                 0.99,0.0,1,
                                 0.03,1,0,
                                 50000,50,2.5,10**-1.2,
                                 0.47,1.85,1.0]) 

sorter = np.argsort(obs_possibilites)
defocus_array=defocus_possibilites[sorter[np.searchsorted(obs_possibilites, obs_int_array, sorter=sorter)]]

nT=2
parInit1=create_parInit(allparameters_proposal,multi=1)
parInit2=create_parInit(allparameters_proposal,multi=1)
parInitnT=np.array([parInit1,parInit2])

def multi_model(parameters):
        
    res=[]
    for i in range(len(obs_int_array)):
        parameters_single=create_x(defocus_array[i],parameters)
        #print(parameters_single)
        res.append(globals()['model'+str(i)](parameters_single))
    #print(res)
    return np.sum(res)

#if obs_int==8600:
#    model = LN_PFS_single(sci_image,var_image,dithering=2)
コード例 #4
0
"""
##################################################################################################################### 
# First swarm  

# constrained parameters describing the pupil and the illumination
stronger_array_06=np.array([1,1,1,1,1,1,1,1,
                        1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0, 
                        0.0,0.0,0.0,0.0,0.0,0.0,
                        0.0,0.0,0.0,0.0,
                        0.0,0.0,0.0,
                        0.0,0.0,0.0,0.0,
                        1.0,1.0,1.0,
                        1.0,1.0,1])

# creat inital parameters  
parInit1=create_parInit(allparameters_proposal=allparameters_proposal,multi=None,pupil_parameters=None,allparameters_proposal_err=None,stronger=2*stronger_array_06,use_optPSF=None,deduced_scattering_slope=None,zmax=zmax_input)
while len(parInit1)<options[0]:
    parInit1_2=create_parInit(allparameters_proposal=allparameters_proposal,multi=None,pupil_parameters=None,allparameters_proposal_err=None,stronger=2*
                              stronger_array_06,use_optPSF=None,deduced_scattering_slope=None,zmax=zmax_input)
    parInit1=np.vstack((parInit1,parInit1_2))

chain = cosmoHammer.LikelihoodComputationChain()
chain.addLikelihoodModule(PFSLikelihoodModule(model))

pso = cosmoHammer.ParticleSwarmOptimizer(chain, low=lower_limits, high=higher_limits,particleCount=options[0],pool=pool)

for i in range(len(pso.swarm)):
    pso.swarm[i].position=parInit1[i]

#returns all swarms and the best particle for all iterations
#swarms, gbests = pso.optimize(maxIter=nsteps,c1=options[1],c2=options[2])