void OurNeighbors::RandomReport (ImageFeaturesList& images) { double allClassesMeanNNDAnyClass = 0.0f; double allClassesMeanStdDevAnyClass = 0.0f; ClassSummaryList classSummaries (log); MLClassList::iterator classIdx; VectorKKStr zScoreSummaryLines; for (classIdx = mlClasses->begin (); classIdx != mlClasses->end (); classIdx++) { MLClassPtr mlClass = *classIdx; if (fromPlankton && (fromPlankton != mlClass)) continue; double randomMeanNND = 0.0f; double randomStdDevNND = 0.0f; double realDataU2Stat = 0.0f; double sampleMeanNND = 0.0f; double sampleStdDevNND = 0.0f; double sampleMaxDist = 0.0f; double sampleMinDist = 0.0f; ImageFeaturesListPtr imagesInClass = images.ExtractExamplesForAGivenClass (mlClass); if (imagesInClass->QueueSize () > 0) { // We are going to make a list of images that has duplicate instances of 'ImageFeatures' objects // This way when we Randomize the locations of each 'sfCentroidRow' and 'sfCentroidCol' we do not // imapct on the original data. ImageFeaturesListPtr imagesToRandomize = new ImageFeaturesList (*imagesInClass, true // 'true means we want to own the data so new instances will be created. ); LLoydsEntryListPtr lloydsEntries = DeriveAllLLoydsBins (*imagesToRandomize); { // We will now get mean and stdDev of nnd for this class NeighborList neighbors (*imagesToRandomize, log); neighbors.FindNearestNeighbors (neighborType, mlClass); neighbors.CalcStatistics (sampleMeanNND, sampleStdDevNND, sampleMaxDist, sampleMinDist); } KKStr randomReportFileName; if (reportFileName.Empty ()) randomReportFileName = "RandomDistanceReport"; else randomReportFileName = osRemoveExtension (reportFileName) + "_Random"; randomReportFileName << "_" << mlClass->Name () << ".txt"; ofstream randomReport (randomReportFileName.Str ()); randomReport << "Random Distribution Report" << endl << endl; randomReport << "Source Directory [" << sourceRootDirPath << "]" << endl; randomReport << "Class [" << mlClass->Name () << "]" << endl; RandomNND randomizeLocations (lastScanLine, *imagesToRandomize, numOfIterations, numOfBuckets, bucketSize, randomReport, log ); randomizeLocations.GenerateReport (); randomMeanNND = randomizeLocations.NND_Mean (); randomStdDevNND = randomizeLocations.NND_StdDev (); realDataU2Stat = randomizeLocations.RealDataU2Stat (); //double sampleMeanNND = 0.0f; //double sampleStdDevNND = 0.0f; double z_Score = Z_Score (sampleMeanNND, randomMeanNND, randomStdDevNND, imagesToRandomize->QueueSize ()); randomReport << endl << endl << endl << "Z-Score" << endl << "=======" << endl << endl << "SampleMeanNND " << "\t" << sampleMeanNND << endl << "SampleStdDevNND " << "\t" << sampleStdDevNND << endl << "RandomMeanNND " << "\t" << randomMeanNND << endl << "RandomStdDevNND " << "\t" << randomStdDevNND << endl << "------- Z-Score " << "\t" << z_Score << endl << endl; KKStr zScoreSummaryLine = mlClass->Name () + "\t" + StrFormatDouble (sampleMeanNND, "###,##0.00") + "\t" + StrFormatDouble (sampleStdDevNND, "###,##0.00") + "\t" + StrFormatDouble (randomMeanNND, "###,##0.00") + "\t" + StrFormatDouble (randomStdDevNND, "###,##0.00") + "\t" + StrFormatDouble (z_Score, "###,##0.000"); zScoreSummaryLines.push_back (zScoreSummaryLine); // The new instance on 'ClassSummary' that is aboiut to be created will take ownership // of lloydsBins. classSummaries.PushOnBack (new ClassSummary (mlClass, lloydsEntries, (float)realDataU2Stat, (float)z_Score)); delete imagesToRandomize; imagesToRandomize = NULL; } delete imagesInClass; imagesInClass = NULL; } if (!fromPlankton) { LLoydsEntryListPtr allClassesLLoydsEntries = DeriveAllLLoydsBins (images); // Create a report for all classes KKStr randomReportFileName; if (reportFileName.Empty ()) randomReportFileName = "RandomDistanceReport_All.txt"; else randomReportFileName = osRemoveExtension (reportFileName) + "_Random_All.txt"; ofstream randomReport (randomReportFileName.Str ()); randomReport << "Source Directory [" << sourceRootDirPath << "]" << endl; randomReport << "Class [" << "All" << "]" << endl; { // Find the mean and stddev of Nearest Neighbor regardless of class. NeighborList allClassesNeighbors (images, log); allClassesNeighbors.FindNearestNeighbors (NeighborType::AnyPlankton, fromPlankton); double allClassesMinDistAnyClass = 0.0f; double allClassesMaxDistAnyClass = 0.0f; allClassesNeighbors.CalcStatistics (allClassesMeanNNDAnyClass, allClassesMeanStdDevAnyClass, allClassesMinDistAnyClass, allClassesMaxDistAnyClass ); } RandomNND randomizeLocations (lastScanLine, images, numOfIterations, numOfBuckets, bucketSize, randomReport, log ); randomizeLocations.GenerateReport (); // All classes Z-Score double allClassesRandomMeanNND = randomizeLocations.NND_Mean (); double allClassesRandomStdDevNND = randomizeLocations.NND_StdDev (); double allClassesRealDataU2Stat = randomizeLocations.RealDataU2Stat (); double z_Score = Z_Score (allClassesMeanNNDAnyClass, allClassesRandomMeanNND, allClassesRandomStdDevNND, images.QueueSize ()); KKStr zScoreSummaryLine = KKStr ("All-Classes") + "\t" + StrFormatDouble (allClassesMeanNNDAnyClass, "###,##0.00") + "\t" + StrFormatDouble (allClassesMeanStdDevAnyClass, "###,##0.00") + "\t" + StrFormatDouble (allClassesRandomMeanNND, "###,##0.00") + "\t" + StrFormatDouble (allClassesRandomStdDevNND, "###,##0.00") + "\t" + StrFormatDouble (z_Score, "###,##0.00"); zScoreSummaryLines.push_back (zScoreSummaryLine); randomReport << endl << endl << endl << "Z-Score" << endl << "=======" << endl << endl << "SampleMeanNND " << "\t" << allClassesMeanNNDAnyClass << endl << "SampleStdDevNND " << "\t" << allClassesMeanStdDevAnyClass << endl << "RandomMeanNND " << "\t" << allClassesRandomMeanNND << endl << "RandomStdDevNND " << "\t" << allClassesRandomStdDevNND << endl << "------- Z-Score " << "\t" << z_Score << endl << endl; classSummaries.PushOnBack (new ClassSummary (MLClass::CreateNewMLClass (KKStr ("AllClasses")), allClassesLLoydsEntries, (float)allClassesRealDataU2Stat, (float)z_Score ) ); } { // Z-Score Summary Report KKB::kkuint32 x; *report << std::endl << std::endl << "Z-Score Summary By Class" << std::endl << std::endl << "ClassName" << "\t" << "SampleMean" << "\t" << "SampleStdDev" << "\t" << "RandomMean" << "\t" << "RandomStdDev" << "\t" << "Z-Score" << std::endl << "=========" << "\t" << "==========" << "\t" << "============" << "\t" << "==========" << "\t" << "============" << "\t" << "=======" << std::endl; for (x = 0; x < zScoreSummaryLines.size (); x++) *report << zScoreSummaryLines[x] << std::endl; } *report << endl << endl << endl; classSummaries.SummaryReport (*report); *report << endl << endl << endl; classSummaries.SpatialOverlapReport (*report); classSummaries.SaveLLoydsBinsData (lloydsBinsFileName, sourceRootDirPath, lastScanLine, baseLLoydsBinSize); } /* RandomReport */