Closed Chuncbs closed 2 years ago
Thanks for pointing this out.
Yes, the following line
err = np.linalg.norm(opq.rotate(X) - opq.decode(opq.encode(X)))
should be
err = np.linalg.norm(X - opq.decode(opq.encode(X)))
It is because:
opq.encode(A)
: A will be rotated and encodedopq.decode(B)
: B will be decoded and un-rotatedopq.decode(opq.encode(X))
: X will be rotated, encoded, decoded, and un-rotated. So the output is "not" rotated.Thus, opq.decode(opq.encode(X))
should be compared to X
, not opq.rotate(X)
.
If I revise the above point and slightly change the parameters, everything seems okay.
def test_parametric_init(self):
- N, D, M, Ks = 100, 12, 4, 10
+ N, D, M, Ks = 100, 12, 2, 20
X = np.random.random((N, D)).astype(np.float32)
opq = nanopq.OPQ(M=M, Ks=Ks)
opq.fit(X, parametric_init=False, rotation_iter=1)
- err_init = np.linalg.norm(opq.rotate(X) - opq.decode(opq.encode(X)))
+ err_init = np.linalg.norm(X - opq.decode(opq.encode(X)))
opq = nanopq.OPQ(M=M, Ks=Ks)
opq.fit(X, parametric_init=True, rotation_iter=1)
- err = np.linalg.norm(opq.rotate(X) - opq.decode(opq.encode(X)))
+ err = np.linalg.norm(X - opq.decode(opq.encode(X)))
- self.assertLess(err_init, err)
+ self.assertLess(err, err_init)
@calvinmccarter What do you think? Let me know if I miss something...
@matsui528 -- yes, you are right, my bad. Thanks for catching this!
Hi! I wonder why that when change M to 4 then the test still fails?
hi,friend ,I have two question .
`def test_parametric_init(self): N, D, M, Ks = 100, 12, 4, 10 X = np.random.random((N, D)).astype(np.float32) opq = nanopq.OPQ(M=M, Ks=Ks) opq.fit(X, parametric_init=False, rotation_iter=1) err_init = np.linalg.norm(opq.rotate(X) - opq.decode(opq.encode(X)))
self.pq.decode(codes) @ self.R.T