LogTransform#

class LogTransform(min_val=0.01, max_val=20.0, log=True, keys=('energy',), clip=False)[source]#

Bases: object

Compress scalar features (e.g. energy) onto [-1, 1].

For each key in keys that is present, replaces the value with either a logarithmic (log=True) or linear (log=False) rescaling onto [-1, 1] derived from min_val/max_val. The log map is 2 * (log10(x + min_val) - log10(min_val)) / (log10(max_val + min_val) - log10(min_val)) - 1. Raises ValueError if a requested key is missing. Registered as LogTransform — use this string as the type in a transform=[...] 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 True use the logarithmic map, otherwise the linear map. Defaults to True.

  • 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 to False.

Note

The correct min_val matters: for PoLAr-MAE/PILArNet energy it must equal the energy threshold (e.g. 0.13), not 0.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
linear_transform(x)[source]#

Transform energy to linear scale on [-1,1]

log_transform(x)[source]#

Transform energy to logarithmic scale on [-1,1]