Changeset 45f4f96


Ignore:
Timestamp:
Nov 8, 2012, 1:13:52 PM (12 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:
22c4f57
Parents:
bb68c0
git-author:
Frederik Heber <heber@…> (07/27/12 12:35:40)
git-committer:
Frederik Heber <heber@…> (11/08/12 13:13:52)
Message:

FIX: Bins are initialized as normalized from samples.

  • Bins are now initialized as normalized from samples.
  • the addition to the histogram by one sample always equals a surface area of one, i.e. we add 1 / binwidth.
  • only then may we sensibly add and subtract different histograms with different binwidths.
  • also added Histogram::area() function and unit test.
Location:
src/Fragmentation/Histogram
Files:
4 edited

Legend:

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

    rbb68c0 r45f4f96  
    119119    bins.insert(vectorbins.begin(), vectorbins.end());
    120120
    121     // 4. place each sample into bin
     121    // 4. place each sample into bin (make count normalized, i.e. always equal to
     122    // surface area of 1)
    122123    BOOST_FOREACH( double value, samples) {
    123124      const Bins_t::iterator biniter = getLowerEndBin(value);
    124125      ASSERT( biniter != bins.end(),
    125126          "Histogram::Histogram() - cannot find bin for value from given samples.");
    126       biniter->second += 1.;
     127      biniter->second += 1./binwidth;
    127128    }
    128129    LOG(2, "DEBUG: Bins are " << printBins() << ".");
     
    189190  return iter;
    190191}
     192
     193double Histogram::area() const
     194{
     195  double area = 0.;
     196  for(Bins_t::const_iterator iter = bins.begin(); iter != bins.end(); ++iter)
     197    area += iter->second*binwidth;
     198  return area;
     199}
  • src/Fragmentation/Histogram/Histogram.hpp

    rbb68c0 r45f4f96  
    5656  /** Adding another histogram onto this one.
    5757   *
     58   * \note The operation is area-conserving, i.e. the new area is the sum of
     59   * both areas.
     60   *
    5861   * @param other other histogram
    5962   * @return ref to this instance
     
    6265
    6366  /** Subtracting another histogram from this one.
     67   *
     68   * \note The operation is area-conserving, i.e. the new area is the
     69   * difference of both areas.
    6470   *
    6571   * @param other other histogram
     
    7379   */
    7480  bool isEmpty() const;
     81
     82  /** Sums all found weights times the Histogram::binwidth.
     83   *
     84   * @return sum over all weights times width.
     85   */
     86  double area() const;
    7587
    7688private:
  • src/Fragmentation/Histogram/unittests/HistogramUnitTest.cpp

    rbb68c0 r45f4f96  
    173173}
    174174
     175/** UnitTest for area()
     176 */
     177void HistogramTest::areaTest()
     178{
     179  histogram = new Histogram(std::vector<double>());
     180  // test on empty histogramgram
     181  CPPUNIT_ASSERT_EQUAL( 0., histogram->area() );
     182
     183  // create non-empty histogram and sum up
     184  Histogram::samples_t sampled_values;
     185  sampled_values += 1.,2.,3.,4., 4.;
     186  delete histogram;
     187  histogram = new Histogram(sampled_values, 4);
     188  CPPUNIT_ASSERT_EQUAL( 5., histogram->area() );
     189  Histogram::samples_t more_values;
     190  more_values += 1.75,2.5,3.;
     191  Histogram otherhistogram(more_values, 3);
     192  CPPUNIT_ASSERT_EQUAL( 3., otherhistogram.area() );
     193
     194}
     195
    175196/** UnitTest for operator+=(), operator-=()
    176197 */
  • src/Fragmentation/Histogram/unittests/HistogramUnitTest.hpp

    rbb68c0 r45f4f96  
    2929    CPPUNIT_TEST ( isEmpty_Test );
    3030    CPPUNIT_TEST ( operator_Test );
     31    CPPUNIT_TEST ( areaTest );
    3132    CPPUNIT_TEST_SUITE_END();
    3233
     
    3940      void isEmpty_Test();
    4041      void operator_Test();
     42      void areaTest();
    4143
    4244private:
Note: See TracChangeset for help on using the changeset viewer.