diff --git a/fractal_dimension/mcmullen_stuff/cubenode.py b/fractal_dimension/mcmullen_stuff/cubenode.py new file mode 100644 index 0000000..854ad4a --- /dev/null +++ b/fractal_dimension/mcmullen_stuff/cubenode.py @@ -0,0 +1,60 @@ +import numpy as np +import math + +class Node: + def __init__(self, tuple, word, words, infertile): + self.tuple = tuple + self.children = [] + self.word = word + self.infertile = infertile + words[str(word)] = self + + def dc_not_too_big(self, g, generator, dual_curvature): + temp = np.matmul(generator, self.tuple) + if g == 0: + temp = [temp[i] for i in (0,1,2,4)] + elif g == 1: + temp = [temp[i] for i in (0,2,3,6)] + elif g == 2: + temp = [temp[i] for i in (0,1,3,5)] + elif g == 3: + temp = [temp[i] for i in (1,4,5,7)] + elif g == 4: + temp = [temp[i] for i in (3,5,6,7)] + elif g == 5: + temp = [temp[i] for i in (2,4,6,7)] + if temp[0] < 0: + return math.sqrt(-temp[0]*temp[1]*temp[2] - temp[0]*temp[1]*temp[3] - temp[0]*temp[2]*temp[3] + temp[1]*temp[2]*temp[3])/math.sqrt(-temp[0] + temp[1] + temp[2] + temp[3]) < dual_curvature + else: + return math.sqrt(temp[0]*temp[1]*temp[2] + temp[0]*temp[1]*temp[3] + temp[0]*temp[2]*temp[3] + temp[1]*temp[2]*temp[3])/math.sqrt(temp[0] + temp[1] + temp[2] + temp[3]) < dual_curvature + + + def next_generation(self, words, dual_curvature, generators): + if self.infertile: + return [self] + if self.children == []: + for g,generator in enumerate(generators): + if len(self.word) == 0 or g != self.word[-1]: + self.children.append(Node(np.matmul(generator,self.tuple), self.word[:] + [g], words, not self.dc_not_too_big(g, generator, dual_curvature))) + if self.children == []: + return [self] + else: + return self.children + + def next(self): + if self.children == []: + return [self] + else: + return self.children + + def leaves(self): + current_leaves = [self] + while True: + new_leaves = [] + for leaf in current_leaves: + new_leaves += leaf.next() + if current_leaves == new_leaves: + break + else: + current_leaves = new_leaves + return current_leaves \ No newline at end of file diff --git a/fractal_dimension/mcmullen_stuff/cubetree.py b/fractal_dimension/mcmullen_stuff/cubetree.py new file mode 100644 index 0000000..35defc8 --- /dev/null +++ b/fractal_dimension/mcmullen_stuff/cubetree.py @@ -0,0 +1,174 @@ +#https://www.desmos.com/calculator/vaskxmhoxh + +from cubenode import Node +import math +import numpy as np +import time +from scipy.sparse import csr_matrix + +def functions(n, z): + if n == 0: + return -1.732050808 + 1j + np.conj(3./(1.732050808 - 1.000000000j + z)) + elif n == 1: + return -2.000000000j + np.conj(3./(2.000000000j + z)) + elif n == 2: + return 1.732050808 + 1j + np.conj(3./(-1.732050808 - 1.000000000j + z)) + elif n == 3: + return 0.202041j + np.conj(0.0306154/(-0.202041j + z)) + elif n == 4: + return 0.174973 - 0.101021j + np.conj(0.0306154/(-0.174973 + 0.101021j + z)) + elif n == 5: + return -0.174973 - 0.101021j + np.conj(0.0306154/(0.174973 + 0.101021j + z)) + +def derivatives(n, z): + if n == 0: + return abs(-0.333333*(1.732050808 - 1.000000000j + z)**2) + elif n == 1: + return abs(-0.333333*(2.000000000j + z)**2) + elif n == 2: + return abs(-0.333333*(-1.732050808 - 1.000000000j + z)**2) + elif n == 3: + return abs(-32.6633*(-0.202041j + z)**2) + elif n == 4: + return abs(-32.6633*(-0.174973 + 0.101021j + z)**2) + elif n == 5: + return abs(-32.6633*(0.174973 + 0.101021j + z)**2) + +def samplePoint(word): + points = [-0.606218 + 0.35j, 0. - 0.7j, 0.606218 + 0.35j, 0. + + 0.181837j, 0.157475 - 0.0909185j, -0.157475 - 0.0909185j] + 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): + + generators = [np.array([[0., 1., 1., 0., -1., 0., 0., 0.], [0., 1., 0., 0., 0., 0., 0., + 0.], [0., 0., 1., 0., 0., 0., 0., 0.], [0., 3., 3., 0., 0., 0., + 0., -1.], [0., 0., 0., 0., 1., 0., 0., 0.], [0., 3., 2., 0., 1., 0., + 0., -1.], [0., 2., 3., 0., 1., 0., 0., -1.], [0., 2., 2., 0., 2., + 0., 0., -1.]]), + np.array([[1., 0., 0., 0., 0., 0., 0., 0.], [1., 0., 3., 2., -1., 0., 0., + 0.], [0., 0., 1., 0., 0., 0., 0., 0.], [0., 0., 0., 1., 0., 0., 0., + 0.], [0., 0., 4., 2., -1., 0., 0., 0.], [0., 0., 3., 3., -1., 0., + 0., 0.], [-1., 0., 1., 1., 0., 0., 0., 0.], [-1., 0., 4., 3., -1., + 0., 0., 0.]]), + np.array([[1., 0., 0., 0., 0., 0., 0., 0.], [1., 0., 0., -1., 0., 1., 0., + 0.], [4., 0., 0., -1., -1., 3., 0., 0.], [0., 0., 0., 1., 0., 0., + 0., 0.], [4., 0., 0., -2., -1., 4., 0., 0.], [0., 0., 0., 0., 0., + 1., 0., 0.], [3., 0., 0., 0., -1., 3., 0., 0.], [3., 0., + 0., -1., -1., 4., 0., 0.]]), + np.array([[0., 0., 0., 0., 3., 3., -1., 0.], [0., 1., 0., 0., 0., 0., 0., + 0.], [0., -1., 0., 0., 4., 3., -1., 0.], [0., -1., 0., 0., 3., + 4., -1., 0.], [0., 0., 0., 0., 1., 0., 0., 0.], [0., 0., 0., 0., 0., + 1., 0., 0.], [0., -2., 0., 0., 4., 4., -1., 0.], [0., -1., 0., 0., + 1., 1., 0., 0.]]), + np.array([[0., 0., 0., 0., -1., 3., 3., 0.], [0., 0., 0., -1., -1., 4., 3., + 0.], [0., 0., 0., -1., -1., 3., 4., 0.], [0., 0., 0., 1., 0., 0., + 0., 0.], [0., 0., 0., -2., -1., 4., 4., 0.], [0., 0., 0., 0., 0., + 1., 0., 0.], [0., 0., 0., 0., 0., 0., 1., 0.], [0., 0., 0., -1., 0., + 1., 1., 0.]]), + np.array([[0., -1., 0., 0., 4., 0., 3., -1.], [0., -1., 0., 0., 4., 0., 2., + 0.], [0., 0., 0., 0., 1., 0., 1., -1.], [0., -1., 0., 0., 3., 0., + 3., 0.], [0., 0., 0., 0., 1., 0., 0., 0.], [0., -1., 0., 0., 3., 0., + 2., 1.], [0., 0., 0., 0., 0., 0., 1., 0.], [0., 0., 0., 0., 0., 0., + 0., 1.]])] + + root = Node([-1,2.632993161855454,2.632993161855454,2.632993161855454,6.265986323710909,6.265986323710909,6.265986323710909,9.898979485566363], [], 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") + 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 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 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") + 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: + for wor in thing.leaves(): + row.append(i) + col.append(words[str(wor.word)]) + data.append(sampleValue(leaf.word)) + 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 < 1000000000 and abs(current_val - previous_val) > 1e-15: + previous_val = current_val + previous_entry = current[0] + current = matrix * current + 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 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") + 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 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") + 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 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") + 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 count1: + print(d, word) + return d + +def generateTree(words, dc): + tt = time.time() + generators = [np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 1., 0., 0., 0., 0., + 0., 0., 0., 0.], [2.70711, 5.41421, 0., 0., -0.292893, 0., 0., 0., + 6.82843, 0.], [7.53553, 10.6569, 0., 0., -0.707107, 0., 0., 0., + 16.4853, 0.], [11.6569, 13.6569, 0., 0., -1., 0., 0., 0., 23.3137, + 0.], [12.6569, 12.6569, 0., 0., -1., 0., 0., 0., 23.3137, + 0.], [9.94975, 8.24264, 0., 0., -0.707107, 0., 0., 0., 16.4853, + 0.], [5.12132, 3., 0., 0., -0.292893, 0., 0., 0., 6.82843, 0.], [0., + 0., 0., 0., 0., 0., 0., 0., 1., 0.], [2.17157, 2.34315, 0., + 0., -0.171573, 0., 0., 0., 3., 0.]]),np.array([[0., 4.82843, 3.41421, + 0., -0.414214, 0., 0., 0., 6.82843, 0.], [0., + 1., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 1., 0., 0., 0., 0., + 0., 0., 0.], [0., 2.41421, 5.82843, 0., -0.414214, 0., 0., 0., + 6.82843, 0.], [0., 6.82843, 11.6569, 0., -1., 0., 0., 0., 16.4853, + 0.], [0., 10.6569, 15.0711, 0., -1.41421, 0., 0., 0., 23.3137, + 0.], [0., 11.6569, 14.0711, 0., -1.41421, 0., 0., 0., 23.3137, + 0.], [0., 9.24264, 9.24264, 0., -1., 0., 0., 0., 16.4853, 0.], [0., + 0., 0., 0., 0., 0., 0., 0., 1., 0.], [0., 2., 2.58579, + 0., -0.242641, 0., 0., 0., 3., 0.]]), np.array([[-1., 0., 11.6569, 6.82843, + 0., 0., 0., 0., 16.4853, 0.], [-0.414214, 0., 5.82843, 2.41421, 0., + 0., 0., 0., 6.82843, 0.], [0., 0., 1., 0., 0., 0., 0., 0., 0., + 0.], [0., 0., 0., 1., 0., 0., 0., 0., 0., 0.], [-0.414214, 0., + 3.41421, 4.82843, 0., 0., 0., 0., 6.82843, 0.], [-1., 0., 9.24264, + 9.24264, 0., 0., 0., 0., 16.4853, 0.], [-1.41421, 0., 14.0711, + 11.6569, 0., 0., 0., 0., 23.3137, 0.], [-1.41421, 0., 15.0711, + 10.6569, 0., 0., 0., 0., 23.3137, 0.], [0., 0., 0., 0., 0., 0., 0., + 0., 1., 0.], [-0.242641, 0., 2.58579, 2., 0., 0., 0., 0., 3., + 0.]]), np.array([[0., 0., 0., 11.6569, 14.0711, 0., -1.41421, 0., 23.3137, + 0.], [0., 0., 0., 9.24264, 9.24264, 0., -1., 0., 16.4853, 0.], [0., + 0., 0., 4.82843, 3.41421, 0., -0.414214, 0., 6.82843, 0.], [0., + 0., 0., 1., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1., 0., 0., + 0., 0., 0.], [0., 0., 0., 2.41421, 5.82843, 0., -0.414214, 0., + 6.82843, 0.], [0., 0., 0., 6.82843, 11.6569, 0., -1., 0., 16.4853, + 0.], [0., 0., 0., 10.6569, 15.0711, 0., -1.41421, 0., 23.3137, + 0.], [0., 0., 0., 0., 0., 0., 0., 0., 1., 0.], [0., 0., 0., 2., + 2.58579, 0., -0.242641, 0., 3., 0.]]), np.array([[0., 0., 0., -3.41421, + 17.4853, 10.2426, 0., 0., 23.3137, 0.], [0., 0., 0., -3.41421, + 18.4853, 9.24264, 0., 0., 23.3137, 0.], [0., 0., 0., -2.41421, + 14.0711, 5.82843, 0., 0., 16.4853, 0.], [0., 0., 0., -1., 6.82843, + 2., 0., 0., 6.82843, 0.], [0., 0., 0., 0., 1., 0., 0., 0., 0., + 0.], [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.], [0., 0., 0., -1., + 4.41421, 4.41421, 0., 0., 6.82843, 0.], [0., 0., 0., -2.41421, + 11.6569, 8.24264, 0., 0., 16.4853, 0.], [0., 0., 0., 0., 0., 0., + 0., 0., 1., 0.], [0., 0., 0., -0.585786, 3.17157, 1.75736, 0., 0., + 3., 0.]]), np.array([[0., 0., 0., 0., -2.41421, 11.6569, 8.24264, 0., + 16.4853, 0.], [0., 0., 0., 0., -3.41421, 17.4853, 10.2426, 0., + 23.3137, 0.], [0., 0., 0., 0., -3.41421, 18.4853, 9.24264, 0., + 23.3137, 0.], [0., 0., 0., 0., -2.41421, 14.0711, 5.82843, 0., + 16.4853, 0.], [0., 0., 0., 0., -1., 6.82843, 2., 0., 6.82843, + 0.], [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.], [0., 0., 0., 0., 0., + 0., 1., 0., 0., 0.], [0., 0., 0., 0., -1., 4.41421, 4.41421, 0., + 6.82843, 0.], [0., 0., 0., 0., 0., 0., 0., 0., 1., 0.], [0., 0., + 0., 0., -0.585786, 3.17157, 1.75736, 0., 3., 0.]]), np.array([[0., 0., + 0., -0.292893, 0., 0., 3., 5.12132, 6.82843, 0.], [0., 0., + 0., -0.707107, 0., 0., 8.24264, 9.94975, 16.4853, 0.], [0., 0., + 0., -1., 0., 0., 12.6569, 12.6569, 23.3137, 0.], [0., 0., 0., -1., + 0., 0., 13.6569, 11.6569, 23.3137, 0.], [0., 0., 0., -0.707107, 0., + 0., 10.6569, 7.53553, 16.4853, 0.], [0., 0., 0., -0.292893, 0., + 0., 5.41421, 2.70711, 6.82843, 0.], [0., 0., 0., 0., 0., 0., 1., + 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 1., 0., 0.], [0., 0., 0., + 0., 0., 0., 0., 0., 1., 0.], [0., 0., 0., -0.171573, 0., 0., + 2.34315, 2.17157, 3., 0.]]),np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [5.82843, 0., -0.414214, + 0., 0., 0., 0., 2.41421, 6.82843, 0.], [11.6569, 0., -1., 0., 0., + 0., 0., 6.82843, 16.4853, 0.], [15.0711, 0., -1.41421, 0., 0., 0., + 0., 10.6569, 23.3137, 0.], [14.0711, 0., -1.41421, 0., 0., 0., 0., + 11.6569, 23.3137, 0.], [9.24264, 0., -1., 0., 0., 0., 0., 9.24264, + 16.4853, 0.], [3.41421, 0., -0.414214, 0., 0., 0., 0., 4.82843, + 6.82843, 0.], [0., 0., 0., 0., 0., 0., 0., 1., 0., 0.], [0., 0., 0., + 0., 0., 0., 0., 0., 1., 0.], [2.58579, 0., -0.242641, 0., 0., 0., + 0., 2., 3., 0.]]),np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [5.41421, 0., 0., 0., 0., + 0., 0., 3., -1.70711, 5.12132], [10.6569, 0., 0., 0., 0., 0., 0., + 8.24264, -4.12132, 12.364], [13.6569, 0., 0., 0., 0., 0., 0., + 12.6569, -5.82843, 17.4853], [12.6569, 0., 0., 0., 0., 0., 0., + 13.6569, -5.82843, 17.4853], [8.24264, 0., 0., 0., 0., 0., 0., + 10.6569, -4.12132, 12.364], [3., 0., 0., 0., 0., 0., 0., + 5.41421, -1.70711, 5.12132], [0., 0., 0., 0., 0., 0., 0., 1., 0., + 0.], [2.34315, 0., 0., 0., 0., 0., 0., 2.34315, -1., 2.], [0., 0., + 0., 0., 0., 0., 0., 0., 0., 1.]]),np.array([[0., 5.82843, 2.41421, 0., 0., 0., 0., -0.414214, 0., 6.82843], [0., + 1., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 1., 0., 0., 0., 0., + 0., 0., 0.], [0., 3.41421, 4.82843, 0., 0., 0., 0., -0.414214, 0., + 6.82843], [0., 9.24264, 9.24264, 0., 0., 0., 0., -1., 0., + 16.4853], [0., 14.0711, 11.6569, 0., 0., 0., 0., -1.41421, 0., + 23.3137], [0., 15.0711, 10.6569, 0., 0., 0., 0., -1.41421, 0., + 23.3137], [0., 11.6569, 6.82843, 0., 0., 0., 0., -1., 0., + 16.4853], [0., 2.58579, 2., 0., 0., 0., 0., -0.242641, 0., + 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]), np.array([[-1., 0., 11.6569, + 6.82843, 0., 0., 0., 0., 0., 16.4853], [-0.414214, 0., 5.82843, + 2.41421, 0., 0., 0., 0., 0., 6.82843], [0., 0., 1., 0., 0., 0., 0., + 0., 0., 0.], [0., 0., 0., 1., 0., 0., 0., 0., 0., 0.], [-0.414214, + 0., 3.41421, 4.82843, 0., 0., 0., 0., 0., 6.82843], [-1., 0., + 9.24264, 9.24264, 0., 0., 0., 0., 0., 16.4853], [-1.41421, 0., + 14.0711, 11.6569, 0., 0., 0., 0., 0., 23.3137], [-1.41421, 0., + 15.0711, 10.6569, 0., 0., 0., 0., 0., 23.3137], [-0.242641, 0., + 2.58579, 2., 0., 0., 0., 0., 0., 3.], [0., 0., 0., 0., 0., 0., 0., + 0., 0., 1.]]), np.array([[0., 0., -3.41421, 18.4853, 9.24264, 0., 0., 0., 0., + 23.3137], [0., 0., -2.41421, 14.0711, 5.82843, 0., 0., 0., 0., + 16.4853], [0., 0., -1., 6.82843, 2., 0., 0., 0., 0., 6.82843], [0., + 0., 0., 1., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1., 0., 0., + 0., 0., 0.], [0., 0., -1., 4.41421, 4.41421, 0., 0., 0., 0., + 6.82843], [0., 0., -2.41421, 11.6569, 8.24264, 0., 0., 0., 0., + 16.4853], [0., 0., -3.41421, 17.4853, 10.2426, 0., 0., 0., 0., + 23.3137], [0., 0., -0.585786, 3.17157, 1.75736, 0., 0., 0., 0., + 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]), np.array([[-1., 0., 0., 0., + 11.6569, 13.6569, 0., 0., 0., 23.3137], [-1., 0., 0., 0., 12.6569, + 12.6569, 0., 0., 0., 23.3137], [-0.707107, 0., 0., 0., 9.94975, + 8.24264, 0., 0., 0., 16.4853], [-0.292893, 0., 0., 0., 5.12132, 3., + 0., 0., 0., 6.82843], [0., 0., 0., 0., 1., 0., 0., 0., 0., + 0.], [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.], [-0.292893, 0., 0., + 0., 2.70711, 5.41421, 0., 0., 0., 6.82843], [-0.707107, 0., 0., 0., + 7.53553, 10.6569, 0., 0., 0., 16.4853], [-0.171573, 0., 0., 0., + 2.17157, 2.34315, 0., 0., 0., 3.], [0., 0., 0., 0., 0., 0., 0., 0., + 0., 1.]]), np.array([[0., 0., 0., 0., 0., 5.82843, 14.0711, -2.41421, 0., + 16.4853], [0., 0., 0., 0., 0., 9.24264, 18.4853, -3.41421, 0., + 23.3137], [0., 0., 0., 0., 0., 10.2426, 17.4853, -3.41421, 0., + 23.3137], [0., 0., 0., 0., 0., 8.24264, 11.6569, -2.41421, 0., + 16.4853], [0., 0., 0., 0., 0., 4.41421, 4.41421, -1., 0., + 6.82843], [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.], [0., 0., 0., + 0., 0., 0., 1., 0., 0., 0.], [0., 0., 0., 0., 0., 2., 6.82843, -1., + 0., 6.82843], [0., 0., 0., 0., 0., 1.75736, 3.17157, -0.585786, + 0., 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., + 1.]]), np.array([[0., -0.414214, 0., 0., 0., 0., 2.41421, 5.82843, 0., + 6.82843], [0., -1., 0., 0., 0., 0., 6.82843, 11.6569, 0., + 16.4853], [0., -1.41421, 0., 0., 0., 0., 10.6569, 15.0711, 0., + 23.3137], [0., -1.41421, 0., 0., 0., 0., 11.6569, 14.0711, 0., + 23.3137], [0., -1., 0., 0., 0., 0., 9.24264, 9.24264, 0., + 16.4853], [0., -0.414214, 0., 0., 0., 0., 4.82843, 3.41421, 0., + 6.82843], [0., 0., 0., 0., 0., 0., 1., 0., 0., 0.], [0., 0., 0., + 0., 0., 0., 0., 1., 0., 0.], [0., -0.242641, 0., 0., 0., 0., 2., + 2.58579, 0., 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]), + np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 1., 0., 0., 0., 0., + 0., 0., 0., 0.], [2., 6.82843, -1., 0., 0., 0., 0., 0., 0., + 6.82843], [5.82843, 14.0711, -2.41421, 0., 0., 0., 0., 0., 0., + 16.4853], [9.24264, 18.4853, -3.41421, 0., 0., 0., 0., 0., 0., + 23.3137], [10.2426, 17.4853, -3.41421, 0., 0., 0., 0., 0., 0., + 23.3137], [8.24264, 11.6569, -2.41421, 0., 0., 0., 0., 0., 0., + 16.4853], [4.41421, 4.41421, -1., 0., 0., 0., 0., 0., 0., + 6.82843], [1.75736, 3.17157, -0.585786, 0., 0., 0., 0., 0., 0., + 3.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])] + + root = Node([3.61312592975275, 3.61312592975275, 3.61312592975275, \ +3.61312592975275, 3.61312592975275, 3.61312592975275, \ +3.61312592975275, 3.61312592975275, 2.23982880884355, \ +-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 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") + 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 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") + 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 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") + 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