Box-counting program to estimate fractal dimension of real line subset (e.g. Cantor set)

195 Views Asked by At

I'm working with several data frames of 500000 real numbers which, mathematically speaking, if $df$ is one of the data frames I'm working with, then $df\subseteq C\subset [0,1]$, where $C$ denotes the middle third Cantor set.

A program is needed to compute the fractal dimension of every data frame using numerical methods; such as box-counting programs. Our objective is to characterize the data frames in two groups by their fractal dimension: the first group (control condition) with a fractal dimension (significantly) less than $\frac{\log(2)}{\log(3)}$ and the second group (experimental condition) with a fractal dimension very close to $\frac{\log(2)}{\log(3)}$, where $\frac{\log(2)}{\log(3)}$ is the fractal dimension of Cantor set.

I have found two MatLab programs to estimate the box-counting dimension for one-dimensional data: https://www.mathworks.com/matlabcentral/fileexchange/13063-boxcount which with random methods computes the dimension, but most of the time fails, and section A.2 of https://fse.studenttheses.ub.rug.nl/12313/1/DimensionofFractals.pdf, page 26, but it doesn't display the fractal dimension computed

(Information for the data frame)

Data used is generated using that sequence space of $0$'s and $2$'s, $\{0,2\}^\mathbb{N}$, is homeomorphic to the middle third Cantor set. So, taking $n$ elements of $\{0,2\}^\mathbb{N}$ where only the first $100$ entries are randomly generated and the rest of the entries are $0$'s and then I compute the ternary representation (the homeomorphism) of each of the $n$ elements to obtain the $n$ elements in the Cantor set.

1

There are 1 best solutions below

0
On

I took the code from section A.2 of https://fse.studenttheses.ub.rug.nl/12313/1/DimensionofFractals.pdf, page 26, as a reference to write a Python code to estimate the fractal dimension of real line subsets.

import numpy as np
import math
import pandas as pd
#file.txt is data frame of n x 1 dimensions. Data are all real numbers
F=pd.read_table("file.txt", header= None)
rows = 12 #Can be increased to improve accuracy
cols = 2
size = rows*cols
R = np.array(([0]*size),dtype=np.float64).reshape(rows,cols)
#Box size parameter (adjustable)
r=0.00489 #Parameter for our data
for l in range(rows):
    N=math.ceil(4.0/r)
    G=np.zeros((N),dtype=np.int16)
    N=len(F)
    C=0
    for i in range(N):
        m=max(math.ceil((F[0][i]+2)/r),1)
        if G[m]==0:
            G[m]=1
            C=C+1
    R[l][0]=r
    R[l][1]=C
    r=r/2.0

print('Fractal dimension is: ',np.log(R[rows][1])/-np.log(R[rows][0]))