Exemplo n.º 1
0
def general_opt_reset(topology):
    """Returns a GeneralOptimizerPSO instance that has been run and reset to check
    default value"""
    pso = GeneralOptimizerPSO(10, 2, {"c1": 0.5, "c2": 0.7, "w": 0.5}, topology=topology)
    pso.optimize(sphere_func, 10, verbose=0)
    pso.reset()
    return pso
Exemplo n.º 2
0
def test_ftol_effect(options, topology):
    """Test if setting the ftol breaks the optimization process accordingly"""
    pso = GeneralOptimizerPSO(10,
                              2,
                              options=options,
                              topology=topology,
                              ftol=1e-1)
    pso.optimize(sphere, 2000)
    assert np.array(pso.cost_history).shape != (2000, )
Exemplo n.º 3
0
 def optimizer_history(self, request, options):
     opt = GeneralOptimizerPSO(
         n_particles=10,
         dimensions=2,
         options=options,
         topology=request.param,
     )
     opt.optimize(sphere, 1000)
     return opt
Exemplo n.º 4
0
 def __optimize(self, cost_function: Callable) -> Tuple[float, np.array]:
     opt = GeneralOptimizerPSO(n_particles=self.vae.latent_dim,
                               dimensions=self.vae.latent_dim,
                               options=self.options,
                               topology=self.topology,
                               bounds=self.bounds)
     cost, z = opt.optimize(cost_function, iters=self.n_iter, fast=True)
     return cost, z
Exemplo n.º 5
0
def general_opt_history(topology):
    """Returns a GeneralOptimizerPSO instance run for 1000 iterations for checking
    history"""
    pso = GeneralOptimizerPSO(10, 2, {"c1": 0.5, "c2": 0.7, "w": 0.5}, topology=topology)
    pso.optimize(sphere_func, 1000, verbose=0)
    return pso