|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdata_structures.AbstractSearchStructure
data_structures.IVFADC
public class IVFADC
This class implements IVFADC (Indexed Very Fast Asymmetric Distance Computation). It can be used for indexing and searching a database according to IVFADC approach.
Field Summary | |
---|---|
private long |
coarseQuantizationTime
|
private double[][] |
coarseQuantizer
The coarse quantizer. |
private gnu.trove.list.array.TByteArrayList[] |
invertedListByteVectors
This vector of TByteArrayList objects is used to store the inverted lists which contain indexed vectors. |
private gnu.trove.list.array.TIntArrayList[] |
invertedListIds
|
private gnu.trove.list.array.TShortArrayList[] |
invertedListShortVectors
|
private com.sleepycat.je.Database |
ivfadcBDB
Berkeley db for persistence of the IVFADC index |
private int |
numCoarseCentroids
Number of centroids in the coarse quantizer |
private int |
numProductCentroids
The number of centroids used to quantize each sub-vector. |
private int |
numSubVectors
The number of sub-vectors used in this product quantization. |
private long |
persistentIndexUpdateTime
|
private long |
productQuantizationTime
|
private double[][][] |
productQuantizer
The sub-quantizers. |
private boolean |
randomBeforeProductQuantization
Whether to apply random orthogonal transformation on the residuals prior to product quantization. |
private RandomOrthogonalTransformation |
randomTransform
This object is used for applying random orthogonal transformation prior to product quantization. |
private int |
subVectorLength
The length of each subvector of the residual vectors. |
private int |
w
The number of lists to visit. |
Fields inherited from class data_structures.AbstractSearchStructure |
---|
cachePercent, cacheSize, countSizeOnLoad, dbEnv, idToNameBDB, idToNameMappings, loadCounter, maxNumVectors, nameToIdBDB, numIndexingThreads, readOnly, syncRate, transactional, vectorLength |
Constructor Summary | |
---|---|
IVFADC(int vectorLength,
int numCoarseCentroids,
int subVectorLength,
int numProductCentroids,
boolean randomTransformation,
int loadCounter,
int maxNumVectors,
java.lang.String BDBEnvHome,
boolean readOnly,
boolean countSizeOnLoad)
Advanced constructor. |
|
IVFADC(int vectorLength,
int numCoarseCentroids,
int subVectorLength,
int numProductCentroids,
boolean randomTransformation,
int maxNumVectors,
java.lang.String BDBEnvHome)
Simple constructor. |
Method Summary | |
---|---|
void |
closeInternal()
Each subclass should implement this method to close the BDB databases that it uses. |
private com.aliasi.util.BoundedPriorityQueue<Result> |
computeKNN_IVFADC(int k,
double[] query,
int w)
|
private double[][] |
computeLookupADC(double[] queryVector)
Takes a query residual vector as input and returns a look-up table containing the distance between each sub-vector of the query vector from each centroid of each sub-quantizer. |
private int |
computeNearestCoarseIndex(double[] vector)
Finds and returns the index of the coarse quantizer's centroid which is closer to the given vector. |
protected int[] |
computeNearestCoarseIndices(double[] vector,
int k)
Returns the indices of the k coarse centroids which are closer to the given vector. |
protected com.aliasi.util.BoundedPriorityQueue<Result> |
computeNearestNeighborsInternal(int k,
double[] query)
This method returns a bounded priority queue of Result objects, corresponding to the k nearest neighbors' ids and their distances from the query vector, ordered by lowest distance. |
private int |
computeNearestProductIndex(double[] subvector,
int subQuantizerIndex)
Finds and returns the index of the centroid of the subquantizer with the given index which is closer to the given subvector. |
private double[] |
computeResidualVector(double[] vector,
int centroidIndex)
|
double[][] |
getCoarseQuantizer()
|
double[][][] |
getProductQuantizer()
|
void |
indexVectorInternal(int id,
double[] vector,
com.sleepycat.je.Transaction txn)
Update the index with the given VLAD vector.Depending on how the coarse and product quantizers are learned, we should apply the appropriate transformations in each step. |
void |
loadCoarseQuantizer(java.lang.String coarseQuantizerFile)
Load the coarse quantizers from a given file |
private void |
loadIndexInMemory()
The previous example shows how to scan through the records in your database sequentially; that is, in the record's sort order. |
void |
loadProductQuantizer(java.lang.String filname)
Load the product quantizer from a given file |
void |
outputIndexingTimesInternal()
This method can be called to output indexing time measurements. |
void |
outputItemsPerList()
|
void |
setCoarseQuantizer(double[][] coarseQuantizer)
With this method we initialize the table holding the coarse quantizers. |
void |
setProductQuantizer(double[][][] productQuantizer)
With this method we initialize the table holding the product quantizer. |
void |
setW(int w)
|
private void |
updatePersistentIndex(int id,
int listId,
byte[] code,
com.sleepycat.je.Transaction txn)
|
private void |
updatePersistentIndex(int id,
int listId,
short[] code,
com.sleepycat.je.Transaction txn)
|
Methods inherited from class data_structures.AbstractSearchStructure |
---|
close, computeNearestNeighbors, createOrOpenBDBEnvAndDbs, getExternalId, getInternalId, getLoadCounter, indexVector, isIndexed, outputIndexingTimes |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private long coarseQuantizationTime
private long productQuantizationTime
private long persistentIndexUpdateTime
private double[][] coarseQuantizer
private boolean randomBeforeProductQuantization
private double[][][] productQuantizer
private int numSubVectors
private int numProductCentroids
private int numCoarseCentroids
private int subVectorLength
private int w
private RandomOrthogonalTransformation randomTransform
private gnu.trove.list.array.TByteArrayList[] invertedListByteVectors
private gnu.trove.list.array.TShortArrayList[] invertedListShortVectors
private gnu.trove.list.array.TIntArrayList[] invertedListIds
private com.sleepycat.je.Database ivfadcBDB
Constructor Detail |
---|
public IVFADC(int vectorLength, int numCoarseCentroids, int subVectorLength, int numProductCentroids, boolean randomTransformation, int loadCounter, int maxNumVectors, java.lang.String BDBEnvHome, boolean readOnly, boolean countSizeOnLoad) throws java.lang.Exception
vectorLength
- The dimensionality of the vectors.numCoarseCentroids
- subVectorLength
- The subvector length.numProductCentroids
- The number of product centroids.randomTransformation
- Whether to perform random transformation.loadCounter
- The initial value of the loadCounter.maxNumVectors
- The maximum number of vectors.BDBEnvHome
- The BDB environment home directory.readOnly
- If true the persistent store will opened only for read access (allows multiple opens).countSizeOnLoad
- Whether the loadCounter will be initialized by the size of the persistent store.
java.lang.Exception
public IVFADC(int vectorLength, int numCoarseCentroids, int subVectorLength, int numProductCentroids, boolean randomTransformation, int maxNumVectors, java.lang.String BDBEnvHome) throws java.lang.Exception
vectorLength
- numCoarseCentroids
- subVectorLength
- numProductCentroids
- randomTransformation
- maxNumVectors
- BDBEnvHome
-
java.lang.Exception
Method Detail |
---|
private com.aliasi.util.BoundedPriorityQueue<Result> computeKNN_IVFADC(int k, double[] query, int w) throws java.lang.Exception
k
- the number of nearest neighbors to returnquery
- the non quantized query vectorw
- the number of list to be searched for neighbors (equal to the number of nearest coarse
centroids where the query vector is assigned)
java.lang.Exception
private double[][] computeLookupADC(double[] queryVector)
queryVector
- (residual)
private int computeNearestCoarseIndex(double[] vector)
vector
-
protected int[] computeNearestCoarseIndices(double[] vector, int k)
vector
- k
-
protected com.aliasi.util.BoundedPriorityQueue<Result> computeNearestNeighborsInternal(int k, double[] query) throws java.lang.Exception
AbstractSearchStructure
computeNearestNeighborsInternal
in class AbstractSearchStructure
k
- The number of nearest neighbors to return.query
- The query vector.
java.lang.Exception
private int computeNearestProductIndex(double[] subvector, int subQuantizerIndex)
subvector
- subQuantizerIndex
-
private double[] computeResidualVector(double[] vector, int centroidIndex) throws java.lang.Exception
java.lang.Exception
public double[][] getCoarseQuantizer()
public double[][][] getProductQuantizer()
public void indexVectorInternal(int id, double[] vector, com.sleepycat.je.Transaction txn) throws java.lang.Exception
indexVectorInternal
in class AbstractSearchStructure
id
- vector
- txn
- A transaction handle.
java.lang.Exception
public void outputIndexingTimesInternal()
outputIndexingTimesInternal
in class AbstractSearchStructure
public void outputItemsPerList()
public void loadCoarseQuantizer(java.lang.String coarseQuantizerFile) throws java.io.IOException
filname
-
java.io.IOException
public void loadProductQuantizer(java.lang.String filname) throws java.io.IOException
filname
-
java.io.IOException
public void setCoarseQuantizer(double[][] coarseQuantizer)
coarseQuantizer
- public void setProductQuantizer(double[][][] productQuantizer)
productQuantizer
- public void setW(int w)
private void loadIndexInMemory() throws java.lang.Exception
java.lang.Exception
private void updatePersistentIndex(int id, int listId, byte[] code, com.sleepycat.je.Transaction txn)
private void updatePersistentIndex(int id, int listId, short[] code, com.sleepycat.je.Transaction txn)
public void closeInternal()
AbstractSearchStructure
closeInternal
in class AbstractSearchStructure
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |