gfn.gym.helpers.bayesian_structure.evaluation¶
The code is adapted from: https://github.com/larslorch/dibs/blob/master/dibs/metrics.py
Functions¶
|
Compute the expected number of edges. |
|
Compute the Expected Structural Hamming Distance. |
|
Get the posterior estimate of DAG-GFlowNet as a collection of graphs |
|
Compute threshold metrics (e.g. AUROC, Precision, Recall, etc...). |
Module Contents¶
- gfn.gym.helpers.bayesian_structure.evaluation.expected_edges(posterior_samples)¶
Compute the expected number of edges.
This function computes the expected number of edges in graphs sampled from the posterior approximation.
- Parameters:
posterior_samples (torch.Tensor) – Samples from the posterior. The tensor 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.
- Returns:
The expected number of edges.
- Return type:
e_edges
- gfn.gym.helpers.bayesian_structure.evaluation.expected_shd(posterior_samples, gt_graph)¶
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.
- Parameters:
posterior_samples (torch.Tensor) – Samples from the posterior. The tensor 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.
gt_graph (torch_geometric.data.Data) – GeometricData instance representing the ground-truth graph.
- Returns:
The Expected SHD.
- Return type:
e_shd
- gfn.gym.helpers.bayesian_structure.evaluation.posterior_estimate(gflownet, env, num_samples=1000, batch_size=100, verbose=True)¶
Get the posterior estimate of DAG-GFlowNet as a collection of graphs sampled from the GFlowNet.
- Parameters:
gflownet (gfn.gflownet.GFlowNet) – GFlowNet instance.
env (gfn.gym.bayesian_structure.BayesianStructure) – BayesianStructure environment.
rng – Optional random generator instance.
num_samples – The number of samples in the posterior approximation.
verbose – If True, display a progress bar for the sampling process.
- Returns:
- torch.Tensor with shape (B, N, N), where B is the number of sample
graphs in the posterior approximation, and N is the number of variables in a graph.
- Return type:
posterior
- gfn.gym.helpers.bayesian_structure.evaluation.threshold_metrics(posterior_samples, gt_graph)¶
Compute threshold metrics (e.g. AUROC, Precision, Recall, etc…).
- Parameters:
posterior_samples (torch.Tensor) – Samples from the posterior. The tensor 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.
gt_graph (torch_geometric.data.Data) – GeometricData instance representing the ground-truth graph.
- Returns:
False Positive Rate
True Positive Rate
Area Under the Receiver Operating Characteristic Curve
Precision
Recall
Area Under the Precision-Recall Curve
Average Precision
- Return type:
A dictionary containing the following metrics