Skip to content
Snippets Groups Projects
Commit 4d09dc3b authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Experimental VectorQuantizer with KDTree.

parent 1e08f03b
No related branches found
No related tags found
No related merge requests found
package azgracompress.quantization.vector; package azgracompress.quantization.vector;
import azgracompress.kdtree.KDTree;
import azgracompress.kdtree.KDTreeBuilder;
import azgracompress.utilities.Utils; import azgracompress.utilities.Utils;
public class VectorQuantizer { public class VectorQuantizer {
...@@ -9,10 +11,14 @@ public class VectorQuantizer { ...@@ -9,10 +11,14 @@ public class VectorQuantizer {
private final int vectorSize; private final int vectorSize;
private final long[] frequencies; private final long[] frequencies;
private final KDTree kdTree;
public VectorQuantizer(final VQCodebook codebook) { public VectorQuantizer(final VQCodebook codebook) {
this.codebookVectors = codebook.getVectors(); this.codebookVectors = codebook.getVectors();
vectorSize = codebookVectors[0].getVector().length; this.vectorSize = codebookVectors[0].getVector().length;
this.frequencies = codebook.getVectorFrequencies(); this.frequencies = codebook.getVectorFrequencies();
kdTree = new KDTreeBuilder(this.vectorSize, 8).buildTree(codebook.getRawVectors());
} }
public int[] quantize(final int[] dataVector) { public int[] quantize(final int[] dataVector) {
...@@ -49,8 +55,18 @@ public class VectorQuantizer { ...@@ -49,8 +55,18 @@ public class VectorQuantizer {
return quantizeIntoIndices(dataVectors, 1); return quantizeIntoIndices(dataVectors, 1);
} }
public int[] quantizeIntoIndices(final int[][] dataVectors, final int maxWorkerCount) { public int[] quantizeIntoIndicesUsingKDTree(final int[][] dataVectors, final int maxWorkerCount) {
assert (dataVectors.length > 0 && dataVectors[0].length % vectorSize == 0) : "Wrong vector size";
int[] indices = new int[dataVectors.length];
for (int vectorIndex = 0; vectorIndex < dataVectors.length; vectorIndex++) {
indices[vectorIndex] = kdTree.findNearestBBF(dataVectors[vectorIndex], 32);
}
return indices;
}
public int[] quantizeIntoIndices(final int[][] dataVectors, final int maxWorkerCount) {
assert (dataVectors.length > 0 && dataVectors[0].length % vectorSize == 0) : "Wrong vector size"; assert (dataVectors.length > 0 && dataVectors[0].length % vectorSize == 0) : "Wrong vector size";
int[] indices = new int[dataVectors.length]; int[] indices = new int[dataVectors.length];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment