Commit 23994e2b by johann dreo

### feat: enforce scale as a ratio

parent 642cf8d1
 ... ... @@ -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) ... ...
 ... ... @@ -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
 #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 ) ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!