double ThresholdCurve::getNPointPrecision(Instances &tcurve, const int n) { if (RELATION_NAME != tcurve.getRelationName() || (tcurve.numInstances() == 0)) { return std::numeric_limits<double>::quiet_NaN(); } int recallInd = tcurve.attribute(RECALL_NAME).index(); int precisInd = tcurve.attribute(PRECISION_NAME).index(); double_array recallVals = tcurve.attributeToDoubleArray(recallInd); int_array sorted = Utils::Sort(recallVals); double isize = 1.0 / (n - 1); double psum = 0; for (int i = 0; i < n; i++) { int pos = binarySearch(sorted, recallVals, i * isize); double recall = recallVals[sorted[pos]]; double precis = tcurve.instance(sorted[pos]).value(precisInd); // interpolate figures for non-endpoints while ((pos != 0) && (pos < sorted.size() - 1)) { pos++; double recall2 = recallVals[sorted[pos]]; if (recall2 != recall) { double precis2 = tcurve.instance(sorted[pos]).value(precisInd); double slope = (precis2 - precis) / (recall2 - recall); double offset = precis - recall * slope; precis = isize * i * slope + offset; break; } } psum += precis; } return psum / n; }
void Instances::copyInstances(const int from, const Instances &dest, const int num) { for (int i = 0; i < num; i++) { Instance *newInstance = new Instance(dest.instance(i).weight(), dest.instance(i).toDoubleArray()); newInstance->setDataset(const_cast<Instances*>(this)); mInstances.push_back(newInstance); } }