Ignore:
Timestamp:
Sep 14, 2016, 6:43:45 PM (8 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, Ubuntu_1604_changes, stable
Children:
ff7ac6
Parents:
760fa22
git-author:
Frederik Heber <heber@…> (09/12/16 14:52:04)
git-committer:
Frederik Heber <heber@…> (09/14/16 18:43:45)
Message:

Histogram uses copy instead of superposeOtherHistogram() when instance is empty.

  • this is preparatory for using += instead of = in initializing the (Orthogonal)Summation with the first value.
  • for the Histogram this changes all the bins and hence the respective regression tests would fail.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Summation/SetValues/Histogram.cpp

    r760fa22 rf856ec  
    206206void Histogram::superposeOtherHistogram(const Histogram &other, const double prefactor)
    207207{
    208   // go through each of the other histogram's bins
    209   if (!other.bins.empty()) {
    210     Bins_t::const_iterator enditer = --other.bins.end(); // (except internal last one)
    211     for (Bins_t::const_iterator biniter = other.bins.begin();
    212         biniter != enditer; /* we advance ourselves in loop */) {
    213       const Bin_t &bin = *biniter;
    214       ++biniter;
    215       const Bin_t &nextbin = *biniter;
    216 
    217       LOG(4, "DEBUG: Current bin is " << bin << ", next bin is " << nextbin << ".");
    218 
    219       // Check first whether start or end actually fit into our histogram, if not extend.
    220       extendMissingBins(bin.first, nextbin.first);
    221 
    222       // The bin will in general not fit into one bin in this histogram, but overlap.
    223       // Hence, we determine the contribution of the bin to each bin in this histogram
    224       // its overlaps into and add this weight to the bin.
    225       Bins_t::const_iterator loweriter = getLowerEndBin(bin.first);
    226       Bins_t::const_iterator upperiter = getHigherEndBin(nextbin.first);
    227 
    228       ASSERT( loweriter->first < upperiter->first,
    229           "Histogram::superposeOtherHistogram() - the bin range is invalid.");
    230       LOG(5, "DEBUG: bin range here is ["
    231           << loweriter->first << ","  << upperiter->first << ").");
    232 
    233       // Next, we create a vector of offsets
    234       typedef std::vector< BinLowerEnd > offsets_t;
    235       offsets_t offsets;
    236       {
    237         offsets.push_back(bin.first);
    238         Bins_t::const_iterator iter = loweriter;
    239         for (++iter; iter != upperiter; ++iter)
    240           if (offsets.back() != iter->first)
    241             offsets.push_back(iter->first);
    242         if (offsets.back() != nextbin.first)
    243           offsets.push_back(nextbin.first);
    244         LOG(4, "DEBUG: Offsets are " << offsets << ".");
     208  // check whether we just copy into an empty histogram
     209  if ((bins.empty()) && (prefactor == +1.)) {
     210    *this = other;
     211  } else {
     212    // go through each of the other histogram's bins
     213    if (!other.bins.empty()) {
     214      Bins_t::const_iterator enditer = --other.bins.end(); // (except internal last one)
     215      for (Bins_t::const_iterator biniter = other.bins.begin();
     216          biniter != enditer; /* we advance ourselves in loop */) {
     217        const Bin_t &bin = *biniter;
     218        ++biniter;
     219        const Bin_t &nextbin = *biniter;
     220
     221        LOG(4, "DEBUG: Current bin is " << bin << ", next bin is " << nextbin << ".");
     222
     223        // Check first whether start or end actually fit into our histogram, if not extend.
     224        extendMissingBins(bin.first, nextbin.first);
     225
     226        // The bin will in general not fit into one bin in this histogram, but overlap.
     227        // Hence, we determine the contribution of the bin to each bin in this histogram
     228        // its overlaps into and add this weight to the bin.
     229        Bins_t::const_iterator loweriter = getLowerEndBin(bin.first);
     230        Bins_t::const_iterator upperiter = getHigherEndBin(nextbin.first);
     231
     232        ASSERT( loweriter->first < upperiter->first,
     233            "Histogram::superposeOtherHistogram() - the bin range is invalid.");
     234        LOG(5, "DEBUG: bin range here is ["
     235            << loweriter->first << ","  << upperiter->first << ").");
     236
     237        // Next, we create a vector of offsets
     238        typedef std::vector< BinLowerEnd > offsets_t;
     239        offsets_t offsets;
     240        {
     241          offsets.push_back(bin.first);
     242          Bins_t::const_iterator iter = loweriter;
     243          for (++iter; iter != upperiter; ++iter)
     244            if (offsets.back() != iter->first)
     245              offsets.push_back(iter->first);
     246          if (offsets.back() != nextbin.first)
     247            offsets.push_back(nextbin.first);
     248          LOG(4, "DEBUG: Offsets are " << offsets << ".");
     249        }
     250
     251        // then, we go through the offsets but the last one and add the respective area
     252        {
     253          offsets_t::const_iterator iter = offsets.begin();
     254          offsets_t::const_iterator nextiter = ++offsets.begin();
     255          for (; iter != --offsets.end(); ++iter, ++nextiter) {
     256            const double length = *nextiter - *iter;
     257            const double weight = bin.second * (length/binwidth);
     258            Bins_t::iterator filliter = getLowerEndBin(*iter);
     259            filliter->second += prefactor * weight;
     260          }
     261        }
     262
     263        LOG(4, "DEBUG: Bins are after summation " << printBins() << ".");
    245264      }
    246 
    247       // then, we go through the offsets but the last one and add the respective area
    248       {
    249         offsets_t::const_iterator iter = offsets.begin();
    250         offsets_t::const_iterator nextiter = ++offsets.begin();
    251         for (; iter != --offsets.end(); ++iter, ++nextiter) {
    252           const double length = *nextiter - *iter;
    253           const double weight = bin.second * (length/binwidth);
    254           Bins_t::iterator filliter = getLowerEndBin(*iter);
    255           filliter->second += prefactor * weight;
    256         }
    257       }
    258 
    259       LOG(4, "DEBUG: Bins are after summation " << printBins() << ".");
    260265    }
    261266  }
Note: See TracChangeset for help on using the changeset viewer.