Beispiel #1
0
 def setUp(self):
     """Sets up test fixtures"""
     self.optimizer = LocalBestPSO
     self.n_particles = 40
     self.dimensions = 20
     self.options = {
         'c1': [1, 2, 3],
         'c2': [1, 2, 3],
         'k': [5, 10, 15],
         'w': [0.9, 0.7, 0.4],
         'p': [1]
     }
     self.mini_options = {'c1': [1, 2], 'c2': 6, 'k': 5, 'w': 0.9, 'p': 0}
     self.bounds = (np.array([-5, -5]), np.array([5, 5]))
     self.iters = 10
     self.objective_func = sphere_func
     self.g = GridSearch(self.optimizer,
                         self.n_particles,
                         self.dimensions,
                         self.options,
                         self.objective_func,
                         self.iters,
                         bounds=None,
                         velocity_clamp=None)
     self.g_mini = GridSearch(self.optimizer,
                              self.n_particles,
                              self.dimensions,
                              self.mini_options,
                              self.objective_func,
                              self.iters,
                              bounds=None,
                              velocity_clamp=None)
Beispiel #2
0
def grid_mini():
    """Returns a GridSearch instance with a smaller search-space"""
    options = {'c1': [1, 2], 'c2': 6, 'k': 5, 'w': 0.9, 'p': 0}
    return GridSearch(LocalBestPSO,
                      n_particles=40,
                      dimensions=20,
                      options=options,
                      objective_func=sphere_func,
                      iters=10,
                      bounds=None)
Beispiel #3
0
def grid_mini():
    """Returns a GridSearch instance with a smaller search-space"""
    options = {"c1": [1, 2], "c2": 6, "k": 5, "w": 0.9, "p": 0}
    return GridSearch(
        LocalBestPSO,
        n_particles=40,
        dimensions=20,
        options=options,
        objective_func=sphere_func,
        iters=10,
        bounds=None,
    )
Beispiel #4
0
 def test_optimizer_type_fail(self):
     """Tests that :code:`optimizer` of type :code:`string` raises
     :code:`TypeError`"""
     bad_optimizer = 'LocalBestPSO'  # a string instead of a class object
     with self.assertRaises(TypeError):
         g = GridSearch(bad_optimizer,
                        self.n_particles,
                        self.dimensions,
                        self.options,
                        self.objective_func,
                        self.iters,
                        bounds=None,
                        velocity_clamp=None)
Beispiel #5
0
def grid():
    """Returns a GridSearch instance"""
    options = {
        'c1': [1, 2, 3],
        'c2': [1, 2, 3],
        'k': [5, 10, 15],
        'w': [0.9, 0.7, 0.4],
        'p': [1]
    }
    return GridSearch(LocalBestPSO,
                      n_particles=40,
                      dimensions=20,
                      options=options,
                      objective_func=sphere_func,
                      iters=10,
                      bounds=None)
Beispiel #6
0
def grid():
    """Returns a GridSearch instance"""
    options = {
        "c1": [1, 2, 3],
        "c2": [1, 2, 3],
        "k": [5, 10, 15],
        "w": [0.9, 0.7, 0.4],
        "p": [1],
    }
    return GridSearch(
        LocalBestPSO,
        n_particles=40,
        dimensions=20,
        options=options,
        objective_func=sphere_func,
        iters=10,
        bounds=None,
    )