CmdLineExpander::CmdLineExpander (const KKStr&  _applicationName,
                                  RunLog&       _log,
                                  const KKStr&  _cmdLine
                                 ):
  applicationName (_applicationName),
  log             (_log)

{
  VectorKKStr  initialParameters;

  KKStr  cmdLine (_cmdLine);

  cmdLine.TrimLeft ();
  while  (!cmdLine.Empty ())
  {
    KKStr  nextField = cmdLine.ExtractQuotedStr ("\n\r\t ", false);  // false = Do not decode escape characters
    nextField.TrimRight ();
    if  (!nextField.Empty ())
      initialParameters.push_back (nextField);
    cmdLine.TrimLeft ();
  }

  BuildCmdLineParameters (initialParameters);
  BuildExpandedParameterPairs ();
}
void  CmdLineExpander::ExtractParametersFromFile (const KKStr&  cmdFileName, 
                                                  VectorKKStr&  cmdFileParameters,
                                                  bool&         validFile
                                                 )
{
  FILE*  in = osFOPEN (cmdFileName.Str (), "r");
  if  (!in)
  {
    log.Level (-1) << endl << endl << endl
         << "ExtractParametersFromFile     *** EROR ***" << endl
         << endl
         << "      Invalid CmdFile[" << cmdFileName << "]" << endl
         << endl;
    validFile = false;
    return;
  }

  KKStr  token;
  bool    eof = false;

  token  = osReadNextQuotedStr (in, " \n\r", eof);
  while  (!eof)
  {
    cmdFileParameters.push_back (token);
    token  = osReadNextQuotedStr (in, " \n\r", eof);
  }

  std::fclose (in);
}  /* ExtractParametersFromFile */
Beispiel #3
0
VectorKKStr  KKStrParser::Split (const char* delStr)
{
  VectorKKStr  tokens;
  while  (MoreTokens ())
   tokens.push_back (this->GetNextToken (delStr));
  return  tokens;
}
Beispiel #4
0
VectorKKStr  Configuration::FormatErrorsWithLineNumbers ()  const
{
  VectorKKStr  errorMsgs;
  for  (kkuint32 i = 0;  i < formatErrors.size ();  i++)
  {
    KKStr  lineNumStr = "    ";
    if  (i < formatErrorsLineNums.size ())
      lineNumStr = StrFormatInt (formatErrorsLineNums[i], "0000");
    errorMsgs.push_back (lineNumStr + ":" + formatErrors[i]); 
  }

  return  errorMsgs;
}  /* FormatErrorsWithLineNumbers */
void  CmdLineExpander::ExpandCmdLine (kkint32 argc, 
                                      char**  argv
                                     )
{
  parmsGood = true;
  
  VectorKKStr  initialParameters;
  {
    kkint32 y;
    for  (y = 1; y < argc;  y++)
      initialParameters.push_back (argv[y]);
  }

  BuildCmdLineParameters (initialParameters);
  BuildExpandedParameterPairs ();

  return;
}  /* ExpandCmdLine */
VectorKKStr  FeatureFileIO::RegisteredDriverNames (bool  canRead,
                                                   bool  canWrite
                                                  )
{
  vector<FeatureFileIOPtr>*  drivers = RegisteredDrivers ();
  VectorKKStr  names;
  vector<FeatureFileIOPtr>::iterator  idx;

  for  (idx = drivers->begin ();  idx != drivers->end ();  idx++)
  {
    FeatureFileIOPtr  driver = *idx;
    if  (canRead  &&  (!driver->CanRead ()))
      continue;

    if  (canWrite  &&  (!driver->CanWrite ()))
      continue;

    names.push_back (driver->DriverName ());
  }

  return  names;
}  /* RegisteredDriverNames */
Beispiel #7
0
/**
 * @brief Constructs a Feature Encoder object.
 * @param[in] _fileDesc 
 * @param[in] _class1 
 * @param[in] _class2 
 * @param[in] _log A log-file stream. All important events will be output to this stream
 */
