Skip to content

Commit 8ae54ee

Browse files
committed
more docs and example
1 parent babbf89 commit 8ae54ee

File tree

8 files changed

+83
-26
lines changed

8 files changed

+83
-26
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.11.6
1+
2.12.0

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ generated datasets, the workflow also includes a number of standard datasets and
9696
9797
.. rubric:: News
9898

99+
* 2024-12-26: Benchpress 2.12.0. This version introduces the :ref:`pyagrum` module, providing access to the `pyAgrum <https://agrum.gitlab.io/>`_ library's structure learning capabilities for discrete valued Bayesian networks.
99100
* 2024-12-16: Benchpress 2.11.0. This version introduces the :ref:`bips_tpc` module, based on the temporal PC (`tPC <https://github.com/bips-hb/tpc>`_) and the `micd <https://github.com/bips-hb/micd>`_ package. It enables causal discovery through the PC algorithm allowing for :ref:`edge_constraints`, mixed data, and missing data handling. Thanks `Leibniz-Institut für Präventionsforschung und Epidemiologie – (BIPS GmbH) <https://github.com/bips-hb>`_.
100101
* 2024-11-30: Benchpress 2.10.0. This version includes algorithms from the `missing value PC (MVPC) <https://github.com/TURuibo/MVPC>`_ package for sampling data with missing values (:ref:`mvpc_gen_data`) and causal discovery (:ref:`mvpc`) in the presence of missing values.
101102
* 2024-11-24: Benchpress 2.9.0. This version comes with three new major features.

workflow/envs/build_images.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/bash
1+
#!/usr/local/bin/bash
22
# Using bash 5
33

44
# ARCH should be arm64 or amd64

