Circle-Packings/fractal_dimension/mcmullen_stuff/decatree.py
2021-07-16 00:59:31 -04:00

414 lines
No EOL
23 KiB
Python

from decanode import Node
import math
import numpy as np
import time
from scipy.sparse import csr_matrix
def functions(n, z):
duals = [[0.527864045000421 + 0.171513425153810j,
0.171513425153810], [0.326237921249264 + 0.449027976579585j,
0.171513425153810], [0.555029102851551j,
0.171513425153810], [-0.326237921249264 + 0.449027976579585j,
0.171513425153810], [-0.527864045000421 + 0.171513425153810j,
0.171513425153810], [-0.527864045000421 - 0.171513425153810j,
0.171513425153810], [-0.326237921249264 - 0.449027976579585j,
0.171513425153810], [-0.555029102851551j,
0.171513425153810], [0.326237921249264 - 0.449027976579585j,
0.171513425153810], [0.527864045000421 - 0.171513425153810j,
0.171513425153810], [1.00000000000000 + 0.324919696232906j,
0.324919696232906], [0.618033988749895 + 0.850650808352040j,
0.324919696232906], [1.05146222423827j,
0.324919696232906], [-0.618033988749895 + 0.850650808352040j,
0.324919696232906], [-1.00000000000000 + 0.324919696232906j,
0.324919696232906], [-1.00000000000000 - 0.324919696232906j,
0.324919696232906], [-0.618033988749895 - 0.850650808352040j,
0.324919696232906], [-1.05146222423827j,
0.324919696232906], [0.618033988749895 - 0.850650808352040j,
0.324919696232906], [1.00000000000000 - 0.324919696232906j,
0.324919696232906]]
return duals[n][0] + np.conj((duals[n][1])**2 / (z-duals[n][0]))
def derivatives(n, z):
duals = [[0.527864045000421 + 0.171513425153810j,
0.171513425153810], [0.326237921249264 + 0.449027976579585j,
0.171513425153810], [0.555029102851551j,
0.171513425153810], [-0.326237921249264 + 0.449027976579585j,
0.171513425153810], [-0.527864045000421 + 0.171513425153810j,
0.171513425153810], [-0.527864045000421 - 0.171513425153810j,
0.171513425153810], [-0.326237921249264 - 0.449027976579585j,
0.171513425153810], [-0.555029102851551j,
0.171513425153810], [0.326237921249264 - 0.449027976579585j,
0.171513425153810], [0.527864045000421 - 0.171513425153810j,
0.171513425153810], [1.00000000000000 + 0.324919696232906j,
0.324919696232906], [0.618033988749895 + 0.850650808352040j,
0.324919696232906], [1.05146222423827j,
0.324919696232906], [-0.618033988749895 + 0.850650808352040j,
0.324919696232906], [-1.00000000000000 + 0.324919696232906j,
0.324919696232906], [-1.00000000000000 - 0.324919696232906j,
0.324919696232906], [-0.618033988749895 - 0.850650808352040j,
0.324919696232906], [-1.05146222423827j,
0.324919696232906], [0.618033988749895 - 0.850650808352040j,
0.324919696232906], [1.00000000000000 - 0.324919696232906j,
0.324919696232906]]
return abs(-1*((z-duals[n][0])**2) / ((duals[n][1])**2))
def samplePoint(word):
points = [0.554257 + 0.180089j, 0.34255 + 0.471479j, 0. +
0.582781j, -0.34255 + 0.471479j, -0.554257 +
0.180089j, -0.554257 - 0.180089j, -0.34255 - 0.471479j, 0. -
0.582781j, 0.34255 - 0.471479j, 0.554257 - 0.180089j, 0.9 +
0.292428j, 0.556231 + 0.765586j, 0. + 0.946316j, -0.556231 +
0.765586j, -0.9 + 0.292428j, -0.9 - 0.292428j, -0.556231 -
0.765586j, 0. - 0.946316j, 0.556231 - 0.765586j, 0.9 - 0.292428j]
p = points[word[-1]]
for letter in word[-2::-1]:
p = functions(letter, p)
return p
def sampleValue(word):
return derivatives(word[0], samplePoint(word))
def generateTree(words, dc):
tt = time.time()
generators = [np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 1., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0.], [3., 5.42705, 0., 0., 0.,
0., -0.190983, 0., 0., 0., 7.23607, 0.], [8.8541, 11.5902, 0., 0.,
0., 0., -0.5, 0., 0., 0., 18.9443, 0.], [15.3262, 17.1353, 0., 0.,
0., 0., -0.809017, 0., 0., 0., 30.6525, 0.], [19.9443, 19.9443, 0.,
0., 0., 0., -1., 0., 0., 0., 37.8885, 0.], [20.9443, 18.9443, 0.,
0., 0., 0., -1., 0., 0., 0., 37.8885, 0.], [17.9443, 14.5172, 0.,
0., 0., 0., -0.809017, 0., 0., 0., 30.6525, 0.], [12.0902, 8.3541,
0., 0., 0., 0., -0.5, 0., 0., 0., 18.9443, 0.], [5.61803, 2.80902,
0., 0., 0., 0., -0.190983, 0., 0., 0., 7.23607, 0.], [0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 1., 0.], [2.21115, 2.10557, 0., 0., 0.,
0., -0.105573, 0., 0., 0., 3., 0.]]),
np.array([[0., 5.8541, 2.61803, 0., 0., 0., 0., 0., -0.236068, 0., 7.23607,
0.], [0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 1.,
0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 3.23607, 5.23607, 0., 0.,
0., 0., 0., -0.236068, 0., 7.23607, 0.], [0., 9.47214, 11.0902, 0.,
0., 0., 0., 0., -0.618034, 0., 18.9443, 0.], [0., 16.3262, 16.3262,
0., 0., 0., 0., 0., -1., 0., 30.6525, 0.], [0., 21.1803, 18.9443,
0., 0., 0., 0., 0., -1.23607, 0., 37.8885, 0.], [0., 22.1803,
17.9443, 0., 0., 0., 0., 0., -1.23607, 0., 37.8885, 0.], [0.,
18.9443, 13.7082, 0., 0., 0., 0., 0., -1., 0., 30.6525, 0.], [0.,
12.7082, 7.8541, 0., 0., 0., 0., 0., -0.618034, 0., 18.9443,
0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.], [0., 2.34164,
2., 0., 0., 0., 0., 0., -0.130495, 0., 3., 0.]]),
np.array([[-1., 0., 13.7082, 7.23607, 0., 0., 0., 0., 0., 0., 18.9443,
0.], [-0.381966, 0., 6.23607, 2.38197, 0., 0., 0., 0., 0., 0.,
7.23607, 0.], [0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0.,
0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.], [-0.381966, 0.,
3.61803, 5., 0., 0., 0., 0., 0., 0., 7.23607, 0.], [-1., 0.,
10.4721, 10.4721, 0., 0., 0., 0., 0., 0., 18.9443, 0.], [-1.61803,
0., 17.9443, 15.3262, 0., 0., 0., 0., 0., 0., 30.6525, 0.], [-2.,
0., 23.1803, 17.7082, 0., 0., 0., 0., 0., 0., 37.8885, 0.], [-2.,
0., 24.1803, 16.7082, 0., 0., 0., 0., 0., 0., 37.8885,
0.], [-1.61803, 0., 20.5623, 12.7082, 0., 0., 0., 0., 0., 0.,
30.6525, 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,
0.], [-0.211146, 0., 2.55279, 1.8695, 0., 0., 0., 0., 0., 0., 3.,
0.]]),
np.array([[0., -1.61803, 0., 20.5623, 12.7082, 0., 0., 0., 0., 0., 30.6525,
0.], [0., -1., 0., 13.7082, 7.23607, 0., 0., 0., 0., 0., 18.9443,
0.], [0., -0.381966, 0., 6.23607, 2.38197, 0., 0., 0., 0., 0.,
7.23607, 0.], [0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.], [0.,
0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.], [0., -0.381966, 0.,
3.61803, 5., 0., 0., 0., 0., 0., 7.23607, 0.], [0., -1., 0.,
10.4721, 10.4721, 0., 0., 0., 0., 0., 18.9443, 0.], [0., -1.61803,
0., 17.9443, 15.3262, 0., 0., 0., 0., 0., 30.6525, 0.], [0., -2.,
0., 23.1803, 17.7082, 0., 0., 0., 0., 0., 37.8885, 0.], [0., -2.,
0., 24.1803, 16.7082, 0., 0., 0., 0., 0., 37.8885, 0.], [0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 1., 0.], [0., -0.211146, 0., 2.55279,
1.8695, 0., 0., 0., 0., 0., 3., 0.]]),
np.array([[0., 0., 0., 0., 18.9443, 21.1803, 0., 0., -1.23607, 0., 37.8885,
0.], [0., 0., 0., 0., 16.3262, 16.3262, 0., 0., -1., 0., 30.6525,
0.], [0., 0., 0., 0., 11.0902, 9.47214, 0., 0., -0.618034, 0.,
18.9443, 0.], [0., 0., 0., 0., 5.23607, 3.23607, 0., 0., -0.236068,
0., 7.23607, 0.], [0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
0.], [0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.], [0., 0., 0.,
0., 2.61803, 5.8541, 0., 0., -0.236068, 0., 7.23607, 0.], [0., 0.,
0., 0., 7.8541, 12.7082, 0., 0., -0.618034, 0., 18.9443, 0.], [0.,
0., 0., 0., 13.7082, 18.9443, 0., 0., -1., 0., 30.6525, 0.], [0.,
0., 0., 0., 17.9443, 22.1803, 0., 0., -1.23607, 0., 37.8885,
0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.], [0., 0., 0.,
0., 2., 2.34164, 0., 0., -0.130495, 0., 3., 0.]]),
np.array([[0., 0., 0., 0., 0., 19.9443, 20.9443, 0., 0., 0.,
28.4164, -9.47214], [0., 0., 0., 0., 0., 20.9443, 19.9443, 0., 0.,
0., 28.4164, -9.47214], [0., 0., 0., 0., 0., 17.9443, 15.3262, 0.,
0., 0., 22.9894, -7.66312], [0., 0., 0., 0., 0., 12.0902, 8.8541,
0., 0., 0., 14.2082, -4.73607], [0., 0., 0., 0., 0., 5.61803, 3.,
0., 0., 0., 5.42705, -1.80902], [0., 0., 0., 0., 0., 1., 0., 0., 0.,
0., 0., 0.], [0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.], [0.,
0., 0., 0., 0., 3., 5.61803, 0., 0., 0., 5.42705, -1.80902], [0.,
0., 0., 0., 0., 8.8541, 12.0902, 0., 0., 0.,
14.2082, -4.73607], [0., 0., 0., 0., 0., 15.3262, 17.9443, 0., 0.,
0., 22.9894, -7.66312], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,
0.], [0., 0., 0., 0., 0., 2.21115, 2.21115, 0., 0., 0., 2., -1.]]),
np.array([[0., 0., 0., 0., 0., 0., 12.7082, 20.5623, 0., -1.61803, 30.6525,
0.], [0., 0., 0., 0., 0., 0., 16.7082, 24.1803, 0., -2., 37.8885,
0.], [0., 0., 0., 0., 0., 0., 17.7082, 23.1803, 0., -2., 37.8885,
0.], [0., 0., 0., 0., 0., 0., 15.3262, 17.9443, 0., -1.61803,
30.6525, 0.], [0., 0., 0., 0., 0., 0., 10.4721, 10.4721, 0., -1.,
18.9443, 0.], [0., 0., 0., 0., 0., 0., 5., 3.61803, 0., -0.381966,
7.23607, 0.], [0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.], [0.,
0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.], [0., 0., 0., 0., 0.,
0., 2.38197, 6.23607, 0., -0.381966, 7.23607, 0.], [0., 0., 0., 0.,
0., 0., 7.23607, 13.7082, 0., -1., 18.9443, 0.], [0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 1., 0.], [0., 0., 0., 0., 0., 0., 1.8695,
2.55279, 0., -0.211146, 3., 0.]]),
np.array([[0., 0., 0., 0., -0.618034, 0., 0., 9.47214, 11.0902, 0., 18.9443,
0.], [0., 0., 0., 0., -1., 0., 0., 16.3262, 16.3262, 0., 30.6525,
0.], [0., 0., 0., 0., -1.23607, 0., 0., 21.1803, 18.9443, 0.,
37.8885, 0.], [0., 0., 0., 0., -1.23607, 0., 0., 22.1803, 17.9443,
0., 37.8885, 0.], [0., 0., 0., 0., -1., 0., 0., 18.9443, 13.7082,
0., 30.6525, 0.], [0., 0., 0., 0., -0.618034, 0., 0., 12.7082,
7.8541, 0., 18.9443, 0.], [0., 0., 0., 0., -0.236068, 0., 0.,
5.8541, 2.61803, 0., 7.23607, 0.], [0., 0., 0., 0., 0., 0., 0., 1.,
0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,
0.], [0., 0., 0., 0., -0.236068, 0., 0., 3.23607, 5.23607, 0.,
7.23607, 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.], [0.,
0., 0., 0., -0.130495, 0., 0., 2.34164, 2., 0., 3., 0.]]),
np.array([[0., 0., -0.236068, 0., 0., 0., 0., 0., 2.61803, 5.8541, 7.23607,
0.], [0., 0., -0.618034, 0., 0., 0., 0., 0., 7.8541, 12.7082,
18.9443, 0.], [0., 0., -1., 0., 0., 0., 0., 0., 13.7082, 18.9443,
30.6525, 0.], [0., 0., -1.23607, 0., 0., 0., 0., 0., 17.9443,
22.1803, 37.8885, 0.], [0., 0., -1.23607, 0., 0., 0., 0., 0.,
18.9443, 21.1803, 37.8885, 0.], [0., 0., -1., 0., 0., 0., 0., 0.,
16.3262, 16.3262, 30.6525, 0.], [0., 0., -0.618034, 0., 0., 0., 0.,
0., 11.0902, 9.47214, 18.9443, 0.], [0., 0., -0.236068, 0., 0., 0.,
0., 0., 5.23607, 3.23607, 7.23607, 0.], [0., 0., 0., 0., 0., 0., 0.,
0., 1., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,
0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.], [0.,
0., -0.130495, 0., 0., 0., 0., 0., 2., 2.34164, 3., 0.]]),
np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [7.23607, -1., 0.,
0., 0., 0., 0., 0., 0., 2., 7.23607, 0.], [16.3262, -2.61803, 0.,
0., 0., 0., 0., 0., 0., 6.23607, 18.9443, 0.], [24.7984, -4.23607,
0., 0., 0., 0., 0., 0., 0., 11.0902, 30.6525,
0.], [29.4164, -5.23607, 0., 0., 0., 0., 0., 0., 0., 14.7082,
37.8885, 0.], [28.4164, -5.23607, 0., 0., 0., 0., 0., 0., 0.,
15.7082, 37.8885, 0.], [22.1803, -4.23607, 0., 0., 0., 0., 0., 0.,
0., 13.7082, 30.6525, 0.], [13.0902, -2.61803, 0., 0., 0., 0., 0.,
0., 0., 9.47214, 18.9443, 0.], [4.61803, -1., 0., 0., 0., 0., 0.,
0., 0., 4.61803, 7.23607, 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0.,
1., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,
0.], [3.10557, -0.552786, 0., 0., 0., 0., 0., 0., 0., 1.65836, 3.,
0.]]),
np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 1., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0.], [3.23607, 5.23607, 0., 0., 0., 0.,
0., -0.236068, 0., 0., 0., 7.23607], [9.47214, 11.0902, 0., 0., 0.,
0., 0., -0.618034, 0., 0., 0., 18.9443], [16.3262, 16.3262, 0., 0.,
0., 0., 0., -1., 0., 0., 0., 30.6525], [21.1803, 18.9443, 0., 0.,
0., 0., 0., -1.23607, 0., 0., 0., 37.8885], [22.1803, 17.9443, 0.,
0., 0., 0., 0., -1.23607, 0., 0., 0., 37.8885], [18.9443, 13.7082,
0., 0., 0., 0., 0., -1., 0., 0., 0., 30.6525], [12.7082, 7.8541, 0.,
0., 0., 0., 0., -0.618034, 0., 0., 0., 18.9443], [5.8541, 2.61803,
0., 0., 0., 0., 0., -0.236068, 0., 0., 0., 7.23607], [2.34164, 2.,
0., 0., 0., 0., 0., -0.130495, 0., 0., 0., 3.], [0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 1.]]),
np.array([[0., 5.8541, 2.61803, 0., 0., 0., 0., 0., -0.236068, 0., 0.,
7.23607], [0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0.,
1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 3.23607, 5.23607, 0.,
0., 0., 0., 0., -0.236068, 0., 0., 7.23607], [0., 9.47214, 11.0902,
0., 0., 0., 0., 0., -0.618034, 0., 0., 18.9443], [0., 16.3262,
16.3262, 0., 0., 0., 0., 0., -1., 0., 0., 30.6525], [0., 21.1803,
18.9443, 0., 0., 0., 0., 0., -1.23607, 0., 0., 37.8885], [0.,
22.1803, 17.9443, 0., 0., 0., 0., 0., -1.23607, 0., 0.,
37.8885], [0., 18.9443, 13.7082, 0., 0., 0., 0., 0., -1., 0., 0.,
30.6525], [0., 12.7082, 7.8541, 0., 0., 0., 0., 0., -0.618034, 0.,
0., 18.9443], [0., 2.34164, 2., 0., 0., 0., 0., 0., -0.130495, 0.,
0., 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]),
np.array([[0., 0., 10.4721, 10.4721, 0., -1., 0., 0., 0., 0., 0.,
18.9443], [0., 0., 5., 3.61803, 0., -0.381966, 0., 0., 0., 0., 0.,
7.23607], [0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0.,
0., 1., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 2.38197, 6.23607,
0., -0.381966, 0., 0., 0., 0., 0., 7.23607], [0., 0., 7.23607,
13.7082, 0., -1., 0., 0., 0., 0., 0., 18.9443], [0., 0., 12.7082,
20.5623, 0., -1.61803, 0., 0., 0., 0., 0., 30.6525], [0., 0.,
16.7082, 24.1803, 0., -2., 0., 0., 0., 0., 0., 37.8885], [0., 0.,
17.7082, 23.1803, 0., -2., 0., 0., 0., 0., 0., 37.8885], [0., 0.,
15.3262, 17.9443, 0., -1.61803, 0., 0., 0., 0., 0., 30.6525], [0.,
0., 1.8695, 2.55279, 0., -0.211146, 0., 0., 0., 0., 0., 3.], [0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]),
np.array([[0., 0., 0., 13.7082, 22.1803, -4.23607, 0., 0., 0., 0., 0.,
30.6525], [0., 0., 0., 9.47214, 13.0902, -2.61803, 0., 0., 0., 0.,
0., 18.9443], [0., 0., 0., 4.61803, 4.61803, -1., 0., 0., 0., 0.,
0., 7.23607], [0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.], [0.,
0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 2.,
7.23607, -1., 0., 0., 0., 0., 0., 7.23607], [0., 0., 0., 6.23607,
16.3262, -2.61803, 0., 0., 0., 0., 0., 18.9443], [0., 0., 0.,
11.0902, 24.7984, -4.23607, 0., 0., 0., 0., 0., 30.6525], [0., 0.,
0., 14.7082, 29.4164, -5.23607, 0., 0., 0., 0., 0., 37.8885], [0.,
0., 0., 15.7082, 28.4164, -5.23607, 0., 0., 0., 0., 0.,
37.8885], [0., 0., 0., 1.65836, 3.10557, -0.552786, 0., 0., 0., 0.,
0., 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]),
np.array([[0., -1.23607, 0., 0., 22.1803, 17.9443, 0., 0., 0., 0., 0.,
37.8885], [0., -1., 0., 0., 18.9443, 13.7082, 0., 0., 0., 0., 0.,
30.6525], [0., -0.618034, 0., 0., 12.7082, 7.8541, 0., 0., 0., 0.,
0., 18.9443], [0., -0.236068, 0., 0., 5.8541, 2.61803, 0., 0., 0.,
0., 0., 7.23607], [0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
0.], [0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
0.], [0., -0.236068, 0., 0., 3.23607, 5.23607, 0., 0., 0., 0., 0.,
7.23607], [0., -0.618034, 0., 0., 9.47214, 11.0902, 0., 0., 0., 0.,
0., 18.9443], [0., -1., 0., 0., 16.3262, 16.3262, 0., 0., 0., 0.,
0., 30.6525], [0., -1.23607, 0., 0., 21.1803, 18.9443, 0., 0., 0.,
0., 0., 37.8885], [0., -0.130495, 0., 0., 2.34164, 2., 0., 0., 0.,
0., 0., 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]),
np.array([[-1., 0., 0., 0., 0., 18.9443, 20.9443, 0., 0., 0., 0.,
37.8885], [-1., 0., 0., 0., 0., 19.9443, 19.9443, 0., 0., 0., 0.,
37.8885], [-0.809017, 0., 0., 0., 0., 17.1353, 15.3262, 0., 0., 0.,
0., 30.6525], [-0.5, 0., 0., 0., 0., 11.5902, 8.8541, 0., 0., 0.,
0., 18.9443], [-0.190983, 0., 0., 0., 0., 5.42705, 3., 0., 0., 0.,
0., 7.23607], [0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.], [0.,
0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.], [-0.190983, 0., 0.,
0., 0., 2.80902, 5.61803, 0., 0., 0., 0., 7.23607], [-0.5, 0., 0.,
0., 0., 8.3541, 12.0902, 0., 0., 0., 0., 18.9443], [-0.809017, 0.,
0., 0., 0., 14.5172, 17.9443, 0., 0., 0., 0., 30.6525], [-0.105573,
0., 0., 0., 0., 2.10557, 2.21115, 0., 0., 0., 0., 3.], [0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 1.]]),
np.array([[0., 0., 0., 0., 0., 0., 15.3262, 17.9443, 0., 0., -7.66312,
22.9894], [0., 0., 0., 0., 0., 0., 19.9443, 20.9443, 0.,
0., -9.47214, 28.4164], [0., 0., 0., 0., 0., 0., 20.9443, 19.9443,
0., 0., -9.47214, 28.4164], [0., 0., 0., 0., 0., 0., 17.9443,
15.3262, 0., 0., -7.66312, 22.9894], [0., 0., 0., 0., 0., 0.,
12.0902, 8.8541, 0., 0., -4.73607, 14.2082], [0., 0., 0., 0., 0.,
0., 5.61803, 3., 0., 0., -1.80902, 5.42705], [0., 0., 0., 0., 0.,
0., 1., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 1., 0.,
0., 0., 0.], [0., 0., 0., 0., 0., 0., 3., 5.61803, 0., 0., -1.80902,
5.42705], [0., 0., 0., 0., 0., 0., 8.8541, 12.0902, 0.,
0., -4.73607, 14.2082], [0., 0., 0., 0., 0., 0., 2.21115, 2.21115,
0., 0., -1., 2.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]),
np.array([[0., 0., 0., 0., 0., 0., 0., 6.23607, 16.3262, -2.61803, 0.,
18.9443], [0., 0., 0., 0., 0., 0., 0., 11.0902, 24.7984, -4.23607,
0., 30.6525], [0., 0., 0., 0., 0., 0., 0., 14.7082,
29.4164, -5.23607, 0., 37.8885], [0., 0., 0., 0., 0., 0., 0.,
15.7082, 28.4164, -5.23607, 0., 37.8885], [0., 0., 0., 0., 0., 0.,
0., 13.7082, 22.1803, -4.23607, 0., 30.6525], [0., 0., 0., 0., 0.,
0., 0., 9.47214, 13.0902, -2.61803, 0., 18.9443], [0., 0., 0., 0.,
0., 0., 0., 4.61803, 4.61803, -1., 0., 7.23607], [0., 0., 0., 0.,
0., 0., 0., 1., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0.,
1., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 2., 7.23607, -1., 0.,
7.23607], [0., 0., 0., 0., 0., 0., 0., 1.65836, 3.10557, -0.552786,
0., 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]),
np.array([[0., 0., 0., 0., 0., -0.236068, 0., 0., 3.23607, 5.23607, 0.,
7.23607], [0., 0., 0., 0., 0., -0.618034, 0., 0., 9.47214, 11.0902,
0., 18.9443], [0., 0., 0., 0., 0., -1., 0., 0., 16.3262, 16.3262,
0., 30.6525], [0., 0., 0., 0., 0., -1.23607, 0., 0., 21.1803,
18.9443, 0., 37.8885], [0., 0., 0., 0., 0., -1.23607, 0., 0.,
22.1803, 17.9443, 0., 37.8885], [0., 0., 0., 0., 0., -1., 0., 0.,
18.9443, 13.7082, 0., 30.6525], [0., 0., 0., 0., 0., -0.618034, 0.,
0., 12.7082, 7.8541, 0., 18.9443], [0., 0., 0., 0., 0., -0.236068,
0., 0., 5.8541, 2.61803, 0., 7.23607], [0., 0., 0., 0., 0., 0., 0.,
0., 1., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,
0.], [0., 0., 0., 0., 0., -0.130495, 0., 0., 2.34164, 2., 0.,
3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]),
np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [5.8541, 0.,
0., -0.236068, 0., 0., 0., 0., 0., 2.61803, 0., 7.23607], [12.7082,
0., 0., -0.618034, 0., 0., 0., 0., 0., 7.8541, 0.,
18.9443], [18.9443, 0., 0., -1., 0., 0., 0., 0., 0., 13.7082, 0.,
30.6525], [22.1803, 0., 0., -1.23607, 0., 0., 0., 0., 0., 17.9443,
0., 37.8885], [21.1803, 0., 0., -1.23607, 0., 0., 0., 0., 0.,
18.9443, 0., 37.8885], [16.3262, 0., 0., -1., 0., 0., 0., 0., 0.,
16.3262, 0., 30.6525], [9.47214, 0., 0., -0.618034, 0., 0., 0., 0.,
0., 11.0902, 0., 18.9443], [3.23607, 0., 0., -0.236068, 0., 0., 0.,
0., 0., 5.23607, 0., 7.23607], [0., 0., 0., 0., 0., 0., 0., 0., 0.,
1., 0., 0.], [2.34164, 0., 0., -0.130495, 0., 0., 0., 0., 0., 2.,
0., 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])]
root = Node([4.23606797749979, 4.23606797749979, 4.23606797749979, \
4.23606797749979, 4.23606797749979, 4.23606797749979, \
4.23606797749979, 4.23606797749979, 4.23606797749979, \
4.23606797749979, 1.89442719099992, -1.00000000000000], [], words, False)
current_leaves = [root]
nodes = 1
while True:
new_leaves = []
for leaf in current_leaves:
next_gen = leaf.next_generation(words, dc, generators)
new_leaves += next_gen
nodes += len(next_gen) if len(next_gen) > 1 else 0
if current_leaves == new_leaves:
break
else:
current_leaves = new_leaves
for i,leaf in enumerate(current_leaves):
words[str(leaf.word)] = i
print(len(current_leaves), "partitions")
print(nodes,"nodes")
print("tree construction (s): %f\ntree construction (m): %f" % (time.time()-tt, (time.time()-tt)/60))
return current_leaves
def constructMatrix(words, dc):
leave = generateTree(words, dc)
row = []
col = []
data = []
for i,leaf in enumerate(leave):
thing = words[str(leaf.word[1:])]
if isinstance(thing,int):
row.append(i)
col.append(thing)
data.append(sampleValue(leaf.word))
else:
sample = sampleValue(leaf.word)
for wor in thing.leaves():
row.append(i)
col.append(words[str(wor.word)])
data.append(sample)
return csr_matrix((data,(row,col)),shape=(len(leave),len(leave)))
def secant(x0,y0,x1,y1,z):
return x0 - (y0-z) * ((x1-x0)/(y1-y0))
def matrixFunction(matrix,l,a):
matrix = matrix.power(a)
vec = np.ones(l)
previous_entry = vec[0]
previous_val = 0
current = matrix * vec
current_val = current[0] / previous_entry
count = 0
while count < 10000000000 and abs(current_val - previous_val) > 1e-15:
previous_val = current_val
previous_entry = current[0]
current = matrix * current
#print(current[0],previous_entry)
current_val = current[0] / previous_entry
count += 1
print("power method:", count)
return current_val
def secantMethod(matrix,l,z,x1,x2,e,its):
k1 = x1
k2 = x2
y1 = matrixFunction(matrix,l,k1)
y2 = matrixFunction(matrix,l,k2)
#y1 = testFunction(k1)
#y2 = testFunction(k2)
count = 1
print(count,k1,y1)
while abs(y1-z)>e and count<its:
k3 = secant(k1,y1,k2,y2,z)
k1 = k2
y1 = y2
k2 = k3
y2 = matrixFunction(matrix,l,k2)
#y2 = testFunction(k2)
count += 1
print(count,k1,y1)
def main():
start = time.time()
words = {}
m = 100
print("maximum:",m)
matrix = constructMatrix(words, m)
#print(matrix)
print("construction (s): %f\nconstruction (m): %f" % (time.time()-start, (time.time()-start)/60))
#print(csr_matrix.transpose(matrix))
print(csr_matrix.count_nonzero(matrix), (matrix.shape[0])*15)
secantMethod(matrix,matrix.shape[0],1,1.33,1.34,10**(-10),1000)
print("total (s): %f\ntotal (m): %f" % (time.time()-start, (time.time()-start)/60))
main()