Module Index : Topics : Keywords
 
 
structure_learning.evaluation.metrics
index
/Users/165421/Documents/code/structure_learning/src/structure_learning/evaluation/metrics.py

This module provides various metrics for evaluating distributions and graphs.
 
It includes implementations of metrics such as KL Divergence, Jensen-Shannon Divergence,
Mean Squared Error, Mean Absolute Error, Expected Structural Hamming Distance, and RHat.
These metrics are used to compare distributions or evaluate the similarity between graphs.
 
Classes:
    Metric: Abstract base class for metrics.
    KLD: Computes the KL Divergence between two distributions.
    JSD: Computes the Jensen-Shannon Divergence between two distributions.
    MSE: Computes the Mean Squared Error between two distributions.
    MAE: Computes the Mean Absolute Error between two distributions.
    SHD: Computes the Expected Structural Hamming Distance between graphs.
    RHat: Computes the RHat metric for multiple distributions.
    MEP: Computes the Marginal Edge Probabilities from a distribution.
    MarginalAncestorProbabilities: Computes the Marginal Ancestor Probabilities from a distribution.
 
Functions:
    entropy: Computes the entropy between two distributions.
    kl_divergence: Computes the KL divergence between two distributions.
    jensen_shannon_divergence: Computes the Jensen-Shannon divergence between two distributions.
    mean_squared_error: Computes the mean squared error between two distributions.
    mean_absolute_error: Computes the mean absolute error between two distributions.
    expected_shd: Computes the Expected Structural Hamming Distance.
    rhat: Computes the RHat metric for the provided distributions and measurements.
    marginal_edge_probabilities: Computes the marginal edge probabilities from a distribution.
    rhat_edge: Computes the RHat metric for edge probabilities across multiple distributions.
    marginal_ancestor_probabilities: Computes the marginal ancestor probabilities from a distribution.

 
Modules
       
numpy
tqdm

 
Classes
       
builtins.object
Metric
JSD
KLD
MAE
MEP
MSE
MarginalAncestorProbabilities
RHat
RHat_edge
SHD

 
class JSD(Metric)
    Computes the Jensen-Shannon Divergence (JSD) between two distributions.
 
This class implements the JSD metric, which measures the similarity between
two probability distributions. It inherits from the Metric base class and
provides a concrete implementation of the compute method.
 
 
Method resolution order:
JSD
Metric
builtins.object

Methods defined here:
compute(self, dist1: structure_learning.distributions.distribution.Distribution, dist2: structure_learning.distributions.distribution.Distribution)

Data descriptors inherited from Metric:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class KLD(Metric)
    Computes the KL Divergence (KLD) between two distributions.
 
This class implements the KLD metric, which measures the difference between
two probability distributions. It inherits from the Metric base class and
provides a concrete implementation of the compute method.
 
 
Method resolution order:
KLD
Metric
builtins.object

Methods defined here:
compute(self, dist1: structure_learning.distributions.distribution.Distribution, dist2: structure_learning.distributions.distribution.Distribution)

Data descriptors inherited from Metric:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class MAE(Metric)
    Computes the Mean Absolute Error (MAE) between two distributions.
 
This class implements the MAE metric, which measures the average absolute difference
between two probability distributions. It inherits from the Metric base class and
provides a concrete implementation of the compute method.
 
 
Method resolution order:
MAE
Metric
builtins.object

Methods defined here:
compute(self, dist1: structure_learning.distributions.distribution.Distribution, dist2: structure_learning.distributions.distribution.Distribution)

Data descriptors inherited from Metric:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class MEP(Metric)
    Computes the Marginal Edge Probabilities (MEP) from a distribution.
This class implements the MEP metric, which calculates the marginal probabilities
of edges in a graph based on a given distribution. It inherits from the Metric base class
and provides a concrete implementation of the compute method.
 
 
Method resolution order:
MEP
Metric
builtins.object

Methods defined here:
compute(self, dist: structure_learning.distributions.distribution.Distribution)
Compute marginal edge probabilities from a distribution.
 
Parameters:
    dist (Distribution):  Distribution over graphs.

Data descriptors inherited from Metric:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class MSE(Metric)
    Computes the Mean Squared Error (MSE) between two distributions.
 
This class implements the MSE metric, which measures the average squared difference
between two probability distributions. It inherits from the Metric base class and
provides a concrete implementation of the compute method.
 
 
Method resolution order:
MSE
Metric
builtins.object

Methods defined here:
compute(self, dist1: structure_learning.distributions.distribution.Distribution, dist2: structure_learning.distributions.distribution.Distribution)

Data descriptors inherited from Metric:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class MarginalAncestorProbabilities(Metric)
    Computes the Marginal Ancestor Probabilities from a distribution.
This class implements the Marginal Ancestor Probabilities metric, which calculates
the marginal probabilities of ancestor relationships in a graph based on a given distribution. 
It inherits from the Metric base class and provides a concrete implementation of the compute method.
 
 
Method resolution order:
MarginalAncestorProbabilities
Metric
builtins.object

Methods defined here:
compute(self, dist: structure_learning.distributions.distribution.Distribution)
Compute marginal ancestor probabilities from a distribution.
 
