deeprob.spn.models package
Submodules
deeprob.spn.models.dgcspn module
- class deeprob.spn.models.dgcspn.DgcSpn(in_features, out_classes=1, n_batch=8, sum_channels=8, depthwise=False, n_pooling=0, optimize_scale=False, in_dropout=None, sum_dropout=None, quantiles_loc=None, uniform_loc=None)[source]
Bases:
ProbabilisticModelInitialize a Deep Generalized Convolutional Sum-Product Network (DGC-SPN).
- Parameters
in_features (Tuple[int, int, int]) – The input size as a (C, D, D) tuple.
out_classes (int) – The number of output classes. Specify 1 in case of plain density estimation.
n_batch (int) – The number of output channels of the base layer.
sum_channels (int) – The number of output channels of spatial sum layers.
depthwise (Union[bool, List[bool]]) – Whether to use depthwise convolutions as product layers at each depth level. The last flag of the list will be considered as the one for the rest of the network. If a single boolean is passed, it will be used for all the network’s product layers.
n_pooling (int) – The number of initial pooling spatial product layers.
optimize_scale (bool) – Whether to train scale and location jointly.
in_dropout (Optional[float]) – The dropout rate for probabilistic dropout at distributions layer outputs. It can be None.
sum_dropout (Optional[float]) – The dropout rate for probabilistic dropout at sum layers. It can be None.
quantiles_loc (Optional[ndarray]) – The mean quantiles for location initialization. It can be None.
uniform_loc (Optional[Tuple[float, float]]) – The uniform range for location initialization. It can be None.
- Raises
ValueError – If a parameter is out of domain.
- forward(x)[source]
Compute the log-likelihood given some evidence. Random variables can be marginalized using NaN values.
- mpe(x)[source]
Compute the maximum at posteriori estimation. Random variables can be marginalized using NaN values.
deeprob.spn.models.ratspn module
- class deeprob.spn.models.ratspn.RatSpn(in_features, base_cls, base_kwargs=None, out_classes=1, rg_depth=2, rg_repetitions=1, rg_batch=2, rg_sum=2, in_dropout=None, sum_dropout=None, random_state=None)[source]
Bases:
ProbabilisticModelInitialize a RAT-SPN.
- Parameters
in_features (int) – The number of input features.
base_cls (Type[RegionGraphLayer]) – The base distribution’s class. It must be a sub-class of RegionGraphLayer.
base_kwargs (Optional[dict]) – Optional additiona parameters to pass to the base distribution’s class constructor.
out_classes (int) – The number of output classes. Specify 1 in case of plain density estimation.
rg_depth (int) – The depth of the region graph.
rg_repetitions (int) – The number of independent repetitions of the region graph.
rg_batch (int) – The number of base distribution batches.
rg_sum (int) – The number of sum nodes per region.
in_dropout (Optional[float]) – The dropout rate for probabilistic dropout at distributions layer outputs. It can be None.
sum_dropout (Optional[float]) – The dropout rate for probabilistic dropout at sum layers. It can be None.
random_state (Optional[Union[int, RandomState]]) – The random state. It can be either None, a seed integer or a Numpy RandomState.
- Raises
ValueError – If a parameter is out of domain.
- forward(x)[source]
Compute the log-likelihood given some evidence. Random variables can be marginalized using NaN values.
- mpe(x, y=None)[source]
Compute the maximum at posteriori estimation. Random variables can be marginalized using NaN values.
- class deeprob.spn.models.ratspn.GaussianRatSpn(in_features, out_classes=1, rg_depth=2, rg_repetitions=1, rg_batch=2, rg_sum=2, in_dropout=None, sum_dropout=None, random_state=None, uniform_loc=None, optimize_scale=False)[source]
Bases:
RatSpnInitialize a Gaussian RAT-SPN.
- Parameters
in_features (int) – The number of input features.
out_classes (int) – The number of output classes. Specify 1 in case of plain density estimation.
rg_depth (int) – The depth of the region graph.
rg_repetitions (int) – The number of independent repetitions of the region graph.
rg_batch (int) – The number of base distributions batches.
rg_sum (int) – The number of sum nodes per region.
in_dropout (Optional[float]) – The dropout rate for probabilistic dropout at distributions layer outputs. It can be None.
sum_dropout (Optional[float]) – The dropout rate for probabilistic dropout at sum layers. It can be None.
random_state (Optional[Union[int, RandomState]]) – The random state. It can be either None, a seed integer or a Numpy RandomState.
uniform_loc (Optional[Tuple[float, float]]) – The optional uniform distribution parameters for location initialization.
optimize_scale (bool) – Whether to train scale and location jointly.
- class deeprob.spn.models.ratspn.BernoulliRatSpn(in_features, out_classes=1, rg_depth=2, rg_repetitions=1, rg_batch=2, rg_sum=2, in_dropout=None, sum_dropout=None, random_state=None)[source]
Bases:
RatSpnInitialize a Bernoulli RAT-SPN.
- Parameters
in_features (int) – The number of input features.
out_classes (int) – The number of output classes. Specify 1 in case of plain density estimation.
rg_depth (int) – The depth of the region graph.
rg_repetitions (int) – The number of independent repetitions of the region graph.
rg_batch (int) – The number of base distributions batches.
rg_sum (int) – The number of sum nodes per region.
in_dropout (Optional[float]) – The dropout rate for probabilistic dropout at distributions layer outputs. It can be None.
sum_dropout (Optional[float]) – The dropout rate for probabilistic dropout at product layer outputs. It can be None.
random_state (Optional[Union[int, RandomState]]) – The random state. It can be either None, a seed integer or a Numpy RandomState.
deeprob.spn.models.sklearn module
- class deeprob.spn.models.sklearn.SPNEstimator(distributions, domains=None, **kwargs)[source]
Bases:
BaseEstimator,DensityMixinScikit-learn density estimator model for Sum Product Networks (SPNs).
- Parameters
- predict_log_proba(X)[source]
Predict using the SPN density estimator, i.e. compute the log-likelihood.
- sample(n=None, X=None)[source]
Sample from the modeled distribution.
- Parameters
- Returns
The samples.
- Raises
ValueError – If both parameters ‘n’ and ‘X’ are passed by.
- Return type
- class deeprob.spn.models.sklearn.SPNClassifier(distributions, domains=None, **kwargs)[source]
Bases:
BaseEstimator,ClassifierMixinScikit-learn classifier model for Sum Product Networks (SPNs).
- Parameters