amisc.transform
Module for data transformation methods.
Includes:
Transform— an abstract interface for specifying a transformation.Linear— a linear transformation \(y=mx+b\).Log— a logarithmic transformation \(y=\log_b(x + \mathrm{offset})\).Minmax— a min-max scaling transformation \(x: (lb, ub) \mapsto (lb_{norm}, ub_{norm})\).Zscore— a z-score normalization transformation \(y=(x-\mu)/\sigma\).
Transform objects can be converted easily to/from strings for serialization.
Linear(transform_args)
Log(transform_args)
Minmax(transform_args)
Bases: Transform
A Minmax transform: \(x: (lb, ub) \mapsto (lb_{norm}, ub_{norm})\).
| ATTRIBUTE | DESCRIPTION |
|---|---|
transform_args |
|
Source code in src/amisc/transform.py
update(lb=None, ub=None, lb_norm=None, ub_norm=None)
Update the parameters of this transform.
| PARAMETER | DESCRIPTION |
|---|---|
lb |
the lower bound in the original variable space
DEFAULT:
|
ub |
the upper bound in the original variable space
DEFAULT:
|
lb_norm |
the lower bound of the transformed space
DEFAULT:
|
ub_norm |
the upper bound of the transformed space
DEFAULT:
|
Source code in src/amisc/transform.py
Transform(transform_args)
Bases: ABC
A base class for all transformations.
| ATTRIBUTE | DESCRIPTION |
|---|---|
transform_args |
the arguments for the transformation
TYPE:
|
Source code in src/amisc/transform.py
from_string(transform_spec)
classmethod
Return a list of Transforms given a list of string specifications. Available transformations are:
- linear — \(x_{norm} = mx + b\) specified as
linear(m, b)orlinear(slope=m, offset=b).m=1, b=0if not specified. - log — \(x_{norm} = \log_b(x)\) specified as
logorlog10for the natural or common logarithms. For a different base, uselog(b). Optionally, specifyoffsetforlog(x+offset). - minmax — \(x_{norm} = \frac{x - a}{b - a}(u - l) + l\) specified as
minmax(a, b, l, u)orminmax(lb=a, ub=b, lb_norm=l, ub_norm=u). Scalesxfrom the range(a, b)to(l, u). By default,(a, b)is the Variable's domain and(l, u)is(0, 1). Use simply asminmaxto use all defaults. - zscore — \(x_{norm} = \frac{x - m}{s}\) specified as
zscore(m, s)orzscore(mu=m, std=s). If the Variable is specified asdistribution=normal, thenzscoredefaults to the Variable's ownmu, std.
Example
will giveWarning
You may optionally leave the minmax arguments blank to defer to the bounds of the parent Variable.
You may also optionally leave the zscore arguments blank to defer to the (mu, std) of the parent
Variable, but this will throw a runtime error if Variable.distribution is not Normal(mu, std).
Source code in src/amisc/transform.py
transform(x, inverse=False, transform_args=None)
Transform the given values x. This wrapper function handles the input type and tries to
return the transformed values in the same type.
| PARAMETER | DESCRIPTION |
|---|---|
x |
the values to transform
TYPE:
|
inverse |
whether to do the inverse transform instead
TYPE:
|
transform_args |
overrides
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ArrayLike
|
the transformed values |
Source code in src/amisc/transform.py
Zscore(transform_args)
Bases: Transform
A Zscore transform: \(y=(x-\mu)/\sigma\).
| ATTRIBUTE | DESCRIPTION |
|---|---|
transform_args |
|
Source code in src/amisc/transform.py
update(mu=None, std=None)
Update the parameters of this transform.
| PARAMETER | DESCRIPTION |
|---|---|
mu |
the mean of the transform
DEFAULT:
|
std |
the standard deviation of the transform
DEFAULT:
|