FeatureEncoder::FeatureEncoder (FileDescConstPtr       _fileDesc,
                                MLClassPtr             _class1,
                                MLClassPtr             _class2,
                                const FeatureNumList&  _selectedFeatures,
                                SVM_EncodingMethod     _encodingMethod,
                                double                 _c_Param
                               ):

    cardinalityDest          (NULL),
    class1                   (_class1),
    class2                   (_class2),
    codedNumOfFeatures       (0),
    c_Param                  (_c_Param),
    destFeatureNums          (NULL),
    destFileDesc             (NULL),
    destWhatToDo             (NULL),
    encodingMethod           (_encodingMethod),
    fileDesc                 (_fileDesc),
    numEncodedFeatures       (0),
    numOfFeatures            (0),
    selectedFeatures         (_selectedFeatures),
    srcFeatureNums           (NULL),
    xSpaceNeededPerExample   (0)
{
  numOfFeatures   = selectedFeatures.NumOfFeatures ();

  xSpaceNeededPerExample = 0;
  srcFeatureNums   = new kkint32[numOfFeatures];
  cardinalityDest  = new kkint32[numOfFeatures];
  destFeatureNums  = new kkint32[numOfFeatures];
  destWhatToDo     = new FeWhatToDo[numOfFeatures];

  VectorKKStr   destFieldNames;

  kkint32  x;

  for  (x = 0;  x < numOfFeatures;  x++)
  {
    kkint32  srcFeatureNum = selectedFeatures[x];
    srcFeatureNums  [x] = srcFeatureNum;
    destFeatureNums [x] = xSpaceNeededPerExample;
    cardinalityDest [x] = 1;
    destWhatToDo    [x] = FeWhatToDo::FeAsIs;

    const Attribute&  attribute = fileDesc->GetAAttribute (srcFeatureNum);
    AttributeType  attributeType = attribute.Type ();
    kkint32        cardinality   = attribute.Cardinality ();

    switch (encodingMethod)
    {
      case SVM_EncodingMethod::Binary:
        if  ((attributeType == AttributeType::Nominal)  ||  (attributeType == AttributeType::Symbolic))
        {
          destWhatToDo    [x] = FeWhatToDo::FeBinary;
          cardinalityDest [x] = cardinality;
          xSpaceNeededPerExample += cardinalityDest[x];
          numEncodedFeatures   += cardinalityDest[x];
          for  (kkint32 zed = 0;  zed < cardinalityDest[x];  zed++)
          {
            KKStr  fieldName = attribute.Name () + "_" + attribute.GetNominalValue (zed);
            destFieldNames.push_back (fieldName);
          }
        }
        else
        {
          xSpaceNeededPerExample++;
          numEncodedFeatures++;
          destWhatToDo [x] = FeWhatToDo::FeAsIs;
          destFieldNames.push_back (attribute.Name ());
        }
        break;


      case  SVM_EncodingMethod::Scaled:
        xSpaceNeededPerExample++;
        numEncodedFeatures++;
        if  ((attributeType == AttributeType::Nominal)  ||
             (attributeType == AttributeType::Symbolic)
            )
          destWhatToDo [x] = FeWhatToDo::FeScale;
        else
          destWhatToDo [x] = FeWhatToDo::FeAsIs;

        destFieldNames.push_back (attribute.Name ());
        break;


      case  SVM_EncodingMethod::NoEncoding:
      default:
        xSpaceNeededPerExample++;
        numEncodedFeatures++;
        destWhatToDo [x] = FeWhatToDo::FeAsIs;
        destFieldNames.push_back (attribute.Name ());
        break;
    }
  }

  codedNumOfFeatures = xSpaceNeededPerExample;

  destFileDesc = FileDesc::NewContinuousDataOnly (destFieldNames);

  xSpaceNeededPerExample++;  // Add one more for the terminating (-1)
}
Beispiel #8
0
void  Test ()
{
  RunLog  log;
  DataBasePtr  dbConn = new DataBase (log);

  //  InstrumentDataPtr  id = dbConn->InstrumentDataGetByScanLine ("TestCruise_01", 4022);

  //{
  //  ImageFeaturesPtr  fv  = NULL;
  //  KKStr imageFileName = "TestCruise_01_00006156_3701";
  //  DataBaseImagePtr dbi = dbConn->ImageLoad (imageFileName);
  //  if  (dbi)
  //    fv  = dbConn->FeatureDataRecLoad (dbi);
  //  delete  fv;
  //  delete  dbi;
  //}

  {
    SipperCruiseListPtr  cruises = dbConn->SipperCruiseLoadAllCruises ();
    delete  cruises;
  }



  bool  cancelFlag = false;

  {
    DataBaseImageGroupPtr  existingGroup = dbConn->ImageGroupLoad ("TestGroup2");

    if  (existingGroup)
    {

      VectorUint*  depthStats = dbConn->ImageGetDepthStatistics 
             (existingGroup, 
              "",         // sipperFileName
              10.0f,      // depthIncrements,
              NULL,       // mlClass,
              'P',        // 'p' = Use Predicted Class
              0.0f, 1.0f, // minProb, maxProb,
              0, 0        // minSize, maxSize
             );

      delete  depthStats;
      depthStats = NULL;



      ClassStatisticListPtr  stats = dbConn->ImageGetClassStatistics 
           (existingGroup,
            "ETP2008_8A_06",
            NULL,
            'P',         // 'P' = Use Predicted Class
            0.0f, 1.0f,  // MinProb,  MaxProb
            0, 0,        // MinSize,  MaxSize
            0.0f, 0.0f   // MinDepth, MaxDepth
           );



      delete  stats;
      stats = NULL;
    }

    DataBaseImageListPtr  images = dbConn->ImagesQuery (existingGroup, true, cancelFlag);
  }

  DataBaseImageGroupPtr g = new  DataBaseImageGroup (-1, "TestGroup2", "Description of group", 0);
  dbConn->ImageGroupInsert (*g);
  if  (dbConn->DuplicateKey ())
  {
    DataBaseImageGroupPtr  existingGroup = dbConn->ImageGroupLoad (g->Name ());
    if  (existingGroup)
    {
      g->ImageGroupId (existingGroup->ImageGroupId ());
      dbConn->ImageGroupDelete (existingGroup->ImageGroupId ());
      dbConn->ImageGroupInsert (*g);
      delete  existingGroup;
      existingGroup = NULL;
    }
  }


  DataBaseImageListPtr  images = dbConn->ImagesQuery (NULL,
                                                      "ETP2008", "8", "A", NULL,
                                                      'P',             // 'P' = Use Predicted Class
                                                      0.0f, 1.0f,      // MinProb,  MaxProb
                                                      0, 0,            // MinSize,  MaxSize
                                                      290.0f, 293.0f,  // MinDepth, MaxDepth
                                                      0,               // Restart Image
                                                      -1,              // unlimited Limit
                                                      true,            // true=Include ThumbNail
                                                      cancelFlag
                                                     );


  VectorKKStr fileNames;
  {
    DataBaseImageList::iterator  idx;
    for  (idx = images->begin ();  idx != images->end ();  idx++)
      fileNames.push_back ((*idx)->ImageFileName ());
  }

  dbConn->ImageGroupEntriesInsert (g->ImageGroupId (), fileNames);

  
  delete  dbConn;
}  /* Test */
void  RandomSplitJobManager::GenerateFinalResultsReport ()
{
  KKStr reportFileName = osGetRootName (ManagerName ()) + "_Results.html;";

  ofstream f (reportFileName.Str ());

  f << "Run Time Parameters" << endl
    << "Run Time"          << "\t" << osGetLocalDateTime ()  << endl
    << "configFileName"    << "\t" << configFileName         << endl
    << "DataFileName"      << "\t" << dataFileName           << endl
    << "Format"            << "\t" << format->DriverName ()  << endl
    << "DataIndexFileName" << "\t" << dataIndexFileName      << endl
    << "NumFolds"          << "\t" << numFolds               << endl
    << "NumSplits"         << "\t" << numSplits              << endl
    << "splitFraction"     << "\t" << splitFraction          << endl
    << endl;


  KKJobList::const_iterator  idx;

  ConfusionMatrix2  avgResults (*(this->MLClasses ()));
  KKB::uint  x = 0;

  for  (idx = Jobs ()->begin ();  idx != Jobs ()->end ();  idx++)
  {
    RandomSplitJobPtr j = dynamic_cast<RandomSplitJobPtr> (*idx);
    if  (j->RandomSplitsResults () != NULL)
    {
      f << endl
        << "Random Split[" << j->SplitNum () << "]" << endl;
      j->RandomSplitsResults ()->PrintConfusionMatrixTabDelimited (f);
      f << endl << endl;

      j->PrintClassCounts (f);
      f << endl << endl;

      avgResults.AddIn (*(j->RandomSplitsResults ()), log);
      x++;
    }
  }

  f << endl << "Mean Average of all random Splits." << endl;
  avgResults.FactorCounts (1.0 / (double)x);
  avgResults.PrintConfusionMatrixTabDelimited (f);
  f << endl 
    << endl
    << endl
    << endl
    << "Class Counts" << endl
    << endl;

  kkuint32  numClasses = (kkuint32)mlClasses->size ();

  VectorFloat   classAccs;
  VectorDouble  knownCounts;
  VectorDouble  predCounts;
  VectorDouble  adjCounts;
  VectorDouble  adjCountsStdError;
  VectorDouble  predDelta;       
  VectorDouble  adjDelta;
  
  KKStr l1, l2, l3;
  mlClasses->ExtractThreeTitleLines (l1, l2, l3);

  VectorKKStr  knownCountLines;
  VectorKKStr  predCountLines;
  VectorKKStr  adjCountLines;
  VectorKKStr  deltaPredCountLines;
  VectorKKStr  deltaAdjCountLines;
  VectorKKStr  accLines;


  ConfusionMatrix2  totalCM (*MLClasses ());
  int  totalCmCount = 0;


  // Known Counts
  for  (idx = Jobs ()->begin ();  idx != Jobs ()->end ();  idx++)
  {
    RandomSplitJobPtr j = dynamic_cast<RandomSplitJobPtr> (*idx);
    if  (j->RandomSplitsResults () != NULL)
    {
      KKStr splitNumStr = StrFormatInt (j->SplitNum (), "ZZZ0");
      j->GetClassCounts (classAccs, knownCounts, predCounts, adjCounts, adjCountsStdError, predDelta, adjDelta);

      totalCM.AddIn (*(j->RandomSplitsResults ()), log);
      totalCmCount++;
      KKStr accLine        = "Acc By Class\t" + splitNumStr;
      KKStr knownLine      = "Known\t"        + splitNumStr;
      KKStr predLine       = "Predicted\t"    + splitNumStr;
      KKStr adjLine        = "Adjusted\t"     + splitNumStr;
      KKStr deltaPredLine  = "Delta Pred\t"   + splitNumStr;
      KKStr deltaAdjLine   = "Delta Adj\t"    + splitNumStr;


      double  totalAcc       = 0.0;
      double  totalDeltaPred = 0.0;
      double  totalDeltaAdj  = 0.0;

      for  (x = 0;  x < numClasses;  x++)
      {
        accLine       << "\t" << StrFormatDouble (classAccs   [x], "zz0.00") << "%";
        knownLine     << "\t" << StrFormatDouble (knownCounts [x], "-Z,ZZZ,ZZ0.0");
        predLine      << "\t" << StrFormatDouble (predCounts  [x], "-Z,ZZZ,ZZ0.0");
        adjLine       << "\t" << StrFormatDouble (adjCounts   [x], "-Z,ZZZ,ZZ0.0");
        deltaPredLine << "\t" << StrFormatDouble (predDelta   [x], "-Z,ZZZ,ZZ0.0");
        deltaAdjLine  << "\t" << StrFormatDouble (adjDelta    [x], "-Z,ZZZ,ZZ0.0");
        totalAcc       += classAccs [x];
        totalDeltaPred += fabs (predDelta[x]);
        totalDeltaAdj  += fabs (adjDelta[x]);
      }


      accLine       << "\t" << StrFormatDouble ((totalAcc        / (double)classAccs.size ()), "ZZ0.00") << "%";
      deltaPredLine << "\t" << StrFormatDouble ((totalDeltaPred  / (double)predDelta.size ()), "ZZ0.00");
      deltaAdjLine  << "\t" << StrFormatDouble ((totalDeltaAdj   / (double)adjDelta.size  ()), "ZZ0.00");

      accLines.push_back            (accLine);
      knownCountLines.push_back     (knownLine);
      predCountLines.push_back      (predLine);
      adjCountLines.push_back       (adjLine);
      deltaPredCountLines.push_back (deltaPredLine);
      deltaAdjCountLines.push_back  (deltaAdjLine);
    }
  }
  double  factor = 0.0;
  if  (totalCmCount > 0)
    factor = 1.0 / (double)totalCmCount;

  totalCM.FactorCounts (factor);

  f << endl << endl
    << "Average Confusion  Matrix" << endl
    << endl;
  totalCM.PrintConfusionMatrixTabDelimited (f);

  f << ""            << "\t" << ""      << "\t" << l1 << endl
    << ""            << "\t" << "Split" << "\t" << l2 << endl
    << "Description" << "\t" << "Num"   << "\t" << l3 << endl;

  f << endl << endl;
  for  (x = 0;  x < knownCountLines.size ();  x++)
    f << knownCountLines[x] << endl;

  f << endl << endl;
  for  (x = 0;  x < predCountLines.size ();  x++)
    f << predCountLines[x] << endl;

  f << endl << endl;
  for  (x = 0;  x < adjCountLines.size ();  x++)
    f << adjCountLines[x] << endl;

  f << endl << endl;
  for  (x = 0;  x < deltaPredCountLines.size ();  x++)
    f << deltaPredCountLines[x] << endl;

  f << endl << endl;
  for  (x = 0;  x < deltaAdjCountLines.size ();  x++)
    f << deltaAdjCountLines[x] << endl;

  f << endl << endl;
  for  (x = 0;  x < knownCountLines.size ();  x++)
    f << accLines[x] << endl;

  VectorFloat  avgAccuracies = totalCM.AccuracyByClass ();
  f << "Avg-Accuracies";
  for  (x = 0;  x < avgAccuracies.size ();  x++)
    f << "\t" << StrFormatDouble (avgAccuracies[x], "zz0.00") << "%";
  f << "\t" << StrFormatDouble (totalCM.Accuracy (), "zz0.00") << "%";
  f << endl;

  f << endl << endl;

  f.close ();
}  /* GenerateFinalResultsReport */
Beispiel #10
0
/**
  *@brief Constructs a Feature Encoder object.
  *@param[in] _param 
  *@param[in] _fileDesc
  *@param[in] _log A log file stream. All important events will be output to this stream
  */
