def test_make_activations_in(self): slipnet = Slipnet.empty() # slipnet contents are ignored in this test self.assertEqual(slipnet.make_activations_in(['a']), {'a': 1.0}) a_in = dict(a=1.5, b=0.5, c=1.2) self.assertEqual( slipnet.make_activations_in(features=['a', 'b', 'd'], activations_in=a_in), dict(a=1.5, b=1.0, c=1.2, d=1.0)) self.assertEqual(a_in, dict(a=1.5, b=0.5, c=1.2))
def test_topna_and_top(self): slipnet = Slipnet.empty() # slipnet contents are ignored in this test d = {'a': 0.9, 'b': 0.2, 'c': 0.3, 'd': 0.4, 'e': 0.5, 'f': 0.6} pred = lambda x: x > 'b' self.assertEqual(slipnet.topna(d, pred=pred, k=None), [ NodeA('f', 0.6), NodeA('e', 0.5), NodeA('d', 0.4), NodeA('c', 0.3) ]) self.assertEqual(slipnet.top(d, pred=pred, k=None), ['f', 'e', 'd', 'c']) self.assertEqual(slipnet.top1(d, pred=pred, k=None), 'f') self.assertEqual(slipnet.topna(d, pred=pred, k=2), [NodeA('f', 0.6), NodeA('e', 0.5)]) self.assertEqual( slipnet.topna(d, pred=pred), # default k: pick only the top 1 [NodeA('f', 0.6)]) self.assertEqual(slipnet.topna(d, k=2), [NodeA('a', 0.9), NodeA('f', 0.6)])
def test_filter_by_type(self): slipnet = Slipnet.empty() # slipnet contents are ignored in this test d = {'a': 0.2, 'b': 0.3, 1: 0.2, 2: 0.3} self.assertEqual(slipnet.top(d, pred=str), ['b']) self.assertEqual(slipnet.top(d, pred=int), [2])
# features. out_d = self.sl.dquery(features=[Equation.make([6, 4], plus)]) self.assertCountEqual( self.sl.top(out_d, pred=int, k=3), [6, 4, 10] ) self.assertEqual( self.sl.top1(out_d, pred=After), After(10) ) self.assertCountEqual( self.sl.top(out_d, pred=Before, k=2), [Before(6), Before(4)] ) sl = Slipnet.empty() def run(features, p=p, g=eqn_graph, k=30): global sl sl = Slipnet(g, p) pr(as_dict(p)) print() print('Input:') pr(features) print() t0 = process_time() out_d = sl.dquery(features=features) t1 = process_time() pts(sl.topna(out_d, k=k)) print() pts(sl.topna(out_d, pred=Equation, k=k))