float search_with_ground_truth(NNIndex& index, const Matrix<float>& inputData, const Matrix<float>& testData, const Matrix<int>& matches, int nn, int checks, float& time, float& dist, int skipMatches) { if (matches.cols<nn) { logger.info("matches.cols=%d, nn=%d\n",matches.cols,nn); throw FLANNException("Ground truth is not computed for as many neighbors as requested"); } KNNResultSet resultSet(nn+skipMatches); SearchParams searchParams(checks); int correct = 0; float distR = 0; StartStopTimer t; int repeats = 0; while (t.value<0.2) { repeats++; t.start(); correct = 0; distR = 0; for (int i = 0; i < testData.rows; i++) { float* target = testData[i]; resultSet.init(target, testData.cols); index.findNeighbors(resultSet,target, searchParams); int* neighbors = resultSet.getNeighbors(); neighbors = neighbors+skipMatches; correct += countCorrectMatches(neighbors,matches[i], nn); distR += computeDistanceRaport(inputData, target,neighbors,matches[i], testData.cols, nn); } t.stop(); } time = (float)(t.value/repeats); float precicion = (float)correct/(nn*testData.rows); dist = distR/(testData.rows*nn); logger.info("%8d %10.4g %10.5g %10.5g %10.5g\n", checks, precicion, time, 1000.0 * time / testData.rows, dist); return precicion; }
// Helper method // Extract all instances given by Guids in iCurrentTestData void CDummyCalendarApp::ExtractInstancesL() { TCalTime startDate; startDate.SetTimeLocalL(iCurrentTestData->iStartDate); TCalTime endDate; endDate.SetTimeLocalL(iCurrentTestData->iEndDate); CalCommon::TCalTimeRange timeRange(startDate, endDate); RPointerArray<CCalInstance> instanceArray; if (iCurrentTestData->iSearchString) { CCalInstanceView::TCalSearchParams searchParams(*iCurrentTestData->iSearchString, iCurrentTestData->iSearchBehaviour); iInstanceView->FindInstanceL(instanceArray, (CalCommon::TCalViewFilter)iCurrentTestData->iFilter, timeRange, searchParams); } else { iInstanceView->FindInstanceL(instanceArray, (CalCommon::TCalViewFilter)iCurrentTestData->iFilter, timeRange); } TBuf<26> startBuf; TBuf<26> endBuf; startDate.TimeLocalL().FormatL(startBuf,KFormatDate()); endDate.TimeLocalL().FormatL(endBuf,KFormatDate()); test.Printf(_L("Checking instances between %S and %S\n"), &startBuf, &endBuf); if (instanceArray.Count() == 0) { test.Printf(_L("No instances found\n")); } else { TInt instanceCount = 0; TTime instTime; TBuf<26> instBuf; while (instanceCount < instanceArray.Count()) { CCalInstance* inst = instanceArray[instanceCount]; CleanupStack::PushL(inst); instTime = inst->Time().TimeLocalL(); instTime.FormatL(instBuf,KFormatDate()); TBuf<62> rptType; TCalRRule rptDef; if (!inst->Entry().GetRRuleL(rptDef)) { rptType.Copy(_L("One off")); } else { switch (rptDef.Type()) { case TCalRRule::EDaily: rptType.Format(_L("Daily every %d days"), rptDef.Interval()); break; case TCalRRule::EWeekly: rptType.Format(_L("Weekly every %d weeks"), rptDef.Interval()); break; case TCalRRule::EMonthly: rptType.Format(_L("MonthlyByDates every %d months"), rptDef.Interval()); break; case TCalRRule::EYearly: rptType.Format(_L("YearlyByDate every %d years"), rptDef.Interval()); break; default: ASSERT(0); break; } } test.Printf(_L("One instance is on %S, %d:%d - %S"), &instBuf, instTime.DateTime().Hour(), instTime.DateTime().Minute(), &rptType); if (iCurrentTestData->iTimes.Find(instTime) == KErrNotFound) { test.Printf(_L("THIS ENTRY WAS NOT EXPECTED\n")); test(0); } instanceCount++; CleanupStack::Pop(inst); } if (iCurrentTestData->iFunction) ASSERT(iCurrentTestData->iFunction->CallBack() == 0); } if (instanceArray.Count() != iCurrentTestData->iTimes.Count()) { test.Printf(_L("Some expected entries were not found!\n")); test(0); } instanceArray.ResetAndDestroy(); }