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 \(\log 3/\log 2 \approx 1.585\).

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

Generate the point cloud and estimate its dimension#

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}")
estimated dimension: 1.5520
exact value log(3)/log(2): 1.5850

Visualize the point cloud and the log-log fit#

plot_ifs_points(points)
plot_box_counting(result)
  • plot 01 sierpinski dimension
  • Box-counting dimension
<Axes: title={'center': 'Box-counting dimension'}, xlabel='1 / box size', ylabel='box count'>

Total running time of the script: (0 minutes 0.313 seconds)

Gallery generated by Sphinx-Gallery