Exemplo n.º 1
0
    def step(self):
        """Take a step in the optimization"""
        rnd_cross = _random((self.npop, self.ndim))
        for i in xrange(self.npop):
            t0, t1, t2 = i, i, i
            while t0 == i:
                t0 = _randint(self.npop)
            while t1 == i or t1 == t0:
                t1 = _randint(self.npop)
            while t2 == i or t2 == t0 or t2 == t1:
                t2 = _randint(self.npop)

            v = self.population[t0, :] + self.F * (self.population[t1, :] -
                                                   self.population[t2, :])

            crossover = rnd_cross[i] <= self.C
            u = np.where(crossover, v, self.population[i, :])

            ri = _randint(self.ndim)
            u[ri] = v[ri]

            ufit = self.m * self.fun(u)

            if ufit < self.fitness[i]:
                self.population[i, :] = u
                self.fitness[i] = ufit
Exemplo n.º 2
0
 def bootstrap_indexes(data, n_samples=10000):
     """
 Given data points data, where axis 0 is considered to delineate points, return
 an generator for sets of bootstrap indexes. This can be used as a list
 of bootstrap indexes (with list(bootstrap_indexes(data))) as well.
     """
     for _ in range(n_samples):
         yield _randint(data.shape[0], size=(data.shape[0], ))
Exemplo n.º 3
0
 def bootstrap_indexes(data, n_samples=10000):
     """
 Given data points data, where axis 0 is considered to delineate points, return
 an generator for sets of bootstrap indexes. This can be used as a list
 of bootstrap indexes (with list(bootstrap_indexes(data))) as well.
     """
     for _ in range(n_samples):
         yield _randint(data.shape[0], size=(data.shape[0],))    
Exemplo n.º 4
0
def sample2():
    return _randint(low=0, high=10)
Exemplo n.º 5
0
def integer_rewards(rbound, N):
    """
    Returns an array of N integer rewards with absolute value <= rbound
    """
    
    return _randint(-rbound,rbound,N)