コード例 #1
0
def __make_data_matrix(all_genes, all_fitnesses):
	par_dtype = [(par, int) for par in parameters_in_genes] 
	fit_dtype = [(stat, float) for stat in fitness_types.keys()]
	par_matrix = np.zeros(shape = len(all_genes), dtype = par_dtype)
	fit_matrix = np.zeros(shape = len(all_genes), dtype = fit_dtype)
	for i, (gene, fitness) in enumerate(zip(all_genes, all_fitnesses)):
		for par, val in gene.items():
			par_matrix[par][i] = val
		for k, stat in enumerate(fitness_weights.keys()):
			fit_matrix[stat][i] = fitness[k]
	return DataFrame(par_matrix), DataFrame(fit_matrix)
コード例 #2
0
ファイル: IO.py プロジェクト: halfdanrump/MarketSimulation
def store_generation_as_data_matrix(generation_data, generation_number, path):
    all_genes = list()
    all_fitnesses = list()
    all_ids = list()
    for gene in generation_data:
        all_genes.append(gene['ind'])
        all_fitnesses.append(gene['fit'])
        if gene.has_key('data_ids'):
            all_ids.append(gene['data_ids'])

    par_dtype = [(par, int) for par in parameters_in_genes] 
    fit_dtype = [(stat, float) for stat in fitness_types.keys()]
    par_matrix = np.zeros(shape = len(all_genes), dtype = par_dtype)
    fit_matrix = np.zeros(shape = len(all_genes), dtype = fit_dtype)
    for i, (gene, fitness) in enumerate(zip(all_genes, all_fitnesses)):
        for par, val in gene.items():
            par_matrix[par][i] = val
        for k, stat in enumerate(fitness_weights.keys()):
            fit_matrix[stat][i] = fitness[k]
    
    np.savez_compressed(path + 'gen_%s_pars'%generation_number, par_matrix)
    np.savez_compressed(path + 'gen_%s_fit'%generation_number, fit_matrix)
    if all_ids: np.savez_compressed(path + 'gen_%s_dataids'%generation_number, all_ids)