SpillStructureClassifier Class Reference

#include <SpillStructureClassifier.h>

List of all members.

Classes

struct  Cleaner
 sub-class Cleaner struct is used to clean up singleton at the end of job. More...

Public Member Functions

SpillStruct::SpillStruct_t Classify (std::vector< double > batches)
SpillStruct::SpillStruct_t Classify (size_t n, double *b)
SpillStruct::SpillStruct_t Classify (size_t n, float *b)
std::string ClassifyAsString (std::vector< double > batches)
std::string ClassifyAsString (size_t n, double *b)
std::string ClassifyAsString (size_t n, float *b)

Static Public Member Functions

static SpillStructureClassifierInstance ()
 No public ctor for singleton, all user access is through Instance().

Private Member Functions

void Normalize (std::vector< double > &v)
void InitTemplates ()
void AddTemplate (SpillStruct::SpillStruct_t e, std::vector< double > v)
 SpillStructureClassifier ()
 Private ctor, users access via Instance().
virtual ~SpillStructureClassifier ()
 SpillStructureClassifier (const SpillStructureClassifier &)
 Method private and not implement, declared to prevent copying.
void operator= (const SpillStructureClassifier &)
 Method private and not implement, declared to prevent assignment.

Private Attributes

std::vector
< SpillStruct::SpillStruct_t
fTemplateEnums
std::vector< std::vector
< double > > 
fTemplateVectors

Static Private Attributes

static SpillStructureClassifierfgTheInstance
 The one-and-only instance.

Friends

struct Cleaner

Detailed Description

Definition at line 43 of file SpillStructureClassifier.h.


Constructor & Destructor Documentation

SpillStructureClassifier::SpillStructureClassifier (  )  [private]

Private ctor, users access via Instance().

private ctor

Definition at line 56 of file SpillStructureClassifier.cxx.

References InitTemplates().

Referenced by Instance().

00057 {
00059   InitTemplates();
00060 }

SpillStructureClassifier::~SpillStructureClassifier (  )  [private, virtual]

Definition at line 62 of file SpillStructureClassifier.cxx.

References fgTheInstance.

00063 {
00064   fgTheInstance = 0;
00065 }

SpillStructureClassifier::SpillStructureClassifier ( const SpillStructureClassifier  )  [private]

Method private and not implement, declared to prevent copying.


Member Function Documentation

void SpillStructureClassifier::AddTemplate ( SpillStruct::SpillStruct_t  e,
std::vector< double >  v 
) [private]

Definition at line 185 of file SpillStructureClassifier.cxx.

References fTemplateEnums, fTemplateVectors, and Normalize().

Referenced by InitTemplates().

00187 {
00188   // normalize only local copy, don't affect source (i.e. no reference above)
00189   Normalize(v);
00190   fTemplateEnums.push_back(e);
00191   fTemplateVectors.push_back(v);
00192 }

SpillStruct::SpillStruct_t SpillStructureClassifier::Classify ( size_t  n,
float *  b 
)

Definition at line 148 of file SpillStructureClassifier.cxx.

References Classify().

00149 {
00150   std::vector<double> batches;
00151   for (size_t i=0; i<n; ++i) batches.push_back(b[i]);
00152   return Classify(batches); // do what we know how to do
00153 }

SpillStruct::SpillStruct_t SpillStructureClassifier::Classify ( size_t  n,
double *  b 
)

Definition at line 140 of file SpillStructureClassifier.cxx.

References Classify().

00141 {
00142   std::vector<double> batches;
00143   for (size_t i=0; i<n; ++i) batches.push_back(b[i]);
00144   return Classify(batches); // do what we know how to do
00145 }

SpillStruct::SpillStruct_t SpillStructureClassifier::Classify ( std::vector< double >  batches  ) 

Definition at line 87 of file SpillStructureClassifier.cxx.

References fTemplateEnums, fTemplateVectors, it, SpillStruct::kUnknown, and Normalize().

Referenced by Classify(), and ClassifyAsString().

00088 {
00089   // careful here ... 
00090   // to avoid modifying passed data we don't pass by reference
00091 
00092   Normalize(batches);
00093 
00094   size_t nb = batches.size();
00095 
00096   double minDiff = 1.0e30;
00097   size_t nt = fTemplateEnums.size();
00098 
00099   size_t minIndx = nt+1;
00100   for (size_t it=0; it<nt; ++it) {
00101     // compare to template
00102     std::vector<double>& avector = fTemplateVectors[it];
00103     size_t nt = avector.size();
00104     // template and batchs should be same length vectors
00105     if ( nt != nb ) {
00106       static int nmsg = 10;
00107       if ( nmsg > 0 ) {
00108         --nmsg;
00109         std::cout << "SpillStructureClassifier template[" 
00110                   << it << "] nt " << nt << " nbatch " << nb
00111                   << std::endl;
00112       }
00113       continue;
00114     }
00115     // calculate variance w/ regard to a template
00116     double diffSum = 0;
00117     for (size_t j=0; j<nb; ++j) {
00118       double diff = (avector[j]-batches[j])*(avector[j]-batches[j]);
00119       diffSum += diff;
00120       //cout << "RWH  j=" << j << " " << std::setw(10) << avector[j] << " " 
00121       //     << std::setw(10) << batches[j] 
00122       //     << " diff " << std::setw(10) << diff << endl;
00123     }
00124     if ( diffSum < minDiff ) {
00125       minDiff = diffSum;
00126       minIndx = it;
00127     }
00128     //cout << "RWH " << it << " " << std::setw(10) << template_names[it] 
00129     //     << " diff " << diffSum << " " << minDiff << " "
00130     //     << minIndx << endl;
00131   }
00132   if ( minIndx > nt ) return SpillStruct::kUnknown;
00133 
00134   //cout << "RWH return " << minIndx << " " << template_names[minIndx] << endl;
00135   return fTemplateEnums[minIndx];
00136 
00137 }

