// Path: src/main/java/gr/iti/mklab/visual/utilities/Result.java
// public class Result implements Comparator<Result> {
// 
// 	/**
// 	 * The distance associated with this result object.
// 	 */
// 	private double distance;
// 
// 	/**
// 	 * The id associated with this result object.
// 	 */
// 	private int id;
// 
// 	public Result() {
// 	}
// 
// 	/**
// 	 * Constructor
// 	 * 
// 	 * @param internalId
// 	 * @param distance
// 	 */
// 	public Result(int internalId, double distance) {
// 		this.id = internalId;
// 		this.distance = distance;
// 	}
// 
// 	public int compare(Result o1, Result o2) {
// 		if ((o1).getDistance() > (o2).getDistance())
// 			return -1;
// 		else if ((o1).getDistance() < (o2).getDistance())
// 			return 1;
// 		else
// 			return 0;
// 	}
// 
// 	public double getDistance() {
// 		return distance;
// 	}
// 
// 	public int getId() {
// 		return id;
// 	}
// 
// }


import gr.iti.mklab.visual.utilities.Result;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import com.aliasi.util.BoundedPriorityQueue;

			}
		}
		return new double[] { centroidIndex, minDistance };
	}

	/**
	 * Returns the indices of the k centroids which are closer to the given descriptor. Can be used for soft
	 * quantization. Fast implementation with a bounded priority queue. TO DO: early stopping!
	 * 
	 * @param descriptor
	 * @param k
	 * @return
	 */
	protected int[] computeKNearestCentroids(double[] descriptor, int k) {
		BoundedPriorityQueue<Result> bpq = new BoundedPriorityQueue<Result>(new Result(), k);

		double minDistance = Double.MAX_VALUE;
		for (int i = 0; i < numCentroids; i++) {
			double distance = 0;
			boolean skip = false;
			for (int j = 0; j < descriptorLength; j++) {
				distance += (codebook[i][j] - descriptor[j]) * (codebook[i][j] - descriptor[j]);
				if (distance > minDistance) {
					skip = true;
					break;
				}
			}
			if (skip) {
				continue;
			}

// Path: src/main/java/gr/iti/mklab/visual/utilities/Result.java
// public class Result implements Comparator<Result> {
// 
// 	/**
// 	 * The distance associated with this result object.
// 	 */
// 	private double distance;
// 
// 	/**
// 	 * The id associated with this result object.
// 	 */
// 	private int id;
// 
// 	public Result() {
// 	}
// 
// 	/**
// 	 * Constructor
// 	 * 
// 	 * @param internalId
// 	 * @param distance
// 	 */
// 	public Result(int internalId, double distance) {
// 		this.id = internalId;
// 		this.distance = distance;
// 	}
// 
// 	public int compare(Result o1, Result o2) {
// 		if ((o1).getDistance() > (o2).getDistance())
// 			return -1;
// 		else if ((o1).getDistance() < (o2).getDistance())
// 			return 1;
// 		else
// 			return 0;
// 	}
// 
// 	public double getDistance() {
// 		return distance;
// 	}
// 
// 	public int getId() {
// 		return id;
// 	}
// 
// }


// Path: src/main/java/gr/iti/mklab/visual/aggregation/AbstractFeatureAggregator.java
import gr.iti.mklab.visual.utilities.Result;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import com.aliasi.util.BoundedPriorityQueue;

			}
		}
		return new double[] { centroidIndex, minDistance };
	}

	/**
	 * Returns the indices of the k centroids which are closer to the given descriptor. Can be used for soft
	 * quantization. Fast implementation with a bounded priority queue. TO DO: early stopping!
	 * 
	 * @param descriptor
	 * @param k
	 * @return
	 */
	protected int[] computeKNearestCentroids(double[] descriptor, int k) {
		BoundedPriorityQueue<Result> bpq = new BoundedPriorityQueue<Result>(new Result(), k);

		double minDistance = Double.MAX_VALUE;
		for (int i = 0; i < numCentroids; i++) {
			double distance = 0;
			boolean skip = false;
			for (int j = 0; j < descriptorLength; j++) {
				distance += (codebook[i][j] - descriptor[j]) * (codebook[i][j] - descriptor[j]);
				if (distance > minDistance) {
					skip = true;
					break;
				}
			}
			if (skip) {
				continue;
			}

			bpq.offer(new Result(i, distance));
