Utilities¶
- class pints.Loggable[source]¶
Interface for classes that can log to a
Logger.- _log_init(logger)[source]¶
Adds this
Loggable'sfields to aLogger.
- _log_write(logger)[source]¶
Logs data for each of the fields specified in
_log_init().
- class pints.Logger[source]¶
Logs numbers to screen and/or a file.
Example
log = pints.Logger() log.add_counter('id', width=2) log.add_float('Length') log.log(1, 1.23456) log.log(2, 7.8901)
- add_counter(name, width=5, max_value=None, file_only=False)[source]¶
Adds a field for positive integers.
Returns this
Loggerobject.- Parameters:
name (str) – This field’s name. Will be displayed in the header.
width (int) – A hint for the width of this column. If numbers exceed this width layout will break, but no information will be lost.
max_value (int|None) – A hint for the maximum number this field will need to display.
file_only (boolean) – If set to
True, this field will not be shown on screen.
- add_float(name, width=9, file_only=False)[source]¶
Adds a field for floating point number.
Returns this
Loggerobject.- Parameters:
name (str) – This field’s name. Will be displayed in the header.
width (int) – A hint for the field’s width. The minimum width is 7.
file_only (boolean) – If set to
True, this field will not be shown on screen.
- add_int(name, width=5, file_only=False)[source]¶
Adds a field for a (positive or negative) integer.
Returns this
Loggerobject.- Parameters:
name (str) – This field’s name. Will be displayed in the header.
width (int) – A hint for the width of this column. If numbers exceed this width layout will break, but no information will be lost.
file_only (boolean) – If set to
True, this field will not be shown on screen.
- add_long_float(name, file_only=False)[source]¶
Adds a field for a maximum precision floating point number.
Returns this
Loggerobject.- Parameters:
name (str) – This field’s name. Will be displayed in the header.
file_only (boolean) – If set to
True, this field will not be shown on screen.
- add_string(name, width, file_only=False)[source]¶
Adds a field showing (at most
widthcharacters of) string values.Returns this
Loggerobject.- Parameters:
name (str) – This field’s name. Will be displayed in the header.
width (int) – The maximum width for strings to display.
file_only (boolean) – If set to
True, this field will not be shown on screen.
- add_time(name, file_only=False)[source]¶
Adds a field showing a formatted time (given in seconds).
Returns this
Loggerobject.- Parameters:
name (str) – This field’s name. Will be displayed in the header.
file_only (boolean) – If set to
True, this field will not be shown on screen.
- class pints.Timer(output=None)[source]¶
Provides accurate timing.
Example
timer = pints.Timer() print(timer.format(timer.time()))
- pints.matrix2d(x)[source]¶
Copies
xand returns a 2d read-only NumPy array of floats with shape(m, n).Raises a
ValueErrorifxhas an incompatible shape.
- pints.vector(x)[source]¶
Copies
xand returns a 1d read-only NumPy array of floats with shape(n,).Raises a
ValueErrorifxhas an incompatible shape.
- pints.sample_initial_points(function, n_points, random_sampler=None, boundaries=None, max_tries=50, parallel=False, n_workers=None)[source]¶
Samples
n_pointsparameter values to use as starting points in a sampling or optimisation routine on the givenfunction.How the initial points are determined depends on the arguments supplied. In order of precedence:
If a method
random_sampleris provided then this will be used to draw the random samples.If no sampler method is given but
functionis aLogPosteriorthen the methodfunction.log_prior().sample()will be used.If no sampler method is supplied and
functionis not aLogPosteriorand ifboundariesare provided then the methodboundaries.sample()will be used to draw samples.
A
ValueErroris raised if none of the above options are available.Each sample
xis tested to ensure thatfunction(x)returns a finite result withinboundariesif these are supplied. If not, a new sample will be drawn. This is repeated at mostmax_triestimes, after which an error is raised.- Parameters:
function – A
pints.ErrorMeasureor apints.LogPDFthat evaluates points in the parameter space. If the latter, it is optional thatfunctionbe of typeLogPosterior.n_points (int) – The number of initial values to generate.
random_sampler – A function that when called returns draws from a probability distribution of the same dimensionality as
function. The only argument to this function should be an integer specifying the number of draws.boundaries – An optional set of boundaries on the parameter space of class
pints.Boundaries.max_tries (int) – Number of attempts to find a finite initial value across all
n_points. By default this is 50 per point.parallel (bool) – Whether to evaluate
functionin parallel (defaults to False).n_workers (int) – Number of workers on which to run parallel evaluation.