ParameterArray
|
Array of parameter values, allowing simple transformation. |
Methods
|
Add additional layers at each index |
|
|
|
Add a single value for a new parameter at all locations. |
|
Return value given by name if it exists, otherwise return default |
|
|
|
Create a new ParameterArray using this instance's standardizer |
|
|
|
Attributes
Transformed values |
|
Standardized values |
- class gumbi.arrays.ParameterArray(stdzr: Standardizer, stdzd=False, **arrays)
Bases:
LayeredArrayArray of parameter values, allowing simple transformation.
ParameterArraystores not only the value of the variable itself but also aStandardizerinstance. This makes it simple to switch between the natural scale of the parameter and its transformed and standardized values through thetandzproperties, 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
Standardizerstdzd (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, andzvalues 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:
- 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