ParameterArray

ParameterArray(stdzr[, stdzd])

Array of parameter values, allowing simple transformation.

Methods

ParameterArray.add_layers([stdzd])

Add additional layers at each index

ParameterArray.drop(name[, missing_ok])

ParameterArray.fill_with(**params)

Add a single value for a new parameter at all locations.

ParameterArray.get(name[, default])

Return value given by name if it exists, otherwise return default

ParameterArray.hstack(parray_list, **kwargs)

ParameterArray.parray(*args, **kwargs)

Create a new ParameterArray using this instance's standardizer

ParameterArray.stack(parray_list[, axis])

ParameterArray.vstack(parray_list, **kwargs)

Attributes

ParameterArray.t

Transformed values

ParameterArray.z

Standardized values

class gumbi.arrays.ParameterArray(stdzr: Standardizer, stdzd=False, **arrays)

Bases: LayeredArray

Array of parameter values, allowing simple transformation.

ParameterArray stores not only the value of the variable itself but also a Standardizer instance. This makes it simple to switch between the natural scale of the parameter and its transformed and standardized values through the t and z properties, respectively.

This class can also be accessed through the alias parray.

Parameters:
  • **arrays – arrays to store with their names as keywords

  • stdzr (Standardizer) – An instance of Standardizer

  • stdzd (bool, default False) – Whether the supplied values are on standardized scale instead of the natural scale

Examples

A parray can created with a single parameter. In this case, r is treated as a LogNormal variable by the stdzr.

>>> from gumbi import ParameterArray as parray
>>> stdzr = Standardizer(d={'μ': -0.307, 'σ': 0.158}, log_vars=['d'])
>>> rpa = parray(d=np.arange(5,10)/10, stdzr=stdzr)
>>> rpa
('d',): [(0.5,) (0.6,) (0.7,) (0.8,) (0.9,)]
>>> rpa.t
('r_t',): [(-0.69314718,) (-0.51082562,) (-0.35667494,) (-0.22314355,) (-0.10536052,)]
>>> rpa.z
('r_z',): [(-2.4439695 ,) (-1.29003559,) (-0.31439838,) ( 0.53073702,) ( 1.27619927,)]

If the parameter is completely absent from the stdzr, its natural, t, and z values are identical.

>>> pa = parray(param=np.arange(5), stdzr=stdzr)
>>> pa
('param',): [(0,) (1,) (2,) (3,) (4,)]
>>> pa.t
('param_t',): [(0,) (1,) (2,) (3,) (4,)]
>>> pa.z
('param_z',): [(0.,) (1.,) (2.,) (3.,) (4.,)]

You can even do monstrous compositions like

>>> np.min(np.sqrt(np.mean(np.square(rpa-rpa[0]-0.05)))).t
('r_t',): (-1.5791256,)

If you have work with an ordinary numpy array, use values().

>>> np.argmax(rpa.values())
4
names

Names of all stored parameters

Type:

list of str

stdzr

An instance of Standardizer

Type:

Standardizer

add_layers(stdzd=False, **arrays)

Add additional layers at each index

fill_with(**params)

Add a single value for a new parameter at all locations.

get(name, default=None)

Return value given by name if it exists, otherwise return default

parray(*args, **kwargs)

Create a new ParameterArray using this instance’s standardizer

property t: LayeredArray

Transformed values

property z: LayeredArray

Standardized values