Changeset dd3a80


Ignore:
Timestamp:
Mar 3, 2010, 7:10:36 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
bc46c1
Parents:
f78203
git-author:
Frederik Heber <heber@…> (03/03/10 18:41:03)
git-committer:
Frederik Heber <heber@…> (03/03/10 19:10:36)
Message:

BUGFIX: rounding imprecision let values appear twice in BinMap.

  • we fix this by always converting bin to integer and then back to double when putting into map in BinData()
  • GetBin returns integer

Signed-off-by: Frederik Heber <heber@…>

Location:
molecuilder/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/analysis_correlation.cpp

    rf78203 rdd3a80  
    342342};
    343343
    344 /** Returns the start of the bin for a given value.
     344/** Returns the index of the bin for a given value.
    345345 * \param value value whose bin to look for
    346346 * \param BinWidth width of bin
    347347 * \param BinStart first bin
    348348 */
    349 double GetBin ( const double value, const double BinWidth, const double BinStart )
    350 {
    351   Info FunctionInfo(__func__);
    352   double bin =(double) (floor((value - BinStart)/BinWidth));
    353   return (bin*BinWidth+BinStart);
     349int GetBin ( const double value, const double BinWidth, const double BinStart )
     350{
     351  Info FunctionInfo(__func__);
     352  int bin =(int) (floor((value - BinStart)/BinWidth));
     353  return (bin);
    354354};
    355355
  • molecuilder/src/analysis_correlation.hpp

    rf78203 rdd3a80  
    5151CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] );
    5252CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
    53 double GetBin ( const double value, const double BinWidth, const double BinStart );
     53int GetBin ( const double value, const double BinWidth, const double BinStart );
    5454void OutputCorrelation( ofstream * const file, const BinPairMap * const map );
    5555void OutputPairCorrelation( ofstream * const file, const BinPairMap * const map );
     
    101101{
    102102  BinPairMap *outmap = new BinPairMap;
    103   double bin = 0.;
     103  int bin = 0;
    104104  double start = 0.;
    105105  double end = 0.;
     
    117117    start = BinStart;
    118118    end = BinEnd;
    119     for (double runner = start; runner <= end; runner += BinWidth)
    120       outmap->insert( pair<double, int> (runner, 0) );
     119    for (int runner = 0; runner <= ceil((end-start)/BinWidth); runner++)
     120      outmap->insert( pair<double, int> ((double)runner*BinWidth+start, 0) );
    121121  }
    122122
    123123  for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
    124124    bin = GetBin (runner->first, BinWidth, start);
    125     BinPairMapInserter = outmap->insert ( pair<double, int> (bin, 1) );
     125    BinPairMapInserter = outmap->insert ( pair<double, int> ((double)bin*BinWidth+start, 1) );
    126126    if (!BinPairMapInserter.second) {  // bin already present, increase
    127127      BinPairMapInserter.first->second += 1;
Note: See TracChangeset for help on using the changeset viewer.