Scale¶
This pages contains classes defined in hakowan.scale module.
ScaleLike = float | Scale
module-attribute
¶
Type alias for scale-like objects.
- A scalar value will be converted to
Uniformscale with the scalar value as the factor. - A Scale object will be unchanged.
Affine
dataclass
¶
Bases: Scale
Scale the data using an affine transformation.
Attributes:
| Name | Type | Description |
|---|---|---|
matrix |
NDArray
|
The affine transformation matrix. |
Source code in hakowan/grammar/scale/scale.py
Clip
dataclass
¶
Bases: Scale
Clip the data to the range [min, max].
Attributes:
| Name | Type | Description |
|---|---|---|
domain |
tuple[float, float]
|
The clip minimum and maximum values. |
Source code in hakowan/grammar/scale/scale.py
Custom
dataclass
¶
Bases: Scale
Scale the data using a custom function.
Attributes:
| Name | Type | Description |
|---|---|---|
function |
Callable
|
The scaling function. E.g. |
Source code in hakowan/grammar/scale/scale.py
Log
dataclass
¶
Bases: Scale
Logarithmic scale.
Attributes:
| Name | Type | Description |
|---|---|---|
base |
float
|
The base of the logarithm. |
Source code in hakowan/grammar/scale/scale.py
Norm
dataclass
¶
Bases: Scale
Reduce a vector attribute to its per-element magnitude (a scalar field).
Unlike the other scales, Norm changes the dimensionality of the attribute:
an N x d vector field becomes an N scalar field holding the row-wise
order-norm. It is therefore only meaningful as the leading scale of an
attribute (any chained child scales operate on the resulting scalar field).
The hakowan.norm() helper is the convenient shorthand for constructing an
attribute carrying this scale.
Attributes:
| Name | Type | Description |
|---|---|---|
order |
float
|
The order of the norm (e.g. |
Source code in hakowan/grammar/scale/scale.py
Normalize
dataclass
¶
Bases: Scale
Normalize the data so that the box defined by domain_min and domain_max is scaled to the box
defined by range_min and range_max.
Attributes:
| Name | Type | Description |
|---|---|---|
range_min |
ArrayLike
|
The minimum value of the output range. |
range_max |
ArrayLike
|
The maximum value of the output range. |
domain_min |
ArrayLike | None
|
The minimum value of the input range. If not specified, the minimum value of the input data will be used. |
domain_max |
ArrayLike | None
|
The maximum value of the input range. If not specified, the maximum value of the input data will be used. |
Source code in hakowan/grammar/scale/scale.py
Scale
dataclass
¶
Base class for all scales.
Source code in hakowan/grammar/scale/scale.py
__imul__(other)
¶
Combine the current scale with the other scale in place. The current scale will be applied
before the other scale.
Source code in hakowan/grammar/scale/scale.py
__mul__(other)
¶
Combine the current scale with the other scale in a new scale. Both the current and
the other scale is not modified. In the new scale, the current scale will be applied
before the other scale.
Source code in hakowan/grammar/scale/scale.py
Uniform
dataclass
¶
Bases: Scale
Scale the data uniformly by multiplying it with a factor.
Attributes:
| Name | Type | Description |
|---|---|---|
factor |
float
|
The scaling factor. |
Source code in hakowan/grammar/scale/scale.py
to_scale(value)
¶
Coerce a scale-like value into a Scale.
This is the single coercion point for ScaleLike
values: a scalar is wrapped as Uniform(factor=value), while an existing
Scale is returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
ScaleLike
|
A float/int (uniform factor) or a |
required |
Returns:
| Type | Description |
|---|---|
Scale
|
The corresponding |