netket.utils.history.History#
- class netket.utils.history.History[source]#
Bases:
objectA class to store a time-series of arbitrary data.
An History object stores several time-series all sharing the same time axis. History behaves like a dictionary, where the various key index the values (y axis) of the time-series. The time-axis is accessed through the attribute History.iters.
Itβs possible to label one time-serie (one key) as the main value, so that when converting to numpy array (for example for plotting with pyplot) that axis is automatically picked by default.
If only one time-series is provided, without a key, then its name will be value.
For managing multiple History objects with independent time axes or complex nested structures, see
HistoryDictandaccum_histories_in_tree().- Inheritance

- __init__(values=None, iters=None, dtype=None, iter_dtype=None, main_value_name=None)[source]#
Creates a new History object.
Values should be an arbitrary type or container to initialize the History with. By default assumes that values correspond to the first iteration 0. If values is a list or collection of lists, an array or range should be passed to values with the correct length.
Optionally itβs possible to specify the dtype of the data and of the time-axis.
- Parameters:
values (
Any) β a type/container of types containing the value at the first iteration, or an iterable/container of iterables containing the values at all iterations (in the latter, values must also be specified). It may also be the dictionary obtained from another History object, when converted to dictionary.iters (
Union[list,ndarray,Array,None]) β an optional iterable of iterations at which values correspond. If unspecified, assumes that values are logged at only one iteration.dtype (
Union[None,str,type[Any],dtype,_SupportsDType]) β If no values or iters are passed, uses this dtype to store data if numericaliter_dtype (
Union[None,str,type[Any],dtype,_SupportsDType]) β If no values or iters are passed, uses this dtype to store iteration numbersmain_value_name (
str|None) β If data is a dict or object with to_dict method, this optional string labels an entry as being the main one.
- Attributes
- iters#
- main_value_name#
The name of the main value in this history object, if defined.
- values#
- Methods
-
- plot(*args, fig=None, show=True, all=None, xscale=None, yscale='auto', **kwargs)[source]#
Plot the history object using matplotlib.
This function is equivalent to calling matplotlib.pyplot.plot on the values of the history object. If multiple keys are present, it will plot only the main value by default. If all=True, it will plot all the keys in the history object.
When plotting a single key, this function is equivalent to calling
plt.plot(history.iters, history[key], *args, **kwargs).For the arguments and keyword arguments, refer to the documentation of
matplotlib.pyplot.plot(). Below we document some extra arguments.- Parameters:
fig (matplotlib.figure.Figure | None) β A matplotlib figure object to plot the data on. If not provided, a new figure is created.
all (
bool|None) β If True, plot all the keys in the history object. If False, plot only the main value. If None, plot only the main value if it is defined, otherwise plot all the keys.show (
bool) β If True, call plt.show() at the end of the function. If False, the plot is not shown.xscale (str | None)
yscale (str | None)
- Return type:
Union[matplotlib.axes.Axes,Iterable[matplotlib.axes.Axes]]