.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/language/plot_spn_dsl.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_language_plot_spn_dsl.py: ================================= Domain Specific Language for SPNs ================================= We start by creating an SPN. Using a Domain-Specific Language (DSL), we can quickly create an SPN of categorical leave nodes like this: .. GENERATED FROM PYTHON SOURCE LINES 9-25 .. image-sg:: /auto_examples/language/images/sphx_glr_plot_spn_dsl_001.png :alt: plot spn dsl :srcset: /auto_examples/language/images/sphx_glr_plot_spn_dsl_001.png :class: sphx-glr-single-img .. code-block:: default from spn.structure.leaves.parametric.Parametric import Categorical from spn.io.Graphics import draw_spn import matplotlib.pyplot as plt spn = 0.4 * ( Categorical(p=[0.2, 0.8], scope=0) * ( 0.3 * (Categorical(p=[0.3, 0.7], scope=1) * Categorical(p=[0.4, 0.6], scope=2)) + 0.7 * (Categorical(p=[0.5, 0.5], scope=1) * Categorical(p=[0.6, 0.4], scope=2)) ) ) + 0.6 * (Categorical(p=[0.2, 0.8], scope=0) * Categorical(p=[0.3, 0.7], scope=1) * Categorical(p=[0.4, 0.6], scope=2)) ax = draw_spn(spn) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.322 seconds) .. _sphx_glr_download_auto_examples_language_plot_spn_dsl.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_spn_dsl.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_spn_dsl.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_