learner = GriceanQuantifierLexicon(make_my_hypothesis, my_weight_function) # We will defautly generate from null the grammar if no value is specified for w in target.all_words(): learner.set_word(w) # populate the finite sample by running the sampler for this many steps for x in mh_sample(learner, data, SAMPLES, skip=0): hypset.push(x, x.posterior_score) return hypset if __name__ == "__main__": # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # MPI interface # Map. SimpleMPI will use a normal MAP if we are not running in MPI allret = MPI_map(run, map(lambda x: [x], DATA_AMOUNTS * CHAINS)) # this many chains ## combine into a single hypothesis set and save outhyp = FiniteBestSet(max=True) for r in allret: print "# Merging ", len(r) outhyp.merge(r) import pickle pickle.dump(outhyp, open(OUT_PATH, 'w'))
s=options.s) for w in target.all_words(): h0.set_word( w, LOTHypothesis(my_grammar, display='lambda recurse_, C, X: %s')) gs = Gibbs(h0, hugeData, proposer=proposer, steps=options.samples) hyps = TopN(N=options.top_count) for s, h in enumerate(gs): hyps.add(h) print h.prior, \ h.likelihood, \ h return hyps ###################################################################################################### # Run Time Code ###################################################################################################### argarray = map(lambda x: [x], options.data_pts * options.chains) if is_master_process(): display_option_summary(options) seen = set() for fs in break_ctrlc(MPI_map(run, argarray, progress_bar=False)): for h in fs.get_all(): seen.add(h) with open(options.out_loc, 'w') as f: pickle.dump(seen, f)
return hyps ################################################################################### # Main Running ################################################################################### argarray = [] for w in target_words: argarray += map(lambda x: [w, x], options.data_pts * options.chains) if is_master_process(): display_option_summary(options) seen = set() for fs in break_ctrlc( MPI_map(run, numpy.random.permutation(argarray), progress_bar=False)): for h in fs.get_all(): if h not in seen: seen.add(h) if h.prior > -Infinity: print '#####', h.prior, \ h.likelihood, \ h \ #sys.stdout.flush() #sys.stdout.flush() import pickle with open(options.out_path, 'w') as f: pickle.dump(seen, f)
# define the data for each model. # Right now, we do this so that every iteration and method uses THE SAME data in order to minimize the variance model2data = dict() for model in models: if re.search(r":", model): # split model string by : to handle different amounts of data m, d = re.split(r":", model) _, make_data = load_example(m) model2data[model] = make_data(int(d)) else: _, make_data = load_example(model) model2data[model] = make_data() # For each process, create the list of parameters params = [list(g) for g in product(range(options.REPETITONS),\ models, [model2data], ['multiple_chains_A', 'multiple_chains_B', 'multiple_chains_C', 'taboo_A', 'taboo_B', 'taboo_C', 'taboo_D', 'particle_swarm_A', 'particle_swarm_B', 'particle_swarm_C', 'particle_swarm_prior_sample_A', 'particle_swarm_prior_sample_B', 'particle_swarm_prior_sample_C', 'mh_sample_A',#, 'mh_sample_B', 'mh_sample_C', 'mh_sample_D', 'mh_sample_E', 'parallel_tempering_A', 'parallel_tempering_B', 'parallel_tempering_C', #'partitionMCMC_A', 'partitionMCMC_B', 'partitionMCMC_C', ## Super slow to make partitions 'enumeration_A'])] # Actually run MPI_map(run_one, params)
return filename, hyps ################################################################################### # Main Running ################################################################################### data = [list(pt) for pt in combinations([KinshipData('Word','ego','Snow', simple_tree_context), KinshipData('Word', 'ego', 'charming', simple_tree_context), KinshipData('Word', 'ego', 'Emma', simple_tree_context), KinshipData('Word', 'ego', 'Mira', simple_tree_context), KinshipData('Word', 'ego', 'rump', simple_tree_context), KinshipData('Word', 'ego', 'Regina', simple_tree_context), KinshipData('Word', 'ego', 'henry', simple_tree_context), KinshipData('Word', 'ego', 'neal', simple_tree_context), KinshipData('Word', 'ego', 'baelfire', simple_tree_context), KinshipData('Word', 'ego', 'Maryann', simple_tree_context)], options.k)] argarray = map(lambda x: [x], data * options.CHAINS) if is_master_process(): display_option_summary(options) hypothesis_space = set() for s, h in MPI_map(run, argarray, progress_bar=True): hypothesis_space.update(h) print "Done with " + s with open(options.OUT_PATH + str(options.k) + "dp_HypothesisSpace.pkl", 'w') as f: pickle.dump(hypothesis_space, f)