diff --git a/sho/bit.py b/sho/bit.py index ca84849..02cd5a4 100644 --- a/sho/bit.py +++ b/sho/bit.py @@ -55,6 +55,7 @@ def rand(domain_width, nb_sensors): def neighb_square(sol, scale, domain_width): """Draw a random array by moving every ones to adjacent cells.""" + assert(0 < scale <= 1) # Copy, because Python pass by reference # and we may not want to alter the original solution. new = copy.copy(sol) @@ -64,7 +65,7 @@ def neighb_square(sol, scale, domain_width): # coordinates of images (row,col). if sol[py][px] == 1: # Add a one somewhere around. - w = scale//2 * domain_width + w = scale/2 * domain_width ny = np.random.randint(py-w,py+w) nx = np.random.randint(px-w,px+w) ny = min(max(0,ny),domain_width-1) diff --git a/sho/num.py b/sho/num.py index bb5e86c..dcdbffd 100644 --- a/sho/num.py +++ b/sho/num.py @@ -50,6 +50,7 @@ def rand(dim, scale): def neighb_square(sol, scale, domain_width): """Draw a random vector in a square of witdh `scale` around the given one.""" + assert(0 < scale <= 1) new = sol + (np.random.random(len(sol)) * scale - scale/2) return new diff --git a/snp.py b/snp.py index 3c2d438..2011f61 100644 --- a/snp.py +++ b/snp.py @@ -1,3 +1,4 @@ +#encoding: utf-8 import math import numpy as np import matplotlib.pyplot as plt @@ -44,6 +45,8 @@ if __name__=="__main__": can.add_argument("-e", "--steady-epsilon", metavar="DVAL", default=0, type=float, help="Stop if the improvement of the objective function value is lesser than DVAL") + can.add_argument("-a", "--variation-scale", metavar="RATIO", default=0.3, type=float, + help="Scale of the variation operators (as a ration of the domain width)") the = can.parse_args() @@ -95,7 +98,7 @@ if __name__=="__main__": dim = d * the.nb_sensors, scale = the.domain_width), make.neig(num.neighb_square, - scale = the.domain_width/10, + scale = the.variation_scale, domain_width = the.domain_width), iters ) @@ -110,7 +113,7 @@ if __name__=="__main__": domain_width = the.domain_width, nb_sensors = the.nb_sensors), make.neig(bit.neighb_square, - scale = the.domain_width/10, + scale = the.variation_scale, domain_width = the.domain_width), iters )