예제 #1
0
파일: nasbot.py 프로젝트: DRealArun/nasbot
 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
파일: nasbot.py 프로젝트: DRealArun/nasbot
def nasbot(func_caller,
           worker_manager,
           budget,
           tp_comp=None,
           mode=None,
           init_pool=None,
           acq='hei',
           options=None,
           reporter='default'):
    """ NASBOT optimisation from a function caller. """
    nn_type = func_caller.domain.nn_type
    if options is None:
        reporter = get_reporter(reporter)
        options = load_options(all_nasbot_args, reporter=reporter)
    if acq is not None:
        options.acq = acq
    if mode is not None:
        options.mode = mode
    if tp_comp is None:
        tp_comp = get_default_otmann_distance(nn_type, 1.0)
    # Initial queries
    if not hasattr(options,
                   'pre_eval_points') or options.pre_eval_points is None:
        if init_pool is None:
            init_pool = get_initial_pool(nn_type)
        options.get_initial_points = lambda n: init_pool[:n]
    return (NASBOT(func_caller,
                   worker_manager,
                   tp_comp,
                   options=options,
                   reporter=reporter)).optimise(budget)
  def test_initial_pool(self):
    """ Unit test for the VGG_net."""
    self.report('Testing the initial pool. ')
    cnns = get_initial_pool('cnn')
    visualise_list_of_nns(cnns, os.path.join(self.save_dir, 'cnn'))
    NN_PERFORMANCE = []
    for nn in cnns:
      NN_dataflow_work = tranfor_net_to_NNdataFlow(nn)
      manager = Manager()
      return_dict = manager.dict()
      p = Process(target=model_cast,args=(NN_dataflow_work,return_dict,))
      p.start()
      p.join()

      NN_PERFORMANCE.append(return_dict['total_time'])
      print("NN_PERFORMANCE:",NN_PERFORMANCE)