Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
erdogant committed Oct 6, 2024
1 parent d20a107 commit a6e6fa0
Show file tree
Hide file tree
Showing 47 changed files with 251 additions and 30 deletions.
12 changes: 6 additions & 6 deletions bnlearn/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@
import bnlearn as bn

# Download dataset
df = pd.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data-original',
delim_whitespace=True, header=None,
names = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'model year', 'origin', 'car name'])
# df = pd.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data-original',
# delim_whitespace=True, header=None,
# names = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'model year', 'origin', 'car name'])

# Cleaning
df.dropna(inplace=True)
df.drop(['model year', 'origin', 'car name'], axis=1, inplace=True)
# # Cleaning
# df.dropna(inplace=True)
# df.drop(['model year', 'origin', 'car name'], axis=1, inplace=True)


# Load example mixed dataset
Expand Down
Binary file modified docs/figs/fig_auto_mpg_lingam_a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/figs/fig_auto_mpg_lingam_b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/pages/doctrees/Continuous Data.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/UseCases.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/environment.pickle
Binary file not shown.
44 changes: 35 additions & 9 deletions docs/pages/html/Continuous Data.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="#modelling-continuous-datasets">Modelling Continuous Datasets</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#lingam-example">LiNGAM Example</a></li>
<li class="toctree-l2"><a class="reference internal" href="#lingam-based-methods">LiNGAM-based Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="#direct-lingam-method">Direct-LiNGAM method</a></li>
<li class="toctree-l2"><a class="reference internal" href="#ica-lingam-method">ICA-LiNGAM method</a></li>
<li class="toctree-l2"><a class="reference internal" href="#pc-method">PC method</a><ul>
Expand Down Expand Up @@ -144,6 +144,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down Expand Up @@ -489,12 +490,34 @@ <h2>Inferences<a class="headerlink" href="#inferences" title="Link to this headi
</section>
<section id="modelling-continuous-datasets">
<h1>Modelling Continuous Datasets<a class="headerlink" href="#modelling-continuous-datasets" title="Link to this heading"></a></h1>
<section id="lingam-example">
<h2>LiNGAM Example<a class="headerlink" href="#lingam-example" title="Link to this heading"></a></h2>
<p>To demonstrate how the LiNGAM works, it is best to do it with a small toy example.</p>
<p>Here’s the improved version of the text:</p>
<p>Let’s create test data containing six variables.
The goal of this dataset is to demonstrate the contribution of different variables and their causal impact on other variables.
<section id="lingam-based-methods">
<h2>LiNGAM-based Methods<a class="headerlink" href="#lingam-based-methods" title="Link to this heading"></a></h2>
<p>Bnlearn includes LiNGAM-based methods which do the estimation of Linear, Non-Gaussian Acyclic Model from observed data. It assumes non-Gaussianity of the noise terms in the causal model.
Various methods are developed and published for which Bnlearn includes two methods: ICA-based LiNGAM <a class="footnote-reference brackets" href="#id6" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a>, DirectLiNGAM <a class="footnote-reference brackets" href="#id7" id="id2" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a>. The following three are not included VAR-LiNGAM <a class="footnote-reference brackets" href="#id8" id="id3" role="doc-noteref"><span class="fn-bracket">[</span>3<span class="fn-bracket">]</span></a>, RCD <a class="footnote-reference brackets" href="#id9" id="id4" role="doc-noteref"><span class="fn-bracket">[</span>4<span class="fn-bracket">]</span></a>, and CAM-UV <a class="footnote-reference brackets" href="#id10" id="id5" role="doc-noteref"><span class="fn-bracket">[</span>5<span class="fn-bracket">]</span></a>.</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id6" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">1</a><span class="fn-bracket">]</span></span>
<p>Shimizu, S., Hoyer, P. O., Hyvarinen, A., Kerminen, A., &amp; Jordan, M. (2006). A linear non-Gaussian acyclic model for causal discovery. Journal of Machine Learning Research, 7(10).</p>
</aside>
<aside class="footnote brackets" id="id7" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id2">2</a><span class="fn-bracket">]</span></span>
<p>Shimizu, S., Inazumi, T., Sogawa, Y., Hyvarinen, A., Kawahara, Y., Washio, T., … &amp; Bollen, K. (2011). DirectLiNGAM: A direct method for learning a linear non-Gaussian structural equation model. The Journal of Machine Learning Research, 12, 1225-1248.</p>
</aside>
<aside class="footnote brackets" id="id8" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id3">3</a><span class="fn-bracket">]</span></span>
<p>Hyvarinen, A., Zhang, K., Shimizu, S., &amp; Hoyer, P. O. (2010). Estimation of a structural vector autoregression model using non-gaussianity. Journal of Machine Learning Research, 11(5).</p>
</aside>
<aside class="footnote brackets" id="id9" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id4">4</a><span class="fn-bracket">]</span></span>
<p>Maeda, T. N., &amp; Shimizu, S. (2020, June). RCD: Repetitive causal discovery of linear non-Gaussian acyclic models with latent confounders. In International Conference on Artificial Intelligence and Statistics (pp. 735-745). PMLR.</p>
</aside>
<aside class="footnote brackets" id="id10" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id5">5</a><span class="fn-bracket">]</span></span>
<p>Maeda, T. N., &amp; Shimizu, S. (2021). Causal Additive Models with Unobserved Variables. UAI.</p>
</aside>
</aside>
<p>To demonstrate how the LiNGAM works, it is best to do it with a small toy example. Let’s create test data containing six variables.</p>
<p>The goal of this dataset is to demonstrate the contribution of different variables and their causal impact on other variables.
All variables must be consistent, as in any other dataset. The sample size is set to n=1000 with a uniform distribution.
If the number of samples is much smaller, say in the tens, the method becomes less reliable due to insufficient information to determine causality.</p>
<p>We will establish dependencies between variables and then allow the model to infer the original values.</p>
Expand Down Expand Up @@ -598,12 +621,13 @@ <h2>Direct-LiNGAM method<a class="headerlink" href="#direct-lingam-method" title

