TrackSolve#

class TrackSolve(ml, tmin=None, tmax=None, update_iter=None)[source]#

Track and/or visualize optimization progress for Pastas models.

Parameters
  • ml (pastas.Model) – pastas Model to track

  • tmin (str or pandas.Timestamp, optional) – start time for simulation, by default None which defaults to first index in ml.oseries.series

  • tmax (str or pandas.Timestamp, optional) – end time for simulation, by default None which defaults to last index in ml.oseries.series

  • update_iter (int, optional) – if visualizing optimization progress, update plot every update_iter iterations, by default nparam

Notes

Interactive plotting of optimization progress requires a matplotlib backend that supports interactive plotting, e.g. mpl.use(“TkAgg”) and mpl.interactive(True). Some possible speedups on the matplotlib side include:

  • mpl.style.use(“fast”)

  • mpl.rcParams[‘path.simplify_threshold’] = 1.0

Examples

Set matplotlib backend and interactive mode (put this at the top of your script):

import matplotlib as mpl
mpl.use("TkAgg")
import matplotlib.pyplot as plt
plt.ion()

Create a TrackSolve object for your model:

track = TrackSolve(ml)

Solve model and store intermediate optimization results:

ml.solve(callback=track.track_solve)

Calculated parameters per iteration are stored in a pandas.DataFrame:

track.parameters

Other stored statistics include track.evp (explained variance percentage), track.rmse_res (root-mean-squared error of the residuals), track.rmse_noise (root mean squared error of the noise, only if noise=True).

To interactively plot model optimization progress while solving pass track.plot_track_solve as callback function:

ml.solve(callback=track.plot_track_solve)

Access the resulting figure through track.fig.

Methods#

__init__

initialize_figure

Initialize figure for plotting optimization progress.

plot_track_solve

Method to plot model simulation while model is being solved.

plot_track_solve_history

Plot optimization history.

track_solve

Append parameters to self.parameters DataFrame and update itercount, rmse values and evp.