def main(fname): """ Main interface """ if os.path.isfile(fname): systems = load_systems(fname) print('Integrating %d systems' % systems.size) core_num = int(multiprocessing.cpu_count() * 4/5) print('Using %d cores' % core_num) data = [] with tqdm(total=len(systems)) as pbar: with multiprocessing.Pool(core_num) as p: for res in p.imap_unordered(analyze_system, systems, chunksize=10): if not res[1] is None: data.append(res) pbar.update() print('Found result for %d systems' % len(data)) data = cluster_data(data) cache_data(data) else: syst = system_from_string(fname) syst, mat, sol = analyze_system(syst, plot_hist=True) if mat is None: print('No sensible steady-state found') else: print(mat) plot_system_evolution(sol, plt.gca()) plt.show()
def main(fname, skip_filtered=True): """ Main interface """ if os.path.isfile(fname): systems = load_systems(fname) if systems.ndim == 0: systems = [np.asscalar(systems)] print('Integrating %d systems' % len(systems)) core_num = int(multiprocessing.cpu_count() * 4 / 5) print('Using %d cores' % core_num) data = [] with tqdm(total=len(systems)) as pbar: with multiprocessing.Pool(core_num) as p: for res in p.imap(analyze_system, systems, chunksize=10): if not skip_filtered or not res[1] is None: data.append(res) pbar.update() print('Found result for %d systems' % len(data)) if not skip_filtered: data = cluster_data(data) cache_data(data) else: syst = system_from_string(fname) syst, mat, sol = analyze_system(syst, use_ode_sde_diff=False) if mat is None: print('No sensible steady-state found') else: print(mat) fig = plt.figure(figsize=(20, 6)) gs = gridspec.GridSpec(1, 3, width_ratios=[1, 1, 2]) plt.style.use('seaborn-poster') plot_system(syst, plt.subplot(gs[0, 0])) plot_corr_mat(mat, plt.subplot(gs[0, 1])) plot_system_evolution(sol, plt.subplot(gs[0, 2])) plt.tight_layout() save_figure('images/single_case.pdf', bbox_inches='tight', dpi=300) plt.close()
return SDESystem(J, F, E, I) def load_systems(fname): """ Support for loading pickled systems from given file """ return np.load(fname) if __name__ == '__main__': if not len(sys.argv) in (1, 2): print('Usage: %s [function selector]' % sys.argv[0]) sys.exit(1) print('Choose generator:') keys = sorted(globals().keys()) for i, name in enumerate(keys): if name.startswith('generate_') and isinstance(globals()[name], typing.Callable): print(' [%d] - %s' % (i, name)) if len(sys.argv) == 1: choice = int(input('-> ')) elif len(sys.argv) == 2: choice = int(sys.argv[1]) print('-> %d' % choice) else: raise RuntimeError('This should never happen :-)') func = globals()[keys[choice]] res = func() cache_data(res, fname='results/systems')