source: src/Fragmentation/Histogram/Histogram.hpp@ e5dbd5

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 Candidate_v1.7.0 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
Last change on this file since e5dbd5 was e5dbd5, checked in by Frederik Heber <heber@…>, 13 years ago

Add printBin() function to Histogram.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Histogram.hpp
3 *
4 * Created on: Jul 26, 2012
5 * Author: heber
6 */
7
8#ifndef HISTOGRAM_HPP_
9#define HISTOGRAM_HPP_
10
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <iosfwd>
18#include <map>
19#include <vector>
20
21class HistogramTest;
22
23/** This class generates a histogram from a given vector of sampled values.
24 *
25 * Most importantly, it also contains operator+=() and operator-=() to perform
26 * sum on the \b histograms.
27 *
28 * This is to be used with the OrthogonalSummation which requires these specific
29 * operator implementations.
30 *
31 */
32class Histogram
33{
34 //!> grant unit test access to private parts
35 friend class HistogramTest;
36public:
37 //!> named type for a vector of sample values
38 typedef std::vector<double> samples_t;
39 //!> named type for the start of a bin
40 typedef double BinLowerEnd;
41 //!> named type for the count of a bin, may be fractional
42 typedef double BinWeight;
43 //!> named type for the pair identifying a bin by its lower end and count
44 typedef std::pair< BinLowerEnd, BinWeight> Bin_t;
45private:
46 //!> named type for a vector of bins
47 typedef std::map< BinLowerEnd, BinWeight > Bins_t;
48public:
49 /** Constructor for class Histogram.
50 *
51 * @param samples samples to put in the histogram.
52 * @param CountBins number of bins (if negative, we choose number by statistical means)
53 */
54 Histogram(const samples_t &samples, const int _CountBins=-1);
55
56 /** Adding another histogram onto this one.
57 *
58 * @param other other histogram
59 * @return ref to this instance
60 */
61 Histogram& operator+=(const Histogram &other);
62
63 /** Subtracting another histogram from this one.
64 *
65 * @param other other histogram
66 * @return ref to this instance
67 */
68 Histogram& operator-=(const Histogram &other);
69
70 /** States whether each bin of this histogram has count of zero.
71 *
72 * @return true - all bins are zero, false - else
73 */
74 bool isEmpty() const;
75
76private:
77 /** Returns the iterator to the bin representing the lower end into which the \a value fits.
78 *
79 * @param _value value to fit.
80 * @return iterator to bin or to bins.end() if not matching
81 */
82 Bins_t::iterator getLowerEndBin(const double _value);
83
84 /** Returns the iterator to the bin representing the upper end into which the \a value fits.
85 *
86 * @param _value value to fit.
87 * @return iterator to bin or to bins.end() if not matching
88 */
89 Bins_t::iterator getHigherEndBin(const double _value);
90
91 /** Helper function to print BinLowerEnd and BinWeight to a string for every bin.
92 *
93 * @return string containing information on each consecutive bin
94 */
95 std::string printBins() const;
96
97private:
98 //!> vector of bins containing the histogram
99 Bins_t bins;
100 //!> width of bin
101 double binwidth;
102 //!> number of bins
103 int CountBins;
104};
105
106/** Function to print an arbitrary pair to ostream.
107 *
108 * @param ost output stream
109 * @param elem element to print
110 * @return ref to given ostream for concatenation
111 */
112std::ostream & operator<<(std::ostream &ost, const Histogram::Bin_t &elem);
113
114
115#endif /* HISTOGRAM_HPP_ */
Note: See TracBrowser for help on using the repository browser.