def test_random_optimise(self):
   """ Test direct optmisation."""
   self.report('Rand optimise:')
   random_minimise = lambda obj, bounds, max_evals: oper_utils.random_minimise(
                                               obj, bounds, max_evals, False, False)
   random_maximise = lambda obj, bounds, max_evals: oper_utils.random_maximise(
                                               obj, bounds, max_evals, False, False)
   self._test_optimise_method(random_minimise, random_maximise, False)
Beispiel #2
0
 def _rand_maximise_obj(self, obj, num_evals):
     """ Maximise with random evaluations. """
     if num_evals is None:
         lead_const = 10 * min(5, self.dim)**2
         num_evals = lambda t: np.clip(lead_const * np.sqrt(min(t, 1000)),
                                       2000, 3e4)
     opt_val, opt_pt = random_maximise(obj, self.bounds, num_evals)
     return opt_val, opt_pt
 def test_random_maximise(self):
     """ Test direct optmisation."""
     self.report('Rand maximise:')
     num_max_successes = 0
     for prob in self.problems:
         prob_bounds = np.concatenate(
             (np.array(prob.lb).reshape(1, -1), np.array(prob.ub).reshape(
                 1, -1)),
             axis=0).T
         max_val_soln, _ = oper_utils.random_maximise(
             prob.obj, prob_bounds, 2 * self.max_evals, False)
         diff = abs(prob.max_val - max_val_soln)
         self.report(
             prob.descr + '(max):: True: %0.4f, Soln: %0.4f,  diff: %0.4f' %
             (prob.max_val, max_val_soln, diff), 'test_result')
         max_is_successful = diff < 1e-3
         num_max_successes += max_is_successful
     # Check if successful
     assert num_max_successes >= 1
Beispiel #4
0
 def _rand_wrap(*args):
   """ A wrapper so as to only return the optimal point. """
   _, opt_pt = random_maximise(*args, vectorised=False)
   return opt_pt