From 51eb2f8f1feed44037ac63d07cd54dc9a131b9b9 Mon Sep 17 00:00:00 2001
From: Vojtech Moravec <vojtech.moravec.st@vsb.cz>
Date: Fri, 16 Oct 2020 13:57:42 +0200
Subject: [PATCH] Disable KDTree for now.

---
 .../qcmp/compression/VQImageCompressor.java   | 21 ++++++++++++++-----
 .../quantization/vector/VectorQuantizer.java  | 16 +++++++-------
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/main/java/cz/it4i/qcmp/compression/VQImageCompressor.java b/src/main/java/cz/it4i/qcmp/compression/VQImageCompressor.java
index 6d10758..60182aa 100644
--- a/src/main/java/cz/it4i/qcmp/compression/VQImageCompressor.java
+++ b/src/main/java/cz/it4i/qcmp/compression/VQImageCompressor.java
@@ -58,7 +58,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
         final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(planeVectors,
                                                                         getCodebookSize(),
                                                                         options.getWorkerCount(),
-                                                                        options.getQuantizationVector());
+                                                                        options.getQuantizationVector(),
+                                                                        true);
         final LBGResult vqResult = vqInitializer.findOptimalCodebook();
         return new VectorQuantizer(vqResult.getCodebook());
     }
@@ -235,8 +236,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
      * @return Indices of codebook vectors.
      */
     private int[] quantizeVectorsImpl(final VectorQuantizer quantizer, final int[][] srcVectors, final int workerCount) {
-        if (useKdTree)
-            return quantizer.quantizeIntoIndicesUsingKDTree(srcVectors, workerCount);
+        //        if (useKdTree)
+        //            return quantizer.quantizeIntoIndicesUsingKDTree(srcVectors, workerCount);
         return quantizer.quantizeIntoIndices(srcVectors, workerCount);
     }
 
@@ -339,9 +340,17 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
         final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(trainingData,
                                                                         getCodebookSize(),
                                                                         options.getWorkerCount(),
-                                                                        options.getQuantizationVector());
+                                                                        options.getQuantizationVector(),
+                                                                        false);
 
         reportStatusToListeners("Starting LBG optimization.");
+        try {
+            System.out.println("Sleeping for 10 seconds...");
+            Thread.sleep(10000);
+        } catch (final InterruptedException e) {
+            e.printStackTrace();
+        }
+
         vqInitializer.setStatusListener(this::reportStatusToListeners);
         final LBGResult lbgResult = vqInitializer.findOptimalCodebook();
         reportStatusToListeners("Learned the optimal codebook.");
@@ -376,7 +385,9 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
         final LBGVectorQuantizer codebookTrainer = new LBGVectorQuantizer(trainingData,
                                                                           256,
                                                                           options.getWorkerCount(),
-                                                                          options.getQuantizationVector());
+                                                                          options.getQuantizationVector(),
+                                                                          false);
+
         codebookTrainer.findOptimalCodebook(vqCodebook -> {
             try {
                 assert ((vqCodebook.getCodebookSize() == vqCodebook.getVectors().length) &&
diff --git a/src/main/java/cz/it4i/qcmp/quantization/vector/VectorQuantizer.java b/src/main/java/cz/it4i/qcmp/quantization/vector/VectorQuantizer.java
index 6f987d8..fe73414 100644
--- a/src/main/java/cz/it4i/qcmp/quantization/vector/VectorQuantizer.java
+++ b/src/main/java/cz/it4i/qcmp/quantization/vector/VectorQuantizer.java
@@ -1,7 +1,5 @@
 package cz.it4i.qcmp.quantization.vector;
 
-import cz.it4i.qcmp.kdtree.KDTree;
-import cz.it4i.qcmp.kdtree.KDTreeBuilder;
 import cz.it4i.qcmp.utilities.Utils;
 
 public class VectorQuantizer {
@@ -15,14 +13,14 @@ public class VectorQuantizer {
     private final int vectorSize;
     private final long[] frequencies;
 
-    private final KDTree kdTree;
+    //    private final KDTree kdTree;
 
     public VectorQuantizer(final VQCodebook codebook) {
         this.codebookVectors = codebook.getVectors();
         this.vectorSize = codebook.getVectors()[0].length;
         this.frequencies = codebook.getVectorFrequencies();
 
-        kdTree = new KDTreeBuilder(this.vectorSize, 8).buildTree(codebook.getVectors());
+        //        kdTree = new KDTreeBuilder(this.vectorSize, 8).buildTree(codebook.getVectors());
     }
 
     public int[] quantize(final int[] dataVector) {
@@ -99,11 +97,11 @@ public class VectorQuantizer {
         return indices;
     }
 
-    public int[] quantizeIntoIndicesUsingKDTree(final int[][] dataVectors, final int maxWorkerCount) {
-
-        return quantizeIntoIndicesImpl(dataVectors, maxWorkerCount, (final int[] queryVector) ->
-                kdTree.findNearestBBF(queryVector, 8));
-    }
+    //    public int[] quantizeIntoIndicesUsingKDTree(final int[][] dataVectors, final int maxWorkerCount) {
+    //
+    //        return quantizeIntoIndicesImpl(dataVectors, maxWorkerCount, (final int[] queryVector) ->
+    //                kdTree.findNearestBBF(queryVector, 8));
+    //    }
 
     public int[] quantizeIntoIndices(final int[][] dataVectors, final int maxWorkerCount) {
 
-- 
GitLab