FeatureEncoder2::FeatureEncoder2 (const ModelParam&  _param,
                                  FileDescConstPtr   _fileDesc
                                 ):
    attributeVector     (_fileDesc->AttributeVector ()),
    cardinalityDest     (NULL),
    cardinalityVector   (_fileDesc->CardinalityVector ()),
    codedNumOfFeatures  (0),
    destFeatureNums     (NULL),
    destWhatToDo        (NULL),
    encodedFileDesc     (NULL),
    encodingMethod      (ModelParam::EncodingMethodType::NoEncoding),
    fileDesc            (_fileDesc),
    numOfFeatures       (0),
    srcFeatureNums      (NULL),
    param               (_param)
    
{
  FeatureNumListConstPtr  selectedFeatures = param.SelectedFeatures ();
  numOfFeatures = param.SelectedFeatures ()->NumOfFeatures ();

  encodingMethod   = param.EncodingMethod ();

  srcFeatureNums   = new kkuint16  [numOfFeatures];
  cardinalityDest  = new kkint32   [numOfFeatures];
  destFeatureNums  = new kkint32   [numOfFeatures];
  destWhatToDo     = new FeWhatToDo[numOfFeatures];

  VectorKKStr   destFieldNames;

  kkint32  x;

  for  (x = 0;  x < numOfFeatures;  x++)
  {
    kkuint16  srcFeatureNum = (*selectedFeatures)[x];
    srcFeatureNums   [x] = srcFeatureNum;
    destFeatureNums  [x] = codedNumOfFeatures;
    cardinalityDest  [x] = 1;
    destWhatToDo     [x] = FeWhatToDo::FeAsIs;

    Attribute  srcAttribute = (fileDesc->Attributes ())[srcFeatureNum];

    switch (encodingMethod)
    {
      case  ModelParam::EncodingMethodType::Binary:
        if  ((attributeVector[srcFeatureNum] == AttributeType::Nominal)  ||
             (attributeVector[srcFeatureNum] == AttributeType::Symbolic)
            )
        {
          destWhatToDo    [x] = FeWhatToDo::FeBinary;
          cardinalityDest [x] = cardinalityVector[srcFeatureNums [x]];
          codedNumOfFeatures   += cardinalityDest[x];
          for  (kkint32 zed = 0;  zed < cardinalityDest[x];  zed++)
          {
            KKStr  fieldName = srcAttribute.Name () + "_" + srcAttribute.GetNominalValue (zed);
            destFieldNames.push_back (fieldName);
          }
        }
        else
        {
          codedNumOfFeatures++;
          destWhatToDo [x] = FeWhatToDo::FeAsIs;
          destFieldNames.push_back (srcAttribute.Name ());
        }
        break;


      case  ModelParam::EncodingMethodType::Scaled:
        codedNumOfFeatures++;
        if  ((attributeVector[srcFeatureNums[x]] == AttributeType::Nominal)  ||
             (attributeVector[srcFeatureNums[x]] == AttributeType::Symbolic)
            )
          destWhatToDo [x] = FeWhatToDo::FeScale;
        else
          destWhatToDo [x] = FeWhatToDo::FeAsIs;

        destFieldNames.push_back (srcAttribute.Name ());
        break;


      case    ModelParam::EncodingMethodType::NoEncoding:
      default:
        codedNumOfFeatures++;
        destWhatToDo [x] = FeWhatToDo::FeAsIs;
        destFieldNames.push_back (srcAttribute.Name ());
        break;
    }
  }

  encodedFileDesc = FileDesc::NewContinuousDataOnly (destFieldNames);
}
Beispiel #11
0
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 */