def plotCost(number_points=0): rand_samples = [] for model_index in range(num_models_regions): region = model_regions[model_index] if number_points: samples = region.points[np.random.choice( region.points.shape[0], number_points, replace=False), :] else: samples = region.points rand_samples.append(samples) all_costs = [] _, axes = plt.subplots(1, 3) for box_plot in range(num_models_fitness): ax = axes.flat[box_plot] #plt.subplot(1,3,box_plot+1) ax.set_title(str(box_plot + 1) + '-bit model') ax.set_xlabel('region id') if box_plot == 0: ax.set_ylabel('cost') model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=models[box_plot]) model_evals = [] for model_index in range(num_models_regions): evals = [] for sample in rand_samples[model_index]: evals.append(-model.eval(sample)[0]) model_evals.append(evals) #plt.boxplot(model_evals) ax.violinplot(model_evals) ax.boxplot(model_evals) ax.set_xticks([1, 2, 3]) all_costs.append(model_evals) #dump data to file f = open(os.path.join(base_path_robustness, "cost_distrib.p"), "wb") pickle.dump(all_costs, f) f.close() plt.savefig(os.path.join(base_path_robustness, 'cost_distrib.pdf'), bbox_inches='tight') plt.show()
def getCosts(number_points=0, file_name=""): rand_samples = [] for model_index in range(num_models_regions): region = model_regions[model_index] if number_points: samples = region.points[np.random.choice( region.points.shape[0], number_points, replace=False), :] else: samples = region.points rand_samples.append(samples) df = pd.DataFrame(columns=['Model id', 'Region id', 'cost']) for model_id in range(num_models_fitness): model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=models[model_id]) for region_id in range(num_models_regions): for sample in rand_samples[region_id]: cost = -model.eval(sample)[0] df = df.append( { 'Model id': model_id + 1, 'Region id': region_id + 1, 'cost': cost }, ignore_index=True) if file_name: df.to_csv(file_name, index=False) return df