psp#

The functions you will use to run a search and read its results. Everything else the package exports is under Advanced.

PSP(model, discretize, control[, save, ...])

Partition a model's parameter space by the ordinal patterns it produces.

PSPLockstep(model, discretize, controls, *)

Run one independent partitioning per control, sharing one model call per iteration.

PSPResult(ordinal_patterns, ordinal_counts, ...)

Container.

rowwise(fn, *[, numpy])

A function that adapts parameter space partitioning evaluations from a batched operation to a sequential one.

read_saved(path[, extension])

Read the files written by PSP(save=True, path=path, extension=extension).

Models written for one parameter set#

psp.rowwise(fn, *, numpy=False)[source]#

A function that adapts parameter space partitioning evaluations from a batched operation to a sequential one. This function is here to help users who are porting models from the R package, which is written for one parameter set at a time. Use it with PSP(..., batched=False).

rowwise(fn) calls fn once per row of its input and stacks the results, so a model or discretize written as in the R package, for a single vector, can be handed to psp.PSP(). Each row is passed as a 1-D tensor, or as a NumPy array when numpy=True; fn may return a tensor, an array, a list or a scalar.

Parameters:
fn

Function of a single parameter set (or a single vector of model output).

numpy

Pass each row to fn as a numpy.ndarray instead of a tensor. Useful for models written with NumPy or SciPy.

Examples

>>> import torch
>>> model = rowwise(lambda par: par.cumsum(0))
>>> model(torch.ones(3, 2))
tensor([[1., 2.],
        [1., 2.],
        [1., 2.]])

Reading saved runs#

psp.read_saved(path, extension='.csv')[source]#

Read the files written by PSP(save=True, path=path, extension=extension).

Requires pandas, which is an optional dependency (pip install psp-torch[notebooks]).

Advanced#

The control settings as a class, the types of the callbacks, the pieces of the saved-run reader, and the two steps of a proposal. You need none of them to run a search.

Control(init, lower, upper, radius, ...)

Validate control arguments for the parameter space partitioning run.

UNBOUNDED

int([x]) -> integer int(x, base=10) -> integer

Model

Discretize

LockstepModel

SavedRun(parameters, continuous)

The two tables written by a run with save=True, as pandas data frames.

saved_paths(path[, extension])

The two files a run with save=True writes: parameters and continuous outputs.

has_pyarrow()

Whether pyarrow, the optional fast csv writer, is installed.

hyper_points(counts, radius, *[, generator])

Random steps of at most radius in each parameter, shape (counts, dimensions).

clamp_parameters(parameters, lower, upper)

Move every parameter set onto the bounds where it left them.

class psp.Control(init, lower, upper, radius, population, iterations, parameter_names, stimuli_names, dimensionality, responses)[source]#

Validate control arguments for the parameter space partitioning run. It checks that the required keys are present and that the values are of the right type and shape. Use

Control.from_mapping({"lower": [0, 0], "upper": [1, 1], ...}), or pass the mapping to psp.PSP() directly.

Attributes:
init

Starting parameter sets, one per row, shape (starts, dimensions).

lower, upper

Bounds of each parameter, shape (dimensions,). Use -inf/inf for an unbounded parameter.

radius

Largest step the search takes in any one parameter, shape (dimensions,).

population

Number of parameter sets each pattern needs before the search stops proposing from it. 2**63 - 1 when unbounded.

iterations

Cap on the number of iterations. 2**63 - 1 when unbounded.

parameter_names, stimuli_names

Column names of the files written with save=True.

dimensionality

Size of the square matrix discretize returns, or None to take it from the first evaluation.

responses

Length of the vector model returns, or None to take it from the first evaluation.

property dimensions#

Number of free parameters.

classmethod from_mapping(control, *, device=None, dtype=None)[source]#

Validate a control mapping with the expected keys.

Required keys: init, lower, upper, radius, and at least one of population and iterations. Optional keys: parameter_names, stimuli_names, dimensionality, responses.

Raises:
ValueError

If any of the required keys are missing, or if any of the values are of the wrong type or shape.

to_mapping()[source]#

The settings as a plain dict.

psp.UNBOUNDED = 0#

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

psp.Model#

alias of Callable[[Tensor], Any]

psp.Discretize#

alias of Callable[[Tensor], Any]

psp.LockstepModel#

alias of Callable[[Tensor, Tensor], Any]

class psp.SavedRun(parameters, continuous)[source]#

The two tables written by a run with save=True, as pandas data frames.

Attributes:
parameters

One row per evaluation: iteration, one column per parameter, pattern.

continuous

One row per evaluation: iteration, one column per model output, pattern.

psp.saved_paths(path, extension='.csv')[source]#

The two files a run with save=True writes: parameters and continuous outputs.

psp.has_pyarrow()[source]#

Whether pyarrow, the optional fast csv writer, is installed.

psp.hyper_points(counts, radius, *, generator=None)[source]#

Random steps of at most radius in each parameter, shape (counts, dimensions).

This is the jumping distribution: a direction picked uniformly on the unit hypersphere (Weisstein, “Hypersphere Point Picking”), scaled in each dimension by a factor drawn uniformly between 0 and that dimension’s radius. The scale factors are drawn once per call and shared by all counts points, as in the C++ implementation.

Parameters:
counts

Number of points.

radius

Radius of each dimension, shape (dimensions,); its device and dtype are used.

generator

Random number generator on the same device as radius.

References

Weisstein, Eric W. “Hypersphere Point Picking.” From MathWorld–A Wolfram Resource. https://mathworld.wolfram.com/HyperspherePointPicking.html

psp.clamp_parameters(parameters, lower, upper)[source]#

Move every parameter set onto the bounds where it left them.