def __init__(self, random=False):
     if random:
         self.__x = [
             rand.getrandbits(1) for _ in range(0, get_number_of_inputs())
         ]
     else:
         self.__x = [0] * get_number_of_inputs()
     self.__fitness = None
     self.tpr = .0
     self.fpr = .0
 def __init__(self, random=False):
     if random:
         self.__x = [
             rand.uniform(L, U) for _ in range(0, get_number_of_inputs())
         ]
         self.__v = [
             rand.uniform(0, 1) for _ in range(0, get_number_of_inputs())
         ]
     else:
         self.__x = [.0] * get_number_of_inputs()
         self.__v = [.0] * get_number_of_inputs()
     self.__fitness = None
     self.tpr = .0
     self.fpr = .0
 def mutate(self, prop):
     self.__x = [
         self.__x[i] if prop <= rand.uniform(0, 1) else self.__x[i] +
         R * rand.uniform(-1, 1) for i in range(0, get_number_of_inputs())
     ]
     self.__fitness = None
     return self
 def update_velocity_and_path(self, pg, t):
     v = cos_sim(pg.__x, self.__x)
     self.__x = [
         self.__x[i] if v > rand.uniform(0, 1) else pg.__x[i]
         for i in range(0, get_number_of_inputs())
     ]
     self.__fitness = None
     return self
 def fitness(self):
     if not self.__fitness:
         self.tpr, self.fpr, n = calc_fitness(self.__x)
         if n == 0:
             return float("inf")
         a = AW * (1.0 / self.tpr)
         b = BW * self.fpr
         c = CW * (n / get_number_of_inputs())
         self.__fitness = a + b + c
     return self.__fitness
 def update_velocity_and_path(self, pg, t):
     self.__v = [
         (vi * exp(-R * t) + rand.uniform(0, 1) * (pg.__x[i] - self.__x[i]))
         for i, vi in enumerate(self.__v)
     ]
     for i in range(0, get_number_of_inputs()):
         s = 1.0 / (1.0 + exp(-self.__v[i] / 2))
         self.__x[i] = 1 if s > rand.uniform(0, 1) else 0
     self.__fitness = None
     return self
 def update_path(self, xc):
     self.__x = [
         self.__x[i] if xc[i] > rand.uniform(0, 1) else (1 - self.__x[i])
         for i in range(0, get_number_of_inputs())
     ]
     self.__fitness = None