deeprob.spn.algorithms package
Submodules
deeprob.spn.algorithms.evaluation module
- deeprob.spn.algorithms.evaluation.parallel_layerwise_eval(layers, eval_func, reverse=False, n_jobs=- 1)[source]
Execute a function per node layerwise in parallel.
- Parameters
layers (List[List[Node]]) – The layers, i.e., the layered topological ordering.
eval_func (Callable[[Node], None]) – The evaluation function for a given node.
reverse (bool) – Whether to reverse the layered topological ordering.
n_jobs (int) – The number of parallel jobs. It follows the joblib’s convention.
- deeprob.spn.algorithms.evaluation.eval_bottom_up(root, x, leaf_func, node_func, leaf_func_kwargs=None, node_func_kwargs=None, return_results=False, n_jobs=0)[source]
Evaluate the SPN bottom up given some inputs and leaves and nodes evaluation functions.
- Parameters
root (Node) – The root of the SPN.
x (ndarray) – The inputs.
leaf_func (Callable[[Leaf, ndarray, Any], ndarray]) – The function to compute at each leaf node.
node_func (Callable[[Node, ndarray, Any], ndarray]) – The function to compute at each inner node.
leaf_func_kwargs (Optional[dict]) – The optional parameters of the leaf evaluation function.
node_func_kwargs (Optional[dict]) – The optional parameters of the inner nodes evaluation function.
return_results (bool) – A flag indicating if this function must return the log likelihoods of each node of the SPN.
n_jobs (int) – The number of parallel jobs. It follows the joblib’s convention. Set to 0 to disable.
- Returns
The outputs. Additionally, it returns the output of each node.
- Raises
ValueError – If a parameter is out of domain.
- Return type
- deeprob.spn.algorithms.evaluation.eval_top_down(root, x, lls, leaf_func, sum_func, leaf_func_kwargs=None, sum_func_kwargs=None, inplace=False, n_jobs=0)[source]
Evaluate the SPN top down given some inputs, the likelihoods of each node and a leaves evaluation function. The leaves to evaluate are chosen by following the nodes given by the sum nodes evaluation function.
- Parameters
root (Node) – The root of the SPN.
x (ndarray) – The inputs with some NaN values.
lls (ndarray) – The log-likelihoods of each node.
leaf_func (Callable[[Leaf, ndarray, Any], ndarray]) – The leaves evaluation function.
sum_func (Callable[[Sum, ndarray, Any], ndarray]) – The sum nodes evaluation function.
leaf_func_kwargs (Optional[dict]) – The optional parameters of the leaf evaluation function.
sum_func_kwargs (Optional[dict]) – The optional parameters of the sum nodes evaluation function.
inplace (bool) – Whether to make inplace assignments.
n_jobs (int) – The number of parallel jobs. It follows the joblib’s convention. Set to 0 to disable.
- Returns
The NaN-filled inputs.
- Raises
ValueError – If a parameter is out of domain.
- Return type
deeprob.spn.algorithms.gradient module
- deeprob.spn.algorithms.gradient.eval_backward(root, lls)[source]
Compute the log-gradients at each SPN node.
- Parameters
- Returns
The log-gradients w.r.t. the nodes.
- Raises
ValueError – If a parameter is out of domain.
- Return type
deeprob.spn.algorithms.inference module
- deeprob.spn.algorithms.inference.likelihood(root, x, return_results=False, n_jobs=0)[source]
Compute the likelihoods of the SPN given some inputs.
- Parameters
root (Node) – The root of the SPN.
x (ndarray) – The inputs. They can be marginalized using NaNs.
return_results (bool) – A flag indicating if this function must return the likelihoods of each node of the SPN.
n_jobs (int) – The number of parallel jobs. It follows the joblib’s convention. Set to 0 to disable.
- Returns
The likelihood values. Additionally, it returns the likelihood values of each node.
- Return type
- deeprob.spn.algorithms.inference.log_likelihood(root, x, return_results=False, n_jobs=0)[source]
Compute the logarithmic likelihoods of the SPN given some inputs.
- Parameters
root (Node) – The root of the SPN.
x (ndarray) – The inputs. They can be marginalized using NaNs.
return_results (bool) – A flag indicating if this function must return the log likelihoods of each node of the SPN.
n_jobs (int) – The number of parallel jobs. It follows the joblib’s convention. Set to 0 to disable.
- Returns
The log likelihood values. Additionally, it returns the log likelihood values of each node.
- Return type
- deeprob.spn.algorithms.inference.mpe(root, x, inplace=False, n_jobs=0)[source]
Compute the Most Probable Explanation of a SPN given some inputs.
- Parameters
- Returns
The NaN-filled inputs.
- Return type
- deeprob.spn.algorithms.inference.node_likelihood(node, x)[source]
Compute the likelihood of a node given the list of likelihoods of its children.
- deeprob.spn.algorithms.inference.node_log_likelihood(node, x)[source]
Compute the log-likelihood of a node given the list of log-likelihoods of its children.
- deeprob.spn.algorithms.inference.leaf_mpe(node, x)[source]
Compute the maximum likelihood estimate of a leaf node.
deeprob.spn.algorithms.moments module
- deeprob.spn.algorithms.moments.moment(root, order=1)[source]
Compute non-central moments of a given order of a smooth and decomposable SPN.
- Parameters
- Returns
The non-central moments with respect to each variable in the scope.
- Raises
ValueError – If the order of the moment is negative.
- Return type
- deeprob.spn.algorithms.moments.leaf_moment(node, x, order)[source]
Compute the moment of a leaf node.
- deeprob.spn.algorithms.moments.expectation(root)[source]
Compute the expectation values of a SPN w.r.t. each of the random variables.
- deeprob.spn.algorithms.moments.variance(root)[source]
Compute the variance values of a SPN w.r.t. each of the random variables.
- deeprob.spn.algorithms.moments.skewness(root)[source]
Compute the skewness values of a SPN w.r.t. each of the random variables.
deeprob.spn.algorithms.sampling module
- deeprob.spn.algorithms.sampling.sample(root, x, inplace=False, n_jobs=0)[source]
Sample some features from the distribution represented by the SPN.
- Parameters
root (Node) – The root of the SPN.
x (ndarray) – The inputs with possible NaN values to fill with sampled values.
inplace (bool) – Whether to make inplace assignments.
n_jobs (int) – The number of parallel jobs. It follows the joblib’s convention. Set to 0 to disable. Warning: disrupts seed determinism.
- Returns
The inputs that are NaN-filled with samples from appropriate distributions.
- Return type
deeprob.spn.algorithms.structure module
- deeprob.spn.algorithms.structure.prune(root, copy=True)[source]
Prune (or simplify) the given SPN to a minimal and equivalent SPN.
- Parameters
- Returns
A minimal and equivalent SPN.
- Raises
ValueError – If the SPN structure is not a directed acyclic graph (DAG).
ValueError – If an unknown node type is found.
- Return type
- deeprob.spn.algorithms.structure.marginalize(root, keep_scope, copy=True)[source]
Marginalize some random variables of a SPN, obtaining the compilation of a marginal query.
- Parameters
- Returns
A SPN in which an EVI query is equivalent to a MAR query under the given scope.
- Raises
ValueError – If the scope of the random variables to keep is not valid.
ValueError – If the SPN structure is not a directed acyclic graph (DAG).
ValueError – If an unknown node type is found.
NotImplementedError – If non-BinaryCLT multivariate leaves are found.
- Return type