workflow/rules/structure_learning_algorithms/pyagrum/pyagrum.json renamed to workflow/rules/structure_learning_algorithms/pyagrum/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"benchmark_setup": [
33
{
4-
"title": "pyagrum_config",
4+
"title": "pyagrum_demo",
55
"data": [
66
{
77
"graph_id": "avneigs4",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
pyAgrum is a scientific C++ and Python library dedicated to Bayesian networks (BN) and other Probabilistic Graphical Models. Based on the C++ aGrUM library, it provides a high-level interface to the C++ part of aGrUM allowing to create, manage and perform efficient computations with Bayesian networks and others probabilistic graphical models : Markov random fields (MRF), influence diagrams (ID) and LIMIDs, credal networks (CN), dynamic BN (dBN), probabilistic relational models (PRM).
22

3+
4+
.. rubric:: Example
5+
6+
Config file: `config.json <https://github.com/felixleopoldo/benchpress/blob/master/workflow/rules/structure_learning_algorithms/pyagrum/config.json>`_
7+
8+
Command:
9+
10+
.. code:: bash
11+
12+
snakemake --cores all --use-singularity --configfile workflow/rules/structure_learning_algorithms/pyagrum/config.json
13+
14+
The following figure shows FP/P vs. TP/P for pattern graphs based on 5 datsets corresponding to 5 realisations of a 80-variables random binary Bayesian network, with an average indegree of 4.
15+
16+
17+
.. _pyagrumplot:
18+
19+
.. figure:: ../../../workflow/rules/structure_learning_algorithms/pyagrum/pattern.png
20+
:width: 320
21+
:alt: pyAgrum FP/P vs. TP/P example
22+
:align: center
23+
24+
FP/P vs. TP/P. for pattern graphs
25+
115 KB
Loading

workflow/rules/structure_learning_algorithms/pyagrum/schema.json

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,41 @@
1111
"description": "Algorithm identifier",
1212
"type": "string"
1313
},
14+
"useMDLCorrection": {
15+
"anyOf":[
16+
{
17+
"type": "boolean"
18+
},
19+
{
20+
"type": "array",
21+
"items": {
22+
"type": "boolean"
23+
}
24+
}
25+
]
26+
},
27+
"useSmoothingPrior": {
28+
"anyOf": [
29+
{
30+
"type": "boolean"
31+
},
32+
{
33+
"type": "array",
34+
"items": {
35+
"type": "boolean"
36+
}
37+
}
38+
]
39+
},
1440
"timeout": {
1541
"$ref": "../../../schemas/definitions.schema.json#/definitions/flexnonnegnumnull"
1642
}
1743
},
18-
"required": ["id", "timeout"],
44+
"required": ["id", "timeout", "useMDLCorrection", "useSmoothingPrior"],
1945
"examples": [
2046
{
2147
"id": "pyagrum",
22-
"useMDLCorrection": [true],
48+
"useMDLCorrection": true,
2349
"useSmoothingPrior": [true, false],
2450
"timeout": null
2551
}

workflow/rules/structure_learning_algorithms/pyagrum/script.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,39 @@ def adjacency_to_csv(bn: BayesNet, *, to_file: str):
2020
writer = csv.writer(csvfile)
2121
# write header
2222
writer.writerow(id_to_name[col_id] for col_id in range(bn.size()))
23-
#write rows
23+
# write rows
2424
adj_mat = bn.adjacencyMatrix()
2525
writer.writerows(row for row in adj_mat)
2626

27+
2728
def myalg():
2829
# Read in data (not used in this algorithm)
2930
df = pd.read_csv(snakemake.input["data"])
3031

3132
# The algorithm goes here
3233
np.random.seed(int(snakemake.wildcards["seed"]))
33-
34-
df = df.iloc[1:] # remove the first row with cardinalities
3534

36-
tmpfile = snakemake.output["adjmat"] + ".tmp.csv" # save the data to a temporary file
37-
df.to_csv(tmpfile, index=False)
35+
df = df.iloc[1:] # remove the first row with cardinalities
36+
37+
tmpfile = (
38+
snakemake.output["adjmat"] + ".tmp.csv"
39+
) # save the data to a temporary file
40+
df.to_csv(tmpfile, index=False)
41+
42+
learner = gum.BNLearner(
43+
tmpfile
44+
) # MIIC is used as default (some score-based are also implented)
45+
46+
os.remove(tmpfile) # remove the temporary file
3847

39-
learner=gum.BNLearner(tmpfile) # MIIC is used as default (some score-based are also implented)
40-
41-
os.remove(tmpfile) # remove the temporary file
42-
4348
if eval(snakemake.wildcards["useMDLCorrection"]):
44-
learner.useMDLCorrection() # for small dataset
45-
49+
learner.useMDLCorrection() # for small dataset
50+
4651
if eval(snakemake.wildcards["useSmoothingPrior"]):
47-
learner.useSmoothingPrior() # smoothing (default weight=1) for parameters
52+
learner.useSmoothingPrior() # smoothing (default weight=1) for parameters
53+
54+
bn = learner.learnBN() # learning
4855

49-
bn = learner.learnBN() # learning
50-
5156
# Save time
5257
tottime = time.perf_counter() - start
5358
with open(snakemake.output["time"], "w") as text_file:
@@ -61,15 +66,17 @@ def myalg():
6166
text_file.write("None")
6267

6368

64-
# This part starts the timer
69+
# This part starts the timer
6570
start = time.perf_counter()
6671

6772
if snakemake.wildcards["timeout"] == "None":
6873
myalg()
6974
else:
70-
with timeoutf(int(snakemake.wildcards["timeout"]),
71-
snakemake.output["adjmat"],
72-
snakemake.output["time"],
73-
snakemake.output["ntests"],
74-
start):
75-
myalg()
75+
with timeoutf(
76+
int(snakemake.wildcards["timeout"]),
77+
snakemake.output["adjmat"],
78+
snakemake.output["time"],
79+
snakemake.output["ntests"],
80+
start,
81+
):
82+
myalg()

0 commit comments

Comments
 (0)