Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Plotting #136

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions pybnf/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,68 @@ def run(self, log_prefix, scheduler_node=None, resume=None, debug=False):
logger.warning('Tried to move pickled algorithm, but it was not found')

if (isinstance(self, SimplexAlgorithm) or self.config.config['refine'] != 1) and self.bootstrap_number is None:
# Make plot if requested
if self.config.config['plot_results']:
self.plot_result(best_pset)

# End of fitting; delete unneeded files
if self.config.config['delete_old_files'] >= 1:
shutil.rmtree(self.sim_dir)

logger.info("Fitting complete")

def plot_result(self, best_pset):
try:
import matplotlib.pyplot as plt
except ImportError:
logger.exception('import matplotlib.pyplot failed')
print1('Could not load matplotlib. Skipping plot.')
return
logger.info('Plotting the results to figure')
job = Job(self.model_list, best_pset, 'plot',
self.sim_dir, self.config.config['wall_time_sim'], None,
self.config.config['normalization'], bool(self.config.config['delete_old_files']))
plot_res = run_job(job, False, self.failed_logs_dir)

simdata = plot_res.simdata
for z, model in enumerate(simdata):
xlist = []
ylist = []
xpointslist = []
ypointslist = []
titlelist = []
xlabellist = []
ylabellist = []
for suffix in simdata[model]:
if suffix not in self.exp_data[model]:
continue
sdata = simdata[model][suffix] # A Data object
edata = self.exp_data[model][suffix] # A Data object
for variable in sdata.cols:
if variable == sdata.indvar:
continue
if variable in edata.cols:
xlist.append(sdata[sdata.indvar])
ylist.append(sdata[variable])
xpointslist.append(edata[sdata.indvar])
ypointslist.append(edata[variable])
xlabellist.append(sdata.indvar)
ylabellist.append(variable)
titlelist.append(suffix)
cols = min(7, len(xlist))
rows = 1 + (len(xlist)-1) // 7
plt.figure(figsize=(cols*3, rows*3))
for i in range(len(xlist)):
plt.subplot(rows, cols, i+1)
plt.plot(xpointslist[i], ypointslist[i], 'ko', markersize=3)
plt.plot(xlist[i], ylist[i], 'r-')
plt.xlabel(xlabellist[i])
plt.ylabel(ylabellist[i])
plt.title(titlelist[i])
plt.suptitle(model)
plt.tight_layout()
plt.show(block=(z == len(simdata)-1))

def cleanup(self):
"""
Called before the program exits due to an exception.
Expand Down
1 change: 1 addition & 0 deletions pybnf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def default_config():
'output_every': 20, 'initialization': 'lh', 'refine': 0, 'bng_command': bng_command, 'smoothing': 1,
'backup_every': 1, 'time_course': (), 'param_scan': (), 'min_objective': -np.inf, 'bootstrap': 0,
'bootstrap_max_obj': None, 'ind_var_rounding': 0, 'local_objective_eval': 0, 'constraint_scale': 1.0,
'plot_results': 0,

'mutation_rate': 0.5, 'mutation_factor': 0.5, 'islands': 1, 'migrate_every': 20, 'num_to_migrate': 3,
'stop_tolerance': 0.002, 'de_strategy': 'rand1',
Expand Down
2 changes: 1 addition & 1 deletion pybnf/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'local_min_limit', 'reserve_size', 'burn_in', 'sample_every', 'output_hist_every',
'hist_bins', 'refine', 'simplex_max_iterations', 'wall_time_sim', 'wall_time_gen', 'verbosity',
'exchange_every', 'backup_every', 'bootstrap', 'crossover_number', 'ind_var_rounding',
'local_objective_eval', 'reps_per_beta']
'local_objective_eval', 'reps_per_beta', 'plot_results']
numkeys_float = ['extra_weight', 'swap_rate', 'min_objective', 'cognitive', 'social', 'particle_weight',
'particle_weight_final', 'adaptive_n_max', 'adaptive_n_stop', 'adaptive_abs_tol', 'adaptive_rel_tol',
'mutation_rate', 'mutation_factor', 'stop_tolerance', 'step_size', 'simplex_step', 'simplex_log_step',
Expand Down