def test_scopes(): print '\bs.', net = network.simple() scopes = net.scopes() for c in net.graph.root.children: assert scopes[net.graph.root] == scopes[c] == set([0,1]) assert False not in [len(scopes[n]) == 1 if n.is_distribution() else len(scopes[n]) == 2 for n in net.pot]
def test_save_load(): print '\bsl.', net1 = network.simple() for n in net1.pot: if n.is_sum(): n.set_weights(rand(len(n.weights))) elif n.is_categorical(): n.set_masses(rand(len(n.masses))) network.save(net1, 'tmp.spn') net2 = network.load('tmp.spn') assert len(net1.pot) == len(net2.pot) for i in range(len(net1.pot)): assert id(net1.pot[i]) != id(net2.pot[i]) for d in [(0,0), (0,1), (1,0), (1,1)]: assert net1.forward(d) == net2.forward(d)
def test_pot(): print '\bp.', net = network.simple() assert len(net.pot) == 7 net.pot = None assert len(net.pot) == 7