def initial_guess(model): ax = plt.subplot(111) t_ref = model.reference_data[:, 0] y_ref = model.reference_data[:, 1:] plt.title('Initial model behavior and reference') plt.plot(t_ref, y_ref, ls='--', linewidth=2) initial_model = deepcopy(nemf.forward_model(model, t_eval=t_ref)) ax = draw_model_output(ax, initial_model) ax.title.set_text('Initial model guess') plt.show() return ax
def test_forward_model_v1(model_minimal_pkl): nemf.forward_model(model_minimal_pkl)
def test_forward_model_v6(model_npzd_stable_refed_pkl): nemf.forward_model(model_npzd_stable_refed_pkl)
def test_forward_model_v5(model_npzd_osci_refed_pkl): nemf.forward_model(model_npzd_osci_refed_pkl)
def test_forward_model_v4(model_npzd_stable_pkl): nemf.forward_model(model_npzd_stable_pkl)
def test_forward_model_v3(model_npzd_osci_pkl): nemf.forward_model(model_npzd_osci_pkl)
def forward_pickler(path,name): model = load_model(path) model = nemf.forward_model(model) write_pickle(model,name)
# NPZD Example # import the module import nemf # provide the path of model/system configuration model_path = 'example_files/NPZD/NPZD_model.yml' ref_data_path = 'example_files/NPZD/NPZD_ref_oscillating.csv' # load the model configuration model_config = nemf.model_class(model_path, ref_data_path) # visualise the model configuration to check for errors nemf.interaction_graph(model_config) # for a simple time evolution of the model call: output_dict = nemf.forward_model(model_config) # the results of the time evolution can be visualized with: nemf.output_summary(output_dict) # if the model shall be fitted as well call: model = nemf.inverse_model(model_config) # to plot the results: nemf.output_summary(model) # writes optimized model to file model.export_to_yaml(path='optimized_model.yml')
def draw_optimization_overview(model): """ reads the data saved in the model class and depending on this data chooses a visualization method to present the results """ fig = plt.figure() fig.suptitle('Results of optimization run') if model.reference_data[:, 0][0] == np.inf: non_steady_state = False else: non_steady_state = True if not np.isnan(model.log['cost'][0]): ax1 = plt.subplot(221) draw_cost(ax1, model.log['cost']) ax2 = plt.subplot(222) draw_parameters(ax2, model.log['parameters'], model) ax3 = plt.subplot(212) if non_steady_state: t_ref = model.reference_data[:, 0] y_ref = model.reference_data[:, 1:] plt.plot(t_ref, y_ref, ls='--', linewidth=2) time_series = nemf.forward_model(model, t_eval=t_ref) time_series_model = time_series.log['time_series'] ax2 = draw_model_output(ax2, model) ax2.title.set_text('optimized model') else: # steady-state t_max = model.configuration['max_time_evo'] t_ref = np.linspace(0, t_max, 1000) y_ref = model.reference_data[:, 1:] plt.hlines(y_ref, t_ref[0], t_ref[-1], ls='--') time_series_model = nemf.forward_model(model, t_eval=t_ref) ax3 = draw_model_output(ax3, time_series_model) ax3.title.set_text('optimized model') else: ax1 = plt.subplot(211) draw_parameters(ax1, model.log['parameters'], model) ax2 = plt.subplot(212) if non_steady_state: t_ref = model.reference_data[:, 0] y_ref = model.reference_data[:, 1:] colors = sns.color_palette('husl', len(model.compartment)) ax2.title.set_text('optimized model') # plotting model output time_series = nemf.forward_model(model, t_eval=t_ref) time_series_model = time_series.log['time_series'] ax2 = draw_model_output(ax2, model, colors=colors) # plotting reference data ax2 = draw_ref_data(ax2, model, colors) else: # steady-state t_max = model.configuration['max_time_evo'] dt = model.configuration['dt_time_evo'] t_ref = np.arange(0, t_max, dt) y_ref = model.reference_data[:, 1:] plt.hlines(y_ref, t_ref[0], t_ref[-1], ls='--') time_series_model = nemf.forward_model(model, t_eval=t_ref) draw_model_output(ax2, time_series_model) ax2.title.set_text('optimized model') return fig