Skip to content

Commit

Permalink
run example multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
clark-hive committed Oct 12, 2022
1 parent 7f33f5e commit 83a4682
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions experiments/mat_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

import numpy as np

from python import vquantizers as vq

if __name__ == '__main__':

N = 128
D = 128
M = 128
codebooks = 16

X = np.random.randint(100, size=(N, D))
Q = np.random.randint(100, size=(D, M))

task = vq.MithralEncoder(codebooks)

task.fit(X)

X_enc = task.encode_X(X)

luts, offset, scale = task.encode_Q(Q.T)

W = task.dists_enc(X_enc, luts, False, offset, scale)

print("W: ", W)
print("-----")

W_real = np.matmul(X, Q)
mse = np.square(W - W_real).mean()
print("mse: ", mse)
print("offset: ", np.abs(W - W_real))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ numpy
scikit-learn
Cython
pytest
numba

0 comments on commit 83a4682

Please sign in to comment.