def add_primitive_interaction(self, experiment, result, valence): label = experiment.get_label() + result.get_label() if label not in self.INTERACTIONS: interaction = Interaction(label, valence) interaction.set_experiment(experiment) interaction.set_result(result) interaction.set_valence(valence) self.INTERACTIONS[label] = interaction
def addget_primitive_interaction(self, experiment, result, valence=None, meaning=None): label = experiment.get_label() + result.get_label() if label not in self.INTERACTIONS: interaction = Interaction(label) interaction.set_experiment(experiment) interaction.set_result(result) interaction.set_valence(valence) interaction.set_meaning(meaning) self.INTERACTIONS[label] = interaction return self.INTERACTIONS[label]
def learn_composite_interaction(self, context_interaction, enacted_interaction): if context_interaction is not None: label = context_interaction.get_label() + enacted_interaction.get_label() if label not in self.INTERACTIONS: valence = context_interaction.get_valence() + enacted_interaction.get_valence() interaction = Interaction(label, valence) interaction.set_pre_interaction(context_interaction) interaction.set_post_interaction(enacted_interaction) interaction.set_valence(valence) self.INTERACTIONS[label] = interaction print "Learn " + label else: interaction = self.INTERACTIONS[label] print 'Incrementing weight for ' + interaction.__repr__() interaction.increment_weight()
def initialize_interactions(self, primitive_interactions): for interaction in primitive_interactions: meaning = interaction experiment_label = primitive_interactions[interaction][0] result_label = primitive_interactions[interaction][1] valence = primitive_interactions[interaction][2] experiment = self.addget_abstract_experiment(experiment_label) result = self.addget_result(result_label) self.addget_primitive_interaction(experiment, result, valence, meaning) for experiment in self.EXPERIMENTS.values(): interaction = Interaction(experiment.get_label() + "r2") interaction.set_valence(1) interaction.set_experiment(experiment) experiment.set_intended_interaction(interaction)
def learn_composite_interaction(self, context_interaction, enacted_interaction): if context_interaction is not None: label = context_interaction.get_label( ) + enacted_interaction.get_label() if label not in self.INTERACTIONS: valence = context_interaction.get_valence( ) + enacted_interaction.get_valence() interaction = Interaction(label) interaction.set_pre_interaction(context_interaction) interaction.set_post_interaction(enacted_interaction) interaction.set_valence(valence) self.INTERACTIONS[label] = interaction print "Learn " + label else: interaction = self.INTERACTIONS[label] print 'Incrementing weight for ' + interaction.__repr__() interaction.increment_weight()
def addget_primitive_interaction(self, experiment, result, valence=None, meaning=None): """ If a primitive interaction is not in the INTERACTIONS dictionary, add it. Otherwise just return it. :param experiment: (str) primitive experiment :param result: (str) primitive result :param valence: (int) valence of the interaction :param meaning: (str) observer's meaning of the interaction :return: (interaction) primitive interaction from the INTERACTIONS dictionary """ label = experiment.get_label() + result.get_label() if label not in self.INTERACTIONS: interaction = Interaction(label) interaction.set_experiment(experiment) interaction.set_result(result) interaction.set_valence(valence) interaction.set_meaning(meaning) self.INTERACTIONS[label] = interaction return self.INTERACTIONS[label]
def learn_composite_interaction(self, context_interaction, enacted_interaction): """ Learn a new composite interaction or reinforce it if already known. :param context_interaction: (Interaction) at time t-1 :param enacted_interaction: (Interaction) just performed """ if context_interaction is not None: label = context_interaction.get_label() + enacted_interaction.get_label() if label not in self.INTERACTIONS: # valence is a sum of primitive interactions valence = context_interaction.get_valence() + enacted_interaction.get_valence() interaction = Interaction(label) interaction.set_pre_interaction(context_interaction) interaction.set_post_interaction(enacted_interaction) interaction.set_valence(valence) self.INTERACTIONS[label] = interaction print "Learn " + label else: interaction = self.INTERACTIONS[label] print 'Incrementing weight for ', interaction interaction.increment_weight()
def __init__(self, primitive_interactions, environment): """Initialize existence with a set of primitive interactions provided as a dictionary: {(str) interaction meaning: ((str) experiment, (str) result, (int) valence)""" self.context_interaction = None self.context_pair_interaction = None # context at previous two steps (t-2, t-1) self.mood = None self.previous_experiment = None self.penultimate_experiment = None self.environment = environment for interaction in primitive_interactions: meaning = interaction experiment_label = primitive_interactions[interaction][0] result_label = primitive_interactions[interaction][1] valence = primitive_interactions[interaction][2] experiment = self.addget_rexperiment(experiment_label) result = self.addget_result(result_label) pi = self.addget_primitive_interaction(experiment, result, valence, meaning) for experiment in self.EXPERIMENTS.values(): interaction = Interaction(experiment.get_label() + "r2") interaction.set_valence(1) experiment.set_intended_interaction(interaction)
def learn_composite_interaction(self, context_interaction, enacted_interaction): """ Learn a new composite interaction or reinforce it if already known. :param context_interaction: (Interaction) at time t-1 :param enacted_interaction: (Interaction) just performed """ if context_interaction is not None: label = context_interaction.get_label( ) + enacted_interaction.get_label() if label not in self.INTERACTIONS: # valence is a sum of primitive interactions valence = context_interaction.get_valence( ) + enacted_interaction.get_valence() interaction = Interaction(label) interaction.set_pre_interaction(context_interaction) interaction.set_post_interaction(enacted_interaction) interaction.set_valence(valence) self.INTERACTIONS[label] = interaction print "Learn " + label else: interaction = self.INTERACTIONS[label] print 'Incrementing weight for ', interaction interaction.increment_weight()