Lesson 11 of 15

Fractals and Hausdorff Dimension

Fractals and Hausdorff Dimension

Fractals are geometric objects that exhibit self-similarity at every scale. Unlike smooth curves (dimension 1) or filled surfaces (dimension 2), fractals can have non-integer dimensions — the Hausdorff dimension.

Box-Counting Dimension

The box-counting (Hausdorff) dimension is defined as:

D=limε0logN(ε)logεD = -\lim_{\varepsilon \to 0} \frac{\log N(\varepsilon)}{\log \varepsilon}

where N(ε)N(\varepsilon) is the number of boxes of side length ε\varepsilon needed to cover the fractal.

Classic Fractal Dimensions

FractalDimensionFormula
Cantor Set≈ 0.6309log(2)/log(3)\log(2) / \log(3)
Koch Curve≈ 1.2619log(4)/log(3)\log(4) / \log(3)
Sierpiński Triangle≈ 1.5850log(3)/log(2)\log(3) / \log(2)

Cantor Set

Start with [0,1]. At each iteration, remove the middle third from every interval. After nn iterations: 2n2^n intervals of length (1/3)n(1/3)^n remain. Self-similarity ratio r=1/3r = 1/3, copies N=2N = 2, so D=log(2)/log(3)D = \log(2)/\log(3).

Koch Curve

Start with a line segment. Replace each segment with four segments of length 1/31/3. Self-similarity: N=4N=4 copies at ratio r=1/3r=1/3, so D=log(4)/log(3)D = \log(4)/\log(3).

Sierpiński Triangle

Start with a filled triangle. Remove the central triangle at each step, leaving 3 copies at half the scale. D=log(3)/log(2)D = \log(3)/\log(2).

Box-Counting in Practice

Given a set of points, estimate DD by counting how many grid boxes of size ε\varepsilon contain at least one point. Plot logN\log N vs log(1/ε)\log(1/\varepsilon); the slope is DD.

Implementation

Implement the following functions:

import math

def hausdorff_dim_cantor():
    # Return log(2)/log(3)
    ...

def hausdorff_dim_koch():
    # Return log(4)/log(3)
    ...

def hausdorff_dim_sierpinski():
    # Return log(3)/log(2)
    ...

def cantor_set_count(n_iterations):
    # Return number of intervals after n iterations = 2^n
    ...

def box_count_estimate(points_x, epsilon):
    # Count distinct grid boxes of size epsilon containing points
    ...
Python runtime loading...
Loading...
Click "Run" to execute your code.