Example #1
0
File: main.py Project: ninickl/bolt
    def encode_X(self, X, **sink):
        if self.algo == 'OPQ':
            X = pq.opq_rotate(X, self.R)
        elif self.algo == 'Bolt':
            X = pq.bopq_rotate(X, self.rotations)

        idxs = pq._encode_X_pq(X, codebooks=self.centroids)

        return idxs + self.offsets  # offsets let us index into raveled dists
Example #2
0
File: main.py Project: ninickl/bolt
    def _fit_query(self, q, quantize=False):
        if self.algo == 'OPQ':
            qR = pq.opq_rotate(q, self.R).ravel()
        elif self.algo == 'Bolt':
            qR = pq.bopq_rotate(q, self.rotations).ravel()
        lut = _fit_pq_lut(qR, centroids=self.centroids,
                          elemwise_dist_func=self.elemwise_dist_func)

        if quantize:
            if False:  # roughly laplace distro, reaching all the way to 0
                ax = sb.distplot(lut.ravel(), hist=False, rug=True)
                ax.set_xlabel('Query dist to centroids (lut dist histogram)')
                ax.set_ylabel('Fraction of queries')
                plt.show()

            lut = np.maximum(0, lut - self.lut_offsets)
            lut = np.floor(lut * self.scale_by).astype(np.int)
            return np.minimum(lut, 255)

        return lut