Skip to content

Instantly share code, notes, and snippets.

@breznak
Created May 21, 2015 06:47
Show Gist options
  • Save breznak/cf1fa05469c147032c15 to your computer and use it in GitHub Desktop.
Save breznak/cf1fa05469c147032c15 to your computer and use it in GitHub Desktop.
Nupic Coordinate Encoder Union percentage
#!python
import numpy as np
import random as r
import nupic
from nupic.encoders.coordinate import CoordinateEncoder as Enc
e=Enc(w=25, n=1000)
print e
output = np.zeros(e.getWidth())
coord = np.array([3, 9])
radius = 1
print e.encodeIntoArray((coord, radius), output)
print output
print e.encodeIntoArray((np.array([4, 9]), radius), output)
print output
print e.encodeIntoArray((np.array([4, 9]), 3), output)
print output
D=128
N=D*D
p=0.1
res = np.zeros(e.getWidth())
for i in range(1,int(N*p)):
x=r.randint(1,D)
y=r.randint(1,D)
e.encodeIntoArray((np.array([x, y]), 1), output)
# print i
# print output, len(output), sum(output)
res = np.logical_or(res, output)
print res
#print np.logical_or(np.array([0,0,1]),np.array([1,0,0]))
@breznak
Copy link
Author

breznak commented May 21, 2015

Q1: I try to encode XY-board (2D, with eucl. distance), is CoordinateEncoder my right choice?
--if so, can I take an advantage of the limited board? (128x128 only)

Q2: on line 29 I visit & encode 10% of the positions, I create a union of the encodings...but then in res I get a "full 1s" encoding, instead of ~10% 1s, as I'd expect! Why is that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment