API reference#

CompositeKernel#

class svdynamics.CompositeKernel(kernels: Sequence[KernelSpec], weights: Sequence[float] | None = None, normalize: bool = True, eps: float = 1e-12)[source]#

Bases: object

Weighted combination of multiple base kernels.

K(X, Y) = sum_m w_m * K_m(X, Y)

Parameters#

kernels:

Sequence of kernel specifications. Each element can be:

  • “rbf”, “linear”, “poly”, or “sigmoid”

  • (“rbf”, {“gamma”: 0.1}), etc.

  • callable kernel(X, Y) -> ndarray

weights:

Optional weights for the kernels. If None, uniform weights are used. Weights are normalized to sum to 1.

normalize:

If True, each base kernel is rescaled using a scalar derived from K(X, X).

eps:

Small constant used for numerical stability.

as_callable() → Callable[[ndarray, ndarray], ndarray][source]#

Return the composite kernel as a callable.

eps: float = 1e-12#
fit_scales(X: ndarray) → CompositeKernel[source]#

Compute and store per-kernel normalization scales from training data.

Once stored, every later call uses these scales, so a point’s kernel values (and the model’s predictions) do not depend on which other points are passed alongside it.

kernels: Sequence[str | Tuple[str, Dict[str, Any]] | Any]#
min_eigenvalues(X: ndarray) → ndarray[source]#

Smallest eigenvalue of each base kernel’s Gram matrix on X.

Optional diagnostic for positive semidefiniteness (PSD). A valid kernel gives values >= 0 up to rounding (about -1e-8 relative to the largest eigenvalue). Sigmoid kernels are not PSD in general and may return clearly negative values. Cost is O(n^3) per kernel, so use a subsample for large X.

normalize: bool = True#
property normalized_weights: ndarray#

Return normalized kernel weights.

property parsed_kernels: List[ParsedKernel]#

Return parsed kernel specifications.

weights: Sequence[float] | None = None#

AdaptiveCompositeKernel#

class svdynamics.AdaptiveCompositeKernel(kernels: Sequence[KernelSpec], weights: Sequence[float] | None = None, normalize: bool = True, eps: float = 1e-12)[source]#

Bases: CompositeKernel

Composite kernel with weights learned from training data.

Kernel weights are estimated using normalized kernel-target alignment.

Parameters#

kernels:

Sequence of kernel specifications.

weights:

Initial kernel weights. These are replaced by learned weights when fit() is called.

normalize:

If True, rescale individual kernels when constructing the composite kernel.

eps:

Small constant used for numerical stability.

fit(X: ndarray, y: ndarray) → AdaptiveCompositeKernel[source]#

Learn kernel weights from training data.

weights: Sequence[float] | None = None#

SVDClassifier#

class svdynamics.SVDClassifier(C: float = 1.0, kernel: KernelArg = 'rbf', degree: int = 3, gamma: str | float = 'scale', coef0: float = 0.0, shrinking: bool = True, probability: bool = False, tol: float = 0.001, cache_size: float = 200.0, class_weight: Dict[Any, float] | None = None, verbose: bool = False, max_iter: int = -1, decision_function_shape: str = 'ovr', break_ties: bool = False, random_state: int | None = None)[source]#

Bases: BaseEstimator, ClassifierMixin

SVC wrapper supporting fixed and adaptive composite kernels.

C: float = 1.0#
break_ties: bool = False#
cache_size: float = 200.0#
class_weight: Dict[Any, float] | None = None#
coef0: float = 0.0#
decision_function(X: ndarray) → ndarray[source]#
decision_function_shape: str = 'ovr'#
degree: int = 3#
fit(X: ndarray, y: ndarray) → SVDClassifier[source]#
gamma: str | float = 'scale'#
kernel: str | CompositeKernel | Any = 'rbf'#
max_iter: int = -1#
property n_support_: ndarray#
predict(X: ndarray) → ndarray[source]#
property predict_log_proba#

Available only when probability estimation is enabled.

property predict_proba#

Available only when probability estimation is enabled.

probability: bool = False#
random_state: int | None = None#
set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') → SVDClassifier#

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters#

sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns#

selfobject

The updated object.

shrinking: bool = True#
property support_: ndarray#
property support_vectors_: ndarray#
tol: float = 0.001#
verbose: bool = False#

SVDRegressor#

class svdynamics.SVDRegressor(C: float = 1.0, kernel: KernelArg = 'rbf', degree: int = 3, gamma: str | float = 'scale', coef0: float = 0.0, tol: float = 0.001, epsilon: float = 0.1, shrinking: bool = True, cache_size: float = 200.0, verbose: bool = False, max_iter: int = -1)[source]#

Bases: BaseEstimator, RegressorMixin

SVR wrapper supporting fixed composite kernels.

C: float = 1.0#
cache_size: float = 200.0#
coef0: float = 0.0#
degree: int = 3#
epsilon: float = 0.1#
fit(X: ndarray, y: ndarray) → SVDRegressor[source]#
gamma: str | float = 'scale'#
kernel: str | CompositeKernel | Any = 'rbf'#
max_iter: int = -1#
property n_support_: ndarray#
predict(X: ndarray) → ndarray[source]#
set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') → SVDRegressor#

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters#

sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns#

selfobject

The updated object.

shrinking: bool = True#
property support_: ndarray#
property support_vectors_: ndarray#
tol: float = 0.001#
verbose: bool = False#