KernelPipeline¶
The kernel-transformation pipeline: component Grams, Hadamard composition, final transform.
::
G = T( T_1(K_1) o T_2(K_2) o ... o T_d(K_d) )
where K_l is the raw Gram of source l (from a kernel, or supplied directly by the
user), T_l its admissible component transform, o the Hadamard product and T the
final admissible transform. By Schur's product theorem G is PSD for any choice.
KernelPipeline
¶
KernelPipeline(
components: Mapping[str, Component | Kernel | str] | Sequence[str],
final: Transform | None = None,
root: bool = False,
)
Composes several sources of the same objects into one GramSpace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
Mapping[str, Component | Kernel | str] | Sequence[str]
|
|
required |
final
|
Transform | None
|
Transform applied to the Hadamard product (default |
None
|
root
|
bool
|
If True, use the |
False
|
Examples:
>>> pipe = KernelPipeline(["activations", "gradients"])
>>> space = pipe(sources={"activations": A, "gradients": Gr}) # from features
>>> space = pipe(grams={"activations": KA, "gradients": KG}) # from your own Grams
Source code in src\fannar\pipeline.py
component_grams
¶
component_grams(
sources: Mapping | None = None, grams: Mapping | None = None
) -> dict[str, ndarray]
T_l(K_l) for every component. A raw Gram in grams takes precedence over the
kernel applied to sources, so any component can be replaced by the user's own matrix.
Source code in src\fannar\pipeline.py
Component
dataclass
¶
Presets¶
paper_pipeline
¶
paper_pipeline(
sources: Sequence[str] = PAPER_SOURCES, shift_by: float = 1.0
) -> KernelPipeline
The instantiation of the paper: linear kernel, (T_a(K) + J) / 2 per source, Hadamard
product and T_tr o T_c.
Source code in src\fannar\pipeline.py
single_source
¶
single_source(
source: str = "activations", angular_shift: bool = True
) -> KernelPipeline
One source alone, with the same component transform as the paper (for ablations), or the
plain linear centred Gram (angular_shift=False), whose distances are the Euclidean
distances between the features -- the geometry the linear CKA and RSA look at.
Source code in src\fannar\pipeline.py
positions_pipeline
¶
positions_pipeline(sources: Sequence[str] = PAPER_SOURCES) -> KernelPipeline
For positions of one input as objects: linear kernels, no angular transform (it would fix
every position's energy), Hadamard product and T_tr o T_c.
Source code in src\fannar\pipeline.py
get_pipeline
¶
get_pipeline(obj) -> KernelPipeline
A KernelPipeline or the name of a preset ("paper", "activations",
"gradients", "parameters", "euclidean").