List of usage examples for weka.core.neighboursearch PerformanceStats incrCoordCount
public void incrCoordCount()
From source file:de.unimannheim.dws.algorithms.CustomPairWiseDistance.java
License:Open Source License
/** * Calculates the distance between two instances. Offers speed up (if the * distance function class in use supports it) in nearest neighbour search * by taking into account the cutOff or maximum distance. Depending on the * distance function class, post processing of the distances by * postProcessDistances(double []) may be required if this function is used. * // w w w. j a v a 2 s .c om * @param first * the first instance * @param second * the second instance * @param cutOffValue * If the distance being calculated becomes larger than * cutOffValue then the rest of the calculation is discarded. * @param stats * the performance stats object * @return the distance between the two given instances or * Double.POSITIVE_INFINITY if the distance being calculated becomes * larger than cutOffValue. */ @Override public double distance(Instance first, Instance second, double cutOffValue, PerformanceStats stats) { double distance = 0; Integer value1 = (new Double(first.valueSparse(0))).intValue(); Integer value2 = (new Double(second.valueSparse(0))).intValue(); validate(); if (value1 > value2) { Integer helper = value1; value1 = value2; value2 = helper; } distance = DistanceMatrix$.MODULE$.getDistance(value1, value2).doubleValue(); if (distance > cutOffValue) { return Double.POSITIVE_INFINITY; } if (stats != null) { stats.incrCoordCount(); } return distance; }
From source file:de.uni_potsdam.hpi.bpt.promnicat.util.WeightedEuclideanDistance.java
License:Open Source License
/** * Calculates the distance between two instances. Offers speed up (if the * distance function class in use supports it) in nearest neighbour search by * taking into account the cutOff or maximum distance. Depending on the * distance function class, post processing of the distances by * postProcessDistances(double []) may be required if this function is used. * * @param first the first instance// w w w. j a v a 2 s. c om * @param second the second instance * @param cutOffValue If the distance being calculated becomes larger than * cutOffValue then the rest of the calculation is * discarded. * @param stats the performance stats object * @return the distance between the two given instances or * Double.POSITIVE_INFINITY if the distance being * calculated becomes larger than cutOffValue. */ public double distance(Instance first, Instance second, double cutOffValue, PerformanceStats stats) { double distance = 0; int firstI, secondI; int firstNumValues = first.numValues(); int secondNumValues = second.numValues(); int numAttributes = m_Data.numAttributes(); int classIndex = m_Data.classIndex(); double weights = 1; validate(); for (int p1 = 0, p2 = 0; p1 < firstNumValues || p2 < secondNumValues;) { weights += first.attribute(p1).weight(); if (p1 >= firstNumValues) firstI = numAttributes; else firstI = first.index(p1); if (p2 >= secondNumValues) secondI = numAttributes; else secondI = second.index(p2); if (firstI == classIndex) { p1++; continue; } if ((firstI < numAttributes) && !m_ActiveIndices[firstI]) { p1++; continue; } if (secondI == classIndex) { p2++; continue; } if ((secondI < numAttributes) && !m_ActiveIndices[secondI]) { p2++; continue; } double diff; if (firstI == secondI) { diff = difference(firstI, first.valueSparse(p1), second.valueSparse(p2)); p1++; p2++; } else if (firstI > secondI) { diff = difference(secondI, 0, second.valueSparse(p2)); p2++; } else { diff = difference(firstI, first.valueSparse(p1), 0); p1++; } if (stats != null) stats.incrCoordCount(); distance = updateDistance(distance, diff); if (distance > cutOffValue) return Double.POSITIVE_INFINITY; } if (weights > 1) { return distance / (weights - 1); } return distance / weights; }
From source file:net.sf.jclal.util.distancefunction.CosineDistance.java
License:Open Source License
/** * Calculates the distance between two instances. Offers speed up (if the * distance function class in use supports it) in nearest neighbour search * by taking into account the cutOff or maximum distance. Depending on the * distance function class, post processing of the distances by * postProcessDistances(double []) may be required if this function is used. * * @param first the first instance/* www .ja v a 2 s .co m*/ * @param second the second instance * @param cutOffValue If the distance being calculated becomes larger than * cutOffValue then the rest of the calculation is discarded. * @param stats the performance stats object * @return the distance between the two given instances or * Double.POSITIVE_INFINITY if the distance being calculated becomes larger * than cutOffValue. */ @Override public double distance(Instance first, Instance second, double cutOffValue, PerformanceStats stats) { double distance = 0; int firstI, secondI; int firstNumValues = first.numValues(); int secondNumValues = second.numValues(); int numAttributes = m_Data.numAttributes(); int classIndex = m_Data.classIndex(); double norm2First = 0, norm2Second = 0; validate(); for (int p1 = 0, p2 = 0; p1 < firstNumValues || p2 < secondNumValues;) { if (p1 >= firstNumValues) { firstI = numAttributes; } else { firstI = first.index(p1); } if (p2 >= secondNumValues) { secondI = numAttributes; } else { secondI = second.index(p2); } if (firstI == classIndex) { p1++; continue; } if ((firstI < numAttributes) && !m_ActiveIndices[firstI]) { p1++; continue; } if (secondI == classIndex) { p2++; continue; } if ((secondI < numAttributes) && !m_ActiveIndices[secondI]) { p2++; continue; } double diff; if (firstI == secondI) { diff = localSimilarity(firstI, first.valueSparse(p1), second.valueSparse(p2)); norm2First += localSimilarity(firstI, first.valueSparse(p1), first.valueSparse(p1)); norm2Second += localSimilarity(secondI, second.valueSparse(p2), second.valueSparse(p2)); p1++; p2++; } else if (firstI > secondI) { diff = localSimilarity(secondI, 0, second.valueSparse(p2)); norm2Second += localSimilarity(secondI, second.valueSparse(p2), second.valueSparse(p2)); p2++; } else { diff = localSimilarity(firstI, first.valueSparse(p1), 0); norm2First += localSimilarity(firstI, first.valueSparse(p1), first.valueSparse(p1)); p1++; } if (stats != null) { stats.incrCoordCount(); } distance = updateDistance(distance, diff); if (distance > cutOffValue) { return Double.POSITIVE_INFINITY; } } return distance / (Math.sqrt(norm2First * norm2Second)); }
From source file:org.stream_gpu.float_knn.float_search.NormalizableDistance.java
License:Open Source License
/** * Calculates the distance between two instances. Offers speed up (if the * distance function class in use supports it) in nearest neighbour search by * taking into account the cutOff or maximum distance. Depending on the * distance function class, post processing of the distances by * postProcessDistances(float []) may be required if this function is used. * * @param first the first instance/*ww w . j a v a 2s . co m*/ * @param second the second instance * @param cutOffValue If the distance being calculated becomes larger than * cutOffValue then the rest of the calculation is * discarded. * @param stats the performance stats object * @return the distance between the two given instances or * float.POSITIVE_INFINITY if the distance being * calculated becomes larger than cutOffValue. */ public float distance(Instance first, Instance second, float cutOffValue, PerformanceStats stats) { float distance = 0; int firstI, secondI; int firstNumValues = first.numValues(); int secondNumValues = second.numValues(); int numAttributes = m_Data.numAttributes(); int classIndex = m_Data.classIndex(); validate(); for (int p1 = 0, p2 = 0; p1 < firstNumValues || p2 < secondNumValues;) { if (p1 >= firstNumValues) firstI = numAttributes; else firstI = first.index(p1); if (p2 >= secondNumValues) secondI = numAttributes; else secondI = second.index(p2); if (firstI == classIndex) { p1++; continue; } if ((firstI < numAttributes) && !m_ActiveIndices[firstI]) { p1++; continue; } if (secondI == classIndex) { p2++; continue; } if ((secondI < numAttributes) && !m_ActiveIndices[secondI]) { p2++; continue; } float diff; if (firstI == secondI) { diff = difference(firstI, (float) first.valueSparse(p1), (float) second.valueSparse(p2)); p1++; p2++; } else if (firstI > secondI) { diff = difference(secondI, 0, (float) second.valueSparse(p2)); p2++; } else { diff = difference(firstI, (float) first.valueSparse(p1), 0); p1++; } if (stats != null) stats.incrCoordCount(); distance = updateDistance(distance, diff); if (distance > cutOffValue) return Float.POSITIVE_INFINITY; } return distance; }