Ignore:
Timestamp:
Nov 8, 2012, 1:13:53 PM (13 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:
9fd889
Parents:
cf18c5
git-author:
Frederik Heber <heber@…> (07/27/12 15:49:06)
git-committer:
Frederik Heber <heber@…> (11/08/12 13:13:53)
Message:

Changed Histogram's cstor to take offset and binwidth instead of CountBins.

  • CountBins was nonsense anyway, could have been taken from samples.size() as well.
  • with these two values, we may also add the samples lateron.
File:
1 edited

Legend:

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

    rcf18c5 r6bed1f  
    9898}
    9999
    100 Histogram::Histogram(const samples_t &samples, const int _CountBins) :
    101     binwidth(0.5),
    102     CountBins(_CountBins)
     100Histogram::Histogram(const samples_t &samples, const BinLowerEnd _offset, const double _binwidth) :
     101    binwidth(_binwidth),
     102    offset(_offset)
    103103{
    104104  // build histogram from samples
    105105  if (!samples.empty()) {
    106     if (CountBins == -1) {
    107       CountBins = ceil(pow(samples.size(), 1./3.));
    108     }
    109     // 2. get min and max and determine width
     106    // 1. get min and max and determine width
    110107    samples_t::const_iterator maxiter = max_element(samples.begin(), samples.end());
    111108    samples_t::const_iterator miniter = min_element(samples.begin(), samples.end());
     
    113110        "Histogram::Histogram() - cannot find min/max despite non-empty range.");
    114111//    LOG(1, "DEBUG: min is " << *miniter << " and max is " << *maxiter << ".");
    115     // as the logic to calculate is a bit more complex, we cannot (sensibly) place
    116     // it in the cstor call in the init list above. However, the binwidth is from
    117     // this point on fixed through the existence of this instance. Hence, we rather
    118     // keep it constant nonetheless and ust const_cast here.
    119     const_cast<double &>(binwidth) = (*maxiter - *miniter)/(CountBins-1);
    120 
    121     // 3. create each bin
    122     BinCreator_t BinCreator( *miniter, binwidth );
    123     std::vector<Bin_t> vectorbins;
    124     // we need one extra bin for get...Bin()'s find to work properly
    125     vectorbins.resize(CountBins+1, Bin_t( make_pair(0., 0.) ) );
    126     std::generate( vectorbins.begin(), vectorbins.end(), BinCreator );
    127     bins.insert(vectorbins.begin(), vectorbins.end());
    128 
    129     // 4. place each sample into bin (make count normalized, i.e. always equal to
    130     // surface area of 1)
     112
     113    // 2. create each bin
     114    {
     115      std::vector<Bin_t> vectorbins;
     116      BinCreator_t BinCreator( getLowerEnd(*miniter), binwidth );
     117      // we need one extra bin for get...Bin()'s find to work properly
     118      const int CountBins = ceil((*maxiter - getLowerEnd(*miniter))/binwidth)+1;
     119      vectorbins.resize(CountBins+1, Bin_t( make_pair(0., 0.) ) );
     120      std::generate( vectorbins.begin(), vectorbins.end(), BinCreator );
     121      bins.insert(vectorbins.begin(), vectorbins.end());
     122    }
     123
     124    // 3. place each sample into bin
    131125    BOOST_FOREACH( double value, samples) {
    132126      const Bins_t::iterator biniter = getLowerEndBin(value);
    133127      ASSERT( biniter != bins.end(),
    134128          "Histogram::Histogram() - cannot find bin for value from given samples.");
     129      // (make bin count normalized, i.e. always equal to surface area of 1)
    135130      biniter->second += 1./binwidth;
    136131    }
     
    293288Histogram::BinLowerEnd Histogram::getLowerEnd(const double _value) const
    294289{
    295   // we need just one bin, to have an offset
    296   const double offset = bins.begin()->first;
    297290  BinLowerEnd start = _value - offset;
    298291  // then divide by binwidth
Note: See TracChangeset for help on using the changeset viewer.