LogTransform#
- class LogTransform(min_val=0.01, max_val=20.0, log=True, keys=('energy',), clip=False)[source]#
Bases:
objectCompress scalar features (e.g. energy) onto
[-1, 1].For each key in
keysthat is present, replaces the value with either a logarithmic (log=True) or linear (log=False) rescaling onto[-1, 1]derived frommin_val/max_val. The log map is2 * (log10(x + min_val) - log10(min_val)) / (log10(max_val + min_val) - log10(min_val)) - 1. RaisesValueErrorif a requested key is missing. Registered asLogTransform— use this string as thetypein atransform=[...]config list.- Parameters:
min_val (float) – Lower reference value of the input range; also the additive offset inside the log. Defaults to
1.0e-2.max_val (float) – Upper reference value of the input range. Defaults to
20.0.log (bool) – If
Trueuse the logarithmic map, otherwise the linear map. Defaults toTrue.keys (tuple) – Keys to transform; a single string is wrapped into a tuple. Defaults to
("energy",).clip (bool) – If
True, clip inputs before mapping (to[0, max_val]for log,[min_val, max_val]for linear). Defaults toFalse.
Note
The correct
min_valmatters: for PoLAr-MAE/PILArNet energy it must equal the energy threshold (e.g.0.13), not0.01— a wrong value degrades downstream results.Example
>>> import numpy as np >>> data = {"energy": np.array([[0.13], [1.0], [20.0]], dtype="f4")} >>> LogTransform(min_val=0.13, max_val=20.0)(data)["energy"].round(3) array([[-0.725], [-0.142], [ 1. ]]) # log-compressed: min_val->-1, max_val->+1