Scale¶
This pages contains classes defined in hakowan.scale module.
Composable transformations from source attributes to visual values.
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
Map an inferred or explicit input domain to an output range.
Scalars and vectors are both supported when bounds have matching shapes.
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)
¶
Append other to this scale chain in place.
A deep copy prevents later mutations of a reused scale from aliasing this chain.
Source code in hakowan/grammar/scale/scale.py
__mul__(other)
¶
Return a new chain that applies this scale before other.
Neither operand is modified.
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 |