.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/neural_network.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_neural_network.py: ================= s. neural network ================= .. currentmodule:: easy_mpl This file shows the usage of :func:`plot_nn` function. .. GENERATED FROM PYTHON SOURCE LINES 10-18 .. code-block:: Python # sphinx_gallery_thumbnail_number = 2 from easy_mpl.utils import plot_nn from easy_mpl.utils import version_info version_info() # print version information of all the packages being used .. rst-class:: sphx-glr-script-out .. code-block:: none {'easy_mpl': '0.21.5', 'matplotlib': '3.9.4', 'numpy': '2.0.2', 'pandas': '2.2.3', 'scipy': '1.13.1'} .. GENERATED FROM PYTHON SOURCE LINES 19-21 To draw a NN, we have to provide the number of layers and number of nodes in each layer as a list. .. GENERATED FROM PYTHON SOURCE LINES 21-23 .. code-block:: Python plot_nn(4, [3, 4, 4, 2]) .. image-sg:: /auto_examples/images/sphx_glr_neural_network_001.png :alt: neural network :srcset: /auto_examples/images/sphx_glr_neural_network_001.png, /auto_examples/images/sphx_glr_neural_network_001_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 24-26 We can also specify colors and labels for nodes. Also, connectio color and spacing can be customized. .. GENERATED FROM PYTHON SOURCE LINES 26-32 .. code-block:: Python plot_nn(4, nodes = [3, 4, 4, 2], fill_color = ['#fff2cc', "#fde6d9", '#dae3f2', '#a9d18f'], labels = [[f'$x_{j}$' for j in range(1, 4)], None, None, ['$\mu$', '$\sigma$']], connection_color = '#c3c2c3', spacing = (1, 0.5)) .. image-sg:: /auto_examples/images/sphx_glr_neural_network_002.png :alt: neural network :srcset: /auto_examples/images/sphx_glr_neural_network_002.png, /auto_examples/images/sphx_glr_neural_network_002_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 33-35 Customized line style for connections between layers and width of edge line of circles .. GENERATED FROM PYTHON SOURCE LINES 35-42 .. code-block:: Python plot_nn(4, nodes = [4, 3, 3, 4], fill_color = ['#c6dae2', "#e3baac", '#e3baac', '#cad09c'], labels = [[f'$x_{j}$' for j in range(4)], None, None, [f'$y_{j}$' for j in range(4)]], connection_color = '#a5a5a5', connection_style = ['-', None, '-', '-'], circle_edge_lw = [0.0, 1.0, 1.0, 0.], spacing = (1, 0.5), x_offset = 0.18) .. image-sg:: /auto_examples/images/sphx_glr_neural_network_003.png :alt: neural network :srcset: /auto_examples/images/sphx_glr_neural_network_003.png, /auto_examples/images/sphx_glr_neural_network_003_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.319 seconds) .. _sphx_glr_download_auto_examples_neural_network.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/sphinx-gallery/sphinx-gallery.github.io/master?urlpath=lab/tree/notebooks/auto_examples/neural_network.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: neural_network.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: neural_network.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: neural_network.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_