def __init__(self,
              num_samples,
              population_size,
              topology,
              train_data,
              test_data,
              directory,
              problem_type='classification',
              max_limit=2,
              min_limit=-2):
     self.num_samples = num_samples
     self.pop_size = population_size
     self.topology = topology
     self.train_data = train_data
     self.test_data = test_data
     self.problem_type = problem_type
     self.directory = directory
     self.w_size = (topology[0] * topology[1]) + (
         topology[1] * topology[2]) + topology[1] + topology[2]
     self.neural_network = Network(topology, train_data, test_data)
     self.min_limits = np.repeat(min_limit, self.w_size)
     self.max_limits = np.repeat(max_limit, self.w_size)
     self.initialize_sampling_parameters()
     self.create_directory(directory)
     PSO.__init__(self, self.pop_size, self.w_size, self.max_limits,
                  self.min_limits, self.neural_network.evaluate_fitness)
예제 #2
0
    def __init__(self,
                 num_samples,
                 burn_in,
                 population_size,
                 topology,
                 train_data,
                 test_data,
                 directory,
                 temperature,
                 swap_sample,
                 parameter_queue,
                 problem_type,
                 main_process,
                 event,
                 active_chains,
                 num_accepted,
                 swap_interval,
                 max_limit=(10),
                 min_limit=-10):
        # Multiprocessing attributes
        multiprocessing.Process.__init__(self)
        self.process_id = temperature
        self.parameter_queue = parameter_queue
        self.signal_main = main_process
        self.event = event
        self.active_chains = active_chains
        self.num_accepted = num_accepted
        self.event.clear()
        self.signal_main.clear()
        # Parallel Tempering attributes
        self.temperature = temperature
        self.swap_sample = swap_sample
        self.swap_interval = swap_interval
        self.burn_in = burn_in
        # MCMC attributes
        self.num_samples = num_samples

        self.topology = topology
        self.train_data = train_data
        self.test_data = test_data
        self.problem_type = problem_type
        self.directory = directory
        self.w_size = (topology[0] * topology[1]) + (
            topology[1] * topology[2]) + topology[1] + topology[2]
        self.neural_network = Network(topology, train_data, test_data)
        self.min_limits = np.repeat(min_limit, self.w_size)
        self.max_limits = np.repeat(max_limit, self.w_size)
        self.initialize_sampling_parameters()
        self.create_directory(directory)
        PSO.__init__(self,
                     pop_size=population_size,
                     num_params=self.w_size,
                     max_limits=self.max_limits,
                     min_limits=self.min_limits,
                     fitness_function=self.neural_network.evaluate_fitness,
                     problem_type=self.problem_type)