1 line
8 KiB
Text
1 line
8 KiB
Text
|
|
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"fractaldimension.ipynb","provenance":[],"authorship_tag":"ABX9TyPDGTZCMhlplMpdJFPM0/7i"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","metadata":{"id":"uo4kxbshsfPU","executionInfo":{"status":"ok","timestamp":1622567114654,"user_tz":240,"elapsed":118,"user":{"displayName":"Dylan Torrance","photoUrl":"","userId":"06723129446585093176"}}},"source":["import random\n","import matplotlib.pyplot as plt\n","from scipy.optimize import curve_fit\n","import numpy as np\n","import math"],"execution_count":27,"outputs":[]},{"cell_type":"code","metadata":{"id":"G01gxmY2QI64"},"source":["####This is poor generator stuff, you can ignore \n","\n","shrink = np.array([[1,0,0,0,0,0,0,0],\n"," [0,0,1,0,0,0,0,0],\n"," [0,0,0,0,0,1,0,0],\n"," [0,0,0,0,0,0,0,1]])\n","q = np.linalg.inv(np.array([[1,-3,-3,-3],\n"," [-3,1,-3,-3],\n"," [-3,-3,1,-3],\n"," [-3,-3,-3,1]]))\n","\n","#take transpose of row reduced gram matrix to get linear relations \n","#pivot columns work \n","\n","linrel = 1/2 * np.array([[2,0,0,0],\n"," [1,1,-1,1],\n"," [0,2,0,0],\n"," [1,1,1,-1],\n"," [-1,1,1,1],\n"," [0,0,2,0],\n"," [1,-1,1,1],\n"," [0,0,0,2]])\n","alpha = np.array([2*math.sqrt(2),2*math.sqrt(2),2*math.sqrt(2),2*math.sqrt(2),0,0,0,0])\n","\n","wtpw = np.matmul(linrel,np.matmul(q,shrink))\n","i = np.identity(8)\n","\n","curv = np.array([-1,2,7,4,11,8,3,6])\n","\n","print(i - 2* np.matmul(np.outer(alpha,alpha),wtpw)/abs(np.matmul(alpha,np.matmul(wtpw,alpha))))\n","\n","print(np.matmul((i - 2*np.matmul(np.outer(alpha,alpha),wtpw)/abs(np.matmul(alpha,np.matmul(wtpw,alpha)))), curv))\n","\n"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"xY_oNcRDl797"},"source":["##This is just a demonstration of how it might walk over the words, can ignore unless you want to see that, not used in the actual calculation.\n","\n","word = [1]\n","while word:\n"," print(word)\n"," if random.uniform(0, len(word))<1:\n"," word = over(word)\n"," else:\n"," word = down(word)"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"5GPpjyI9ivpl","executionInfo":{"status":"ok","timestamp":1622567124989,"user_tz":240,"elapsed":490,"user":{"displayName":"Dylan Torrance","photoUrl":"","userId":"06723129446585093176"}}},"source":["##These are the main functions used for \n","\n","\n","#function that returns the new curvature for the nth generator, just for checking whether we should go deeper into the word tree or start going down \n","def transval(n,root):\n"," return 2*sum(root)-3*root[n-1]\n","\n","#function for when the word would have given a curvature that is too big \n","def down(word): \n"," #if not word:\n"," #return word #this is older stuff you can probably ignore\n","\n"," if word[-1] == 4: #if the word ends in the last generator, drop that and repeat this whole function with that new word\n"," word.pop()\n"," word = down(word)\n"," elif len(word)>1 and word[-1]+1==word[-2]: #if the word has length 2 and the last two generators are n+1, n\n"," if word[-1]==3: #if the word ended in \"43\", then drop those two (since that is as far as we could go in this part of the tree), and if it is nonempty, then call this whole function again \n"," word.pop()\n"," word.pop()\n"," if word: \n"," word = down(word)\n"," else: #if it ended in somehting like \"21\", then that becomes \"23\", like it skips over \"22,\" since that wouldn't be reduced.\n"," word[-1]=word[-1]+2\n"," else: #if it wasn't one of the weird above cases then just change the last generator to the one after that \n"," word[-1]=word[-1]+1\n"," return word\n","\n","#function for when the word gives a curvature that's still under the bound\n","#just adds a 1 or 2 at the end of the word, which is basically like the left-most
|