Parameters:
    dist (Distribution):  Distribution over graphs.

Data descriptors inherited from Metric:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Metric(builtins.object)
    Abstract base class for metrics.
 
This class serves as a blueprint for all metric implementations. It defines
the structure and behavior that all derived metric classes must follow.
 
  Methods defined here:
compute(self, **kwargs)

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class RHat(Metric)
    Computes the RHat metric for multiple distributions.
 
This class implements the RHat metric, which is used to assess the convergence
of multiple distributions. It inherits from the Metric base class and provides
a concrete implementation of the compute method.
 
 
Method resolution order:
RHat
Metric
builtins.object

Methods defined here:
compute(self, dists: List[structure_learning.distributions.distribution.Distribution], prop='logp')

Data descriptors inherited from Metric:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class RHat_edge(Metric)
    Computes the RHat metric for edge probabilities across multiple distributions.
This class implements the RHat metric for edge probabilities, which assesses the convergence
of edge probabilities across multiple distributions. It inherits from the Metric base class and
provides a concrete implementation of the compute method.
 
 
Method resolution order:
RHat_edge
Metric
builtins.object

Methods defined here:
compute(self, dists: List[structure_learning.distributions.distribution.Distribution])
Compute rhat metric for edge probabilities across multiple distributions.
Parameters:
    dists (list):       distributions (must be normalised)

Data descriptors inherited from Metric:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class SHD(Metric)
    Computes the Expected Structural Hamming Distance (SHD) between graphs.
 
This class implements the SHD metric, which measures the expected structural
difference between a posterior approximation and a ground-truth graph. It inherits
from the Metric base class and provides a concrete implementation of the compute method.
 
 
Method resolution order:
SHD
Metric
builtins.object

Methods defined here:
compute(self, dags: Union[structure_learning.distributions.distribution.Distribution, structure_learning.data_structures.graph.Graph], true_graph: structure_learning.data_structures.graph.Graph)

Data descriptors inherited from Metric:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
Functions
       
entropy(P, Q)
expected_shd(chain_list: List[numpy.ndarray], true_DAG: numpy.ndarray, p: List = None)
Compute the Expected Structural Hamming Distance.
 
This function computes the Expected SHD between a posterior approximation
given as a collection of samples from the posterior, and the ground-truth
graph used in the original data generation process.
Code from:
https://github.com/tristandeleu/jax-dag-gflownet/blob/master/dag_gflownet/utils/metrics.py
 
Parameters:
    chain_list (list (numpy.ndarray)):  Posterior approximation.
                                        The array must have size `(B, N, N)`, where `B` is the
                                        number of sample graphs from the posterior approximation,
                                        and `N` is the number of variables in the graphs.
    true_DAG (numpy.ndarray):           Adjacency matrix of the ground-truth graph.
                                        The array must have size `(N, N)`,
                                        where `N` is the number of variables in the graph.
 
Returns:
    (float):                            The Expected SHD.
get_metric(metric: str)
Retrieve a metric instance by its name.
 
Parameters:
    metric (str):   Name of the metric.
    
Returns:
    Metric:         Instance of the requested metric.
jensen_shannon_divergence(P: list, Q: list, epsilon: float = 1e-10)
Compute the jensen_shannon_divergence between two distributions.
Requires that the two distributions have the same length.
kl_divergence(P: list, Q: list, epsilon: float = 1e-10)
Computes the KL divergence between two distributions.
Requires that the two distributions have the same length and keys.
marginal_ancestor_probabilities(dist: structure_learning.distributions.distribution.Distribution)
Compute marginal ancestor probabilities from a distribution.
 
Parameters:
    dist (Distribution):  Distribution over graphs. 
 
Returns:
    numpy.ndarray:       Marginal ancestor probability matrix.
marginal_edge_probabilities(dist: structure_learning.distributions.distribution.Distribution)
Compute marginal edge probabilities from a distribution.
 
Parameters:
    dist (Distribution):  Distribution over graphs.
 
Returns:
    numpy.ndarray:       Marginal edge probability matrix.
mean_absolute_error(P: list, Q: list)
Compute mean absolute error.
mean_squared_error(P: list, Q: list)
Compute mean squared error.
reduce(...)
reduce(function, iterable[, initial]) -> value
 
Apply a function of two arguments cumulatively to the items of a sequence
or iterable, from left to right, so as to reduce the iterable to a single
value.  For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
((((1+2)+3)+4)+5).  If initial is present, it is placed before the items
of the iterable in the calculation, and serves as a default when the
iterable is empty.
rhat(P: list, th: list)
Compute rhat metric for the provided distributions and measurement.
 
Parameters:
    P (list):       distributions (must be normalised)
    th (list):      scores/measurements
rhat_edge(dists: List[structure_learning.distributions.distribution.Distribution])
Compute rhat metric for edge probabilities across multiple distributions.
 
Parameters:
    dists (list):       distributions (must be normalised)
 
Returns:
    numpy.ndarray:     R-hat values for each edge.

 
Data
        List = typing.List
Union = typing.Union