Lesson 9 of 15

Box-Counting Dimension

Box-Counting Dimension

The box-counting dimension (also called Minkowski dimension) is the most practical way to measure the fractal dimension of a set. It quantifies how detail changes with scale.

Definition

Cover the set with boxes (intervals) of size ε. Let N(ε) be the minimum number of boxes needed. The box-counting dimension is:

D = lim_{ε→0} log(N(ε)) / log(1/ε)

Examples

ShapeDimension
Point0
Line segment1
Filled square2
Cantor setlog(2)/log(3) ≈ 0.631
Sierpiński trianglelog(3)/log(2) ≈ 1.585

The Cantor Set

The middle-thirds Cantor set is constructed by repeatedly removing the middle third of each interval:

  • Start: [0, 1]
  • Step 1: [0, 1/3] ∪ [2/3, 1]
  • Step 2: [0, 1/9] ∪ [2/9, 1/3] ∪ [2/3, 7/9] ∪ [8/9, 1]
  • ...

After n steps, there are 2ⁿ intervals each of length 3⁻ⁿ.

Computing Box-Counting Dimension

In practice, we estimate D as the slope of log N(ε) vs log(1/ε) using linear regression on several values of ε.

Your Task

Implement:

  1. cantor_set(n) — return list of (a, b) intervals after n iterations
  2. box_count_cantor(n, epsilon) — count boxes of size epsilon covering the Cantor set
  3. box_counting_dimension(counts, epsilons) — estimate dimension via linear regression
Python runtime loading...
Loading...
Click "Run" to execute your code.