def get_llh_hypothesis( data_tag, asimov_data, ntrials, template_maker, template_params, minimizer_settings, save_steps, check_octant): """ Runs the llh fitter ntrials number of times, pulling pseudo data sets from asimov_data. \Params: * data_tag - hierarchy type running for assumed true. * asimov_data - asimov (unfluctuated) data from which to generate poisson fluctuated pseudo data * ntrials - number of trials to run for each hierarchy hypothesis * template_maker - instance of TemplateMaker class, from which to fit pseudo data to * template_params - dictionary of parameters at which to test the pseudo data and find the best match llh * minimizer_settings - settings for bfgs minimizer in llh fit * save_steps - flag to save the optimizer steps * check_octant - boolean to check both octants of theta23 \returns - trials list that holds the dictionaries of llh results. """ trials = [] for itrial in xrange(1,ntrials+1): results = {} # one trial of results tprofile.info("start trial %d"%itrial) logging.info(">"*10 + "Running trial: %05d"%itrial + "<"*10) results['seed'] = get_seed() logging.info(" RNG seed: %ld"%results['seed']) # Get random map generated from asimov data (or from data_tag). fmap = get_random_map(asimov_data, seed=results['seed']) for hypo_tag, hypo_normal in [('hypo_NMH',True),('hypo_IMH',False)]: physics.info( "Finding best fit for %s under %s assumption"%(data_tag,hypo_tag)) with Timer() as t: llh_data = find_max_llh_bfgs( fmap, template_maker, template_params, minimizer_settings, save_steps, normal_hierarchy=hypo_normal, check_octant=check_octant) tprofile.info("==> elapsed time for optimizer: %s sec"%t.secs) # Store the LLH data results[hypo_tag] = llh_data trials += [results] tprofile.info("stop trial %d"%itrial) return trials
results[data_tag] = {} # 0) get a random seed and store with the data results[data_tag]['seed'] = get_seed() # 1) get a pseudo data fmap from fiducial model (best fit vals of params). fmap = get_pseudo_data_fmap(template_maker, get_values(select_hierarchy(params, normal_hierarchy=data_normal)), seed=results[data_tag]['seed']) # 2) find max llh (and best fit free params) from matching pseudo data # to templates. for hypo_tag, hypo_normal in [('hypo_NMH',True),('hypo_IMH',False)]: physics.info("Finding best fit for %s under %s assumption"%(data_tag,hypo_tag)) profile.info("start optimizer") llh_data = find_max_llh_bfgs(fmap,template_maker,params, minimizer_settings,args.save_steps,normal_hierarchy=hypo_normal) profile.info("stop optimizer") #Store the LLH data results[data_tag][hypo_tag] = llh_data #Store this trial trials += [results] profile.info("stop trial %d"%itrial) #Assemble output dict output = {'trials' : trials, 'template_settings' : template_settings, 'minimizer_settings' : minimizer_settings} #And write to file
pseudo_data_settings['params'], normal_hierarchy=data_normal)), seed=results[data_tag]['seed'], chan=channel) # 2) find max llh (and best fit free params) from matching pseudo data # to templates. for hypo_tag, hypo_normal in [('hypo_NMH', True), ('hypo_IMH', False)]: physics.info("Finding best fit for %s under %s assumption" % (data_tag, hypo_tag)) with Timer() as t: llh_data = find_max_llh_bfgs(fmap, template_maker, template_settings['params'], minimizer_settings, args.save_steps, normal_hierarchy=hypo_normal) profile.info("==> elapsed time for optimizer: %s sec" % t.secs) # Store the LLH data results[data_tag][hypo_tag] = llh_data # Store this trial trials += [results] profile.info("stop trial %d" % itrial) except: logging.warn("ERROR IN TRIAL %i, so outputting what we have now!!" % itrial)
# Prepare to store all the steps steps = {key:[] for key in atm_params.keys()} steps['llh'] = [] # Iterate over the cartesian product, and set fixed parameter to value for pos in product(*steplist): pos_dict = dict(list(pos)) print "Running at params-pos dict: ",pos_dict for k,v in pos_dict.items(): hypo_params[k]['value'] = v steps[k].append(v) with Timer() as t: llh_data = find_max_llh_bfgs(asimov_data_set,template_maker,hypo_params, minimizer_settings,args.save_steps, normal_hierarchy=hypo_normal) profile.info("==> elapsed time for optimizer: %s sec"%t.secs) steps['llh'].append(llh_data['llh'][-1]) # Then save the minimized free params later?? #print "\n\nsteps: ",steps #Store the LLH data results[data_tag][hypo_tag] = steps except: print "error message: ",sys.exc_info() logging.warn("ERROR: outputting what we have now...")