Skip to content

Instantly share code, notes, and snippets.

@tejasshah93
Last active March 29, 2017 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tejasshah93/f7e9e7df2b60cdcefdc7b970c7b20fe2 to your computer and use it in GitHub Desktop.
Save tejasshah93/f7e9e7df2b60cdcefdc7b970c7b20fe2 to your computer and use it in GitHub Desktop.
PySparNN custom distance different outputs
# In[5]:
B = sparse.csr_matrix([[1, 1, 1],[1, 1, 1],[1, 1, 1]])
A = sparse.csr_matrix(
[
[2, 2, 1],
[1, 0, 1],
[1, 1, 1]
])
# In[6]:
u_dist = UserCustomDistance(A, range(A.shape[0]))
u_dist._distance(A)
# Out[6]:
array([[-2., 1., 0.],
[ 1., 1., 1.],
[ 0., 1., 0.]])
# In[7]:
su_dist = SpencerUserCustomDistance(A, range(A.shape[0]))
su_dist._distance(A)
# Out[7]:
array([[-6, 0, -2],
[ 0, 1, 1],
[-2, 1, 0]])
# In [8]:
u_dist._distance(B)
Out[8]:
array([[ 0., 1., 0.],
[ 0., 1., 0.],
[ 0., 1., 0.]])
# In [9]:
su_dist._distance(B)
Out[9]:
array([[-2, 1, 0],
[-2, 1, 0],
[-2, 1, 0]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment