Data and Kernel Transformations

class kerch.transform.TransformTree(*args, **kwargs)[source]

Bases: Transform

Creates a tree of transform for efficient computing, with cache management.

Parameters:
  • explicit (bool) – True is the transform are to be computed in the explicit formulation, False instead.

  • sample (Tensor or function handle) – Default sample on which the statistics are to be computed.

  • default_transform (List[str]) – Optional default list of transform., defaults to None.

  • diag_fun (Function handle) – Optional function handle to directly compute the diagonal of the implicit formulation to increase computation speed.

add_offspring(val: Transform) None
add_parent(val: Transform) None
apply(oos=None, x=None, y=None, transform: List[str] = None) Tensor[source]

Applies the transform to the value to out-of-sample data. Either value is a function handle and you can use x (explicit) and x, y (explicit) to specify the data. Either directly give a Tensor.

Warning

If value is a Tensor, some transform may not work in implicit formulation. For example, the unit sphere normalization requires k(x,x) for all out-of-sample points. Some combinations may be even more intricate.

Parameters:
  • x (Tensor) – Relevant if using a function handle for value.

  • y (Tensor) – Relevant if using a function handle for value in implicit mode.

  • transform (List[str]) – Transforms to be used. If none are to be used, i.e. getting the raw data back, please specify [], not None, which will return the default transform used for the sample., defaults to None, i.e., the default transform.

static beautify_transform(transform: list[str]) None | List[Transform][source]

Creates a list of _Transform classes and removes duplicates.

Parameters:

transform (List[str]) – list of the different transform.

cache_keys(private: bool = False) Iterable[str]

Returns an iterable containing the different cache keys. We refer to the Cache Management documentation for more information.

Parameters:

private (bool, optional) – Some cache elements are private and are not returned unless set to True. Defaults to False.

property cache_level: str

Cache level for saving temporary execution results during the execution. The higher the cache, the more is saved. Defaults to 'normal' unless set otherwise during instantiation. The different possible values are:

  • "none": the cache is non-existent and everything is computed on the go.

  • "light": the cache is very light. For example, only the kernel matrix and statistics of the sample points are saved.

  • "normal": same as light, but the statistics of the out-of-sample points are also saved.

  • "heavy": in addition to the statistics, the final kernel matrices of the out-of-sample points are saved.

  • "total": every step of any computation is saved.

We refer to the Cache Management documentation for further information.

property default: bool
property default_transforms: List

Default list of transforms to be applied.

property explicit: bool
property final_transform: ABCMeta

Final transform to be applied, which is the last element of default_transforms.

property is_leaf: bool
property is_root: bool
property offspring: dict
oos(x=None, y=None) Tensor
property parent: Transform | None
print_cache(private: bool = False) None

Prints the cache content. We refer to the Cache Management documentation for further information.

Parameters:

private (bool, optional) – Some cache elements are private and are not returned unless set to True. Defaults to False.

property projected_sample: Tensor

Sample after transform. Retrieved from cache if relevant.

reset(recurse=False, reset_persisting=True) None

Resets the cache to be empty. We refer to the Cache Management documentation for more information.

Parameters:
  • recurse (bool, optional) – If True, resets the cache of this module and also of its potential children. otherwise, it only resets the cache for this module. Defaults to True.

  • reset_persisting (bool, optional) – Persisting elements are meant to resist to a cache reset (see _save()). The option allows to also reset them if True. Defaults to True.

revert(value, transform: List[str] = None) Tensor[source]

Reverts the transform (runs the tree backwards) to the value to out-of-sample data.

Parameters:
  • value (Tensor) – Out-of-sample data.

  • transform (List[str]) – Transforms to be used. If none are to be used, i.e. getting the raw data back, please specify [], not None, which will return the default transform used for the sample., defaults to None, i.e., the default transform.

property sample: Tensor
statistics_oos(x=None, y=None, oos=None) torch.Tensor | torch.Tensor, torch.Tensor
statistics_sample(sample=None) Tensor