<span class="c1"># Load data set</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">bn</span><span class="o">.</span><span class="n">import_example</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="s1">&#39;auto_mpg&#39;</span><span class="p">)</span>
<span class="k">del</span> <span class="n">df</span><span class="p">[</span><span class="s1">&#39;origin&#39;</span><span class="p">]</span>

<span class="c1"># Structure learning</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">bn</span><span class="o">.</span><span class="n">structure_learning</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">methodtype</span><span class="o">=</span><span class="s1">&#39;direct-lingam&#39;</span><span class="p">,</span> <span class="n">params_lingam</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;random_state&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">})</span>

<span class="c1"># Compute edge strength</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">bn</span><span class="o">.</span><span class="n">independence_test</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">df</span><span class="p">)</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">bn</span><span class="o">.</span><span class="n">independence_test</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">df</span><span class="p">,</span> <span class="n">prune</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

<span class="c1"># Plot</span>
<span class="n">bn</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
Expand Down Expand Up @@ -632,12 +656,14 @@ <h2>ICA-LiNGAM method<a class="headerlink" href="#ica-lingam-method" title="Link

<span class="c1"># Load data set</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">bn</span><span class="o">.</span><span class="n">import_example</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="s1">&#39;auto_mpg&#39;</span><span class="p">)</span>
<span class="k">del</span> <span class="n">df</span><span class="p">[</span><span class="s1">&#39;origin&#39;</span><span class="p">]</span>


<span class="c1"># Structure learning</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">bn</span><span class="o">.</span><span class="n">structure_learning</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">methodtype</span><span class="o">=</span><span class="s1">&#39;ica-lingam&#39;</span><span class="p">)</span>

<span class="c1"># Compute edge strength</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">bn</span><span class="o">.</span><span class="n">independence_test</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">df</span><span class="p">)</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">bn</span><span class="o">.</span><span class="n">independence_test</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">df</span><span class="p">,</span> <span class="n">prune</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

<span class="c1"># Plot</span>
<span class="n">bn</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Create DAG.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Example Datasets.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<li class="toctree-l1"><a class="reference internal" href="#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Inference.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Licence.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Parameter learning.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Plot.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Predict.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Quickstart.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<li class="toctree-l1"><a class="reference internal" href="Examples.html#create-a-bayesian-network-learn-its-parameters-from-data-and-perform-the-inference">Create a Bayesian Network, learn its parameters from data and perform the inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html">Use Case Titanic</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-medical-domain">Use Case Medical domain</a></li>
<li class="toctree-l1"><a class="reference internal" href="UseCases.html#use-case-continuous-datasets">Use Case Continuous Datasets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Parameters and attributes</span></p>
<ul>
Expand Down
Loading

0 comments on commit a6e6fa0

Please sign in to comment.