Lexicon

At some point it becomes tiresome to create variables for every symbol we need. In addition having separate variables doesnt allow us to search for similar symbols, for this reason I created a Lexicon class.

In VSA literature this is known also as Cleanup memory (CUP), Why ?

(Read more at bbHTM link)

Because when you manipulate symbols you build blends the result after several operations accumulate noise you need to clean it up to the closest clean item. This is where CUP comes in … you just store all clean vectors and do best match search.

import sys
sys.path.extend(['../../ilib'])
from ilexicon import *
x = iLexicon(vsize=2000, spaOnbits=0.02)

x.add('circle')
x.add('square')
x.add_items(['one', 'two', 'three'])

print x.circle
22:26:109:199:207:235:237:353:462:575:584:612:651:708:717:924:993:1028:1084:1154:1165:1174:1233:1241:1272:1298:1300:1388:1429:1437:1463:1507:1579:1598:1632:1692
1695:1771:1830:1901

After we create the iLexicon object just use .add methods to add symbols. In case you dont provide an iSDP it will be randomly generated. Once created you can access the symbols as object attribute, by dict key or index.

For quick tests just call .az() method to create 26 symbols with names from ‘a’ to ‘z’.

x.az()
print (x.a * x.b) // x.a
print (x.a * x.b * x.c) // x.a
print (x.a * x.b * x.c * x.d) // x.a
print (x.a * x.b * x.c * x.d * x.e) // x.a
print
print isdp.thin(isdp.union([x.a, x.b, x.c, x.d]), 0.02) // x.a
0.575
0.275
0.15
0.075

0.325

here we can see how adding one more symbol to the operation decreaces the percentage of bits that are included in the result …

print (x.a | x.b) // x.a
print (x.a | x.b | x.c) // x.a
print (x.a | x.b | x.c | x.d) // x.a
print (x.a | x.b | x.c | x.d | x.e) // x.a
0.519480519481
0.344827586207
0.258064516129
0.20942408377
print x.a // (x.a | x.b) 
print x.a // (x.a | x.b | x.c)
print x.a // (x.a | x.b | x.c | x.d)
print x.a // (x.a | x.b | x.c | x.d | x.e)
1.0
1.0
1.0
1.0
x.bm(x.z)
'z'
x.permuted_syms(syms='abc', repeat=2)
x.ac
71:91:125:206:247:270:347:416:581:732:764:792:798:848:913:914:946:995:1169:1179:1215:1223:1249:1287:1331:1348:1406:1412:1423:1494:1521:1592:1611:1716:1727:1833
1841:1899:1913:1987
x.bt(x.a, topn=3 )
['a', 'ab', 'b']
ix = x.bixs(x.a)[0]
print x[ix] // x.a
print x['a'] // x.a
1.0
1.0
x.a / x.ab
23
x.a in x.ab
True
x.a == x.a
True
print x.info
Shape : (100, 40)
Sparsity : 0.02
Dynamic Memory :==================
items:37, max items:100, spa-nbits:40
grow % : 0.1, size: 2000

Sequences

from sequence import *
s = Sequence(lex=x)
s.add(x.a)
s.add(x.b)
s.add(x.c)
s.add(x.d)
s[1]
'a'
s[1:4]
['a', 'b', 'c']