Esempio n. 1
0
    def initialise_visible_agents(self, sim, generated_data_number,
                                  PF_add_threshold, train_mode,
                                  type_selection_mode,
                                  parameter_estimation_mode, polynomial_degree,
                                  apply_adversary, type_estimation_mode,
                                  mutation_rate, do_estimation):

        agent_index = 0

        self.apply_adversary = apply_adversary

        param_estim = None

        # if do_estimation:

        for agent in sim.agents:
            x, y = agent.get_position()
            u_a = unknown_agent.UnknownAgent(x, y, agent.direction,
                                             agent.index)
            if not do_estimation:
                u_a.agent_type = agent.agent_type
                u_a.set_parameters(sim, agent.level, agent.radius, agent.angle)

            else:
                param_estim = parameter_estimation.ParameterEstimation(
                    generated_data_number, PF_add_threshold, train_mode,
                    apply_adversary, mutation_rate)

                param_estim.estimation_initialisation()

                param_estim.estimation_configuration(
                    type_selection_mode, parameter_estimation_mode,
                    polynomial_degree, type_estimation_mode)
                if parameter_estimation_mode == 'MIN':
                    param_estim.l1_estimation.train_data.initialise_particle_data_set(
                        u_a, sim)
                    param_estim.l2_estimation.train_data.initialise_particle_data_set(
                        u_a, sim)
                    param_estim.f1_estimation.train_data.initialise_particle_data_set(
                        u_a, sim)
                    param_estim.f2_estimation.train_data.initialise_particle_data_set(
                        u_a, sim)

                u_a.agents_parameter_estimation = param_estim
                u_a.set_type_parameters(sim)

            u_a.find_estimated_target(sim)
            self.visible_agents.append(u_a)
            agent_index += 1

        if sim.enemy_agent is not None:
            x, y = sim.enemy_agent.get_position()
            a = unknown_agent.UnknownAgent(x, y, sim.enemy_agent.direction,
                                           agent_index)
            a.agent_type = 'w'

            self.visible_agents.append(a)

        return
Esempio n. 2
0
 def initialise_parameter_estimation(self, type_selection_mode,
                                     parameter_estimation_mode,
                                     generated_data_number,
                                     PF_add_threshold, PF_del_threshold,
                                     PF_weight):
     param_estim = parameter_estimation.ParameterEstimation()
     param_estim.estimation_initialisation()
     polynomial_degree = 4
     param_estim.estimation_configuration(type_selection_mode,
                                          parameter_estimation_mode,
                                          generated_data_number,
                                          polynomial_degree,
                                          PF_add_threshold,
                                          PF_del_threshold, PF_weight)
     self.estimated_parameter = param_estim
Esempio n. 3
0
    def initialise_visible_agents(self, sim, generated_data_number,
                                  PF_add_threshold, train_mode,
                                  type_selection_mode,
                                  parameter_estimation_mode, polynomial_degree,
                                  apply_adversary, type_estimation_mode,
                                  mutation_rate):

        agent_index = 0
        self.apply_adversary = apply_adversary
        for agent in sim.agents:
            x, y = agent.get_position()
            a = unknown_agent.Agent(x, y, agent.direction, agent_index)
            a.agent_type = agent.agent_type
            a.level = agent.level
            a.radius = agent.radius
            a.angle = agent.angle

            self.visible_agents.append(a)
            agent_index += 1

        if sim.enemy_agent is not None:
            x, y = sim.enemy_agent.get_position()
            a = unknown_agent.Agent(x, y, sim.enemy_agent.direction,
                                    agent_index)
            a.agent_type = 'w'

            self.visible_agents.append(a)

        for unknown_a in self.visible_agents:

            param_estim = parameter_estimation.ParameterEstimation(
                generated_data_number, PF_add_threshold, train_mode,
                apply_adversary, mutation_rate, unknown_a, sim)

            param_estim.estimation_initialisation()

            param_estim.estimation_configuration(type_selection_mode,
                                                 parameter_estimation_mode,
                                                 polynomial_degree,
                                                 type_estimation_mode)

            unknown_a.agents_parameter_estimation = param_estim

        return
Esempio n. 4
0
# real_sim.draw_map_with_level()
main_sim.draw_map()
main_sim.log_map(logfile)

used_mem_before = psutil.virtual_memory().used

search_tree = None

time_step = 0
begin_time = time.time()

polynomial_degree = 4
agants_parameter_estimation = []
for i in range(len(main_sim.agents)):
    param_estim = parameter_estimation.ParameterEstimation()
    param_estim.estimation_initialisation()

    param_estim.estimation_configuration(type_selection_mode,
                                         parameter_estimation_mode,
                                         generated_data_number,
                                         polynomial_degree, PF_add_threshold,
                                         PF_del_threshold, PF_weight)

    agants_parameter_estimation.append(param_estim)

while main_sim.items_left() > 0:
    # while time_step < 110:
    print 'main run count: ', time_step

    for i in range(len(main_sim.agents)):
Esempio n. 5
0
    def initialise_visible_agents(self, sim, generated_data_number,
                                  PF_add_threshold, train_mode,
                                  type_selection_mode,
                                  parameter_estimation_mode, polynomial_degree,
                                  apply_adversary, type_estimation_mode,
                                  mutation_rate):
        self.apply_adversary = apply_adversary

        # 1. getting the map empty positions
        empty_positions = []
        empty_positions = [(int(x), int(y)) for x in range(sim.dim_w)
                           for y in range(sim.dim_h)]
        empty_positions.remove(sim.main_agent.get_position())

        # 2. taking the visible and invisible content
        self.agent_memory = list()
        self.item_memory = list()
        self.init_visibility(sim)

        # 3. setting memory and map
        # a. visible stuff
        for ag in self.visible_agents:
            ag.already_seen = True
            pos = ag.position
            empty_positions.remove(pos)
            self.agent_memory.append(ag)

        for item in self.visible_items:
            item.already_seen = True
            pos = item.get_position()
            empty_positions.remove(pos)
            self.item_memory.append(item)

        # b. removing the visible position
        for x in range(sim.dim_w):
            for y in range(sim.dim_h):
                if self.see_object((x, y)):
                    self.already_seen_position.add((x, y))
                    if (x, y) in empty_positions:
                        empty_positions.remove((x, y))

        # c. invisible stuff
        for item in self.invisible_items:
            item.already_seem = False
            x, y = sample(empty_positions, 1)[0]
            item.position = position.position(x, y)
            empty_positions.remove((x, y))
            self.item_memory.append(item)

        for ag in self.invisible_agents:
            ag.already_seen = False
            pos = sample(empty_positions, 1)[0]
            ag.position = pos
            empty_positions.remove(pos)
            self.agent_memory.append(ag)

        # 4. starting the param estimation
        for unknown_a in self.agent_memory:
            param_estim = parameter_estimation.ParameterEstimation(
                generated_data_number, PF_add_threshold, train_mode,
                mutation_rate, apply_adversary, unknown_a, sim)
            param_estim.estimation_initialisation()
            param_estim.estimation_configuration(type_selection_mode,
                                                 parameter_estimation_mode,
                                                 polynomial_degree,
                                                 type_estimation_mode)

            unknown_a.agents_parameter_estimation = param_estim