@Override public double compare(final int[] h1, final int[] h2) { return -1 * COSINE_SIM.compare(h1, h2); } },
@Override public boolean isDistance() { return dst.isDistance(); } };
@SuppressWarnings("unchecked") protected <T extends FeatureVector> FVComparator<T> getComp(T fv, FeatureComparison type) { if (fv instanceof ByteFV) return (FVComparator<T>) ByteFVComparison.valueOf(type.name()); if (fv instanceof ShortFV) return (FVComparator<T>) ShortFVComparison.valueOf(type.name()); if (fv instanceof IntFV) return (FVComparator<T>) IntFVComparison.valueOf(type.name()); if (fv instanceof FloatFV) return (FVComparator<T>) FloatFVComparison.valueOf(type.name()); if (fv instanceof DoubleFV) return (FVComparator<T>) DoubleFVComparison.valueOf(type.name()); return null; }
@SuppressWarnings("unchecked") protected <T extends FeatureVector> FVComparator<T> getComp(T fv, FeatureComparison type) { if (fv instanceof ByteFV) return (FVComparator<T>) ByteFVComparison.valueOf(type.name()); if (fv instanceof ShortFV) return (FVComparator<T>) ShortFVComparison.valueOf(type.name()); if (fv instanceof IntFV) return (FVComparator<T>) IntFVComparison.valueOf(type.name()); if (fv instanceof FloatFV) return (FVComparator<T>) FloatFVComparison.valueOf(type.name()); if (fv instanceof DoubleFV) return (FVComparator<T>) DoubleFVComparison.valueOf(type.name()); return null; }
/** * Compare this FV to another with the given method. * * @param h the feature to compare against. * @param method the method to compare with. * @return a score determined by the comparison method. */ public double compare(IntFV h, IntFVComparison method) { return method.compare(this, h); }
@SuppressWarnings("unchecked") protected <T extends FeatureVector> FVComparator<T> getComp(T fv, FeatureComparison type) { if (fv instanceof ByteFV) return (FVComparator<T>) ByteFVComparison.valueOf(type.name()); if (fv instanceof ShortFV) return (FVComparator<T>) ShortFVComparison.valueOf(type.name()); if (fv instanceof IntFV) return (FVComparator<T>) IntFVComparison.valueOf(type.name()); if (fv instanceof FloatFV) return (FVComparator<T>) FloatFVComparison.valueOf(type.name()); if (fv instanceof DoubleFV) return (FVComparator<T>) DoubleFVComparison.valueOf(type.name()); return null; }
@Override public boolean isDistance() { return dst.isDistance(); } };
/** * Compare this FV to another with the given method. * * @param h the feature to compare against. * @param method the method to compare with. * @return a score determined by the comparison method. */ public double compare(IntFV h, IntFVComparison method) { return method.compare(this, h); }
@SuppressWarnings("unchecked") protected <T extends FeatureVector> FVComparator<T> getComp(T fv, FeatureComparison type) { if (fv instanceof ByteFV) return (FVComparator<T>) ByteFVComparison.valueOf(type.name()); if (fv instanceof ShortFV) return (FVComparator<T>) ShortFVComparison.valueOf(type.name()); if (fv instanceof IntFV) return (FVComparator<T>) IntFVComparison.valueOf(type.name()); if (fv instanceof FloatFV) return (FVComparator<T>) FloatFVComparison.valueOf(type.name()); if (fv instanceof DoubleFV) return (FVComparator<T>) DoubleFVComparison.valueOf(type.name()); return null; }
/** * Compare this FV to another with the given method. * * @param h the feature to compare against. * @param method the method to compare with. * @return a score determined by the comparison method. */ public double compare(MultidimensionalIntFV h, IntFVComparison method) { return method.compare(this, h); }
/** * Get a feature comparison class for the given feature and metric. * @param fv The feature vector * @param type The feature comparison type * @return A comparable class */ @SuppressWarnings("unchecked") protected <T extends FeatureVector> FVComparator<T> getComp( T fv, FeatureComparison type ) { if (fv instanceof ByteFV) return (FVComparator<T>) ByteFVComparison.valueOf(type.name()); if (fv instanceof ShortFV) return (FVComparator<T>) ShortFVComparison.valueOf(type.name()); if (fv instanceof IntFV) return (FVComparator<T>) IntFVComparison.valueOf(type.name()); if (fv instanceof FloatFV) return (FVComparator<T>) FloatFVComparison.valueOf(type.name()); if (fv instanceof DoubleFV) return (FVComparator<T>) DoubleFVComparison.valueOf(type.name()); return null; }
@Override public double compare(int[] o1, int[] o2) { return dst.compare(o1, o2); }
/** * Get a feature comparison class for the given feature and metric. * @param fv The feature vector * @param type The feature comparison type * @return A comparable class */ @SuppressWarnings("unchecked") protected <T extends FeatureVector> FVComparator<T> getComp( T fv, FeatureComparison type ) { if (fv instanceof ByteFV) return (FVComparator<T>) ByteFVComparison.valueOf(type.name()); if (fv instanceof ShortFV) return (FVComparator<T>) ShortFVComparison.valueOf(type.name()); if (fv instanceof IntFV) return (FVComparator<T>) IntFVComparison.valueOf(type.name()); if (fv instanceof FloatFV) return (FVComparator<T>) FloatFVComparison.valueOf(type.name()); if (fv instanceof DoubleFV) return (FVComparator<T>) DoubleFVComparison.valueOf(type.name()); return null; }
@Override public double compare(IntFV h1, IntFV h2) { return compare(h1.values, h2.values); }
@Override public double compare(int[] o1, int[] o2) { return dst.compare(o1, o2); }
/** * Compare this FV to another with the given method. * * @param h the feature to compare against. * @param method the method to compare with. * @return a score determined by the comparison method. */ public double compare(MultidimensionalIntFV h, IntFVComparison method) { return method.compare(this, h); }
@Override public double compare(IntFV h1, IntFV h2) { return compare(h1.values, h2.values); }
@Override public double compare(final int[] h1, final int[] h2) { return -1 * COSINE_SIM.compare(h1, h2); } },
/** * Construct the SDC with the given quantiser, centroids (corresponding to * the quantiser's internal assigners), and data. * * @param pq * the Product Quantiser * @param pqCentroids * the centroids corresponding to the the Product Quantiser's * internal assigners. * @param dataPoints * the data to index */ public IntSDCNearestNeighbours(IntProductQuantiser pq, int[][][] pqCentroids, int[][] dataPoints) { super(pq, dataPoints); this.distances = new int[pq.assigners.length][][]; for (int i = 0; i < pq.assigners.length; i++) { final int[][] centroids = pqCentroids[i]; distances[i] = new int[centroids.length][centroids.length]; for (int j = 0; j < centroids.length; j++) { for (int k = j; k < centroids.length; k++) { distances[i][j][k] = (int) IntFVComparison.SUM_SQUARE.compare(centroids[j], centroids[k]); distances[i][k][j] = distances[i][j][k]; } } } }
/** * Construct the SDC with the given quantiser, centroids (corresponding to * the quantiser's internal assigners), and data. * * @param pq * the Product Quantiser * @param pqCentroids * the centroids corresponding to the the Product Quantiser's * internal assigners. * @param dataPoints * the data to index */ public IntSDCNearestNeighbours(IntProductQuantiser pq, int[][][] pqCentroids, int[][] dataPoints) { super(pq, dataPoints); this.distances = new int[pq.assigners.length][][]; for (int i = 0; i < pq.assigners.length; i++) { final int[][] centroids = pqCentroids[i]; distances[i] = new int[centroids.length][centroids.length]; for (int j = 0; j < centroids.length; j++) { for (int k = j; k < centroids.length; k++) { distances[i][j][k] = (int) IntFVComparison.SUM_SQUARE.compare(centroids[j], centroids[k]); distances[i][k][j] = distances[i][j][k]; } } } }