Esempio n. 1
0
 def _clack_words(self):
     if self._learning_words:
         sight_pattern = self.s_knowledge_in.get_pattern()
         sight_class = "None"
         sight_knowledge = RbfKnowledge(sight_pattern, sight_class)
         self.words_net.clack(sight_knowledge)
         CulturalNetwork.serialize(self.words_net,
                                   "persistent_memory/words_net.p")
         self._learning_words = False
     else:
         hearing_pattern = self.h_knowledge_in.get_pattern()
         hearing_class = self.h_knowledge_in.get_class()
         hearing_knowledge = RbfKnowledge(hearing_pattern, hearing_class)
         self.syllables_net.clack(hearing_knowledge)
         CulturalNetwork.serialize(self.syllables_net,
                                   "persistent_memory/syllables_net.p")
         syll_hearing_id = self.syllables_net.get_last_clack_id()
         sight_pattern = self.s_knowledge_in.get_pattern()
         # Recognize
         if self.snb.recognize_sight(sight_pattern) == "HIT":
             sight_id = self.snb.snb_s.get_rneurons_ids()[0]
         else:
             sight_class = "syll_" + str(syll_hearing_id)
             sight_knowledge = RbfKnowledge(sight_pattern, sight_class)
             self.snb.learn_sight(sight_knowledge)
             sight_id = self.snb.snb_s.get_last_learned_id()
         self.snb.save("persistent_memory/sight_snb.p",
                       "persistent_memory/hearing_snb.p")
         # Learn relation in new net
         rel_knowledge = RelKnowledge(syll_hearing_id, sight_id)
         self.ss_rnb.learn(rel_knowledge)
         RelNetwork.serialize(self.ss_rnb, "persistent_memory/ss_rnb.p")
         self._learning_syllables = False
 def _clack_addition(self):
     s_pattern = self.s_knowledge_in.get_pattern()
     self.state = self.snb.recognize_sight(s_pattern)
     if self.state == "HIT":
         hearing_id = self._get_hearing_id_recognize()
         self.am_net.clack(hearing_id)
         CulturalNetwork.serialize(self.am_net, "persistent_memory/am_net.p")
 def erase_all_knowledge(self):
     # snb
     self.snb = SensoryNeuralBlock()
     self.snb.save("persistent_memory/sight_snb.p", "persistent_memory/hearing_snb.p")
     # Relational Neural Block
     self.rnb = RelNetwork(100)
     RelNetwork.serialize(self.rnb, "persistent_memory/rnb.p")
     # Addition by memory network
     self.am_net = CulturalNetwork(100)
     CulturalNetwork.serialize(self.am_net, "persistent_memory/am_net.p")
     # Syllables net
     self.syllables_net = CulturalNetwork(100)
     CulturalNetwork.serialize(self.syllables_net, "persistent_memory/syllables_net.p")
     # Words net
     self.words_net = CulturalNetwork(100)
     CulturalNetwork.serialize(self.words_net, "persistent_memory/words_net.p")
     # Sight-Syllables rel network
     self.ss_rnb = RelNetwork(100)
     RelNetwork.serialize(self.ss_rnb, "persistent_memory/ss_rnb.p")
     # Geometric Neural Block
     self.gnb = GeometricNeuralBlock()
     GeometricNeuralBlock.serialize(self.gnb, "persistent_memory/gnb.p")
     ################ INTENTIONS ####################################################################################
     self.episodic_memory = EpisodicMemoriesBlock()
     EpisodicMemoriesBlock.serialize(self.episodic_memory, "persistent_memory/episodic_memory.p")
     self.decisions_block = DecisionsBlock()
     DecisionsBlock.serialize(self.decisions_block, "persistent_memory/decisions_block.p")
     self.internal_state = InternalState()
     InternalState.serialize(self.internal_state, "persistent_memory/internal_state.p")
     self.desired_state = InternalState([0.5,1,1])
     InternalState.serialize(self.desired_state, "persistent_memory/desired_state.p")
 def create_kernel(self):
     # snb
     self.snb = SensoryNeuralBlock("no_data", "no_data", self.project_id)
     self.snb.save("snb_s", "snb_h", self.project_id, self.brain)
     # Relational Neural Block
     self.rnb = RelNetwork(100)
     RelNetwork.serialize(self.rnb, "rnb", self.project_id)
     # Addition by memory network
     self.am_net = CulturalNetwork(100)
     CulturalNetwork.serialize(self.am_net, "am_net", self.project_id)
     # Syllables net
     self.syllables_net = CulturalNetwork(100)
     CulturalNetwork.serialize(self.syllables_net, "syllables_net",
                               self.project_id)
     # Words net
     self.words_net = CulturalNetwork(100)
     CulturalNetwork.serialize(self.words_net, "words_net", self.project_id)
     # Sight-Syllables rel network
     self.ss_rnb = RelNetwork(100)
     RelNetwork.serialize(self.ss_rnb, "ss_rnb", self.project_id)
     # Geometric Neural Block
     self.gnb = GeometricNeuralBlock()
     GeometricNeuralBlock.serialize(self.gnb, "gnb", self.project_id)
     ################ INTENTIONS ####################################################################################
     self.episodic_memory = EpisodicMemoriesBlock()
     EpisodicMemoriesBlock.serialize(self.episodic_memory,
                                     "episodic_memory", self.project_id)
     self.decisions_block = DecisionsBlock()
     DecisionsBlock.serialize(self.decisions_block, "decisions_block",
                              self.project_id)
     self.internal_state = InternalState()
     InternalState.serialize(self.internal_state, "internal_state",
                             self.project_id)
     self.desired_state = InternalState([0.75, 0.75, 0.75])
     InternalState.serialize(self.desired_state, "desired_state",
                             self.project_id)
