├── .gitignore ├── craw2binned ├── src ├── RW_200s7.png ├── LERW_200s7.png ├── RW_200s7hdpi.png ├── LERW_200s7hdpi.png ├── LERW_fromCoord.png ├── LERW_fromCoord.py ├── LoopErasedRandomWalk.py ├── RWandLERW.py └── BD_LERW.py ├── plots ├── BD_LERW_stats.png ├── BD_LERW_intersection_(horiz_dis).png ├── BD_LERW_intersection_(verti_dis).png ├── hist │ ├── cbins │ │ └── LERW_cluster_sizes_50_histogram.png │ └── dbins │ │ ├── LERW_cluster_sizes_50_histogram.png │ │ ├── RW1D_cluster_sizes_50_histogram.png │ │ ├── RW2D_cluster_sizes_50_histogram.png │ │ ├── LERW_cluster_sizes_100_histogram.png │ │ ├── LERW_cluster_sizes_200_histogram.png │ │ ├── LERW_cluster_sizes_400_histogram.png │ │ ├── RW1D_cluster_sizes_100_histogram.png │ │ ├── RW1D_cluster_sizes_200_histogram.png │ │ ├── RW1D_cluster_sizes_400_histogram.png │ │ ├── RW2D_cluster_sizes_100_histogram.png │ │ ├── RW2D_cluster_sizes_200_histogram.png │ │ └── RW2D_cluster_sizes_400_histogram.png ├── LERW_horizontal_displacement_distribution_loglog.png └── LERW_horizontal_displacement_distribution_histogram.png ├── jobs ├── qsub_RW.sh ├── qsub_LERW.sh ├── qsub_LERW_series.sh ├── qsub_RW1D_series.sh └── qsub_RW2D_series.sh ├── README.md ├── BD_LERW_ratio.py ├── BD_LERW_area.py ├── LERW_fromCoord.py ├── RW1D_cluster_sizes.py ├── LERW_cluster_sizes.py ├── raw2hist_dbins.py ├── RW_cluster_sizes.py ├── raw2hist_cbins.py ├── LERW_horizontal_displacement_distribution.py ├── BD_LERW_intersection.py ├── RW2D_cluster_sizes.py ├── BD_LERW_stats.py ├── LERW.py ├── raw2binned.c ├── craw2binned.c └── ItsNot_ThreeHalves.ps /.gitignore: -------------------------------------------------------------------------------- 1 | stud/ 2 | archive/ 3 | data/ -------------------------------------------------------------------------------- /craw2binned: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/craw2binned -------------------------------------------------------------------------------- /src/RW_200s7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/src/RW_200s7.png -------------------------------------------------------------------------------- /src/LERW_200s7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/src/LERW_200s7.png -------------------------------------------------------------------------------- /src/RW_200s7hdpi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/src/RW_200s7hdpi.png -------------------------------------------------------------------------------- /src/LERW_200s7hdpi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/src/LERW_200s7hdpi.png -------------------------------------------------------------------------------- /src/LERW_fromCoord.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/src/LERW_fromCoord.png -------------------------------------------------------------------------------- /plots/BD_LERW_stats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/BD_LERW_stats.png -------------------------------------------------------------------------------- /plots/BD_LERW_intersection_(horiz_dis).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/BD_LERW_intersection_(horiz_dis).png -------------------------------------------------------------------------------- /plots/BD_LERW_intersection_(verti_dis).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/BD_LERW_intersection_(verti_dis).png -------------------------------------------------------------------------------- /plots/hist/cbins/LERW_cluster_sizes_50_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/cbins/LERW_cluster_sizes_50_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/LERW_cluster_sizes_50_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/LERW_cluster_sizes_50_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/RW1D_cluster_sizes_50_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/RW1D_cluster_sizes_50_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/RW2D_cluster_sizes_50_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/RW2D_cluster_sizes_50_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/LERW_cluster_sizes_100_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/LERW_cluster_sizes_100_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/LERW_cluster_sizes_200_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/LERW_cluster_sizes_200_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/LERW_cluster_sizes_400_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/LERW_cluster_sizes_400_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/RW1D_cluster_sizes_100_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/RW1D_cluster_sizes_100_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/RW1D_cluster_sizes_200_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/RW1D_cluster_sizes_200_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/RW1D_cluster_sizes_400_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/RW1D_cluster_sizes_400_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/RW2D_cluster_sizes_100_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/RW2D_cluster_sizes_100_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/RW2D_cluster_sizes_200_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/RW2D_cluster_sizes_200_histogram.png -------------------------------------------------------------------------------- /plots/hist/dbins/RW2D_cluster_sizes_400_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/hist/dbins/RW2D_cluster_sizes_400_histogram.png -------------------------------------------------------------------------------- /plots/LERW_horizontal_displacement_distribution_loglog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/LERW_horizontal_displacement_distribution_loglog.png -------------------------------------------------------------------------------- /plots/LERW_horizontal_displacement_distribution_histogram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hr/RandomWalk/exp/plots/LERW_horizontal_displacement_distribution_histogram.png -------------------------------------------------------------------------------- /jobs/qsub_RW.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## one day 3 | #PBS -l walltime=15:00:00 4 | #PBS -l mem=1000mb 5 | #PBS -l ncpus=1 6 | 7 | cd $PBS_O_WORKDIR 8 | 9 | echo script $0 10 | pwd 11 | hostname 12 | date 13 | time ./RW_cluster_sizes.py > RW_cluster_sizes.dat 2>&1 14 | date 15 | -------------------------------------------------------------------------------- /jobs/qsub_LERW.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## one day 3 | #PBS -l walltime=15:00:00 4 | #PBS -l mem=1000mb 5 | #PBS -l ncpus=1 6 | 7 | cd $PBS_O_WORKDIR 8 | 9 | echo script $0 10 | pwd 11 | hostname 12 | date 13 | time ./LERW_horizontal_displacement_distribution.py > LERW_horizontal_displacement_distribution.dat 2>&1 14 | date 15 | -------------------------------------------------------------------------------- /jobs/qsub_LERW_series.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## one day 3 | #PBS -l walltime=15:00:00 4 | #PBS -l mem=1000mb 5 | #PBS -l ncpus=1 6 | 7 | cd $PBS_O_WORKDIR 8 | 9 | echo script $0 10 | pwd 11 | hostname 12 | date 13 | s=30001 14 | for L in 50 100 200 400 15 | do 16 | s=$(( $s + 5 )) 17 | time ./LERW_cluster_sizes.py -i 100000 -L $L -C $L -s $s > LERW_cluster_sizes_${L}.dat 2>&1 18 | done 19 | date 20 | -------------------------------------------------------------------------------- /jobs/qsub_RW1D_series.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## one day 3 | #PBS -l walltime=15:00:00 4 | #PBS -l mem=1000mb 5 | #PBS -l ncpus=1 6 | 7 | cd $PBS_O_WORKDIR 8 | 9 | echo script $0 10 | pwd 11 | hostname 12 | date 13 | s=20001 14 | for L in 50 100 200 400 15 | do 16 | s=$(( $s + 5 )) 17 | time ./RW1D_cluster_sizes.py -i 100000 -L $L -C $L -s $s > RW1D_cluster_sizes_${L}.dat 2>&1 18 | done 19 | date 20 | -------------------------------------------------------------------------------- /jobs/qsub_RW2D_series.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## one day 3 | #PBS -l walltime=15:00:00 4 | #PBS -l mem=1000mb 5 | #PBS -l ncpus=1 6 | 7 | cd $PBS_O_WORKDIR 8 | 9 | echo script $0 10 | pwd 11 | hostname 12 | date 13 | s=10001 14 | for L in 50 100 200 400 15 | do 16 | s=$(( $s + 5 )) 17 | time ./RW2D_cluster_sizes.py -i 100000 -L $L -C $L -s $s > RW2D_cluster_sizes_${L}.dat 2>&1 18 | done 19 | date 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Random Walks 2 | An implementation of random walks (*RW*) and loop erased random walks (*LERW*) in Python. This is the code produced for the research on the statistics of random walks, particularly loop erased random walks, conducted by Habib Rehman (@HR) and Dr. Gunnar Pruessner (g.pruessner@imperial.ac.uk) of the Imperial College London. 3 | 4 | To consider: 5 | 1. Statistics of enclosed area between bidirectional LERWs 6 | 2. Statistics of the area 7 | 3. Statistics of intersections 8 | 4. Average distribution/variance of the number of intersections 9 | 5. Average eccentricity of ellipse 10 | 11 | This repo is also accesible via the shortened link http://git.io/RandomWalk 12 | -------------------------------------------------------------------------------- /BD_LERW_ratio.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Bidirectional Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory 7 | # Distribution of the displacement of the intersections 8 | # Habib Rehmann and Gunnar Pruessner 9 | # 10 | import numpy as np 11 | import matplotlib.pyplot as plt 12 | from LERW import LERW 13 | 14 | intr = [] 15 | randomwalk = LERW() 16 | randomwalk.gen_bidirectional(realizations=5, Length=200, Circ=200) 17 | LERW_LeftRight = randomwalk.trajectories_leftright 18 | LERW_RightLeft = randomwalk.trajectories_rightleft 19 | 20 | for i in range(len(LERW_RightLeft)): 21 | intersection = set(LERW_LeftRight[i]).intersection(LERW_RightLeft[i]) 22 | if intersection: 23 | intr.append(intersection) 24 | 25 | 26 | 27 | # Distribution of the horizontal displacement of the intersections 28 | # x = np.array([x[0] for i in range(len(intr)) for x in intr[i]]) 29 | 30 | print("The ratio of number intersections to the total number of coordinates is {}:{} = {}".format(len(intr), len(LERW_RightLeft), float(len(intr)/len(LERW_RightLeft)))) 31 | -------------------------------------------------------------------------------- /BD_LERW_area.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Bidirectional Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory 7 | # Distribution of the displacement of the intersections 8 | # Habib Rehmann and Gunnar Pruessner 9 | # 10 | 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | from LERW import LERW 14 | 15 | n = 1 16 | length = 20 17 | areas = [] # list of intersections' enclosed area 18 | 19 | randomwalk = LERW() 20 | randomwalk.gen_bidirectional(realizations=n, Length=length, Circ=20) 21 | LERW_LeftRight = randomwalk.trajectories_leftright[0] 22 | LERW_RightLeft = randomwalk.trajectories_rightleft[0] 23 | # Calc: enclosed area between the intersections of bidirectional random walks 24 | 25 | 26 | for i in range(length): 27 | lr = [x for j, x in enumerate(LERW_LeftRight) if x[0] == i] 28 | rl = [x for j, x in enumerate(LERW_RightLeft) if x[0] == i] 29 | 30 | if len(lr) > 1 or len(rl) > 1: 31 | print("At {}:\n\tleft-right: {}, \n\tright-left: {}".format(i, lr, rl)) 32 | # 33 | # print areas 34 | 35 | 36 | 37 | # Plot random walk 38 | # plt.savefig(__file__[:-3]+".png", bbox_inches="tight", dpi=250) 39 | -------------------------------------------------------------------------------- /LERW_fromCoord.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory. 7 | # Habib Rehmann and Gunnar Pruessner 8 | # 9 | 10 | 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | import random 14 | from LERW import LERW 15 | import itertools 16 | 17 | 18 | randomwalk = LERW() 19 | randomwalk.gen_fromCoord(realizations=8, Length=200, Circ=200) 20 | # x = np.array(x) 21 | 22 | for walk in randomwalk.trajectories: 23 | randomwalk.plot(LERW=walk, c=random.choice(['b', 'g', 'r', 'c', 'm', 'y', 'k'])) 24 | 25 | # Distribution of size of loops erased with repect to displacement histogram 26 | 27 | # the histogram of the data 28 | # n, bins, patches = plt.hist(x, bins=150, normed=1, facecolor='green', alpha=0.75) 29 | # 30 | # plt.xlabel('Size of loops erased for coordinate') 31 | # plt.ylabel('Frequency') 32 | # plt.yscale('log', nonposy='clip') 33 | # plt.xscale('log', nonposy='clip') 34 | # # plt.loglog(x, basex=2) 35 | # plt.title(r'$\mathrm{Histogram\ of\ the\ horizontal\ displacement\ distribution:}\ $') 36 | # plt.grid(True) 37 | # 38 | # plt.savefig("plots/"+__file__[:-3]+"_histogram.png", bbox_inches="tight") 39 | -------------------------------------------------------------------------------- /RW1D_cluster_sizes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Escape time of a random walker from a cylinder with reflecting 4 | # boundaries on the left and open boundaries on the right. 5 | # PNG output of a single trajectory. 6 | # Habib Rehmann and Gunnar Pruessner 7 | # 8 | 9 | import random 10 | 11 | # https://docs.python.org/2/howto/argparse.html 12 | import argparse 13 | parser = argparse.ArgumentParser() 14 | parser.add_argument("-s", "--seed", type=int, help="seed of the RNG", default=7) 15 | parser.add_argument("-L", "--Length", type=int, help="length of the system (PBC apply)", default=200) 16 | parser.add_argument("-i", "--iterations", type=int, help="iterations", default=100) 17 | args = parser.parse_args() 18 | 19 | 20 | print "# Info: seed = ", args.seed 21 | print "# Info: Length = ", args.Length 22 | print "# Info: iterations = ", args.iterations 23 | 24 | xStart = 0 25 | 26 | random.seed(args.seed) # set random seed 27 | for i in range(args.iterations): 28 | x = xStart # x coordinate of point. 29 | 30 | # Generate a randomwalk 31 | s=0 32 | while True: 33 | s += 1 34 | if (bool(random.getrandbits(1))): 35 | x += 1 36 | else: 37 | x -= 1 38 | if (x >= args.Length): 39 | x -= args.Length 40 | if (x < 0): 41 | x += args.Length 42 | if (x==xStart): 43 | print s 44 | break 45 | 46 | -------------------------------------------------------------------------------- /LERW_cluster_sizes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory. 7 | # Habib Rehmann and Gunnar Pruessner 8 | # 9 | 10 | 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | from LERW import LERW 14 | import itertools 15 | 16 | # https://docs.python.org/2/howto/argparse.html 17 | import argparse 18 | parser = argparse.ArgumentParser() 19 | parser.add_argument("-s", "--seed", type=int, help="seed of the RNG", default=7) 20 | parser.add_argument("-L", "--Length", type=int, help="length of the system", default=200) 21 | parser.add_argument("-C", "--Circ", type=int, help="Circ of the system (PBC apply)", default=200) 22 | parser.add_argument("-i", "--iterations", type=int, help="iterations", default=100) 23 | args = parser.parse_args() 24 | 25 | 26 | print "# Info: seed = ", args.seed 27 | print "# Info: Length = ", args.Length 28 | print "# Info: Circ = ", args.Circ 29 | print "# Info: iterations = ", args.iterations 30 | 31 | 32 | randomwalk = LERW(seed=args.seed) 33 | randomwalk.generate(realizations=args.iterations, Length=args.Length, Circ=args.Circ) 34 | ELsizes = randomwalk.ErasedLoopSizes 35 | x = list(itertools.chain(*ELsizes)) 36 | 37 | for s in list(itertools.chain(*ELsizes)): 38 | print s 39 | -------------------------------------------------------------------------------- /raw2hist_dbins.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Bidirectional Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory 7 | # Distribution of the displacement of the intersections 8 | # Habib Rehmann and Gunnar Pruessner 9 | # 10 | import numpy as np 11 | import matplotlib.pyplot as plt 12 | from LERW import LERW 13 | import subprocess 14 | 15 | dpath = "data/qsub/" 16 | spath = "plots/hist/dbins/" 17 | p = subprocess.Popen(['ls', '-v', dpath], stdout=subprocess.PIPE) 18 | fnames = p.communicate()[0].split('\n')[:-1] 19 | data = [] 20 | 21 | # Using matplotlib generated bin sizes 22 | for fname in fnames: 23 | for line in open(dpath+fname): 24 | if (line.strip()).isdigit(): 25 | data.append(int(line.strip())) 26 | 27 | 28 | # # Distribution of the horizontal displacement of the intersections 29 | x = np.array(data) 30 | n, bins, patches = plt.hist(x, 70, normed=1, facecolor='green', alpha=0.75) 31 | 32 | plt.yscale('log', nonposy='clip') 33 | plt.xscale('log', nonposy='clip') 34 | plt.xlabel('Cluster size (sys size: {})'.format(fname[-6:-4])) 35 | plt.ylabel('Frequency') 36 | plt.title(r'$\mathrm{'+fname[:-4].replace('_', '\ ')+':}\ $') 37 | plt.grid(True) 38 | 39 | plt.savefig(spath+fname[:-4]+"_histogram.png", bbox_inches="tight") 40 | -------------------------------------------------------------------------------- /RW_cluster_sizes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Escape time of a random walker from a cylinder with reflecting 4 | # boundaries on the left and open boundaries on the right. 5 | # PNG output of a single trajectory. 6 | # Habib Rehmann and Gunnar Pruessner 7 | # 8 | 9 | import random 10 | from numpy import cos, sin, radians 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | 14 | seed = 7 15 | N = 1 # Stepsize 16 | Length = 200 # length of the cyclinder 17 | Circ = 200 # circumference of cyclinder 18 | xStart = 0 # x coordinate of starting location. Origin is at centre of square 19 | yStart = Circ / 2 20 | 21 | # 200x200 with 200 realisations take about 50s on yangtze 22 | 23 | random.seed(seed) # set random seed 24 | for i in range(5000): 25 | x = xStart # x coordinate of point. 26 | y = yStart # y coordinate of point. 27 | 28 | # Generate a randomwalk 29 | s=0 30 | while True: 31 | s += 1 32 | if (bool(random.getrandbits(1))): 33 | if (bool(random.getrandbits(1))): 34 | x += 1 35 | else: 36 | x -= 1 37 | else: 38 | if (bool(random.getrandbits(1))): 39 | y += 1 40 | else: 41 | y -= 1 42 | 43 | if (x >= Length): 44 | x -= Length 45 | if (x < 0): 46 | x += Length 47 | if (y >= Circ): 48 | y -= Circ 49 | if (y < 0): 50 | y += Circ 51 | 52 | if ((x==xStart) and (y==yStart)): 53 | print s 54 | break 55 | 56 | -------------------------------------------------------------------------------- /raw2hist_cbins.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Bidirectional Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory 7 | # Distribution of the displacement of the intersections 8 | # Habib Rehmann and Gunnar Pruessner 9 | # 10 | import numpy as np 11 | import matplotlib.pyplot as plt 12 | from LERW import LERW 13 | import subprocess 14 | import os 15 | 16 | dpath = "data/qsub/" 17 | spath = "plots/hist/cbins/" 18 | p = subprocess.Popen(['ls', '-v', dpath], stdout=subprocess.PIPE) 19 | fnames = p.communicate()[0].split('\n')[:-1] 20 | fname = "LERW_cluster_sizes_50.dat" 21 | 22 | for fname in fnames: 23 | p = subprocess.Popen(['./craw2binned', '-f', dpath+fname], stdout=subprocess.PIPE) 24 | bins = p.communicate()[0].split('\n')[:-1] 25 | x, y = [], [] 26 | for coord in bins: 27 | x.append(coord.split('\t')[0]) 28 | y.append(coord.split('\t')[1]) 29 | x, y = np.array(x), np.array(y) 30 | 31 | 32 | # Distribution of cluster sizes 33 | #n, bins, patches = plt.hist(x, 70, normed=1, facecolor='green', alpha=0.75) 34 | 35 | plt.yscale('log', nonposy='clip') 36 | plt.xscale('log', nonposy='clip') 37 | plt.xlabel('Cluster size (sys size: {})'.format(fname[-6:-4])) 38 | plt.ylabel('Frequency') 39 | plt.title(r'$\mathrm{'+fname[:-4].replace('_', '\ ')+':}\ $') 40 | plt.grid(True) 41 | plt.plot(x, y) 42 | 43 | plt.savefig(spath+fname[:-4]+"_histogram.png", bbox_inches="tight") 44 | -------------------------------------------------------------------------------- /LERW_horizontal_displacement_distribution.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory. 7 | # Habib Rehmann and Gunnar Pruessner 8 | # 9 | 10 | 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | from LERW import LERW 14 | import itertools 15 | 16 | 17 | randomwalk = LERW() 18 | randomwalk.generate(realizations=50, Length=200, Circ=200) 19 | ELsizes = randomwalk.ErasedLoopSizes 20 | x = list(itertools.chain(*ELsizes)) 21 | 22 | # for s in list(itertools.chain(*ELsizes)): 23 | # print s 24 | 25 | 26 | # ELsizes = list(map(list, zip(*ELsizes))) 27 | # x = [] 28 | 29 | # for i in range(len(ELsizes)): 30 | # x.append(np.mean(ELsizes[i])) 31 | x = np.array(x) 32 | # Distribution of size of loops erased with repect to displacement histogram 33 | 34 | # the histogram of the data 35 | n, bins, patches = plt.hist(x, bins=150, normed=1, facecolor='green', alpha=0.75) 36 | 37 | plt.xlabel('Size of loops erased for coordinate') 38 | plt.ylabel('Frequency') 39 | plt.yscale('log', nonposy='clip') 40 | plt.xscale('log', nonposy='clip') 41 | # plt.yscale('log') 42 | # plt.xscale('log') 43 | # plt.loglog(x, basex=2) 44 | plt.title(r'$\mathrm{Histogram\ of\ the\ horizontal\ displacement\ distribution:}\ $') 45 | plt.grid(True) 46 | 47 | plt.savefig("plots/"+__file__[:-3]+"_histogram.png", bbox_inches="tight") 48 | 49 | # x = [ pow(10,i) for i in x] 50 | # plt.title(r'$\mathrm{Double\ logarithmic\ (scales)\ plot\ for\ distribution:}\ $') 51 | # plt.grid(True) 52 | # plt.loglog(x, pow(x, 10) , basex=2) 53 | # plt.savefig("plots/"+__file__[:-3]+"_loglog.png", bbox_inches="tight", dpi=200) 54 | -------------------------------------------------------------------------------- /BD_LERW_intersection.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Bidirectional Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory 7 | # Distribution of the displacement of the intersections 8 | # Habib Rehmann and Gunnar Pruessner 9 | # 10 | import numpy as np 11 | import matplotlib.pyplot as plt 12 | from LERW import LERW 13 | 14 | intr = [] 15 | randomwalk = LERW() 16 | randomwalk.gen_bidirectional(realizations=5, Length=200, Circ=200) 17 | LERW_LeftRight = randomwalk.trajectories_leftright 18 | LERW_RightLeft = randomwalk.trajectories_rightleft 19 | # plt.plot(*zip(*lerwrl), color='g', linewidth=0.3) 20 | for i in range(len(LERW_RightLeft)): 21 | intr.append(list(set(LERW_LeftRight[i]).intersection(LERW_RightLeft[i]))) 22 | 23 | 24 | 25 | # Distribution of the horizontal displacement of the intersections 26 | x = np.array([x[0] for i in range(len(intr)) for x in intr[i]]) 27 | n, bins, patches = plt.hist(x, 70, normed=1, facecolor='green', alpha=0.75) 28 | 29 | plt.xlabel('Horizontal displacement') 30 | plt.ylabel('Frequency') 31 | plt.title(r'$\mathrm{Distribution\ of\ the\ horizontal\ displacement\ of\ the\ intersections:}\ $') 32 | plt.grid(True) 33 | 34 | plt.savefig("plots/"+"plots/"+__file__[:-3]+"_(horiz_dis).png", bbox_inches="tight") 35 | 36 | # Distribution of the vertical displacement of the intersections 37 | 38 | # n, bins, patches = plt.hist(x, 70, normed=1, facecolor='green', alpha=0.75) 39 | # 40 | # plt.xlabel('Vertical displacement') 41 | # plt.ylabel('Frequency') 42 | # plt.title(r'$\mathrm{Distribution\ of\ the\ vertical\ displacement\ of\ the\ intersections:}\ $') 43 | # plt.grid(True) 44 | # 45 | # # Plot random walk 46 | # plt.savefig("plots/"+__file__[:-3]+"_(verti_dis).png", bbox_inches="tight") 47 | -------------------------------------------------------------------------------- /RW2D_cluster_sizes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Escape time of a random walker from a cylinder with reflecting 4 | # boundaries on the left and open boundaries on the right. 5 | # PNG output of a single trajectory. 6 | # Habib Rehmann and Gunnar Pruessner 7 | # 8 | 9 | import random 10 | 11 | 12 | # 200x200 with 200 realisations take about 50s on yangtze 13 | 14 | # https://docs.python.org/2/howto/argparse.html 15 | import argparse 16 | parser = argparse.ArgumentParser() 17 | parser.add_argument("-s", "--seed", type=int, help="seed of the RNG", default=7) 18 | parser.add_argument("-L", "--Length", type=int, help="length of the system (PBC apply)", default=200) 19 | parser.add_argument("-C", "--Circ", type=int, help="Circ of the system (PBC apply)", default=200) 20 | parser.add_argument("-i", "--iterations", type=int, help="iterations", default=100) 21 | args = parser.parse_args() 22 | 23 | 24 | print "# Info: seed = ", args.seed 25 | print "# Info: Length = ", args.Length 26 | print "# Info: Circ = ", args.Circ 27 | print "# Info: iterations = ", args.iterations 28 | 29 | xStart = 0 # x coordinate of starting location. Origin is at centre of square 30 | yStart = args.Circ / 2 31 | 32 | random.seed(args.seed) # set random seed 33 | for i in range(args.iterations): 34 | x = xStart # x coordinate of point. 35 | y = yStart # y coordinate of point. 36 | 37 | # Generate a randomwalk 38 | s=0 39 | while True: 40 | s += 1 41 | if (bool(random.getrandbits(1))): 42 | if (bool(random.getrandbits(1))): 43 | x += 1 44 | else: 45 | x -= 1 46 | else: 47 | if (bool(random.getrandbits(1))): 48 | y += 1 49 | else: 50 | y -= 1 51 | 52 | if (x >= args.Length): 53 | x -= args.Length 54 | if (x < 0): 55 | x += args.Length 56 | if (y >= args.Circ): 57 | y -= args.Circ 58 | if (y < 0): 59 | y += args.Circ 60 | 61 | if ((x==xStart) and (y==yStart)): 62 | print s 63 | break 64 | 65 | -------------------------------------------------------------------------------- /src/LERW_fromCoord.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory. 7 | # Habib Rehmann and Gunnar Pruessner 8 | # 9 | 10 | import random 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | 14 | seed = 10 # random seed 15 | Length = 20 # length of the cyclinder 16 | Circ = 20 # circumference of cyclinder 17 | s = 0 # Step number. 18 | 19 | trajectory = [] # List of the x coordinates of all points visited. 20 | # (Length x Circ) 2D array of zeros 21 | lattice = np.zeros((Length, Circ), dtype=int) 22 | random.seed(seed) 23 | 24 | xStart = random.randint(0, Length) # x coordinate of starting location 25 | yStart = random.randint(0, Length) # y coordinate of starting location 26 | x, y = xStart, yStart 27 | 28 | # Generate a randomwalk 29 | while True: 30 | s += 1 31 | if (bool(random.getrandbits(1))): 32 | if (bool(random.getrandbits(1))): 33 | x += 1 34 | else: 35 | x -= 1 36 | else: 37 | if (bool(random.getrandbits(1))): 38 | y += 1 39 | else: 40 | y -= 1 41 | 42 | # Periodic boundaries 43 | if (x >= Length): 44 | x -= Length 45 | elif (x < 0): 46 | x += Length 47 | if (y >= Circ): 48 | y -= Circ 49 | elif (y < 0): 50 | y += Circ 51 | 52 | if (x == xStart and y == yStart): 53 | break 54 | 55 | lattice[x][y] += 1 56 | trajectory.append((x, y)) 57 | 58 | x0 = None 59 | y0 = None 60 | pos = 0 61 | 62 | # Loop erasure 63 | while pos < len(trajectory): 64 | x, y = trajectory[pos] 65 | if lattice[x][y] > 1 and (not x0): 66 | x0, y0 = x, y 67 | pos0 = pos 68 | elif (x == x0) and (y == y0) and (lattice[x][y] == 1): 69 | del trajectory[pos0:pos] 70 | x0, y0 = None, None 71 | pos = pos0 72 | lattice[x][y] -= 1 73 | pos += 1 74 | 75 | # Plot random walk 76 | dpi = 300 77 | fig, ax = plt.subplots() 78 | fig.set_size_inches(3, Circ * 3. / Length) 79 | ax.set_xlim(0, Length - 1) 80 | ax.set_ylim(0, Circ - 1) 81 | ax.get_xaxis().set_visible(False) 82 | ax.get_yaxis().set_visible(False) 83 | plt.plot(*zip(*trajectory), marker=".",linewidth=0.3) 84 | plt.savefig("plots/"+__file__[:-3]+".png", bbox_inches="tight", dpi=dpi) 85 | -------------------------------------------------------------------------------- /src/LoopErasedRandomWalk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory. 7 | # Habib Rehmann and Gunnar Pruessner 8 | # 9 | 10 | import random 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | 14 | seed = 10 # random seed 15 | Length = 200 # length of the cyclinder 16 | Circ = 200 # circumference of cyclinder 17 | x = 0 # x coordinate of starting location 18 | # y coordinate of starting location. Origin is at centre of square 19 | y = Circ / 2 20 | s = 7 # Step number. 21 | 22 | trajectory = [] # List of the x coordinates of all points visited. 23 | # (Length x Circ) 2D array of zeros 24 | lattice = np.zeros((Length, Circ), dtype=int) 25 | random.seed(seed) 26 | 27 | # Generate a randomwalk 28 | while True: 29 | s += 1 30 | if (bool(random.getrandbits(1))): 31 | if (bool(random.getrandbits(1))): 32 | x += 1 33 | else: 34 | x -= 1 35 | else: 36 | if (bool(random.getrandbits(1))): 37 | y += 1 38 | else: 39 | y -= 1 40 | 41 | if (x >= Length): 42 | break 43 | elif (x < 0): 44 | x = 0 45 | if (y >= Circ): 46 | y -= Circ 47 | elif (y < 0): 48 | y += Circ 49 | 50 | lattice[x][y] += 1 51 | trajectory.append((x, y)) 52 | 53 | x0 = None 54 | y0 = None 55 | pos = 0 56 | 57 | # Loop erasure 58 | while pos < len(trajectory): 59 | x, y = trajectory[pos] 60 | if lattice[x][y] > 1 and (not x0): 61 | x0, y0 = x, y 62 | pos0 = pos 63 | # print("First repeated element ", pos0, x0, y0) 64 | elif (x == x0) and (y == y0) and (lattice[x][y] == 1): 65 | # print("Deleting from ", pos0, " to ", pos) 66 | del trajectory[pos0:pos] 67 | x0, y0 = None, None 68 | pos = pos0 69 | lattice[x][y] -= 1 70 | pos += 1 71 | 72 | # Plot random walk 73 | dpi = 300 74 | fig, ax = plt.subplots() 75 | fig.set_size_inches(3, Circ * 3. / Length) 76 | ax.set_xlim(0, Length - 1) 77 | ax.set_ylim(0, Circ - 1) 78 | ax.get_xaxis().set_visible(False) 79 | ax.get_yaxis().set_visible(False) 80 | plt.plot(*zip(*trajectory), linewidth=0.3) 81 | plt.savefig(__file__[:-3]+".png", bbox_inches="tight", dpi=dpi) 82 | -------------------------------------------------------------------------------- /src/RWandLERW.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory. 7 | # Habib Rehmann and Gunnar Pruessner 8 | # 9 | 10 | import random 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | 14 | seed = 10 # random seed 15 | Length = 200 # length of the cyclinder 16 | Circ = 200 # circumference of cyclinder 17 | x = 0 # x coordinate of starting location 18 | # y coordinate of starting location. Origin is at centre of square 19 | y = Circ / 2 20 | s = 0 # Step number. 21 | 22 | trajectory = [] # List of the x coordinates of all points visited. 23 | # (Length x Circ) 2D array of zeros 24 | lattice = np.zeros((Length, Circ), dtype=int) 25 | random.seed(seed) 26 | 27 | # Generate a randomwalk 28 | while True: 29 | s += 1 30 | if (bool(random.getrandbits(1))): 31 | if (bool(random.getrandbits(1))): 32 | x += 1 33 | else: 34 | x -= 1 35 | else: 36 | if (bool(random.getrandbits(1))): 37 | y += 1 38 | else: 39 | y -= 1 40 | 41 | if (x >= Length): 42 | break 43 | elif (x < 0): 44 | x = 0 45 | if (y >= Circ): 46 | y -= Circ 47 | elif (y < 0): 48 | y += Circ 49 | 50 | lattice[x][y] += 1 51 | trajectory.append((x, y)) 52 | 53 | x0 = None 54 | y0 = None 55 | pos = 0 56 | 57 | dpi = 500 58 | fig, ax = plt.subplots() 59 | fig.set_size_inches(3, Circ * 3. / Length) 60 | ax.set_xlim(0, Length - 1) 61 | ax.set_ylim(0, Circ - 1) 62 | ax.get_xaxis().set_visible(False) 63 | ax.get_yaxis().set_visible(False) 64 | plt.plot(*zip(*trajectory), color="r", linewidth=0.2) 65 | 66 | # Loop erasure 67 | while pos < len(trajectory): 68 | x, y = trajectory[pos] 69 | if lattice[x][y] > 1 and (not x0): 70 | x0, y0 = x, y 71 | pos0 = pos 72 | # print("First repeated element ", pos0, x0, y0) 73 | elif (x == x0) and (y == y0) and (lattice[x][y] == 1): 74 | # print("Deleting from ", pos0, " to ", pos) 75 | del trajectory[pos0:pos] 76 | x0, y0 = None, None 77 | pos = pos0 78 | lattice[x][y] -= 1 79 | pos += 1 80 | 81 | # Plot random walk 82 | 83 | plt.plot(*zip(*trajectory), linewidth=0.3) 84 | plt.savefig("RandomWalk.png", bbox_inches="tight", dpi=dpi) 85 | -------------------------------------------------------------------------------- /BD_LERW_stats.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Bidirectional Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory. 7 | # Habib Rehmann and Gunnar Pruessner 8 | # 9 | 10 | import random 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | from copy import deepcopy 14 | 15 | seed = 10 # random seed 16 | Length = 200 # length of the cyclinder 17 | Circ = 200 # circumference of cyclinder 18 | x = 0 # x coordinate of starting location 19 | # y coordinate of starting location. Origin is at centre of square 20 | y = Circ / 2 21 | s = 0 # Step number. 22 | 23 | trajectory = [] # List of the x coordinates of all points visited. 24 | # (Length x Circ) 2D array of zeros 25 | lattice = np.zeros((Length, Circ), dtype=int) 26 | random.seed(seed) 27 | 28 | # Plot config 29 | dpi = 300 30 | fig, ax = plt.subplots() 31 | fig.set_size_inches(3, Circ * 3. / Length) 32 | ax.set_xlim(0, Length - 1) 33 | ax.set_ylim(0, Circ - 1) 34 | ax.get_xaxis().set_visible(False) 35 | ax.get_yaxis().set_visible(False) 36 | 37 | def plotit(LERW, c, lw): 38 | Plots = [] 39 | prevInd = 0 40 | for pos in range(len(LERW)): 41 | x, y = LERW[pos] 42 | if (x == Length) or (x == 0) or (y == Circ) or (y == Circ) or (y == 0): 43 | Plots.append(LERW[prevInd:pos]) 44 | prevInd = pos 45 | pos += 1 46 | 47 | for plot in Plots: 48 | plt.plot(*zip(*plot), color=c, linewidth=lw) 49 | 50 | # Generate a randomwalk 51 | while True: 52 | s += 1 53 | if (bool(random.getrandbits(1))): 54 | if (bool(random.getrandbits(1))): 55 | x += 1 56 | else: 57 | x -= 1 58 | else: 59 | if (bool(random.getrandbits(1))): 60 | y += 1 61 | else: 62 | y -= 1 63 | 64 | if (x >= Length): 65 | break 66 | elif (x < 0): 67 | x = 0 68 | if (y >= Circ): 69 | y -= Circ 70 | elif (y < 0): 71 | y += Circ 72 | 73 | lattice[x][y] += 1 74 | trajectory.append((x, y)) 75 | 76 | # Loop erasure (tranversal from left to right) 77 | lerw = deepcopy(trajectory) 78 | lcpy = deepcopy(lattice) 79 | x0, y0 = None, None 80 | pos = 0 81 | 82 | while pos < len(lerw): 83 | x, y = lerw[pos] 84 | if lcpy[x][y] > 1 and (not x0): 85 | x0, y0 = x, y 86 | pos0 = pos 87 | elif (x == x0) and (y == y0) and (lcpy[x][y] == 1): 88 | del lerw[pos0:pos] 89 | x0, y0 = None, None 90 | pos = pos0 91 | lcpy[x][y] -= 1 92 | pos += 1 93 | 94 | # plt.plot(*zip(*lerw), color='b', linewidth=0.3) 95 | plotit(lerw, 'b', 0.3) 96 | 97 | 98 | # Loop erasure (tranversal from right to left) 99 | lerw = deepcopy(trajectory[::-1]) 100 | lcpy = deepcopy(lattice) 101 | x0, y0 = None, None 102 | pos = 0 103 | 104 | while pos < len(lerw): 105 | x, y = lerw[pos] 106 | if lcpy[x][y] > 1 and (not x0): 107 | x0, y0 = x, y 108 | pos0 = pos 109 | elif (x == x0) and (y == y0) and (lcpy[x][y] == 1): 110 | del lerw[pos0:pos] 111 | x0, y0 = None, None 112 | pos = pos0 113 | lcpy[x][y] -= 1 114 | pos += 1 115 | 116 | # plt.plot(*zip(*lerw), color='g', linewidth=0.3) 117 | plotit(lerw, 'g', 0.3) 118 | 119 | # Plot random walk 120 | plt.savefig( "plots/"+__file__[:-3]+".png", bbox_inches="tight", dpi=dpi) 121 | -------------------------------------------------------------------------------- /src/BD_LERW.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Bidirectional Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory. 7 | # Habib Rehmann and Gunnar Pruessner 8 | # 9 | 10 | import random 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | from copy import deepcopy 14 | 15 | seed = 10 # random seed 16 | Length = 200 # length of the cyclinder 17 | Circ = 200 # circumference of cyclinder 18 | x = 0 # x coordinate of starting location 19 | # y coordinate of starting location. Origin is at centre of square 20 | y = Circ / 2 21 | s = 0 # Step number. 22 | realizations = 8 23 | 24 | trajectory = [] # List of the x coordinates of all points visited. 25 | # (Length x Circ) 2D array of zeros 26 | lattice = np.zeros((Length, Circ), dtype=int) 27 | random.seed(seed) 28 | 29 | # Plot config 30 | dpi = 300 31 | fig, ax = plt.subplots() 32 | fig.set_size_inches(3, Circ * 3. / Length) 33 | ax.set_xlim(0, Length - 1) 34 | ax.set_ylim(0, Circ - 1) 35 | ax.get_xaxis().set_visible(False) 36 | ax.get_yaxis().set_visible(False) 37 | 38 | def plot(LERW, c='g', Length = Length, Circ = Circ): 39 | for pos in range(len(LERW)): 40 | x, y = LERW[pos] 41 | if (x == Length) or (x == 0) or (y == Circ) or (y == Circ) or (y == 0): 42 | LERW[pos] = (np.nan, np.nan) 43 | pos += 1 44 | plt.plot(*zip(*LERW), color=c, linewidth=0.2) 45 | 46 | # Generate a randomwalk 47 | for i in range(realizations): 48 | s = 0 49 | x = 0 # x coordinate of starting location 50 | y = Circ / 2 # y coordinate of starting location 51 | lattice = np.zeros((Length, Circ), dtype=int) 52 | trajectory = [] 53 | 54 | while True: 55 | s += 1 56 | if (bool(random.getrandbits(1))): 57 | if (bool(random.getrandbits(1))): 58 | x += 1 59 | else: 60 | x -= 1 61 | else: 62 | if (bool(random.getrandbits(1))): 63 | y += 1 64 | else: 65 | y -= 1 66 | 67 | if (x >= Length): 68 | break 69 | elif (x < 0): 70 | x = 0 71 | if (y >= Circ): 72 | y -= Circ 73 | elif (y < 0): 74 | y += Circ 75 | 76 | lattice[x][y] += 1 77 | trajectory.append((x, y)) 78 | 79 | x0, y0, pos = None, None, 0 80 | 81 | 82 | # Loop erasure 83 | LERW_LeftRight = deepcopy(trajectory) 84 | lcpy = deepcopy(lattice) 85 | x0, y0 = None, None 86 | pos = 0 87 | 88 | while pos < len(LERW_LeftRight): 89 | x, y = LERW_LeftRight[pos] 90 | if lcpy[x][y] > 1 and (not x0): 91 | x0, y0 = x, y 92 | pos0 = pos 93 | elif (x == x0) and (y == y0) and (lcpy[x][y] == 1): 94 | del LERW_LeftRight[pos0:pos] 95 | x0, y0 = None, None 96 | pos = pos0 97 | lcpy[x][y] -= 1 98 | pos += 1 99 | 100 | 101 | plot(LERW_LeftRight) 102 | 103 | # Loop erasure (tranversal from right to left) 104 | LERW_RightLeft = deepcopy(trajectory[::-1]) 105 | lcpy = deepcopy(lattice) 106 | x0, y0 = None, None 107 | pos = 0 108 | 109 | while pos < len(LERW_RightLeft): 110 | x, y = LERW_RightLeft[pos] 111 | if lcpy[x][y] > 1 and (not x0): 112 | x0, y0 = x, y 113 | pos0 = pos 114 | elif (x == x0) and (y == y0) and (lcpy[x][y] == 1): 115 | del LERW_RightLeft[pos0:pos] 116 | x0, y0 = None, None 117 | pos = pos0 118 | lcpy[x][y] -= 1 119 | pos += 1 120 | 121 | plot(LERW_RightLeft, 'r') 122 | 123 | 124 | 125 | # Plot random walk 126 | plt.savefig(__file__[:-3]+".png", bbox_inches="tight", dpi=dpi) 127 | -------------------------------------------------------------------------------- /LERW.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # An implementation of a Loop Erased Random Walk (LERW) 4 | # from a cylinder with reflecting boundaries on the left 5 | # and open boundaries on the right. 6 | # PNG output of a single trajectory. 7 | # Habib Rehmann and Gunnar Pruessner 8 | # 9 | 10 | import random 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | from copy import deepcopy 14 | 15 | class LERW: 16 | def __init__(self, **kwargs): 17 | self.seed = kwargs.get('seed', 10) # random seed 18 | self.trajectories = [] # List of the coordinates of all points visited. 19 | self.ErasedLoopSizes = [] # List of the sizes of the erased loops 20 | 21 | def generate(self, **kwargs): 22 | self.Length = kwargs.get('Length', 200) # length of the cyclinder 23 | self.Circ = kwargs.get('Circ', 200) # circumference of cyclinder 24 | self.realizations = kwargs.get('realizations', 1) # length of the cyclinder 25 | random.seed(self.seed) 26 | 27 | for i in range(self.realizations): 28 | s = 0 29 | x = 0 # x coordinate of starting location 30 | y = self.Circ / 2 # y coordinate of starting location 31 | lattice = np.zeros((self.Length, self.Circ), dtype=int) 32 | trajectory = [] 33 | ELsize = [] 34 | 35 | while True: 36 | s += 1 37 | if (bool(random.getrandbits(1))): 38 | if (bool(random.getrandbits(1))): 39 | x += 1 40 | else: 41 | x -= 1 42 | else: 43 | if (bool(random.getrandbits(1))): 44 | y += 1 45 | else: 46 | y -= 1 47 | 48 | if (x >= self.Length): 49 | break 50 | elif (x < 0): 51 | x = 0 52 | if (y >= self.Circ): 53 | y -= self.Circ 54 | elif (y < 0): 55 | y += self.Circ 56 | 57 | lattice[x][y] += 1 58 | trajectory.append((x, y)) 59 | 60 | x0, y0, pos = None, None, 0 61 | 62 | 63 | # Loop erasure 64 | while pos < len(trajectory): 65 | x, y = trajectory[pos] 66 | if lattice[x][y] > 1 and (not x0): 67 | x0, y0 = x, y 68 | pos0 = pos 69 | elif (x == x0) and (y == y0) and (lattice[x][y] == 1): 70 | del trajectory[pos0:pos] 71 | ELsize.append(pos - pos0 - 1) 72 | x0, y0 = None, None 73 | pos = pos0 74 | lattice[x][y] -= 1 75 | pos += 1 76 | self.ErasedLoopSizes.append(ELsize) 77 | self.trajectories.append(trajectory) 78 | 79 | def gen_bidirectional(self, **kwargs): 80 | self.Length = kwargs.get('Length', 200) # length of the cyclinder 81 | self.Circ = kwargs.get('Circ', 200) # circumference of cyclinder 82 | self.realizations = kwargs.get('realizations', 1) # length of the cyclinder 83 | self.trajectories_leftright = [] 84 | self.trajectories_rightleft = [] 85 | random.seed(self.seed) 86 | 87 | for i in range(self.realizations): 88 | s = 0 89 | x = 0 # x coordinate of starting location 90 | y = self.Circ / 2 # y coordinate of starting location 91 | lattice = np.zeros((self.Length, self.Circ), dtype=int) 92 | trajectory = [] 93 | 94 | while True: 95 | s += 1 96 | if (bool(random.getrandbits(1))): 97 | if (bool(random.getrandbits(1))): 98 | x += 1 99 | else: 100 | x -= 1 101 | else: 102 | if (bool(random.getrandbits(1))): 103 | y += 1 104 | else: 105 | y -= 1 106 | 107 | if (x >= self.Length): 108 | break 109 | elif (x < 0): 110 | x = 0 111 | if (y >= self.Circ): 112 | y -= self.Circ 113 | elif (y < 0): 114 | y += self.Circ 115 | 116 | lattice[x][y] += 1 117 | trajectory.append((x, y)) 118 | 119 | x0, y0, pos = None, None, 0 120 | 121 | 122 | # Loop erasure 123 | LERW_LeftRight = deepcopy(trajectory) 124 | lcpy = deepcopy(lattice) 125 | x0, y0 = None, None 126 | pos = 0 127 | 128 | while pos < len(LERW_LeftRight): 129 | x, y = LERW_LeftRight[pos] 130 | if lcpy[x][y] > 1 and (not x0): 131 | x0, y0 = x, y 132 | pos0 = pos 133 | elif (x == x0) and (y == y0) and (lcpy[x][y] == 1): 134 | del LERW_LeftRight[pos0:pos] 135 | x0, y0 = None, None 136 | pos = pos0 137 | lcpy[x][y] -= 1 138 | pos += 1 139 | 140 | 141 | # Loop erasure (tranversal from right to left) 142 | LERW_RightLeft = deepcopy(trajectory[::-1]) 143 | lcpy = deepcopy(lattice) 144 | x0, y0 = None, None 145 | pos = 0 146 | 147 | while pos < len(LERW_RightLeft): 148 | x, y = LERW_RightLeft[pos] 149 | if lcpy[x][y] > 1 and (not x0): 150 | x0, y0 = x, y 151 | pos0 = pos 152 | elif (x == x0) and (y == y0) and (lcpy[x][y] == 1): 153 | del LERW_RightLeft[pos0:pos] 154 | x0, y0 = None, None 155 | pos = pos0 156 | lcpy[x][y] -= 1 157 | pos += 1 158 | 159 | self.trajectories_leftright.append(LERW_LeftRight) 160 | self.trajectories_rightleft.append(LERW_RightLeft) 161 | 162 | def gen_fromCoord(self, **kwargs): 163 | self.Length = kwargs.get('Length', 200) # length of the cyclinder 164 | self.Circ = kwargs.get('Circ', 200) # circumference of cyclinder 165 | self.realizations = kwargs.get('realizations', 1) # length of the cyclinder 166 | random.seed(self.seed) 167 | xStart = kwargs.get('xStart', random.randint(0, self.Length)) 168 | yStart = kwargs.get('yStart', random.randint(0, self.Length)) 169 | x, y = xStart, yStart 170 | 171 | for i in range(self.realizations): 172 | s = 0 173 | x, y = xStart, yStart 174 | lattice = np.zeros((self.Length, self.Circ), dtype=int) 175 | trajectory = [] 176 | # Generate a randomwalk 177 | while True: 178 | s += 1 179 | if (bool(random.getrandbits(1))): 180 | if (bool(random.getrandbits(1))): 181 | x += 1 182 | else: 183 | x -= 1 184 | else: 185 | if (bool(random.getrandbits(1))): 186 | y += 1 187 | else: 188 | y -= 1 189 | 190 | # Periodic boundaries 191 | if (x >= self.Length): 192 | x -= self.Length 193 | elif (x < 0): 194 | x += self.Length 195 | if (y >= self.Circ): 196 | y -= self.Circ 197 | elif (y < 0): 198 | y += self.Circ 199 | 200 | if (x == xStart and y == yStart): 201 | break 202 | 203 | lattice[x][y] += 1 204 | trajectory.append((x, y)) 205 | 206 | self.trajectories.append(trajectory) 207 | 208 | @property 209 | def trajectories(self): 210 | return self.trajectories 211 | 212 | @property 213 | def ErasedLoopSizes(self): 214 | return self.ErasedLoopSizes 215 | 216 | @property 217 | def trajectories_rightleft(self): 218 | return self.trajectories_rightleft 219 | 220 | @property 221 | def trajectories_leftright(self): 222 | return self.trajectories_leftright 223 | 224 | def plot(self, **kwargs): 225 | LERW = kwargs.get('LERW', self.trajectories) 226 | c = kwargs.get('c', 'g') 227 | Length = kwargs.get('Length', self.Length) 228 | Circ = kwargs.get('Circ', self.Circ) 229 | figname = kwargs.get('figname', 'LERW_output') 230 | 231 | fig, ax = plt.subplots() 232 | fig.set_size_inches(3, self.Circ * 3. / self.Length) 233 | ax.set_xlim(0, self.Length - 1) 234 | ax.set_ylim(0, self.Circ - 1) 235 | ax.get_xaxis().set_visible(False) 236 | ax.get_yaxis().set_visible(False) 237 | 238 | Plots = [] 239 | prevInd = 0 240 | for pos in range(len(LERW)): 241 | x, y = LERW[pos] 242 | if (x == Length) or (x == 0) or (y == Circ) or (y == Circ) or (y == 0): 243 | Plots.append(LERW[prevInd:pos]) 244 | prevInd = pos 245 | pos += 1 246 | 247 | for plot in Plots: 248 | plt.plot(*zip(*plot), color=c, linewidth=0.2) 249 | plt.savefig(figname, bbox_inches='tight', dpi=kwargs.get('dpi', 300)) 250 | -------------------------------------------------------------------------------- /raw2binned.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is based on Francesc's freq2dens_lo.c. 3 | * GP has ironed out some bits for better ease of use. 4 | * 5 | * $Header: /home/ma/p/pruess/.cvsroot/BD/raw2binned.c,v 1.11 2015/07/06 16:32:22 pruess Exp $ 6 | * 7 | * 8 | This program takes a list of numbers corresponding to frequencies of a variable, or simply avalanche sizes. They don't need to be sorted. It outputs the pdf. 9 | 10 | It takes in account discreteness effects as proposed by Corral et al. in [1]. It can also be used for continuous variables simply by by using a resolution of R=0 11 | 12 | 20 Apr 2015 13 | Just to clarify: 14 | This program takes a stream of event sizes (not of their frequencies, 15 | as it says above) and creates a nizely binned histogram from that data. 16 | 17 | The header prior to me writing this message is 18 | Header: /home/ma/p/pruess/.cvsroot/BD/raw2binned.c,v 1.9 2014/07/23 16:03:24 pruess Exp 19 | 20 | 21 | 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | int spit_out_minmax=0; 33 | int minmax_fixed_by_hand=0; 34 | int data_out_of_minmax=0; 35 | int force_last_bin_correction=0; 36 | 37 | int main(int argc, char *argv[]){ 38 | long long int valid, lines, comments, line_spoiled_by_comment; 39 | char buffer[8192]; 40 | int i, nbins=5; 41 | FILE *fp=stdin; 42 | double R=1., min=0, max=-1.; 43 | double smin; 44 | double data; 45 | int ch; 46 | long long int *n; 47 | double *s; 48 | long long int N; 49 | double De,dens; 50 | int clean=0; 51 | char *p; 52 | 53 | setlinebuf(stdout); 54 | printf("# $Header: /home/ma/p/pruess/.cvsroot/BD/raw2binned.c,v 1.11 2015/07/06 16:32:22 pruess Exp $\n"); 55 | printf("# Command:"); 56 | for (i=0; imax) { 86 | fprintf(stderr, "Failed to scan min:max, should be -m 1.3:42.0, minmax)) { 134 | fprintf(stderr, "You cannot bin a stdin stream without stating min and max.\n"); 135 | exit(EXIT_FAILURE); 136 | } 137 | 138 | #define DD fprintf(stderr, "%s::%i\n", __FILE__, __LINE__) 139 | 140 | 141 | lines=comments=valid=line_spoiled_by_comment=0LL; 142 | if ((spit_out_minmax==1) || (min>max)) { 143 | lines=0LL; 144 | while (fgets(buffer, sizeof(buffer)-1, fp)!=NULL) { 145 | if ((++lines %100000)==0) printf("#Info %lli lines read at minmax.\n", lines); 146 | buffer[sizeof(buffer)-1]=0; 147 | if (buffer[0]=='#') {comments++; continue;} 148 | else { 149 | if (clean==1) { 150 | for (p=buffer+1; *p; p++) { if (*p=='#') break;} 151 | if (*p=='#') { 152 | line_spoiled_by_comment++; 153 | printf("# Spoiled line: ["); 154 | for (p=buffer; *p; p++) { 155 | if (*p!='\n') fputc(*p, stdout); 156 | else printf("\n# "); 157 | } 158 | printf("]\n"); 159 | continue; 160 | } 161 | } 162 | if (sscanf(buffer,"%lf",&data)==1) { 163 | valid++; 164 | if (data<=0) printf("# Info data=%g in line %lli, data excluded.\n", data, lines); 165 | else if (min>max) min=max=data; 166 | else if(datamax) max=data; 168 | } else { 169 | printf("# Scan failed in line: ["); 170 | for (p=buffer; *p; p++) { 171 | if (*p!='\n') fputc(*p, stdout); 172 | else printf("\n# "); 173 | } 174 | printf("]\n"); 175 | } 176 | } 177 | } 178 | rewind(fp); 179 | } 180 | 181 | printf("# Info: Read %lli lines, %lli comments, %lli valid, %lli spoiled; %lli unaccounted.\n", 182 | lines, comments, valid, line_spoiled_by_comment, lines-valid-comments-line_spoiled_by_comment); 183 | if (valid<=0) { 184 | printf("# No valid lines. Exiting.\n"); 185 | exit(0); 186 | } 187 | 188 | 189 | if (spit_out_minmax==1) { 190 | printf("Min: %10.20g\nMax: %10.20g\n-m %10.20g:%10.20g\n", min, max, min, max); 191 | return(0); 192 | } 193 | 194 | printf("#Info: parameters nbins, min, max: %i %g %g\n", nbins, min, max); 195 | 196 | if ((min<0) || (max<0)) { 197 | fprintf(stderr, "min<0 or max<0, %g %g\n", min, max); 198 | exit(EXIT_FAILURE); 199 | } 200 | 201 | //log binning base 202 | double b=pow(10,1/((double)nbins)); 203 | smin=pow(b,(int)(log(min)/log(b)))/sqrt(sqrt(b)); 204 | int kmax=(int)(log(max/smin)/log(b))+1; 205 | 206 | printf("#Info: parameters b, smin, kmax: %g %g %i\n", b, smin, kmax); 207 | 208 | #define MALLOC(a,n) if ((a=malloc(sizeof(*a)*(n)))==NULL) { fprintf(stderr, "Not enough memory for %s, requested %i bytes, %i items of size %i. %i::%s\n", #a, (int)(sizeof(*a)*n), n, (int)sizeof(*a), errno, strerror(errno)); exit(EXIT_FAILURE); } else { printf("#Info malloc(3)ed %i bytes (%i items of %i bytes) for %s.\n", (int)(sizeof(*a)*(n)), n, (int)sizeof(*a), #a); } 209 | 210 | 211 | MALLOC(n, kmax); 212 | MALLOC(s, kmax+1); 213 | 214 | for(i=0;i=min) && (data<=max)){ 257 | n[(int)(log(data/smin)/log(b))]++; // counting 258 | // fprintf(stderr,"val %.32G, bin %d [%.32G,%.32G)\n",data,(int)(log(data/smin)/log(b)),s[(int)(log(data/smin)/log(b))],s[(int)(log(data/smin)/log(b))+1]); // counting 259 | } 260 | else data_out_of_minmax=1; 261 | }else { 262 | printf("# Scan failed in line: ["); 263 | for (p=buffer; *p; p++) { 264 | if (*p!='\n') fputc(*p, stdout); 265 | else printf("\n# "); 266 | } 267 | printf("]\n"); 268 | } 269 | 270 | } 271 | } 272 | fclose(fp); 273 | 274 | printf("# Info: Read %lli lines, %lli comments, %lli valid, %lli spoiled; %lli unaccounted.\n", 275 | lines, comments, valid, line_spoiled_by_comment, lines-valid-comments-line_spoiled_by_comment); 276 | if (comments+valid!=lines) { 277 | fprintf(stderr, "WARNING: Some invalid lines were not comments.\n"); 278 | fprintf(stdout, "# WARNING: Some invalid lines were not comments.\n"); 279 | } 280 | 281 | // get total 282 | for(N=0, i=0;i=0;i--) if(n[i]!=0){ 307 | s[i+1]=max; 308 | break; 309 | } 310 | 311 | } 312 | 313 | 314 | if( data_out_of_minmax ){ 315 | 316 | fprintf(stdout, "# WARNING: some data was outside the range (possibly provided\n" 317 | "# via -m) as a result, first and last bin were corrected\n" 318 | "# corrected (they became smaller)\n"); 319 | 320 | fprintf(stderr, "WARNING: some data was outside the range (possibly provided\n" 321 | " via -m) as a result, first and last bin were\n" 322 | " corrected (they became smaller)\n"); 323 | 324 | for(i=0;i<=kmax;i++) if(n[i]!=0){ 325 | s[i]=min; 326 | break; 327 | } 328 | for(i=kmax-1;i>=0;i--) if(n[i]!=0){ 329 | s[i+1]=max; 330 | break; 331 | } 332 | } 333 | 334 | // normalizei and print 335 | for(i=0; i 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | int spit_out_minmax=0; 33 | int minmax_fixed_by_hand=0; 34 | int data_out_of_minmax=0; 35 | int force_last_bin_correction=0; 36 | 37 | int main(int argc, char *argv[]){ 38 | long long int valid, lines, comments, line_spoiled_by_comment; 39 | char buffer[8192]; 40 | int i, nbins=5; 41 | FILE *fp=stdin; 42 | double R=1., min=0, max=-1.; 43 | double smin; 44 | double data; 45 | int ch; 46 | long long int *n; 47 | double *s; 48 | long long int N; 49 | double De,dens; 50 | int clean=0; 51 | char *p; 52 | 53 | setlinebuf(stdout); 54 | // printf("# $Header: /home/ma/p/pruess/.cvsroot/BD/raw2binned.c,v 1.11 2015/07/06 16:32:22 pruess Exp $\n"); 55 | // printf("# Command:"); 56 | // for (i=0; imax) { 86 | fprintf(stderr, "Failed to scan min:max, should be -m 1.3:42.0, minmax)) { 134 | fprintf(stderr, "You cannot bin a stdin stream without stating min and max.\n"); 135 | exit(EXIT_FAILURE); 136 | } 137 | 138 | #define DD fprintf(stderr, "%s::%i\n", __FILE__, __LINE__) 139 | 140 | 141 | lines=comments=valid=line_spoiled_by_comment=0LL; 142 | if ((spit_out_minmax==1) || (min>max)) { 143 | lines=0LL; 144 | while (fgets(buffer, sizeof(buffer)-1, fp)!=NULL) { 145 | if ((++lines %100000)==0) //printf("#Info %lli lines read at minmax.\n", lines) 146 | ; 147 | buffer[sizeof(buffer)-1]=0; 148 | if (buffer[0]=='#') {comments++; continue;} 149 | else { 150 | if (clean==1) { 151 | for (p=buffer+1; *p; p++) { if (*p=='#') break;} 152 | if (*p=='#') { 153 | line_spoiled_by_comment++; 154 | printf("# Spoiled line: ["); 155 | for (p=buffer; *p; p++) { 156 | if (*p!='\n') fputc(*p, stdout); 157 | else printf("\n# "); 158 | } 159 | printf("]\n"); 160 | continue; 161 | } 162 | } 163 | if (sscanf(buffer,"%lf",&data)==1) { 164 | valid++; 165 | if (data<=0) // printf("# Info data=%g in line %lli, data excluded.\n", data, lines) 166 | ; 167 | else if (min>max) min=max=data; 168 | else if(datamax) max=data; 170 | } else { 171 | printf("# Scan failed in line: ["); 172 | for (p=buffer; *p; p++) { 173 | if (*p!='\n') fputc(*p, stdout); 174 | else printf("\n# "); 175 | } 176 | printf("]\n"); 177 | } 178 | } 179 | } 180 | rewind(fp); 181 | } 182 | 183 | // printf("# Info: Read %lli lines, %lli comments, %lli valid, %lli spoiled; %lli unaccounted.\n", 184 | // lines, comments, valid, line_spoiled_by_comment, lines-valid-comments-line_spoiled_by_comment); 185 | if (valid<=0) { 186 | printf("# No valid lines. Exiting.\n"); 187 | exit(0); 188 | } 189 | 190 | 191 | if (spit_out_minmax==1) { 192 | printf("Min: %10.20g\nMax: %10.20g\n-m %10.20g:%10.20g\n", min, max, min, max); 193 | return(0); 194 | } 195 | 196 | // printf("#Info: parameters nbins, min, max: %i %g %g\n", nbins, min, max); 197 | 198 | if ((min<0) || (max<0)) { 199 | fprintf(stderr, "min<0 or max<0, %g %g\n", min, max); 200 | exit(EXIT_FAILURE); 201 | } 202 | 203 | //log binning base 204 | double b=pow(10,1/((double)nbins)); 205 | smin=pow(b,(int)(log(min)/log(b)))/sqrt(sqrt(b)); 206 | int kmax=(int)(log(max/smin)/log(b))+1; 207 | 208 | // printf("#Info: parameters b, smin, kmax: %g %g %i\n", b, smin, kmax); 209 | 210 | #define MALLOC(a,n) if ((a=malloc(sizeof(*a)*(n)))==NULL) { fprintf(stderr, "Not enough memory for %s, requested %i bytes, %i items of size %i. %i::%s\n", #a, (int)(sizeof(*a)*n), n, (int)sizeof(*a), errno, strerror(errno)); exit(EXIT_FAILURE); } 211 | 212 | 213 | MALLOC(n, kmax); 214 | MALLOC(s, kmax+1); 215 | 216 | for(i=0;i=min) && (data<=max)){ 260 | n[(int)(log(data/smin)/log(b))]++; // counting 261 | // fprintf(stderr,"val %.32G, bin %d [%.32G,%.32G)\n",data,(int)(log(data/smin)/log(b)),s[(int)(log(data/smin)/log(b))],s[(int)(log(data/smin)/log(b))+1]); // counting 262 | } 263 | else data_out_of_minmax=1; 264 | }else { 265 | printf("# Scan failed in line: ["); 266 | for (p=buffer; *p; p++) { 267 | if (*p!='\n') fputc(*p, stdout); 268 | else printf("\n# "); 269 | } 270 | printf("]\n"); 271 | } 272 | 273 | } 274 | } 275 | fclose(fp); 276 | 277 | // printf("# Info: Read %lli lines, %lli comments, %lli valid, %lli spoiled; %lli unaccounted.\n", 278 | // lines, comments, valid, line_spoiled_by_comment, lines-valid-comments-line_spoiled_by_comment); 279 | // if (comments+valid!=lines) { 280 | // fprintf(stderr, "WARNING: Some invalid lines were not comments.\n"); 281 | // fprintf(stdout, "# WARNING: Some invalid lines were not comments.\n"); 282 | // } 283 | 284 | // get total 285 | for(N=0, i=0;i=0;i--) if(n[i]!=0){ 310 | s[i+1]=max; 311 | break; 312 | } 313 | 314 | } 315 | 316 | 317 | if( data_out_of_minmax ){ 318 | 319 | // fprintf(stdout, "# WARNING: some data was outside the range (possibly provided\n" 320 | // "# via -m) as a result, first and last bin were corrected\n" 321 | // "# corrected (they became smaller)\n"); 322 | // 323 | // fprintf(stderr, "WARNING: some data was outside the range (possibly provided\n" 324 | // " via -m) as a result, first and last bin were\n" 325 | // " corrected (they became smaller)\n"); 326 | 327 | for(i=0;i<=kmax;i++) if(n[i]!=0){ 328 | s[i]=min; 329 | break; 330 | } 331 | for(i=kmax-1;i>=0;i--) if(n[i]!=0){ 332 | s[i+1]=max; 333 | break; 334 | } 335 | } 336 | 337 | // normalizei and print 338 | for(i=0; i> matrix makepattern 348 | /Pat1 exch def 349 | << Tile8x8 350 | /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke 351 | 0 4 M 4 8 L 8 4 L 4 0 L 0 4 L stroke} 352 | >> matrix makepattern 353 | /Pat2 exch def 354 | << Tile8x8 355 | /PaintProc {0.5 setlinewidth pop 0 0 M 0 8 L 356 | 8 8 L 8 0 L 0 0 L fill} 357 | >> matrix makepattern 358 | /Pat3 exch def 359 | << Tile8x8 360 | /PaintProc {0.5 setlinewidth pop -4 8 M 8 -4 L 361 | 0 12 M 12 0 L stroke} 362 | >> matrix makepattern 363 | /Pat4 exch def 364 | << Tile8x8 365 | /PaintProc {0.5 setlinewidth pop -4 0 M 8 12 L 366 | 0 -4 M 12 8 L stroke} 367 | >> matrix makepattern 368 | /Pat5 exch def 369 | << Tile8x8 370 | /PaintProc {0.5 setlinewidth pop -2 8 M 4 -4 L 371 | 0 12 M 8 -4 L 4 12 M 10 0 L stroke} 372 | >> matrix makepattern 373 | /Pat6 exch def 374 | << Tile8x8 375 | /PaintProc {0.5 setlinewidth pop -2 0 M 4 12 L 376 | 0 -4 M 8 12 L 4 -4 M 10 8 L stroke} 377 | >> matrix makepattern 378 | /Pat7 exch def 379 | << Tile8x8 380 | /PaintProc {0.5 setlinewidth pop 8 -2 M -4 4 L 381 | 12 0 M -4 8 L 12 4 M 0 10 L stroke} 382 | >> matrix makepattern 383 | /Pat8 exch def 384 | << Tile8x8 385 | /PaintProc {0.5 setlinewidth pop 0 -2 M 12 4 L 386 | -4 0 M 12 8 L -4 4 M 8 10 L stroke} 387 | >> matrix makepattern 388 | /Pat9 exch def 389 | /Pattern1 {PatternBgnd KeepColor Pat1 setpattern} bind def 390 | /Pattern2 {PatternBgnd KeepColor Pat2 setpattern} bind def 391 | /Pattern3 {PatternBgnd KeepColor Pat3 setpattern} bind def 392 | /Pattern4 {PatternBgnd KeepColor Landscape {Pat5} {Pat4} ifelse setpattern} bind def 393 | /Pattern5 {PatternBgnd KeepColor Landscape {Pat4} {Pat5} ifelse setpattern} bind def 394 | /Pattern6 {PatternBgnd KeepColor Landscape {Pat9} {Pat6} ifelse setpattern} bind def 395 | /Pattern7 {PatternBgnd KeepColor Landscape {Pat8} {Pat7} ifelse setpattern} bind def 396 | } def 397 | % 398 | % 399 | %End of PostScript Level 2 code 400 | % 401 | /PatternBgnd { 402 | TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse 403 | } def 404 | % 405 | % Substitute for Level 2 pattern fill codes with 406 | % grayscale if Level 2 support is not selected. 407 | % 408 | /Level1PatternFill { 409 | /Pattern1 {0.250 Density} bind def 410 | /Pattern2 {0.500 Density} bind def 411 | /Pattern3 {0.750 Density} bind def 412 | /Pattern4 {0.125 Density} bind def 413 | /Pattern5 {0.375 Density} bind def 414 | /Pattern6 {0.625 Density} bind def 415 | /Pattern7 {0.875 Density} bind def 416 | } def 417 | % 418 | % Now test for support of Level 2 code 419 | % 420 | Level1 {Level1PatternFill} {Level2PatternFill} ifelse 421 | % 422 | /Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont 423 | dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall 424 | currentdict end definefont pop 425 | end 426 | %%EndProlog 427 | %%Page: 1 1 428 | gnudict begin 429 | gsave 430 | 50 50 translate 431 | 0.100 0.100 scale 432 | 90 rotate 433 | 0 -5040 translate 434 | 0 setgray 435 | newpath 436 | (Helvetica) findfont 140 scalefont setfont 437 | /Helvetica findfont 140 scalefont setfont 438 | /Helvetica findfont 140 scalefont setfont 439 | /Helvetica findfont 140 scalefont setfont 440 | /Helvetica findfont 140 scalefont setfont 441 | 1.000 UL 442 | LTb 443 | 714 280 M 444 | 63 0 V 445 | 6213 0 R 446 | -63 0 V 447 | 630 280 M 448 | ( 0.1) Rshow 449 | 1.000 UL 450 | LTb 451 | 714 1342 M 452 | 31 0 V 453 | 6245 0 R 454 | -31 0 V 455 | 714 1964 M 456 | 31 0 V 457 | 6245 0 R 458 | -31 0 V 459 | 714 2405 M 460 | 31 0 V 461 | 6245 0 R 462 | -31 0 V 463 | 714 2747 M 464 | 31 0 V 465 | 6245 0 R 466 | -31 0 V 467 | 714 3026 M 468 | 31 0 V 469 | 6245 0 R 470 | -31 0 V 471 | 714 3263 M 472 | 31 0 V 473 | 6245 0 R 474 | -31 0 V 475 | 714 3467 M 476 | 31 0 V 477 | 6245 0 R 478 | -31 0 V 479 | 714 3648 M 480 | 31 0 V 481 | 6245 0 R 482 | -31 0 V 483 | 714 3810 M 484 | 63 0 V 485 | 6213 0 R 486 | -63 0 V 487 | -6297 0 R 488 | ( 1) Rshow 489 | 1.000 UL 490 | LTb 491 | 714 4872 M 492 | 31 0 V 493 | 6245 0 R 494 | -31 0 V 495 | 714 280 M 496 | 0 63 V 497 | 0 4529 R 498 | 0 -63 V 499 | 714 140 M 500 | ( 1) Cshow 501 | 1.000 UL 502 | LTb 503 | 1029 280 M 504 | 0 31 V 505 | 0 4561 R 506 | 0 -31 V 507 | 1445 280 M 508 | 0 31 V 509 | 0 4561 R 510 | 0 -31 V 511 | 1659 280 M 512 | 0 31 V 513 | 0 4561 R 514 | 0 -31 V 515 | 1760 280 M 516 | 0 63 V 517 | 0 4529 R 518 | 0 -63 V 519 | 0 -4669 R 520 | ( 10) Cshow 521 | 1.000 UL 522 | LTb 523 | 2075 280 M 524 | 0 31 V 525 | 0 4561 R 526 | 0 -31 V 527 | 2491 280 M 528 | 0 31 V 529 | 0 4561 R 530 | 0 -31 V 531 | 2705 280 M 532 | 0 31 V 533 | 0 4561 R 534 | 0 -31 V 535 | 2806 280 M 536 | 0 63 V 537 | 0 4529 R 538 | 0 -63 V 539 | 0 -4669 R 540 | ( 100) Cshow 541 | 1.000 UL 542 | LTb 543 | 3121 280 M 544 | 0 31 V 545 | 0 4561 R 546 | 0 -31 V 547 | 3537 280 M 548 | 0 31 V 549 | 0 4561 R 550 | 0 -31 V 551 | 3751 280 M 552 | 0 31 V 553 | 0 4561 R 554 | 0 -31 V 555 | 3852 280 M 556 | 0 63 V 557 | 0 4529 R 558 | 0 -63 V 559 | 0 -4669 R 560 | ( 1000) Cshow 561 | 1.000 UL 562 | LTb 563 | 4167 280 M 564 | 0 31 V 565 | 0 4561 R 566 | 0 -31 V 567 | 4583 280 M 568 | 0 31 V 569 | 0 4561 R 570 | 0 -31 V 571 | 4797 280 M 572 | 0 31 V 573 | 0 4561 R 574 | 0 -31 V 575 | 4898 280 M 576 | 0 63 V 577 | 0 4529 R 578 | 0 -63 V 579 | 0 -4669 R 580 | ( 10000) Cshow 581 | 1.000 UL 582 | LTb 583 | 5213 280 M 584 | 0 31 V 585 | 0 4561 R 586 | 0 -31 V 587 | 5629 280 M 588 | 0 31 V 589 | 0 4561 R 590 | 0 -31 V 591 | 5843 280 M 592 | 0 31 V 593 | 0 4561 R 594 | 0 -31 V 595 | 5944 280 M 596 | 0 63 V 597 | 0 4529 R 598 | 0 -63 V 599 | 0 -4669 R 600 | ( 100000) Cshow 601 | 1.000 UL 602 | LTb 603 | 6259 280 M 604 | 0 31 V 605 | 0 4561 R 606 | 0 -31 V 607 | 6675 280 M 608 | 0 31 V 609 | 0 4561 R 610 | 0 -31 V 611 | 6889 280 M 612 | 0 31 V 613 | 0 4561 R 614 | 0 -31 V 615 | 6990 280 M 616 | 0 63 V 617 | 0 4529 R 618 | 0 -63 V 619 | 0 -4669 R 620 | ( 1e+06) Cshow 621 | 1.000 UL 622 | LTb 623 | 1.000 UL 624 | LTb 625 | 714 4872 N 626 | 714 280 L 627 | 6276 0 V 628 | 0 4592 V 629 | -6276 0 V 630 | Z stroke 631 | 1.000 UP 632 | 1.000 UL 633 | LTb 634 | 1.000 UP 635 | 1.000 UL 636 | LT0 637 | /Helvetica findfont 140 scalefont setfont 638 | LTb 639 | 6339 4739 M 640 | ('LERW_cluster_sizes_200.dat_binned' u 1:\($2*$1**1.5\)) Rshow 641 | LT0 642 | 6423 4739 M 643 | 399 0 V 644 | 714 2162 M 645 | 772 280 L 646 | 391 0 R 647 | 50 3129 V 648 | 181 -988 V 649 | 199 -243 V 650 | 219 849 V 651 | 219 6 V 652 | 203 45 V 653 | 208 -240 V 654 | 210 68 V 655 | 208 -135 V 656 | 208 -77 V 657 | 208 -90 V 658 | 210 -71 V 659 | 209 -89 V 660 | 209 -98 V 661 | 210 -100 V 662 | 209 -80 V 663 | 209 -107 V 664 | 209 -93 V 665 | 209 -16 V 666 | 210 60 V 667 | 209 71 V 668 | 209 -31 V 669 | 209 -245 V 670 | 209 -502 V 671 | 6206 461 L 672 | 22 -181 V 673 | 714 2162 Pls 674 | 1213 3409 Pls 675 | 1394 2421 Pls 676 | 1593 2178 Pls 677 | 1812 3027 Pls 678 | 2031 3033 Pls 679 | 2234 3078 Pls 680 | 2442 2838 Pls 681 | 2652 2906 Pls 682 | 2860 2771 Pls 683 | 3068 2694 Pls 684 | 3276 2604 Pls 685 | 3486 2533 Pls 686 | 3695 2444 Pls 687 | 3904 2346 Pls 688 | 4114 2246 Pls 689 | 4323 2166 Pls 690 | 4532 2059 Pls 691 | 4741 1966 Pls 692 | 4950 1950 Pls 693 | 5160 2010 Pls 694 | 5369 2081 Pls 695 | 5578 2050 Pls 696 | 5787 1805 Pls 697 | 5996 1303 Pls 698 | 6206 461 Pls 699 | 6622 4739 Pls 700 | 1.000 UL 701 | LT1 702 | /Helvetica findfont 140 scalefont setfont 703 | LTb 704 | 6339 4599 M 705 | ('RW1D_cluster_sizes_200.dat_binned' u 1:\($2*$1**1.5\)) Rshow 706 | LT1 707 | 6423 4599 M 708 | 399 0 V 709 | 871 2481 M 710 | 871 280 L 711 | 523 0 R 712 | 0 2724 V 713 | 199 67 V 714 | 219 -664 V 715 | 219 -5 V 716 | 203 -86 V 717 | 208 182 V 718 | 210 -139 V 719 | 208 58 V 720 | 208 -7 V 721 | 208 11 V 722 | 210 -30 V 723 | 209 -3 V 724 | 209 9 V 725 | 210 -3 V 726 | 209 28 V 727 | 209 215 V 728 | 209 406 V 729 | 209 254 V 730 | 210 -169 V 731 | 209 -845 V 732 | 5578 376 L 733 | 6 -96 V 734 | stroke 735 | LT2 736 | /Helvetica findfont 140 scalefont setfont 737 | LTb 738 | 6339 4459 M 739 | (0.95*x**-0.13) Rshow 740 | LT2 741 | 6423 4459 M 742 | 399 0 V 743 | 714 3731 M 744 | 63 -28 V 745 | 64 -28 V 746 | 63 -28 V 747 | 64 -27 V 748 | 63 -28 V 749 | 63 -28 V 750 | 64 -28 V 751 | 63 -28 V 752 | 64 -27 V 753 | 63 -28 V 754 | 63 -28 V 755 | 64 -28 V 756 | 63 -28 V 757 | 64 -27 V 758 | 63 -28 V 759 | 63 -28 V 760 | 64 -28 V 761 | 63 -28 V 762 | 63 -27 V 763 | 64 -28 V 764 | 63 -28 V 765 | 64 -28 V 766 | 63 -28 V 767 | 63 -28 V 768 | 64 -27 V 769 | 63 -28 V 770 | 64 -28 V 771 | 63 -28 V 772 | 63 -28 V 773 | 64 -27 V 774 | 63 -28 V 775 | 64 -28 V 776 | 63 -28 V 777 | 63 -28 V 778 | 64 -27 V 779 | 63 -28 V 780 | 64 -28 V 781 | 63 -28 V 782 | 63 -28 V 783 | 64 -27 V 784 | 63 -28 V 785 | 64 -28 V 786 | 63 -28 V 787 | 63 -28 V 788 | 64 -27 V 789 | 63 -28 V 790 | 64 -28 V 791 | 63 -28 V 792 | 63 -28 V 793 | 64 -28 V 794 | 63 -27 V 795 | 63 -28 V 796 | 64 -28 V 797 | 63 -28 V 798 | 64 -28 V 799 | 63 -27 V 800 | 63 -28 V 801 | 64 -28 V 802 | 63 -28 V 803 | 64 -28 V 804 | 63 -27 V 805 | 63 -28 V 806 | 64 -28 V 807 | 63 -28 V 808 | 64 -28 V 809 | 63 -27 V 810 | 63 -28 V 811 | 64 -28 V 812 | 63 -28 V 813 | 64 -28 V 814 | 63 -28 V 815 | 63 -27 V 816 | 64 -28 V 817 | 63 -28 V 818 | 64 -28 V 819 | 63 -28 V 820 | 63 -27 V 821 | 64 -28 V 822 | 63 -28 V 823 | 64 -28 V 824 | 63 -28 V 825 | 63 -27 V 826 | 64 -28 V 827 | 63 -28 V 828 | 63 -28 V 829 | 64 -28 V 830 | 63 -27 V 831 | 64 -28 V 832 | 63 -28 V 833 | 63 -28 V 834 | 64 -28 V 835 | 63 -27 V 836 | 64 -28 V 837 | 63 -28 V 838 | 63 -28 V 839 | 64 -28 V 840 | 63 -28 V 841 | 64 -27 V 842 | 63 -28 V 843 | 1.000 UP 844 | stroke 845 | LT3 846 | /Helvetica findfont 140 scalefont setfont 847 | LTb 848 | 6339 4319 M 849 | ('LERW_cluster_sizes_100.dat_binned' u 1:\($2*$1**1.5\)) Rshow 850 | LT3 851 | 6423 4319 M 852 | 399 0 V 853 | 714 2165 M 854 | 779 280 L 855 | 378 0 R 856 | 56 3125 V 857 | 181 -984 V 858 | 199 -241 V 859 | 219 848 V 860 | 219 8 V 861 | 203 41 V 862 | 208 -233 V 863 | 210 59 V 864 | 208 -132 V 865 | 208 -80 V 866 | 208 -88 V 867 | 210 -84 V 868 | 209 -103 V 869 | 209 -92 V 870 | 210 -93 V 871 | 209 -44 V 872 | 209 60 V 873 | 209 74 V 874 | 209 -25 V 875 | 210 -250 V 876 | 209 -447 V 877 | 5578 752 L 878 | 67 -472 V 879 | 714 2165 Crs 880 | 1213 3405 Crs 881 | 1394 2421 Crs 882 | 1593 2180 Crs 883 | 1812 3028 Crs 884 | 2031 3036 Crs 885 | 2234 3077 Crs 886 | 2442 2844 Crs 887 | 2652 2903 Crs 888 | 2860 2771 Crs 889 | 3068 2691 Crs 890 | 3276 2603 Crs 891 | 3486 2519 Crs 892 | 3695 2416 Crs 893 | 3904 2324 Crs 894 | 4114 2231 Crs 895 | 4323 2187 Crs 896 | 4532 2247 Crs 897 | 4741 2321 Crs 898 | 4950 2296 Crs 899 | 5160 2046 Crs 900 | 5369 1599 Crs 901 | 5578 752 Crs 902 | 6622 4319 Crs 903 | 1.000 UL 904 | LTb 905 | 714 4872 N 906 | 714 280 L 907 | 6276 0 V 908 | 0 4592 V 909 | -6276 0 V 910 | Z stroke 911 | 1.000 UP 912 | 1.000 UL 913 | LTb 914 | stroke 915 | grestore 916 | end 917 | showpage 918 | --------------------------------------------------------------------------------