def testOrderEightWords(self): # number of words along the search path nr_words = 8 cues = ['cottage', 'swiss', 'cake'] target = 'cheese' target_id = self.net.voc[target] # get word ids cue_ids = [self.net.voc[c] for c in cues] act_alg, visited_alg = spread_activity(init_nodes=cue_ids, target=target_id, W=self.net.W, max_visited=nr_words) self.net.setup_problem(cues, target) self.net.max_visited = nr_words self.net.run() visited_net = self.net.visited() np.testing.assert_equal(visited_alg, visited_net) a1 = self.net.a[self.net.t_max, visited_net] a2 = act_alg[visited_alg] # tolerate diffrences in activities up to 0.1 np.testing.assert_allclose(a1, a2, rtol=1e-1)
def testEqual(self): equal = 0 not_equal = [] for i, rat_item in enumerate(self.items): # words cues, target = rat_item[:3], rat_item[3] # word ids cue_ids = [self.net.voc[c] for c in cues] target_id = self.net.voc[target] # run the algorithm simulation _, visited_alg = spread_activity(init_nodes=cue_ids, target=target_id, W=self.net.W, max_visited=self.nr_words) # ...and the network simulation self.net.setup_problem(cues, target) print '\n', i, cues, target, target_id # WTA can fail if noise added to two equal numbers is not enough # to pick a winner. If this happens, the simulation is repeated ok = True while ok: try: self.net.run() ok = False except BaseException: print 'WTA failed, retrying the run!' continue l1, l2 = visited_alg, list(self.net.visited()) if target_id in set(l1) and target_id not in set(l2) or\ target_id not in set(l1) and target_id in set(l2): not_equal.append(i) else: print 'ok', equal equal += 1 print 'A:', l1 print 'N:', l2 print not_equal
def testActivityEqualThreeCues(self): cues = ['match', 'game', 'stick'] target = 'fire' target_id = self.net.voc[target] max_visited = 3 self.net.max_visited = max_visited self.net.setup_problem(cues, target) act_alg, _ = spread_activity(init_nodes=self.net.cue_ids, target=target_id, W=self.net.W, max_visited=max_visited) self.net.run() np.testing.assert_almost_equal(act_alg, self.net.a[self.net.t_max], decimal=2)
def testActivityEqualSingleCue(self): cue = 'match' target = 'fire' target_id = self.net.voc[target] max_visited = 1 self.net.max_visited = max_visited act_alg, _ = spread_activity(init_nodes=[self.net.voc[cue]], target=target_id, W=self.net.W, max_visited=max_visited) self.net.setup_problem([cue], target) self.net.run() np.testing.assert_almost_equal(act_alg, self.net.a[self.net.t_max], decimal=3)