Пример #1
0
def test_get_swapping_matrix(rng):
    gen = UnitLengthVectors(64, rng)
    a = SemanticPointer(next(gen), algebra=VtbAlgebra()).v
    b = SemanticPointer(next(gen), algebra=VtbAlgebra()).v

    m = VtbAlgebra().get_swapping_matrix(64)
    assert np.allclose(VtbAlgebra().bind(a, b), np.dot(m, VtbAlgebra().bind(b, a)))
Пример #2
0
def test_unbind(Simulator, side, seed):
    rng = np.random.RandomState(seed)
    vocab = spa.Vocabulary(36, pointer_gen=rng, algebra=VtbAlgebra())
    vocab.populate("A; B")

    with spa.Network(seed=seed) as model:
        vtb = VTB(100,
                  36,
                  unbind_left=(side == "left"),
                  unbind_right=(side == "right"))

        if side == "left":
            left = nengo.Node(vocab["B"].v)
            right = nengo.Node(vocab.parse("B*A").v)
        elif side == "right":
            left = nengo.Node(vocab.parse("A*B").v)
            right = nengo.Node(vocab["B"].v)
        else:
            raise ValueError("Invalid 'side' value.")

        nengo.Connection(left, vtb.input_left)
        nengo.Connection(right, vtb.input_right)

        p = nengo.Probe(vtb.output, synapse=0.03)

    with Simulator(model) as sim:
        sim.run(0.2)

    assert_sp_close(sim.trange(),
                    sim.data[p],
                    vocab.parse("A * B * ~B"),
                    skip=0.15,
                    atol=0.3)
def test_is_valid_dimensionality():
    assert not VtbAlgebra().is_valid_dimensionality(-1)
    assert not VtbAlgebra().is_valid_dimensionality(0)
    assert not VtbAlgebra().is_valid_dimensionality(15)
    assert not VtbAlgebra().is_valid_dimensionality(24)
    assert VtbAlgebra().is_valid_dimensionality(1)
    assert VtbAlgebra().is_valid_dimensionality(16)
    assert VtbAlgebra().is_valid_dimensionality(25)
Пример #4
0
class TestConfig(object):
    """Parameters affecting all Nengo SPA testes.

    These are essentially global variables used by py.test to modify aspects
    of the Nengo SPA tests. We collect them in this class to provide a mini
    namespace and to avoid using the ``global`` keyword.

    The values below are defaults. The functions in the remainder of this
    module modify these values accordingly.
    """

    algebras = [HrrAlgebra(), VtbAlgebra()]
Пример #5
0
def test_bind(Simulator, seed):
    rng = np.random.RandomState(seed)
    vocab = spa.Vocabulary(16, pointer_gen=rng, algebra=VtbAlgebra())
    vocab.populate("A; B")

    with spa.Network(seed=seed) as model:
        vtb = VTB(100, 16)
        nengo.Connection(nengo.Node(vocab["A"].v), vtb.input_left)
        nengo.Connection(nengo.Node(vocab["B"].v), vtb.input_right)
        p = nengo.Probe(vtb.output, synapse=0.03)

    with Simulator(model) as sim:
        sim.run(0.2)

    assert_sp_close(sim.trange(),
                    sim.data[p],
                    vocab.parse("A*B"),
                    skip=0.15,
                    atol=0.3)
def test_is_singleton():
    assert VtbAlgebra() is VtbAlgebra()