| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/stat/TeSpatialStatistics.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00026 #ifndef  __TERRALIB_INTERNAL_SPATIALSTATISTICS_H
    00027 #define  __TERRALIB_INTERNAL_SPATIALSTATISTICS_H
    00028
    00029 #include <string>
    00030 #include <vector>
    00031 #include <map>
    00032 #include <set>
    00033 using namespace std;
    00034
    00035 #include "../kernel/TeStatistics.h"
    00036 #include "../kernel/TeProgress.h"
    00037 #include "../kernel/TeSTEvent.h"
    00038 #include "../kernel/TeNeighbours.h"
    00039
    00051 template<typename Set, typename Matrix>
    00052 bool
    00053 TeLocalMean (Set* elemSet, Matrix* proxMatrix, int indexAttr=0);
    00054
    00061 template<typename Set, typename Matrix>
    00062 bool
    00063 TeZAndWZ (Set* elemSet, Matrix* proxMatrix, int indexAttr);
    00064
    00078 template<typename Set, typename Matrix>
    00079 double
    00080 TeMoranIndex2 (Set* elemSet, const double& mean, const double& var, Matrix* proxMatrix, int indexAttr=0);
    00081
    00088 template<typename Set>
    00089 double
    00090 TeMoranIndex (Set* elemSet, int indexZ, int indexWZ);
    00091
    00092
    00101 template<typename Set, typename Matrix>
    00102 double
    00103 TeGlobalMoranSignificance (Set* elemSet, Matrix* proxMatrix, int indexAttr,
    00104                                                                      unsigned int permutationsNumber, double moranIndex);
    00105
    00106
    00113 template<typename Set>
    00114 void
    00115 TeMoranMap (Set* elemSet, int indexLISAMap, int indexBoxMap);
    00116
    00125 template<typename Set, typename Matrix> bool
    00126 TeGStatistics (Set* elemSet, Matrix* proxMatrix, int indexAttr=0 );
    00127
    00128
    00136 template<typename Set> void
    00137 TeBoxMap (Set* elemSet, int indexZ, int indexWZ, double mean);
    00138
    00147 template<typename Set> bool
    00148 TeLisaStatisticalSignificance ( Set* elemSet, int indexZ, int indexLISA, int indexNeighNum, int permutationsNumber);
    00149
    00150
    00157 template<typename Set> void
    00158 TeLisaMap (Set* elemSet, int indexSignifLISA, int /* permutationNumber */);
    00159
    00165 template <typename It> void
    00166 TeEmpiricalBayes (It rBegin, It rEnd, It n, double mean, double variance, It bayes)
    00167 {
    00168            double w= 0.;
    00169            while (rBegin != rEnd)
    00170            {
    00171                       w = variance / ( variance + ( mean/(*n)) );
    00172                       *bayes = w*(*rBegin) + (1-w)*mean;
    00173                       rBegin++; n++; bayes++;
    00174            }
    00175 }
    00176
    00177 //* Calculates the Local Bayes estimation from a container of values */
    00178 template <typename It> void
    00179 TeSpatialEmpiricalBayes (It rBegin, It rEnd, It n, It mean, It variance, It bayes)
    00180 {
    00181            double w = 0.;
    00182            while (rBegin != rEnd)
    00183            {
    00184                       w = (*variance)/( (*variance) + ( (*mean)/n ));
    00185                       *bayes = w*(*rBegin) + (1-w)*(*mean);
    00186                       rBegin++; n++; mean++; variance++; bayes++;
    00187            }
    00188 }
    00189
    00193 // --- Template function implementation ---
    00194 template<typename Set, typename Matrix>  bool
    00195 TeLocalMean (Set* elemSet, Matrix* proxMatrix, int indexAttr)
    00196 {
    00197            typename Set::iterator itObjs = elemSet->begin();
    00198            int numberNeighbors;
    00199
    00200            if(!proxMatrix->getWeightsParams())
    00201                       return false;
    00202            bool isNorm = proxMatrix->getWeightsParams()->norm_;
    00203
    00204            //adds the attributes in the set
    00205            TeAttribute att;
    00206            att.rep_.type_ = TeREAL;
    00207            att.rep_.decimals_ = 15;
    00208            att.rep_.name_ = "LocalMean";
    00209
    00210            elemSet->addProperty(att);
    00211
    00212            att.rep_.name_  = "NumNeighbors";
    00213            att.rep_.type_ = TeINT;
    00214            elemSet->addProperty(att);
    00215
    00216            while (itObjs != elemSet->end())
    00217            {
    00218                       double sum = 0.;
    00219                       double localMean = 0.;
    00220
    00221                       TeNeighboursMap neighbors = proxMatrix->getMapNeighbours((*itObjs).objectId());
    00222                       typename TeNeighboursMap::iterator itNeigs = neighbors.begin();
    00223                       numberNeighbors = neighbors.size();
    00224
    00225                       while(itNeigs != neighbors.end())
    00226                       {
    00227                                  //retrieve the neighbor attribute value
    00228                                  string valAux;
    00229                                  string objIdAux = (*itNeigs).first;
    00230                                  if(!elemSet->getAttributeValue(objIdAux, indexAttr, valAux))
    00231                                             return false;
    00232                                  double val = atof(valAux.c_str());
    00233
    00234                                  // find the weight associated with the neighbor (attribute of index 0)
    00235                                  double weight = (*itNeigs).second.Weight();
    00236                                  //verify if the weight is normalized by number of neighbours
    00237                                  if(!isNorm)
    00238                                             weight = weight/numberNeighbors;
    00239                                  sum +=  weight * val;
    00240                                  ++itNeigs;
    00241                       }
    00242
    00243                       localMean = sum;
    00244
    00245                       (*itObjs).addPropertyValue(Te2String(localMean,9));
    00246                       (*itObjs).addPropertyValue(Te2String(numberNeighbors));
    00247
    00248                       ++itObjs;
    00249            }
    00250
    00251            return true;
    00252 }
    00253
    00254 template<typename Set, typename Matrix>
    00255 bool
    00256 TeZAndWZ (Set* elemSet, Matrix* proxMatrix, int indexAttr)
    00257 {
    00258            // calculate the standard deviation Z
    00259            double mean = TeFirstMoment (elemSet->begin(), elemSet->end(), 0);
    00260
    00261            TeAttribute att;
    00262            att.rep_.type_ = TeREAL;
    00263            att.rep_.decimals_ = 15;
    00264            att.rep_.name_ = "Z";
    00265            elemSet->addProperty(att);
    00266
    00267            typename Set::iterator it = elemSet->begin();
    00268            while (it != elemSet->end())
    00269            {
    00270                       double val = (*it)[indexAttr];
    00271                       (*it).addPropertyValue(Te2String((val-mean), 9));
    00272                       ++it;
    00273            }
    00274
    00275            int indexZ = elemSet->getAttributeList().size()-1;
    00276
    00277            // calculate the local mean of Z (WZ)
    00278            att.rep_.name_ = "WZ";
    00279            att.rep_.type_ = TeREAL;
    00280            elemSet->addProperty(att);
    00281
    00282            typename Set::iterator itObjs = elemSet->begin();
    00283            int numberNeighbors;
    00284
    00285            if(!proxMatrix->getWeightsParams())
    00286                       return false;
    00287            bool isNorm = proxMatrix->getWeightsParams()->norm_;
    00288
    00289            while (itObjs != elemSet->end())
    00290            {
    00291                       double sum = 0.;
    00292                       TeNeighboursMap neighbors = proxMatrix->getMapNeighbours((*itObjs).objectId());
    00293                       typename TeNeighboursMap::iterator itNeigs = neighbors.begin();
    00294                       numberNeighbors = neighbors.size();
    00295
    00296                       while(itNeigs != neighbors.end())
    00297                       {
    00298                                  //retrieve the neighbor attribute value
    00299                                  string valAux;
    00300                                  string objIdAux = (*itNeigs).first;
    00301                                  if(!elemSet->getAttributeValue(objIdAux, indexZ, valAux))
    00302                                             return false;
    00303                                  double val = atof(valAux.c_str());
    00304
    00305                                  // find the weight associated with the neighbor (attribute of index 0)
    00306                                  double weight = (*itNeigs).second.Weight();
    00307                                  //verify if the weight is normalized by number of neighbours
    00308                                  if(!isNorm)
    00309                                             weight = weight/numberNeighbors;
    00310                                  sum +=  weight * val;
    00311                                  ++itNeigs;
    00312                       }
    00313                       (*itObjs).addPropertyValue(Te2String(sum,9));
    00314                       ++itObjs;
    00315            }
    00316            return true;
    00317 }
    00318
    00319 template<typename Set, typename Matrix> double
    00320 TeMoranIndex2 (Set* elemSet, const double& mean, const double& var, Matrix* proxMatrix, int indexAttr)
    00321 {
    00322            double moran = 0;
    00323            typename Set::iterator itObjs = elemSet->begin();
    00324            int numberObjs = elemSet->numSTInstance();
    00325            if(!proxMatrix->getWeightsParams())
    00326                       return false;
    00327            bool isNorm = proxMatrix->getWeightsParams()->norm_;
    00328
    00329            while ( itObjs != elemSet->end())
    00330            {
    00331                       double normObjVal = (*itObjs)[indexAttr] - mean;
    00332                       double li = 0.;
    00333                       double weightSum = 0.;
    00334
    00335
    00336                       TeNeighboursMap neighbors = proxMatrix->getMapNeighbours((*itObjs).objectId());
    00337                       typename TeNeighboursMap::iterator itNeigs = neighbors.begin();
    00338                       int numberNeighbors = neighbors.size();
    00339
    00340                       while(itNeigs != neighbors.end())
    00341                       {
    00342                                  //retrieve the neighbor attribute value
    00343                                  string valAux;
    00344                                  string objIdAux = (*itNeigs).first;
    00345                                  if(!elemSet->getAttributeValue (objIdAux, indexAttr, valAux))
    00346                                             return 0.;
    00347                                  double val = atof(valAux.c_str());
    00348
    00349                                   // normalize the property
    00350                                  double normNeighVal =  val - mean;
    00351
    00352                                  // find the weight associated with the neighbor (attribute of index 0)
    00353                                  double weight = (*itNeigs).second.Weight();
    00354                                  //verify if the weight is normalized by number of neighbours
    00355                                  if(!isNorm)
    00356                                             weight = weight/numberNeighbors;
    00357                                  li +=  weight * ( normNeighVal )  * ( normObjVal );  // se dividir pela vari�ncia � o �ndice local de moran
    00358                                  weightSum += weight;
    00359                                  ++itNeigs;
    00360                       }
    00361
    00362                       if (weightSum != 0.)
    00363                                  li /= weightSum;
    00364
    00365                       moran += li;
    00366
    00367                       ++itObjs;
    00368            }
    00369
    00370            if ( numberObjs > 1 )
    00371                       return moran /  ( var * ( numberObjs - 1 ) );
    00372            else
    00373                       return moran / var;
    00374 }
    00375
    00376 template<typename Set> double
    00377 TeMoranIndex (Set* elemSet, int indexZ, int indexWZ)
    00378 {
    00379            double variance = 0.;
    00380            double sum = 0;
    00381            int number = 0;
    00382
    00383            variance = TeSecondMoment (elemSet->begin(), elemSet->end(), 0, indexZ);
    00384            typename Set::iterator it = elemSet->begin();
    00385
    00386            //keep
    00387            TeAttribute att;
    00388            att.rep_.type_ = TeREAL;
    00389            att.rep_.decimals_ = 15;
    00390            att.rep_.name_ = "MoranIndex";
    00391            elemSet->addProperty(att);
    00392
    00393            while (it != elemSet->end())
    00394            {
    00395                       double z = (*it)[indexZ];
    00396                       double wz = (*it)[indexWZ];
    00397                       double ZxWZ;
    00398                       if(variance==0)
    00399                                  ZxWZ = 0.;
    00400                       else
    00401                                  ZxWZ = (z*wz)/variance;
    00402
    00403                       //keep
    00404                       (*it).addPropertyValue(Te2String(ZxWZ, 9));
    00405
    00406                       sum += ZxWZ;
    00407                       number++;
    00408                       ++it;
    00409            }
    00410
    00411            return sum /= number;
    00412 }
    00413
    00414 template<typename Set, typename Matrix> double
    00415 TeGlobalMoranSignificance (Set* elemSet, Matrix* proxMatrix, int indexAttr,
    00416                                                                      unsigned int permutationsNumber, double moranIndex)
    00417 {
    00418
    00419            vector<double> permutationsResults(permutationsNumber);
    00420            double significance;
    00421
    00422            unsigned int objectsNumber = elemSet->numSTInstance();
    00423
    00424            //progress bar
    00425            if(TeProgress::instance())
    00426                       TeProgress::instance()->setTotalSteps(permutationsNumber);
    00427
    00428            vector<double> deviations(objectsNumber);
    00429            vector<double>::iterator itDev = deviations.begin();
    00430            typename Set::iterator itObjs = elemSet->begin();
    00431            while(itObjs != elemSet->end())
    00432            {
    00433                       (*itDev) = (*itObjs)[indexAttr]; //attribute value
    00434                       ++itObjs;
    00435                       ++itDev;
    00436            }
    00437
    00438            TeStatisticValMap stat;
    00439            if(!TeCalculateStatistics(elemSet->begin(), elemSet->end(), stat, 0))
    00440                       return 0.;
    00441
    00442            double mean = stat[TeMEAN];
    00443            double var = stat[TeVARIANCE];
    00444
    00445            srand(time(0));
    00446            unsigned int i;
    00447            for (i = 0; i < permutationsNumber; i++)
    00448            {
    00449                       Set changedObjects;
    00450                       if(elemSet->getTheme())
    00451                                  changedObjects.setTheme(elemSet->getTheme());
    00452                       else if(elemSet->getLayer())
    00453                                  changedObjects.setLayer(elemSet->getLayer());
    00454
    00455                       changedObjects.setAttributeList(elemSet->getAttributeList());
    00456
    00457                       itObjs = elemSet->begin();
    00458
    00459                       // chande values
    00460                       while(itObjs != elemSet->end())
    00461                       {
    00462                                  TeSTEvent stoChange;
    00463                                  stoChange.objectId((*itObjs).objectId());
    00464
    00465                                  double ranaux = rand();
    00466                                  int randon = (int) ((ranaux * (objectsNumber-1))/RAND_MAX);
    00467                                  double value = deviations[randon];
    00468                                  stoChange.addPropertyValue(Te2String(value,9));
    00469                                  changedObjects.insertSTInstance (stoChange);
    00470                                  ++itObjs;
    00471                       }
    00472
    00473                       permutationsResults[i] = TeMoranIndex2 (&changedObjects, mean, var, proxMatrix, 0);
    00474
    00475                       if(TeProgress::instance())
    00476                       {
    00477                                  if (TeProgress::instance()->wasCancelled())
    00478                                  {
    00479                                             TeProgress::instance()->reset();
    00480                                             return 0.;
    00481                                  }
    00482                                  else
    00483                                             TeProgress::instance()->setProgress(i);
    00484                       }
    00485            }
    00486
    00487            // verify the significance
    00488            int position = 0;
    00489            significance = 0;
    00490            unsigned int k;
    00491            for (k = 0; k < permutationsNumber; k++)
    00492            {
    00493                       if (moranIndex < permutationsResults[k]) //>
    00494                                  position++;
    00495            }
    00496            if ( moranIndex >= 0)
    00497                       significance = (double) (position+1) / (permutationsNumber+1);
    00498            else
    00499                       significance = (double) (permutationsNumber-position)/(permutationsNumber+1);
    00500
    00501
    00502            if (TeProgress::instance())
    00503                       TeProgress::instance()->reset();
    00504
    00505            return significance;
    00506 }
    00507
    00508
    00509 template<typename Set>  void
    00510 TeMoranMap (Set* elemSet, int indexLISAMap, int indexBoxMap)
    00511 {
    00512            //keep
    00513            TeAttribute att;
    00514            att.rep_.decimals_ = 15;
    00515            att.rep_.type_ = TeREAL;
    00516            att.rep_.name_ = "MoranMap";
    00517            elemSet->addProperty(att);
    00518
    00519            typename Set::iterator it = elemSet->begin();
    00520            while ( it != elemSet->end())
    00521            {
    00522                       double result = 0.0;
    00523                       int lisaMap = (int)((*it)[indexLISAMap]);
    00524
    00525                       if (lisaMap != 0)
    00526                                  result = (*it)[indexBoxMap];
    00527
    00528                       //keep
    00529                       (*it).addPropertyValue(Te2String(result, 9));
    00530
    00531                       ++it;
    00532            }
    00533 }
    00534
    00535 template<typename Set, typename Matrix>  bool
    00536 TeGStatistics (Set* elemSet, Matrix* proxMatrix, int indexAttr)
    00537 {
    00538
    00539            typename Set::iterator itObjs = elemSet->begin();
    00540            double totalSum = 0.;
    00541            double excludSum = 0.;
    00542
    00543            totalSum = TeSum(itObjs, elemSet->end(), indexAttr);
    00544
    00545            itObjs = elemSet->begin();
    00546
    00547            //progress bar
    00548            int step = 0;
    00549            int numSteps = elemSet->numSTInstance();
    00550            if(TeProgress::instance())
    00551                       TeProgress::instance()->setTotalSteps(numSteps);
    00552
    00553            //adds the index attributes in the sET
    00554            TeAttribute att;
    00555            att.rep_.name_ = "G";
    00556            att.rep_.type_ = TeREAL;
    00557            att.rep_.decimals_ = 15;
    00558            elemSet->addProperty(att);
    00559
    00560            att.rep_.name_ = "GStar";
    00561            elemSet->addProperty(att);
    00562
    00563            while ( itObjs != elemSet->end() )
    00564            {
    00565                       double valObj = (*itObjs)[indexAttr];
    00566                       excludSum = totalSum - valObj;
    00567
    00568                       double G = 0;
    00569                       double GStar = valObj;
    00570
    00571                       TeNeighboursMap neighbors = proxMatrix->getMapNeighbours((*itObjs).objectId());
    00572                       typename TeNeighboursMap::iterator itNeigs = neighbors.begin();
    00573                       int neigNumber = neighbors.size();
    00574
    00575                       if(itNeigs != neighbors.end())
    00576                       {
    00577                                  while(itNeigs != neighbors.end())
    00578                                  {
    00579                                             // retrieve the property value associated to this neighbor
    00580                                             double val;
    00581                                             string valAux;
    00582                                             string objIdAux = (*itNeigs).first;
    00583                                             if(!elemSet->getAttributeValue (objIdAux, indexAttr, valAux))
    00584                                                        return false;
    00585                                             val = atof(valAux.c_str());
    00586                                             G +=  val;
    00587                                             GStar +=  val;
    00588
    00589                                             ++itNeigs;
    00590                                  }
    00591
    00592                                  G /= neigNumber;
    00593                                  GStar /= (neigNumber+1);
    00594
    00595                                  G /= excludSum;
    00596                                  GStar /= totalSum;
    00597                       }
    00598
    00599                       //insert the index G in the set
    00600                       (*itObjs).addPropertyValue(Te2String(G, 9));
    00601                       //insert the index GStar in the set
    00602                       (*itObjs).addPropertyValue(Te2String(GStar,9));
    00603
    00604                       ++itObjs;
    00605
    00606                       if(TeProgress::instance())
    00607                       {
    00608                                  if (TeProgress::instance()->wasCancelled())
    00609                                  {
    00610                                             TeProgress::instance()->reset();
    00611                                             return false;
    00612                                  }
    00613                                  else
    00614                                             TeProgress::instance()->setProgress(step);
    00615                       }
    00616                       ++step;
    00617            }
    00618
    00619
    00620            if (TeProgress::instance())
    00621                       TeProgress::instance()->reset();
    00622            return true;
    00623 }
    00624
    00625 template<typename Set>  void
    00626 TeBoxMap (Set* elemSet, int indexZ, int indexWZ, double mean)
    00627 {
    00628            //keep in the set
    00629            TeAttribute att;
    00630            att.rep_.name_ = "BoxMap";
    00631            att.rep_.type_ = TeINT;
    00632            elemSet->addProperty(att);
    00633
    00634            typename Set::iterator it_begin = elemSet->begin();
    00635            while ( it_begin != elemSet->end())
    00636            {
    00637                       int result=0;
    00638
    00639                       if ( ((*it_begin)[indexZ] >= mean) &&  ((*it_begin)[indexWZ] >= mean))
    00640                                  result = 1;
    00641                       else if ( ((*it_begin)[indexZ] < mean)  &&  ((*it_begin)[indexWZ] >= mean))
    00642                                  result = 4;
    00643                       else if ( ((*it_begin)[indexZ] < mean)  &&  ((*it_begin)[indexWZ] < mean))
    00644                                  result = 2;
    00645                       else if ( ((*it_begin)[indexZ] >= mean) &&  ((*it_begin)[indexWZ] < mean))
    00646                                  result = 3;
    00647
    00648                       (*it_begin).addPropertyValue(Te2String(result));
    00649
    00650                       ++it_begin;
    00651            }
    00652 }
    00653
    00654 template<typename Set>  bool
    00655 TeLisaStatisticalSignificance (Set* elemSet, int indexZ, int indexLISA,
    00656                                                                                                     int indexNeighNum, int permutationsNumber)
    00657  {
    00658            double sum;
    00659            double WZperm;
    00660            double significance;
    00661
    00662            typename Set::iterator it = elemSet->begin();
    00663
    00664            double variance = TeSecondMoment (it, elemSet->end(), 0, indexZ);
    00665
    00666            int index = 0;
    00667            it = elemSet->begin();
    00668            int objectsNumber = elemSet->numSTInstance();
    00669
    00670            //progress bar
    00671            int step = 0;
    00672            if(TeProgress::instance())
    00673                       TeProgress::instance()->setTotalSteps(objectsNumber);
    00674
    00675            vector<double> deviations(objectsNumber);
    00676            vector<double>::iterator it_dev = deviations.begin();
    00677            while(it != elemSet->end())
    00678            {
    00679                       (*it_dev) = (*it)[indexZ];
    00680                       ++it;
    00681                       ++it_dev;
    00682            }
    00683
    00684            it = elemSet->begin();
    00685            srand(time(0));
    00686
    00687            //keep
    00688            TeAttribute att;
    00689            att.rep_.name_ = "LISASig";
    00690            att.rep_.type_ = TeREAL;
    00691            att.rep_.decimals_ = 15;
    00692            elemSet->addProperty(att);
    00693
    00694            while ( it != elemSet->end())
    00695            {
    00696                       int neighborsNumber = (int)((*it)[indexNeighNum]);
    00697
    00698                       vector<double> permut(permutationsNumber);
    00699
    00700                       for (int j = 0; j < permutationsNumber; j++)
    00701                       {
    00702                                  int randon = 0;
    00703                                  sum = 0;
    00704                                  set<int> setNeigh;
    00705                                  for (int k = 0; k < neighborsNumber; k++)
    00706                                  {
    00707                                             double ranaux = rand();
    00708                                             randon = (int)((ranaux * (objectsNumber-1))/RAND_MAX);
    00709                                             if (index == randon || (setNeigh.find(randon) != setNeigh.end()) )
    00710                                                        k--;       // raffle annulled
    00711                                             else
    00712                                             {
    00713                                                        setNeigh.insert(randon);
    00714                                                        sum += deviations[randon];
    00715                                             }
    00716                                  }
    00717
    00718                                  if(neighborsNumber==0)
    00719                                             WZperm = 0.;
    00720                                  else
    00721                                             WZperm = sum/neighborsNumber;
    00722
    00723                                  if(variance==0)
    00724                                             permut[j] = 0.;
    00725                                  else
    00726                                             permut[j] = deviations[index] * WZperm / variance;
    00727                       }
    00728
    00729                       int position = 0;
    00730                       for (int k = 0; k < permutationsNumber; k++)
    00731                       {
    00732                                  if (((*it)[indexLISA]) > permut[k])
    00733                                             position++;
    00734                       }
    00735                       if ( ((*it)[indexLISA]) >= 0)
    00736                                  significance = (double) (permutationsNumber-position)/(permutationsNumber+1);
    00737                       else
    00738                                  significance = (double) position/( permutationsNumber + 1 );
    00739
    00740                       (*it).addPropertyValue(Te2String(significance, 9));
    00741
    00742                       ++it;
    00743                       ++index;
    00744
    00745                       if(TeProgress::instance())
    00746                       {
    00747                                  if (TeProgress::instance()->wasCancelled())
    00748                                  {
    00749                                             TeProgress::instance()->reset();
    00750                                             return false;
    00751                                  }
    00752                                  else
    00753                                             TeProgress::instance()->setProgress(step);
    00754                       }
    00755                       ++step;
    00756            }
    00757
    00758            if (TeProgress::instance())
    00759                       TeProgress::instance()->reset();
    00760
    00761            return true;
    00762 }
    00763
    00764
    00765 template<typename Set> void
    00766 TeLisaMap (Set* elemSet, int indexSignifLISA, int /* permutationNumber */)
    00767 {
    00768            //keep
    00769            TeAttribute att;
    00770            att.rep_.name_ = "LISAMap";
    00771            att.rep_.type_ = TeINT;
    00772            elemSet->addProperty(att);
    00773
    00774            typename Set::iterator begin = elemSet->begin();
    00775            while (begin != elemSet->end())
    00776            {
    00777                       int significanceClass = 0;
    00778                       if ( ( (*begin)[indexSignifLISA] <= 0.001 ))  /*&& (permutationNumber >= 999)*/
    00779                                  significanceClass = 3;
    00780                       else if ( ((*begin)[indexSignifLISA] <= 0.01) && ((*begin)[indexSignifLISA] > 0.001 )) /*&& (permutationNumber >= 99)*/
    00781                                  significanceClass = 2;
    00782                       else if ( ((*begin)[indexSignifLISA] <= 0.05) && ((*begin)[indexSignifLISA] > 0.01))
    00783                                  significanceClass = 1;
    00784
    00785                       //keep
    00786                       (*begin).addPropertyValue(Te2String(significanceClass));
    00787
    00788                       ++begin;
    00789            }
    00790 }
    00791
    00795 #endif
    00796

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines