예제 #1
0
 def reinterpret(self, vocab=None):
     return Transformed(
         self,
         np.eye(self.type.dimensions),
         TAnyVocabOfDim(self.type.dimensions)
         if vocab is None else TVocabulary(vocab),
     )
def test_translate(rng):
    v1 = spa.Vocabulary(16, pointer_gen=rng)
    v1.populate('A; B')
    v2 = spa.Vocabulary(16, pointer_gen=rng)
    v2.populate('A; B')

    assert_allclose(spa.translate(PointerSymbol('A', TVocabulary(v1)),
                                  v2).evaluate().dot(v2['A']),
                    1.,
                    atol=0.2)
예제 #3
0
    def __init__(self, data, vocab=None, algebra=None, name=None):
        super(
            SemanticPointer,
            self).__init__(TAnyVocab if vocab is None else TVocabulary(vocab))
        self.algebra = self._get_algebra(vocab, algebra)

        self.v = np.array(data, dtype=float)
        if len(self.v.shape) != 1:
            raise ValidationError("'data' must be a vector", "data", self)
        self.v.setflags(write=False)

        self.vocab = vocab
        self.name = name