• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Robust.cpp

Go to the documentation of this file.
00001 #include "Robust.h"
00002 
00003 //------------------------------------------------------------------------------
00004 // Class Robust
00005 //-------------------------------------------------
00006 // Public Members
00007 
00008 Robust::Robust(unsigned sampleSetSize_)
00009 { 
00010   sampleSetSize = sampleSetSize_; 
00011   numF          = 0;
00012   sampleSet = NULL;
00013 } 
00014 
00015 //------------------------------------------------------------------------------
00016 // Class Robust
00017 //-------------------------------------------------
00018 // Protected Members
00019 
00020 void Robust::allocateSampleSet(int numNoise)
00021 {
00022 #ifdef DEBUG
00023   cout << "Robust::allocateSampleSet()" << endl;
00024 #endif
00025 
00026   sampleSet = new double* [sampleSetSize];
00027 
00028   for (unsigned i = 0; i < sampleSetSize; i++)
00029     sampleSet[i] = new double[numNoise];
00030 }
00031 
00032 void Robust::deallocateSampleSet() 
00033 {
00034 #ifdef DEBUG
00035   cout << "Robust::deallocateSampleSet()" << endl;
00036 #endif
00037  
00038   if (sampleSet == NULL)
00039     return;
00040 
00041   for (unsigned i = 0; i < sampleSetSize; i++)
00042     delete [] sampleSet[i];    
00043 
00044   delete [] sampleSet;
00045   sampleSet = NULL;
00046 }
00047 
00048 /* Generates sampleSetSize Monte Carlo samples, which are noise vectors consisting of:
00049  *  numNoiseNorm normal noise elements,
00050  *  followed by numNoiseUnif uniform noise elements
00051  */
00052 void Robust::generateSampleSet_MC(int numNoise, int* numNoiseNorm, int* numNoiseUnif) 
00053 {
00054 #ifdef DEBUG 
00055   cout << "Robust::generateSampleSet_MC()" << endl;
00056 #endif
00057   
00058   if (sampleSet == NULL)
00059     allocateSampleSet(numNoise);
00060 
00061   unsigned pos;
00062   for (unsigned i = 0; i < sampleSetSize; i++)
00063   { 
00064     pos = 0;
00065 
00066     if (numNoiseNorm != NULL)
00067     {
00068       for (int j = 0; j < *numNoiseNorm; j++)
00069         sampleSet[i][pos++] = normReal();  
00070     }       
00071 
00072     if (numNoiseUnif != NULL)
00073     {
00074       for (int j = 0; j < *numNoiseUnif; j++)
00075         sampleSet[i][pos++] = uniReal();  
00076     }
00077   }
00078 }
00079 
00080 /* Generates sampleSetSize Latin Hypercube samples, which are noise vectors consisting of:
00081  *  numNoiseNorm normal noise elements,
00082  *  followed by numNoiseUnif uniform noise elements
00083  */
00084 void Robust::generateSampleSet_LH(int numNoise, int* numNoiseNorm, int* numNoiseUnif) 
00085 {
00086 #ifdef DEBUG
00087   cout << "Robust::generateSampleSet_LH()" << endl;
00088 #endif
00089 
00090   if (sampleSet == NULL)
00091     allocateSampleSet(numNoise);
00092 
00093   vector<int> intervalId(sampleSetSize, 0); 
00094   vector<double> P(sampleSetSize, 0);
00095   for (int j = 0; j < numNoise; j++)
00096   {
00097     /* Generate random permutation of interval ids, each sample is assigned a unique interval */          
00098     randPerm(intervalId, sampleSetSize);
00099   
00100     for (unsigned i = 0; i < sampleSetSize; i++)
00101     {
00102       /* Probability P determines position within interval */       
00103       P[i] = (intervalId[i] - uniReal())/ sampleSetSize;
00104 
00105       /* Inverse distribution function in case of uniform noise U(0,1): quantile(dist, p) == p */
00106       sampleSet[i][j] = P[i];
00107 
00108       /* Apply inverse distribution function in case of normal noise */
00109       if (numNoiseNorm != NULL)
00110       {
00111         if (j < *numNoiseNorm)
00112         {
00113           sampleSet[i][j] = boost::math::quantile(normDistMath, P[i]); // Inverse for normal cdf, i.e., quantile(dist, p) = x <=> cdf(dist, x) == p. 
00114         }
00115       }
00116     }
00117   }
00118 }
00119 
00120 

Generated on Tue Oct 4 2011 16:25:19 for WDN by  doxygen 1.7.2