artlib.optimized.backends.torch.GaussianARTMAP

Gaussian ARTMAP [7] (Torch backend).

Classes

_TorchGaussianARTMAPConfig

_TorchGaussianARTMAP

Torch-accelerated Gaussian ARTMAP with export hooks for artlib synchronization.

GaussianARTMAP

GaussianARTMAP for Classification. optimized with torch.

Functions

_to_device(→ torch.Tensor)

Module Contents

artlib.optimized.backends.torch.GaussianARTMAP._to_device(x: torch.Tensor | numpy.ndarray, device, dtype=torch.float32) torch.Tensor
class artlib.optimized.backends.torch.GaussianARTMAP._TorchGaussianARTMAPConfig
input_dim: int
rho: float
alpha: float = 1e-10
sigma_init: numpy.ndarray | torch.Tensor | float = 0.1
epsilon: float = 1e-07
match_tracking: bool = True
device: str = 'cuda'
dtype: torch.dtype = Ellipsis
clamp_inputs: bool = False
fallback_to_choice_on_fail: bool = True
class artlib.optimized.backends.torch.GaussianARTMAP._TorchGaussianARTMAP(cfg: _TorchGaussianARTMAPConfig)

Torch-accelerated Gaussian ARTMAP with export hooks for artlib synchronization.

Category weight layout (numpy-compatible on export): [ mean(D), sigma(D), inv_sigma(D), sqrt_det_sigma(1), n(1) ] -> length 3D + 2

cfg
device
dtype
input_dim
mean: torch.Tensor | None = None
sigma: torch.Tensor | None = None
inv_var: torch.Tensor | None = None
sqrt_det: torch.Tensor | None = None
counts: torch.Tensor | None = None
map_y: torch.Tensor | None = None
_sigma_init
property n_cat: int
_ensure_capacity()
_validate_prepared(X: torch.Tensor)
_free_mem_bytes() int
prepare_data(X: torch.Tensor | numpy.ndarray) torch.Tensor
_gaussian_terms_for(I: torch.Tensor) Tuple[torch.Tensor, torch.Tensor]

Compute exp(-0.5 * (x-μ)^T Σ^{-1} (x-μ)) and priors p(cj) for all categories.

Returns:

[K] (likelihood numerator without constants and det term) p_cj: [K] (counts / sum_counts; zero-safe)

Return type:

exp_term

_choice_and_match(I: torch.Tensor) Tuple[torch.Tensor, torch.Tensor]

Returns (T, m) over all categories for single input I.

T = p(x|cj) * p(cj) with p(x|cj) ∝ exp_term / (alpha + sqrt_det). m = exp_term (match criterion).

_commit_new_category(I: torch.Tensor, y: int)

Initialize new Gaussian with mean=I, sigma=sigma_init, n=1.

_learn_in_category(j: int, I: torch.Tensor)

Update mean, sigma, inv_var, sqrt_det, counts; replicate numpy reference.

partial_fit_and_export(X_prepared: torch.Tensor | numpy.ndarray, y: torch.Tensor | numpy.ndarray, epsilon: float = 1e-10, match_tracking: Literal['MT+', 'MT-', 'MT0', 'MT1', 'MT~'] = 'MT+') Tuple[numpy.ndarray, list[numpy.ndarray], numpy.ndarray]

Incremental training on already-prepared inputs (raw, not complement-coded).

Returns:

chosen category indices per-sample weights_arrays (list[np.ndarray]): per-category weights (float64) cluster_labels_out (np.ndarray): map from categories to class labels

Return type:

labels_a_out (np.ndarray)

predict_ab_prepared(X_prepared: torch.Tensor | numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray]

Return (a_idx, b_labels) for prepared inputs.

class artlib.optimized.backends.torch.GaussianARTMAP.GaussianARTMAP(rho: float, sigma_init: numpy.ndarray | float, alpha: float = 1e-10, input_dim: int | None = None, device: str = 'cuda', dtype: torch.dtype = torch.float64)

Bases: artlib.optimized.backends.torch._TorchSimpleARTMAP._TorchSimpleARTMAP

GaussianARTMAP for Classification. optimized with torch.

This module implements GaussianARTMAP

GaussianARTMAP is a non-modular classification model which has been highly optimized for run-time performance. Fit and predict functions are implemented in torch for efficient execution. This class acts as a wrapper for the underlying torch functions and to provide compatibility with the artlib style and usage. Functionally, GaussianARTMAP behaves as a special case of SimpleARTMAP instantiated with GaussianART.

_device = 'cuda'
_dtype = Ellipsis
_backend: _TorchGaussianARTMAP | None = None
_declared_input_dim = None
_ensure_backend(X: numpy.ndarray)