Changeset 7d507c


Ignore:
Timestamp:
Oct 14, 2013, 11:42:04 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, 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_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
e0ae58d
Parents:
adb51ab
git-author:
Frederik Heber <heber@…> (09/27/13 12:58:04)
git-committer:
Frederik Heber <heber@…> (10/14/13 23:42:04)
Message:

FIX: Histogram::superposeOtherHistogram() could not deal with empty bins.

  • also fixed verbosity lag of printing bins after summation.
File:
1 edited

Legend:

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

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