GithubHelp home page GithubHelp logo

Comments (1)

matsui528 avatar matsui528 commented on May 18, 2024

Not sure such a nested PQ is useful of not, becuase a PQ with an increased parameter would be usually better. But the following nested PQ should work.

import nanopq
import numpy as np

N, D = 1000, 24
X = np.random.random((N, D)).astype(np.float32)  # 1,000 24-dim vectors

# Instantiate with M=4 sub-spaces, with the number of centrods per sub-space is Ks=16
M, Ks = 4, 16
pq = nanopq.PQ(M=M, Ks=Ks)

# Train codewords
pq.fit(X)

# codewords
# The shape is (4, 16, 6), this means that:
# - 4 supspaces
# - 16 codewords for each supspace
# - A codeword is a 6-dim vector
print(pq.codewords.shape)  

# Given the codewords, train second-level PQ instances
# For each subspace, create a PQ instance, with M=2 and Ks=4
second_level_pqs = []
for m in range(M):
    second_level_pq = nanopq.PQ(M=2, Ks=4)
    second_level_pq.fit(pq.codewords[m])  # Train by corresponding codewords
    second_level_pqs.append(second_level_pq)

# Check
print(second_level_pqs[0].codewords.shape) # shape = (2, 4, 3)

from nanopq.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.