netket.utils.history.History#

class netket.utils.history.History[source]#

Bases: object

A 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 HistoryDict and accum_histories_in_tree().

Inheritance
Inheritance diagram of netket.utils.history.History
__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 numerical

  • iter_dtype (Union[None, str, type[Any], dtype, _SupportsDType]) – If no values or iters are passed, uses this dtype to store iteration numbers

  • main_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
append(val, it=None)[source]#

Append another value to this history object.

Parameters:
  • val (Any) – the value in the next timestep

  • it (Number | None) – the time corresponding to this new value. If not defined, increment by 1.

get()[source]#

Returns a tuple containing times and values of this history object

Return type:

tuple[Union[ndarray, Array], Union[ndarray, Array]]

keys()[source]#
Return type:

list

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]]

to_dict()[source]#

Converts the history object to dict.

Used for serialization

Return type:

dict