示例#1
0
 def _set_up_acq_opt_ga(self):
     """ Determines the mutation operator for the internal GA. """
     # First the sampling distribution for the GA mutation operator
     mut_arg = self.options.ga_mutation_op_distro
     if isinstance(mut_arg, list):
         self.ga_mutation_op = get_nn_modifier_from_args(
             self.domain.constraint_checker, dflt_num_steps_probs=mut_arg)
     elif isinstance(mut_arg, (int, long, float)):
         self.ga_mutation_op = get_nn_modifier_from_args(
             self.domain.constraint_checker, dflt_max_num_steps=mut_arg)
     elif mut_arg.startswith('d'):
         ga_mutation_probs = [float(x) for x in mut_arg[1:].split('-')]
         self.ga_mutation_op = get_nn_modifier_from_args(
             self.domain.constraint_checker,
             dflt_num_steps_probs=ga_mutation_probs)
     elif mut_arg.startswith('n'):
         ga_mutation_num_steps = int(x[1:])
         self.ga_mutation_op = get_nn_modifier_from_args(
             self.domain.constraint_checker,
             dflt_max_num_steps=ga_mutation_num_steps)
     else:
         raise ValueError('Cannot parse ga_mutation_op_distro=%s.' %
                          (self.options.ga_mutation_op_distro))
     # The initial pool
     self.ga_init_pool = get_initial_pool(self.domain.get_type())
     # The number of evaluations
     if self.get_acq_opt_max_evals is None:
         lead_const = min(5, self.domain.get_dim())**2
         self.get_acq_opt_max_evals = lambda t: np.clip(
             lead_const * np.sqrt(t), 50, 500)
示例#2
0
def get_nn_opt_arguments():
  """ Returns arguments for NN Optimisation. """
  ret = Namespace()
  ret.cnn_constraint_checker = CNNConstraintChecker(50, 5, 1e8, 0, 5, 5, 200, 1024, 8)
  ret.mlp_constraint_checker = MLPConstraintChecker(50, 5, 1e8, 0, 5, 5, 200, 1024, 8)
  ret.cnn_mutation_op = get_nn_modifier_from_args(ret.cnn_constraint_checker,
                                                   [0.5, 0.25, 0.125, 0.075, 0.05])
  ret.mlp_mutation_op = get_nn_modifier_from_args(ret.mlp_constraint_checker,
                                                   [0.5, 0.25, 0.125, 0.075, 0.05])
  # Create the initial pool
  ret.cnn_init_pool = get_initial_cnn_pool()
  ret.cnn_init_vals = [cnn_syn_func1(cnn) for cnn in ret.cnn_init_pool]
  ret.mlp_init_pool = get_initial_mlp_pool('reg')
  ret.mlp_init_vals = [mlp_syn_func1(mlp) for mlp in ret.mlp_init_pool]
  # Create a domain
  ret.nn_domain = NNDomain(None, None)
  ret.cnn_domain = NNDomain('cnn', ret.cnn_constraint_checker)
  ret.mlp_domain = NNDomain('mlp-reg', ret.mlp_constraint_checker)
  # Return
  return ret
示例#3
0
def get_opt_problem(nn_type):
    """ Gets parameters for the optimisation problem. """
    if nn_type == 'cnn':
        constraint_checker = CNNConstraintChecker(50, 1e8, 5, 5, 200, 1024, 8)
        init_points = get_initial_cnn_pool()
        func_caller = FunctionCaller(cnn_syn_func1, NNDomain(None, None))
    elif nn_type.startswith('mlp'):
        constraint_checker = MLPConstraintChecker(50, 1e8, 5, 5, 200, 1024, 8)
        init_points = get_initial_mlp_pool(CLASS_OR_REG)
        func_caller = FunctionCaller(mlp_syn_func1, NNDomain(None, None))
    else:
        raise ValueError('Unknown nn_type: %s.' % (nn_type))
    # Common stuff
    mutation_op = get_nn_modifier_from_args(constraint_checker,
                                            [0.5, 0.25, 0.125, 0.075, 0.05])
    init_vals = [func_caller.eval_single(nn)[0] for nn in init_points]
    return constraint_checker, func_caller, mutation_op, init_points, init_vals