std::string SpillStructureClassifier::ClassifyAsString ( size_t  n,
float *  b 
)

Definition at line 168 of file SpillStructureClassifier.cxx.

References bfld::AsString(), and Classify().

00169 {
00170   return SpillStruct::AsString(Classify(n,b));
00171 }

std::string SpillStructureClassifier::ClassifyAsString ( size_t  n,
double *  b 
)

Definition at line 162 of file SpillStructureClassifier.cxx.

References bfld::AsString(), and Classify().

00163 {
00164   return SpillStruct::AsString(Classify(n,b));
00165 }

std::string SpillStructureClassifier::ClassifyAsString ( std::vector< double >  batches  ) 

Definition at line 156 of file SpillStructureClassifier.cxx.

References bfld::AsString(), and Classify().

00157 {
00158   return SpillStruct::AsString(Classify(batches));
00159 }

void SpillStructureClassifier::InitTemplates (  )  [private]

Definition at line 196 of file SpillStructureClassifier.cxx.

References AddTemplate(), SpillStruct::k1p6slip, SpillStruct::k2p6slip, SpillStruct::k3p6slip, SpillStruct::k4p6slip, SpillStruct::k5batch, SpillStruct::k5p6slip, and SpillStruct::k6batch.

Referenced by SpillStructureClassifier().

00197 {
00198   // different scenarios
00199   std::vector<double> test(6);
00200   test[0] = 1;
00201   test[1] = 1;
00202   test[2] = 1;
00203   test[3] = 1;
00204   test[4] = 1;
00205   test[5] = 1;
00206   AddTemplate(SpillStruct::k6batch,test);
00207   
00208   test[0] = 0;
00209   AddTemplate(SpillStruct::k5batch,test);
00210 
00211   test[0] = 1.9;
00212   AddTemplate(SpillStruct::k1p6slip,test);
00213 
00214   test[1] = 1.9;
00215   AddTemplate(SpillStruct::k2p6slip,test);
00216 
00217   test[2] = 1.9;
00218   AddTemplate(SpillStruct::k3p6slip,test);
00219 
00220   test[3] = 1.9;
00221   AddTemplate(SpillStruct::k4p6slip,test);
00222 
00223   test[4] = 1.9;
00224   AddTemplate(SpillStruct::k5p6slip,test);
00225 
00226 }

SpillStructureClassifier & SpillStructureClassifier::Instance (  )  [static]

No public ctor for singleton, all user access is through Instance().

Instance() returns the one-and-only instance; creating it if one doesn't yet exist. Also declares "cleaner" for dtor call

Definition at line 67 of file SpillStructureClassifier.cxx.

References fgTheInstance, SpillStructureClassifier(), and SpillStructureClassifier::Cleaner::UseMe().

00068 {
00071 
00072   // Cleaner dtor calls SpillStructureClassifier dtor at job end
00073   static Cleaner cleaner;
00074 
00075   if ( ! fgTheInstance ) {
00076     // need to create one
00077     cleaner.UseMe();   // dummy call to quiet compiler warnings
00078     fgTheInstance = new SpillStructureClassifier();
00079   }
00080   
00081   return *fgTheInstance;
00082 }

void SpillStructureClassifier::Normalize ( std::vector< double > &  v  )  [private]

Definition at line 175 of file SpillStructureClassifier.cxx.

References n.

Referenced by AddTemplate(), and Classify().

00176 {
00177   // pass by reference, so return value is modified
00178   size_t n = v.size();
00179   double sum = 0;
00180   for (size_t i=0; i<n; ++i) sum += v[i];
00181   if  ( sum == 0 ) sum = 1.0e-20;
00182   for (size_t i=0; i<n; ++i) v[i] /= sum;
00183 }

void SpillStructureClassifier::operator= ( const SpillStructureClassifier  )  [private]

Method private and not implement, declared to prevent assignment.


Friends And Related Function Documentation

friend struct Cleaner [friend]

Definition at line 92 of file SpillStructureClassifier.h.


Member Data Documentation

The one-and-only instance.

Define static variable which holds the one-and-only instance.

Definition at line 70 of file SpillStructureClassifier.h.

Referenced by Instance(), SpillStructureClassifier::Cleaner::~Cleaner(), and ~SpillStructureClassifier().

Definition at line 65 of file SpillStructureClassifier.h.

Referenced by AddTemplate(), and Classify().

std::vector<std::vector<double> > SpillStructureClassifier::fTemplateVectors [private]

Definition at line 66 of file SpillStructureClassifier.h.

Referenced by AddTemplate(), and Classify().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1