Esempio n. 5
0
 def __init__(self):
     CulturalNetwork.__init__(self)
Esempio n. 6
0
    def __init__(self):
        grid_size = 16
        # HEURISTICS: radius = (1/3)*2^(ENCODING_SIZE)
        # where ENCODING_SIZE is bit size of every pattern element (8 bits for us)
        radius = 24
        # Calculate pattern size based on grid_size and size of a Nibble (4)
        pattern_size = pow(grid_size, 2) / 4
        # Set neural network data size
        RbfNetwork.PATTERN_SIZE = pattern_size
        # Set neural network default radius
        RbfNetwork.DEFAULT_RADIUS = radius
        # Set pattern size in RBF knowledge
        RbfKnowledge.PATTERN_SIZE = pattern_size

        # If there are no persisten memory related files, create them
        if not os.path.isfile("persistent_memory/sight_snb.p"):
            self.erase_all_knowledge()

        # SNB
        self.snb = SensoryNeuralBlock("persistent_memory/sight_snb.p",
                                      "persistent_memory/hearing_snb.p")
        # Relational Neural Block
        self.rnb = RelNetwork.deserialize("persistent_memory/rnb.p")
        # Analytical neuron
        self.analytical_n = AnalyticalNeuron()
        # Addition by memory network
        self.am_net = CulturalNetwork.deserialize("persistent_memory/am_net.p")
        # Geometric Neural Block
        self.gnb = GeometricNeuralBlock.deserialize("persistent_memory/gnb.p")
        # Syllables net
        self.syllables_net = CulturalNetwork.deserialize(
            "persistent_memory/syllables_net.p")
        # Words net
        self.words_net = CulturalNetwork.deserialize(
            "persistent_memory/words_net.p")
        # Sight-Syllables rel network
        self.ss_rnb = RelNetwork.deserialize("persistent_memory/ss_rnb.p")

        # ################### INTENTIONS MODULES ########################################################################
        self.episodic_memory = EpisodicMemoriesBlock.deserialize(
            "persistent_memory/episodic_memory.p")
        self.decisions_block = DecisionsBlock.deserialize(
            "persistent_memory/decisions_block.p")

        self.internal_state = InternalState.deserialize(
            "persistent_memory/internal_state.p")
        self.desired_state = InternalState.deserialize(
            "persistent_memory/desired_state.p")

        # Internal state "Ports" (Three components real valued vector)
        self._internal_state_in = None

        # Memory that stores short term bip inputs for making a decision
        self._intentions_short_term_memory = []
        self._output_memory = None
        # ###############################################################################################################

        # _bbcc_words
        self._learning_words = False
        self._learning_syllables = False
        self._enable_bbcc = False

        # Output "ports" (related to senses)
        self.s_knowledge_out = None
        self.h_knowledge_out = None

        # Input "ports" (senses)
        self.s_knowledge_in = None
        self.h_knowledge_in = None

        self._working_domain = "ADDITION"
        self.state = "MISS"
    def __init__(self, user, project, frontend_request):
        grid_size = 16
        # HEURISTICS: radius = (1/3)*2^(ENCODING_SIZE)
        # where ENCODING_SIZE is bit size of every pattern element (8 bits for us)
        radius = 24
        # Calculate pattern size based on grid_size and size of a Nibble (4)
        pattern_size = pow(grid_size, 2) / 4
        # Set neural network data size
        RbfNetwork.PATTERN_SIZE = pattern_size
        # Set neural network default radius
        RbfNetwork.DEFAULT_RADIUS = radius
        # Set pattern size in RBF knowledge
        RbfKnowledge.PATTERN_SIZE = pattern_size
        # If there are no persisten memory related files, create them
        self.user = user

        self.hearing_id = -1

        if frontend_request == "CREATE":

            self.brain = brain(user=self.user, name=project)
            self.brain.save()
            self.project_id = self.brain.id
            self.project_name = project
            self.create_kernel()
            self.message = 'the brain has been created successfully, the id is ' + str(
                self.project_id)

        if frontend_request == "LOAD":

            self.project_id = project
            # SNB
            self.snb = SensoryNeuralBlock("snb_s", "snb_h", self.project_id)
            #print(self.snb.snb_h.__dict__)
            #for i in self.snb.snb_h.neuron_list:
            #if i._knowledge!= None:
            #print(i._knowledge)
            # Relational Neural Block
            self.rnb = RelNetwork.deserialize("rnb", self.project_id)
            #print(self.rnb.__dict__)
            #for i in self.rnb.neuron_list:
            #if i._knowledge!= None:
            #print(i.__dict__)
            #print(i._knowledge.__dict__)
            # Addition by memory network
            self.am_net = CulturalNetwork.deserialize("am_net",
                                                      self.project_id)
            #print(self.am_net.__dict__)
            #for i in self.am_net.group_list:
            #if i._knowledge!= None:
            #print(i.__dict__)
            # Geometric Neural Block
            self.gnb = GeometricNeuralBlock.deserialize("gnb", self.project_id)
            #print(self.gnb.__dict__)
            #for i in self.gnb._addition_structure.neurons:
            #if i._knowledge!= None:
            #print(i.__dict__)
            # Syllables net
            self.syllables_net = CulturalNetwork.deserialize(
                "syllables_net", self.project_id)
            #print(self.syllables_net.__dict__)
            #for i in self.syllables_net.group_list:
            #if i._knowledge!= None:
            #print(i.__dict__)
            # Words net
            self.words_net = CulturalNetwork.deserialize(
                "words_net", self.project_id)
            #print(self.words_net.__dict__)
            #for i in self.words_net.group_list:
            #if i._knowledge!= None:
            #print(i.__dict__)
            # Sight-Syllables rel network
            self.ss_rnb = RelNetwork.deserialize("ss_rnb", self.project_id)
            #print(self.ss_rnb.__dict__)
            # for i in self.ss_rnb.neuron_list:
            #     if i._knowledge!= None:
            #         print(i._knowledge.__dict__)

            #################### INTENTIONS MODULES ########################################################################
            self.episodic_memory = EpisodicMemoriesBlock.deserialize(
                "episodic_memory", self.project_id)
            #print(self.episodic_memory.__dict__)
            #for i in self.episodic_memory.group_list:
            #print(i.__dict__)
            #for k in i.group:
            #print(k.__dict__)
            # if isinstance(k._knowledge, int):
            #     asd=int(k._knowledge)
            #     print(asd)
            # else:
            #     print(k._knowledge.__dict__)
            self.decisions_block = DecisionsBlock.deserialize(
                "decisions_block", self.project_id)
            #print(self.decisions_block.__dict__)
            #print(self.decisions_block.conscious_block.decision_prediction_block.predictive_net.__dict__)
            self.internal_state = InternalState.deserialize(
                "internal_state", self.project_id)
            #print('internal',self.internal_state.__dict__)
            self.desired_state = InternalState.deserialize(
                "desired_state", self.project_id)
            #print('desired',self.desired_state.__dict__)

            self.message = "BRAIN SUCCESFULLY LOADED"

        ################################################# NON-deserialize data################
        # Analytical neuron
        self.analytical_n = AnalyticalNeuron()
        #print(self.analytical_n.__dict__)

        # Internal state "Ports" (Three components real valued vector)
        self._internal_state_in = None

        # Memory that stores short term bip inputs for making a decision
        self._intentions_short_term_memory = []
        self._output_memory = None
        # ###############################################################################################################

        # _bbcc_words
        self._learning_words = False
        self._learning_syllables = False
        self._enable_bbcc = False

        # Output "ports" (related to senses)
        self.s_knowledge_out = None
        self.h_knowledge_out = None

        # Input "ports" (senses)
        self.s_knowledge_in = None
        self.h_knowledge_in = None

        self._working_domain = "ADDITION"
        self.state = "MISS"