def testCreatingLinks(self): l = HTMLevel(0, {"size": [1], "nodeCloning": True}, previous_level_size=[1]) prev_size = [8, 8] correct_links = {0: range(np.prod(prev_size))} links = l._get_links([1, 1], prev_size) self.assertEqual(links, correct_links)
def testCreatingLinks(self): l = HTMLevel(0, { 'size': [1], 'nodeCloning': True }, previous_level_size=[1]) prev_size = [8, 8] correct_links = {0: range(np.prod(prev_size))} links = l._get_links([1, 1], prev_size) self.assertEqual(links, correct_links)
def runTest(self): params = {"transitionMemory": 4, "requestedGroupsCount": 3} l = HTMLevel(0, {"size": [1], "nodeCloning": True}, previous_level_size=[1]) for p in patterns: l.do_spatial_learning([p]) for p in patterns: l.do_temporal_learning([p]) desired_TAM = np.array([[2.0, 4.0, 3.0, 5.0], [3.0, 0.0, 4.0, 2.0], [4.0, 0.0, 0.0, 3.0], [0.0, 0.0, 0.0, 0.0]]) self.assertEqual(np.array_equal(l.nodes[0].tp.TAM, desired_TAM), True) l.finalize_learning() self.assertEqual(len(l.nodes[0].tp.temporal_groups), params["requestedGroupsCount"]) # testing creating nodes using params params = { "nodeCloning": True, "size": [8, 8], "overlap": [0, 0], # Spatial pooler "maxCoincidenceCount": 128, "spatialPoolerAlgorithm": "gaussian", "sigma": 1, "maxDistance": 0.1, # Temporal pooler "requestedGroupsCount": 20, "temporalPoolerAlgorithm": "maxProp", "transitionMemory": 4, } l = HTMLevel(1, params, previous_level_size=[1]) self.assertEqual(len(l.nodes), 1)
def runTest(self): params = {'transitionMemory': 4, 'requestedGroupsCount': 3} l = HTMLevel(0, { 'size': [1], 'nodeCloning': True }, previous_level_size=[1]) for p in patterns: l.do_spatial_learning([p]) for p in patterns: l.do_temporal_learning([p]) desired_TAM = np.array([[2., 4., 3., 5.], [3., 0., 4., 2.], [4., 0., 0., 3.], [0., 0., 0., 0.]]) self.assertEqual(np.array_equal(l.nodes[0].tp.TAM, desired_TAM), True) l.finalize_learning() self.assertEqual(len(l.nodes[0].tp.temporal_groups), params['requestedGroupsCount']) # testing creating nodes using params params = { 'nodeCloning': True, 'size': [8, 8], 'overlap': [0, 0], # Spatial pooler 'maxCoincidenceCount': 128, 'spatialPoolerAlgorithm': 'gaussian', 'sigma': 1, 'maxDistance': 0.1, # Temporal pooler 'requestedGroupsCount': 20, 'temporalPoolerAlgorithm': 'maxProp', 'transitionMemory': 4, } l = HTMLevel(1, params, previous_level_size=[1]) self.assertEqual(len(l.nodes), 1)
def create_network(self, params): """Create network based on the provided parameters. Args: params: list of dicts sorted starting from the bottom level """ if params is None: raise ValueError("Parameter 'params' should not be empty.") if self.verbose: print("Creating network...") for level_no in range(len(params)): if level_no == 0: # assuming rectangular arrangement of nodes if self.is_image_sensor: self.patch_size = [ int(self.sensor.width / params[0]['size'][0]), int(self.sensor.height / params[0]['size'][1]) ] if self.verbose: print("Patch size is set to %s." % self.patch_size) prev_level_size = params[0]['size'] else: prev_level_size = params[level_no - 1]['size'] level = HTMLevel(level_no, params=params[level_no], debug=self.debug, previous_level_size=prev_level_size) self.add_level(level) for level_no in range(len(self.levels) - 1): self.levels[level_no].above_links = self.levels[level_no + 1].links if self.verbose: print("=" * 40)