.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fractals_chaos/box_counting/plot_01_sierpinski_dimension.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_fractals_chaos_box_counting_plot_01_sierpinski_dimension.py: Box-counting dimension of the Sierpinski triangle ======================================================= Generates the Sierpinski triangle via the chaos game and estimates its box-counting dimension, comparing against the known closed-form value :math:`\log 3/\log 2 \approx 1.585`. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: Python import numpy as np from mathematicskit.fractals_chaos import SierpinskiTriangle, box_counting_dimension from mathematicskit.fractals_chaos.visualizers.plots import plot_box_counting, plot_ifs_points .. GENERATED FROM PYTHON SOURCE LINES 17-19 Generate the point cloud and estimate its dimension ----------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 19-25 .. code-block:: Python points = SierpinskiTriangle().generate(60000, seed=0) result = box_counting_dimension(points) print(f"estimated dimension: {result.dimension:.4f}") print(f"exact value log(3)/log(2): {np.log(3.0) / np.log(2.0):.4f}") .. rst-class:: sphx-glr-script-out .. code-block:: none estimated dimension: 1.5520 exact value log(3)/log(2): 1.5850 .. GENERATED FROM PYTHON SOURCE LINES 26-28 Visualize the point cloud and the log-log fit ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python plot_ifs_points(points) plot_box_counting(result) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /api/gallery/fractals_chaos/box_counting/images/sphx_glr_plot_01_sierpinski_dimension_001.png :alt: plot 01 sierpinski dimension :srcset: /api/gallery/fractals_chaos/box_counting/images/sphx_glr_plot_01_sierpinski_dimension_001.png :class: sphx-glr-multi-img * .. image-sg:: /api/gallery/fractals_chaos/box_counting/images/sphx_glr_plot_01_sierpinski_dimension_002.png :alt: Box-counting dimension :srcset: /api/gallery/fractals_chaos/box_counting/images/sphx_glr_plot_01_sierpinski_dimension_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.313 seconds) .. _sphx_glr_download_api_gallery_fractals_chaos_box_counting_plot_01_sierpinski_dimension.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_sierpinski_dimension.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_sierpinski_dimension.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_sierpinski_dimension.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_