2323import powerlaw
2424import warnings
2525import matplotlib .patches as mpatches
26- import seaborn as sns
26+ import argparse
27+ from termcolor import colored
2728
2829# Automatically setting the local path to this repo for easy file writing and saving
2930dir_path = path .dirname (path .realpath (__file__ ))
3031# Only keep the warnings printed in the output
3132warnings .filterwarnings ("ignore" )
3233
3334
35+
36+
37+ parser = argparse .ArgumentParser (formatter_class = argparse .RawDescriptionHelpFormatter ,
38+ description = 'Uses the lattice object from lattice.py to perform different experiments.\n \
39+ Call functions by their name!\n \
40+ func \' comp_average_fitness\' runs the model and plots the evolution of average fitness and the threshold at the end\n \
41+ func \' comp_avalanche_time\' compares the avalanche time between fintess generated unifromly or by the gaussin random generator\n \
42+ func \' comp_mutation_dist\' compares the distribution of the distance between mutations for models using gaussin/uniform random generator\n \
43+ func \' is_free_variation\' compares the impact of the density on the avalanche time \n \
44+ func \' comp_cluster_sizes\' compares the cluster size distribution for different grid sizes \n \
45+ func \' comp_moving_vs_stationary\' compares the cluster sizes and avalanche time between a \n \
46+ func \' comp_diff_dim\' the cluster size for 2D/3D model \n \
47+ func \' get_fitness_dist\' the fitness distribution after n iterations ' )
48+
49+
50+
51+ parser .add_argument ("-func" ,type = str , help = 'Defines which function to execute' )
52+ parser .add_argument ('-itr' , type = int ,default = 200 , help = 'Number of iteration for the model (default : 50)' )
53+ parser .add_argument ('-rep' , type = int ,default = 10 , help = 'Number of repetition (default : 10)' )
54+ parser .add_argument ('-std' , type = float ,default = 0.3 , help = 'Standard deviation for gaussian random generator (default : 0.3)' )
55+ parser = parser .parse_args ()
56+
57+
58+
3459def print_statement (alpha , r , p , name ):
3560
3661 print ("The slope of {} disrtibution is {}" .format (name , round (alpha , 4 )))
@@ -42,7 +67,8 @@ def print_statement(alpha, r, p, name):
4267
4368def comp_average_fitness (size = (20 , 20 ), iteration = 2000 , repetition = 10 , std = 0.3 ):
4469 """
45- Plots the average fitness for different distribution and the threshold
70+ Plots the average fitness for different distribution and the threshold for a model
71+ using uniform/gaussian random generator
4672 :param : number of iterations, number of repetition and standard deviation for gaussian distribution
4773 """
4874
@@ -104,7 +130,7 @@ def comp_average_fitness(size=(20, 20), iteration=2000, repetition=10, std=0.3):
104130
105131def comp_avalanche_time (size = (20 , 20 ), iteration = 2000 , repetition = 10 , std = 0.2 ):
106132 """
107- Plots the avalanche distribution in a log-log plot
133+ Plots the avalanche distribution in a log-log plot for a model using uniform/gaussian random generator
108134 :param : number of iterations, number of repetition and standard deviation for gaussian distribution
109135
110136 """
@@ -158,7 +184,7 @@ def comp_avalanche_time(size=(20, 20), iteration=2000, repetition=10, std=0.2):
158184
159185def comp_mutation_dist (size = (20 , 20 ), iteration = 2000 , repetition = 10 , std = 0.2 ):
160186 """
161- Plots the distribution between distances between mutations
187+ Plots the distribution between distances between mutations for a model using uniform/gaussian random generator
162188 :param : size of the grid,number of iterations, number of repetition and standard deviation for gaussian distribution
163189 """
164190
@@ -215,7 +241,7 @@ def comp_mutation_dist(size=(20, 20), iteration=2000, repetition=10, std=0.2):
215241
216242def comp_diff_neighbours (size = (20 , 20 ), iteration = 2000 , repetition = 10 ):
217243 """
218- Plots the avalanche distribution in a log-log plot
244+ Plots the avalanche distribution in a log-log plot for a model using Moore/van Neumann Neighbourhood
219245 :param : number of iterations, number of repetition and standard deviation for gaussian distribution
220246
221247 """
@@ -388,7 +414,13 @@ def is_free_variation(i_min=0, i_max=1, i_iter=6, iterations=2000):
388414
389415
390416def comp_cluster_sizes (iterations = 2000 ):
391- # Compares the cluster sizes of different sizes of grid
417+ """
418+ Compares the cluster sizes of different sizes of grid using uniform random generator for the fitness
419+ :param iterations: number of steps to run for the Bak-Sneppen model
420+ """
421+
422+
423+ print (colored ("Warning this function might take long (2000 itr ~ 40 min)" ,'red' ))
392424
393425 small = Lattice (size = (20 , 20 ), torus_mode = True , rand_dist = ('uniform' ,), free_percent = 0 , iterations = iterations ,
394426 age_fraction = 1 / 10 )
@@ -437,8 +469,9 @@ def comp_cluster_sizes(iterations=2000):
437469
438470def comp_moving_vs_stationary (size = (20 , 20 ), iteration = 2000 , repetition = 10 ):
439471 """
440- Compares the cluster sizes and avalanche time
441-
472+ Compares the cluster sizes and avalanche time between a stationary model and a model where the nodes
473+ can move to free space
474+ :param : number of iterations, number of repetition and standard deviation for gaussian distribution
442475 """
443476 # Get a comparison between the different random distribution
444477 iterations = iteration
@@ -493,7 +526,7 @@ def comp_moving_vs_stationary(size=(20, 20), iteration=2000, repetition=10):
493526
494527def comp_diff_dim (iterations = 2000 ):
495528 """
496- Compares
529+ Compares the cluster size distribution for 2 Dimensions and 3 Dimensions
497530 """
498531 # Compares the cluster sizes of different sizes of grid
499532
@@ -552,3 +585,34 @@ def get_fitness_dist(iterations=20000):
552585 plt .legend ()
553586 plt .savefig (path .join (dir_path , 'figures/fitness_distance_itr={}.png' .format (iterations )), dpi = 300 )
554587 plt .show ()
588+
589+
590+
591+
592+ if len (sys .argv ) >= 1 :
593+
594+ if parser .func == 'comp_average_fitness' :
595+ comp_average_fitness (iteration = parser .itr ,repetition = parser .rep ,std = parser .std )
596+
597+ elif parser .func == 'comp_average_fitness' :
598+ comp_average_fitness (iteration = parser .itr ,repetition = parser .rep ,std = parser .std )
599+
600+ elif parser .func == 'comp_avalanche_time' :
601+ comp_avalanche_time (iteration = parser .itr ,repetition = parser .rep ,std = parser .std )
602+
603+ elif parser .func == 'comp_mutation_dist' :
604+ comp_mutation_dist (iteration = parser .itr ,repetition = parser .rep ,std = parser .std )
605+ elif parser .func == 'is_free_variation' :
606+ is_free_variation (iterations = parser .itr )
607+
608+ elif parser .func == 'comp_cluster_sizes' :
609+ comp_cluster_sizes (iterations = parser .itr )
610+
611+ elif parser .func == 'comp_moving_vs_stationary' :
612+ comp_moving_vs_stationary (iteration = parser .itr ,repetition = parser .rep )
613+
614+ elif parser .func == 'comp_diff_dim' :
615+ comp_diff_dim (iterations = parser .itr )
616+
617+ elif parser .func == 'get_fitness_dist' :
618+ get_fitness_dist (iterations = parser .itr )
0 commit comments