def randomPairing(n, w=None, seed=None): '''generates a (uniformly) random non-crossing pairing of length 2n If w != None, then generates a pairing from a Galton-Watson tree with weight sequence w''' if w == None: path = dp.randomDyckPath(n, seed=seed) else: tree = ut.randomTree(n + 1, w, seed=seed) path = ut.treeToDyckPath(tree) prng = Pairing(path) return prng
def main(): print('OrderedTree methods are used') w = np.array([1] * 3) #rw = tu.rescale(w) #This rescaling is done in function that generates Lukasiewicz path #print(rw) n = 10 seed = 12345 #seed = 0 #(random - changing from one execution to another) tr = randomTree(n, w, SEED=seed) #tr = randomBTree(n, SEED = seed) print(tr) tr.draw(drawLabels=True) heights, sizes = tr.calcHeightsSizes(0) print("heights = " + str(heights)) print("sizes = " + str(sizes)) ''' These are some drawings and calculations associated with Slim Trees ''' n = 400 #n = 20 seed = 12345 seed = 0 k = 10 tr = randomSlimTree(k, n, SEED=seed) #print(tr) #fig, ax = tr.draw(drawLabels = True, block = False) #fig, ax = tr.draw(drawLabels = False, block = False) #fig1, (ax1, ax2) = plt.subplots(nrows=1, ncols=2) _, ax = tr.draw(drawLabels=False, block=False) H, v = tr.height() dist = tr.heightVertex(v) print("Height of vertex " + str(v) + " is " + str(dist)) tr.drawPathToVertex(ax, v) print("Height of the tree is " + str(H)) v = 1 S = tr.sizeVertex(v) print("size of vertex " + str(v) + " is " + str(S)) n = 5 seed = 3 path = dp.randomDyckPath(n, seed=seed) print("path = ", path) tr = fromDyck(path) _, ax = tr.draw(drawLabels=True, block=False) plt.show()
def main(): ''' #Generate and prints a random tree (weighted) n = 100 w = [1, 1, 1] tree = randomTree(n, w) print(tree) tree.draw(drawLabels = True) #Creates a random Dyck path and plot it #path = randomDyckPath(n) path = treeToDyckPath(tree) #print(path) S = np.cumsum([0] + path) fig1, ax1 = plt.subplots(nrows=1, ncols=1) ax1.plot(S) ax1.grid(True) ax1.xaxis.set_ticks(np.arange(0,S.shape[0])) ax1.yaxis.set_ticks(np.arange(0, np.max(S) + 1)) #Generates a random meander, finds a random cluster cycle (all #point in the cycle are near each other and prints them. n = 100 mndr = mr.randomMeander(n) fig, ax = mndr.draw() clusters = findQuasiClusters(mndr) print("clusters = \n", clusters) #here it looks for the largest quasi cluster cycle -- some gaps are allowed. mgs = 9 cycle = largestCluster(mndr, max_gap_size = mgs) print("Largest quasi cluster cycle is ", cycle) print("Its length is ", largestClusterLength(mndr, max_gap_size= mgs)) mndr.drawCycle(cycle, ax = ax) ''' #let us generate all non-crossing pairings of length n n = 6 A = allPairings(n) print(len(A)) ''' p = [3, 2, 1, 0, 5, 4] q = [1, 0, 3, 2, 5, 4] mndr = Meander(p, q) mndr.draw() x = dot(p, q) print(x) ''' M = dotMatrix(n) print(type(M)) print(M) path = "/Users/vladislavkargin/Dropbox/Programs/forPapers/Meanders/" print(os.path.isdir(path)) np.savetxt(path + "Matrix" + str(n) + ".csv", M.astype(int), delimiter=',') w = la.eigvalsh(M) print(w) q = 0.5 #q = 7/8 Mq = q**(n - M) print(Mq) w = la.eigvalsh(Mq) print("Eigenvalues: ", w) print("Maximum eigenvalue: ", max(w)) print("Minimal Eigenvalue: ", min(w)) print("Minimal Eigenvalue * C_n^2: ", min(w) * (Mq.shape[0]**2)) print("Number of Negative Eigenvalues: ", (w[w < 0]).shape[0]) print("Index: ", (w[w > 0]).shape[0] - (w[w < 0]).shape[0]) plt.plot(w) plt.grid() ''' I used this for an example in my Math 447 class. plotRandomProperMeander(5) plt.grid(True) ''' '''This is for paper. It is now available as a notebook in Colab''' ''' seed = 3 n = 5 path1 = randomDyckPath(n, seed = seed) plotDyckPath(path1) prng1 = pg.Pairing(path = path1) prng1.draw() area = areaDyckPath(path1) print("Area of path1 is ", area) path2 = randomDyckPath(n, seed = seed + 2) #plotDyckPath(path2, method = "lowerLatticePath") area = areaDyckPath(path2) print("Area of path2 is ", area) prng2 = pg.Pairing(path = path2) mndr = Meander(prng1, prng2) mndr.draw(drawCycles=True) mr.drawAsPolygon(mndr) ''' seed = 3 n = 10 path1 = dp.randomDyckPath(n, seed=seed) dp.plotDyckPath(path1) area = dp.areaDyckPath(path1) print("Area of path1 is ", area) nvalleys = len(dp.valleys(path1)) print("Number of valleys is ", nvalleys) n = 4 np.random.seed() perm = np.random.permutation(n) print(perm) cycles = cmb.cyclesOfPerm(perm) print(cycles) plt.show()
def random231perm(n): ''' generates a random 231 permutation of n objects, like 3 0 2 1 for n = 4''' path = dp.randomDyckPath(n) p = dp.pathTo231perm(path) return p