Exemple #1
0
    def enacted_interaction(self, interaction, data):
        # Post enacted interaction event
        AppState.state.get_event_manager().post_event(
            events.AgentEnactionEvent(self, interaction, -1))
        self.interaction_memory.add_interaction_to_history(interaction)

        print "%s - Enacted: %s" % (self.name, interaction)
Exemple #2
0
    def enacted_interaction(self, interaction, data):
        # Learn interaction if it is not yet known
        if interaction not in self.interaction_memory.get_primitive_interactions(
        ):
            self.interaction_memory.add_interaction(interaction)

        # Post enacted interaction event
        AppState.state.get_event_manager().post_event(
            events.AgentEnactionEvent(
                self, interaction,
                self.interaction_memory.get_valence(interaction)))
        self.interaction_memory.add_interaction_to_history(interaction)

        if not self.enacted == None:
            self.learn_composite_interaction(self.enacted, interaction)
        self.enacted = interaction
Exemple #3
0
    def enacted_interaction(self, interaction_, data):
        self.enacting_interaction_step += 1
        intended_primitive_interaction = data

        self.enacted_sequence.append(interaction_)

        # Learn interaction if it is not yet known
        if interaction_ not in self.interaction_memory.get_primitive_interactions(
        ):
            self.interaction_memory.add_interaction(interaction_)

        # Post enacted interaction event
        AppState.state.get_event_manager().post_event(
            events.AgentEnactionEvent(
                self, interaction_,
                self.interaction_memory.get_valence(interaction_)))
        self.interaction_memory.add_interaction_to_history(interaction_)

        if (not interaction_ == intended_primitive_interaction
                or self.enacting_interaction_step >= len(
                    self.enacting_interaction_sequence)):
            # Failed or done enacting
            self.enacting_interaction = False

            # Reconstruct enacted interaction from hierarchy of intended
            # interaction
            enacted = self.intended_interaction.reconstruct_from_hierarchy(
                self.enacted_sequence)
            AppState.get_state().get_logger().info("%s - Enacted: %s" %
                                                   (self.name, enacted))

            # Add the interaction as an alternative interaction if the intended interaction failed
            if enacted != self.intended_interaction:
                if self.interaction_memory.add_alternative_interaction(
                        self.intended_interaction, enacted):
                    AppState.get_state().get_logger().info(
                        "%s - Interaction added as alternative" % self.name)

            # Step 5: add new or reinforce existing composite interactions
            learned_or_reinforced = []
            if isinstance(enacted, interaction.CompositeInteraction):
                learned_or_reinforced.append(enacted)

            if len(self.history) >= 1:
                previous = self.history[-1]
                # <interaction at t-1, enacted interaction>
                t1enacted = interaction.CompositeInteraction(previous, enacted)
                learned_or_reinforced.append(t1enacted)

                if len(self.history) >= 2:
                    penultimate = self.history[-2]
                    # <interaction at t-2, interaction at t-1>
                    t2t1 = interaction.CompositeInteraction(
                        penultimate, previous)

                    # <<interaction at t-2, interaction at t-1>, enacted interaction>
                    t2t1_enacted = interaction.CompositeInteraction(
                        t2t1, enacted)
                    learned_or_reinforced.append(t2t1_enacted)

                    # <interaction at t-2, <interaction at t-1, enacted interaction>>
                    t2_t1enacted = interaction.CompositeInteraction(
                        penultimate, t1enacted)
                    learned_or_reinforced.append(t2_t1enacted)
            for composite in learned_or_reinforced:
                if composite not in self.interaction_memory.get_composite_interactions(
                ):
                    self.interaction_memory.add_interaction(composite)
                else:
                    self.interaction_memory.increment_weight(composite)

            # Keep history of last 100 actions performed
            if len(self.history) > 100:
                self.history.pop(0)
            self.history.append(enacted)
            """
            According to the paper:

            for pre_interaction in self.context:
                composite = interaction.CompositeInteraction(pre_interaction, enacted)
                learned_or_reinforced.append(composite)
                if composite not in self.interaction_memory.get_composite_interactions():
                    self.interaction_memory.add_interaction(composite)
                else:
                    self.interaction_memory.increment_weight(composite)
            """

            # Step 6: update context
            self.update_context(enacted, learned_or_reinforced)
        else:
            # Not done
            pass