def test_slipnet_kwargs1(self) -> None: fm = FARGModel() qargs = (Before(4), After(11), SearchFor(Equation)) self.assertEqual( fm.mk_slipnet_args(qargs, []), dict(activations_in=dict(((Before(4), 1.0), (After(11), 1.0))), pred=(Equation, ), k=20, num_get=1))
def features_of(self) -> Iterable[Node]: for operand in as_iter(self.operands): yield Before(operand) if self.operator: yield self.operator if self.operands and self.operator: result = self.operator(*self.operands) yield After(result)
def test_pulse_slipnet(self) -> None: fm = FARGModel(seed=1, slipnet=Slipnet(eqn_graph)) activations_in = {Before(4): 1.0, After(9): 1.0} nodes = fm.pulse_slipnet( activations_in=activations_in, # type: ignore[arg-type] pred=Equation, num_get=20) self.assertTrue(all(isinstance(node, Equation) for node in nodes)) self.assertTrue(Equation.make([5, 4], plus) in nodes)
def test_slipnet_kwargs2(self) -> None: fm = FARGModel() ca = fm.build(self.pons_start_canvas()) cr0 = CellRef(ca, 0) qargs = (QBeforeFromAvails(), QAfter(), SearchFor()) sources = dict(source=cr0, features=15, type=Equation) self.assertEqual( fm.mk_slipnet_args(qargs, sources), dict(activations_in=dict(((Before(4), 1.0), (Before(5), 1.0), (Before(6), 1.0), (After(15), 1.0))), pred=(Equation, ), k=20, num_get=1))
def test_exclude_existing_nodes_from_slipnet_results(self) -> None: fm = FARGModel(seed=1, slipnet=Slipnet(eqn_graph)) eqn1 = fm.build(Equation.make([5, 4], plus)) eqn2 = Equation.make([6, 4], plus) eqn3 = Equation.make([4, 4], plus) # eqn1 is a node in the workspace; eqn2 and eqn3 are not. activations_in: ADict = {Before(4): 1.0, After(9): 1.0} d = fm.slipnet.dquery(activations_in=activations_in) self.assertIn(eqn1, Slipnet.top(d=d, k=None)) self.assertIn(eqn2, Slipnet.top(d=d, k=None)) self.assertIn(eqn3, Slipnet.top(d=d, k=None)) self.assertIn(Before(5), Slipnet.top(d=d, k=None)) excl1 = Exclude(eqn1) returned_slipnodes = Slipnet.top(d=d, pred=excl1, k=None) self.assertNotIn(eqn1, returned_slipnodes) self.assertIn(eqn2, returned_slipnodes) self.assertIn(Before(5), returned_slipnodes) self.assertIn(5, returned_slipnodes) pred2 = Equation returned_slipnodes = Slipnet.top(d=d, pred=pred2, k=None) self.assertIn(eqn1, returned_slipnodes) self.assertIn(eqn2, returned_slipnodes) self.assertNotIn(Before(5), returned_slipnodes) self.assertNotIn(5, returned_slipnodes) pred3 = (Equation, int) returned_slipnodes = Slipnet.top(d=d, pred=pred3, k=None) self.assertIn(eqn1, returned_slipnodes) self.assertIn(eqn2, returned_slipnodes) self.assertNotIn(Before(5), returned_slipnodes) self.assertIn(5, returned_slipnodes) pred4 = (Equation, int, Exclude(eqn1)) returned_slipnodes = Slipnet.top(d=d, pred=pred4, k=None) self.assertNotIn(eqn1, returned_slipnodes) self.assertIn(eqn2, returned_slipnodes) self.assertNotIn(Before(5), returned_slipnodes) self.assertIn(5, returned_slipnodes) ee: CallablePred = ExcludeExisting().bind_ws( fm) # type: ignore[assignment] pred5 = (Equation, int, ee) returned_slipnodes = Slipnet.top(d=d, pred=pred5, k=None) self.assertNotIn(eqn1, returned_slipnodes) self.assertIn(eqn2, returned_slipnodes) self.assertNotIn(Before(5), returned_slipnodes) self.assertIn(5, returned_slipnodes) # Now we call fm.pulse_slipnet() returned_slipnodes = fm.pulse_slipnet(activations_in=activations_in, pred=(Equation, int), k=200, num_get=200) self.assertIn(eqn1, returned_slipnodes) self.assertIn(eqn2, returned_slipnodes) self.assertNotIn(Before(5), returned_slipnodes) self.assertIn(5, returned_slipnodes) returned_slipnodes = fm.pulse_slipnet(activations_in=activations_in, pred=(Equation, int, ExcludeExisting()), k=200, num_get=200) self.assertNotIn(eqn1, returned_slipnodes) self.assertIn(eqn2, returned_slipnodes) self.assertNotIn(Before(5), returned_slipnodes) self.assertIn(5, returned_slipnodes)
def test_qafter(self) -> None: fm = FARGModel() qarg = QAfter() self.assertCountEqual(as_iter(qarg.get_items(fm, {'features': 15})), [After(15)])
als = fm.alogs print() pr(als) print() ls = list(als.logs.values()) print('PULSED:') pr(ls[0].pulsed_nodes()) pred = (Consumer, int) n=20 print() ls[0].plot(pred, n=n, pr=True) """ # Experiment: Pulse just Before(4), After(9). Consumer(5+4) and # Consumer(13-4) should win big, and the nodes Before(5), Before(13), # 5, and 3 should light up. fm = FARGModel(seed=1, slipnet=Slipnet(eqn_graph)) activations_in = {Before(4): 1.0, After(9): 1.0} #lenable(LogAdjustedDeltas) nodes = fm.pulse_slipnet( activations_in=activations_in, # type: ignore[arg-type] pred=Consumer, k=5, num_get=3, alog=fm.start_alog((None, None))) ls = list(fm.alogs.logs.values()) print('\nPlotted, final activations:') ls[0].plot(n=15, pr=True) print('\nNodes chosen:') pts(nodes, key=short)