Interfaces¶
Abstract base classes defining standard interfaces for SPFlow modules.
Classifier¶
Abstract base class for modules that support classification.
sklearn Wrappers¶
scikit-learn compatible wrappers for density estimation and classification.
- class spflow.interfaces.sklearn.SPFlowDensityEstimator(model=None, *, structure_learner='learn_spn', structure_learner_kwargs=None, fit_params=True, leaf='normal', leaf_out_channels=1, min_instances_slice=100, min_features_slice=2, device=None, dtype=None, channel_agg='logmeanexp', repetition_agg='logmeanexp')[source]¶
Bases:
BaseEstimator,DensityMixinscikit-learn compatible density estimator for SPFlow models.
Supports two workflows: - Structure learning: learn a model from data via learn_spn or learn_prometheus. - Parameter fitting: fit parameters of a provided SPFlow model via MLE.
- Parameters:
model (
Module|None) – Optional SPFlow model to fit and use for scoring/sampling.structure_learner (
Literal['learn_spn','prometheus']) – “learn_spn” or “prometheus”. Only used when model is None.structure_learner_kwargs (
dict[str,Any] |None) – Keyword arguments forwarded to the structure learner.fit_params (
bool) – If True and model is provided, run MLE (maximum_likelihood_estimation) in fit.leaf (
Literal['normal']) – Leaf family used when learning structure and model is None. Currently supports “normal”.leaf_out_channels (
int) – Output channels for the leaf module template (passed to Normal).min_instances_slice (
int) – Stopping criterion for structure learning (forwarded if not overridden).min_features_slice (
int) – Stopping criterion for structure learning (forwarded if not overridden).device (
str|None) – Torch device string (e.g., “cpu”, “cuda”). If None, uses model device or the active PyTorch default device.dtype (
Optional[Literal['float32','float64']]) – Torch dtype string (“float32”, “float64”) for inputs.channel_agg (
Literal['logmeanexp','logsumexp','first']) – How to aggregate multiple output channels into a scalar log-likelihood.repetition_agg (
Literal['logmeanexp','logsumexp','first']) – How to aggregate multiple repetitions into a scalar log-likelihood.
- class spflow.interfaces.sklearn.SPFlowClassifier(model, *, device=None, dtype=None)[source]¶
Bases:
BaseEstimator,ClassifierMixinscikit-learn compatible classifier wrapper for SPFlow classifiers.
This wrapper delegates to a provided SPFlow model that implements predict_proba(torch.Tensor) -> torch.Tensor.
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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.Added in version 1.3.
Parameters¶
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns¶
- selfobject
The updated object.