Changeset 6bed1f
- Timestamp:
- Nov 8, 2012, 1:13:53 PM (12 years ago)
- 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)
- Location:
- src/Fragmentation/Histogram
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Histogram/Histogram.cpp
rcf18c5 r6bed1f 98 98 } 99 99 100 Histogram::Histogram(const samples_t &samples, const int _CountBins) :101 binwidth( 0.5),102 CountBins(_CountBins)100 Histogram::Histogram(const samples_t &samples, const BinLowerEnd _offset, const double _binwidth) : 101 binwidth(_binwidth), 102 offset(_offset) 103 103 { 104 104 // build histogram from samples 105 105 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 110 107 samples_t::const_iterator maxiter = max_element(samples.begin(), samples.end()); 111 108 samples_t::const_iterator miniter = min_element(samples.begin(), samples.end()); … … 113 110 "Histogram::Histogram() - cannot find min/max despite non-empty range."); 114 111 // 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 131 125 BOOST_FOREACH( double value, samples) { 132 126 const Bins_t::iterator biniter = getLowerEndBin(value); 133 127 ASSERT( biniter != bins.end(), 134 128 "Histogram::Histogram() - cannot find bin for value from given samples."); 129 // (make bin count normalized, i.e. always equal to surface area of 1) 135 130 biniter->second += 1./binwidth; 136 131 } … … 293 288 Histogram::BinLowerEnd Histogram::getLowerEnd(const double _value) const 294 289 { 295 // we need just one bin, to have an offset296 const double offset = bins.begin()->first;297 290 BinLowerEnd start = _value - offset; 298 291 // then divide by binwidth -
src/Fragmentation/Histogram/Histogram.hpp
rcf18c5 r6bed1f 49 49 typedef std::map< BinLowerEnd, BinWeight > Bins_t; 50 50 public: 51 Histogram() : 52 binwidth(0.5), 53 offset(0.) 54 {} 55 56 /** Constructor for class Histogram. 57 * 58 * @param offset where the bins should start 59 * @param binwidth width of the bins 60 */ 61 Histogram(const BinLowerEnd _offset, const double _binwidth) : 62 binwidth(_binwidth), 63 offset(_offset) 64 {} 65 51 66 /** Constructor for class Histogram. 52 67 * 53 68 * @param samples samples to put in the histogram. 54 * @param CountBins number of bins (if negative, we choose number by statistical means) 69 * @param offset where the bins should start 70 * @param binwidth width of the bins 55 71 */ 56 Histogram(const samples_t &samples, const int _CountBins=-1);72 Histogram(const samples_t &samples, const BinLowerEnd _offset, const double _binwidth); 57 73 58 74 /** Adding another histogram onto this one. … … 142 158 //!> width of bin 143 159 const double binwidth; 144 //!> number ofbins145 int CountBins;160 //!> offset for the start of the bins 161 const BinLowerEnd offset; 146 162 }; 147 163 -
src/Fragmentation/Histogram/unittests/HistogramUnitTest.cpp
rcf18c5 r6bed1f 84 84 sampled_values += 1.,2.,3.,4.; 85 85 CPPUNIT_ASSERT_EQUAL( (size_t)4, sampled_values.size() ); 86 histogram = new Histogram(sampled_values, 4);86 histogram = new Histogram(sampled_values, 1., 1.); 87 87 CPPUNIT_ASSERT_EQUAL( (size_t)4+1, histogram->bins.size() ); 88 88 CPPUNIT_ASSERT( histogram->bins.end() != histogram->bins.begin() ); … … 99 99 sampled_values += 1.,2.,3.,4.; 100 100 CPPUNIT_ASSERT_EQUAL( (size_t)4, sampled_values.size() ); 101 histogram = new Histogram(sampled_values, 4);101 histogram = new Histogram(sampled_values, 1., 1.); 102 102 103 103 // check values inside … … 133 133 sampled_values += 1.,2.,3.,4.; 134 134 CPPUNIT_ASSERT_EQUAL( (size_t)4, sampled_values.size() ); 135 histogram = new Histogram(sampled_values, 4);135 histogram = new Histogram(sampled_values, 1., 1.); 136 136 137 137 // check values inside … … 172 172 Histogram::samples_t sampled_values; 173 173 sampled_values += 1.,2.,3.,4.; 174 histogram = new Histogram(sampled_values, 4);174 histogram = new Histogram(sampled_values, 1., 1.); 175 175 176 176 // go through each bin and check against getLowerEnd() … … 189 189 void HistogramTest::isEmpty_Test() 190 190 { 191 histogram = new Histogram( std::vector<double>());191 histogram = new Histogram(1., 1.); 192 192 // test on empty histogramgram 193 193 CPPUNIT_ASSERT( histogram->isEmpty() ); … … 197 197 sampled_values += 1.,2.,3.,4.; 198 198 delete histogram; 199 histogram = new Histogram(sampled_values, 4);199 histogram = new Histogram(sampled_values, 1., 1.); 200 200 CPPUNIT_ASSERT( !histogram->isEmpty() ); 201 201 … … 206 206 void HistogramTest::areaTest() 207 207 { 208 histogram = new Histogram( std::vector<double>());208 histogram = new Histogram(1., 1.); 209 209 // test on empty histogramgram 210 210 CPPUNIT_ASSERT_EQUAL( 0., histogram->area() ); … … 214 214 sampled_values += 1.,2.,3.,4., 4.; 215 215 delete histogram; 216 histogram = new Histogram(sampled_values, 4);216 histogram = new Histogram(sampled_values, 1., 1.); 217 217 CPPUNIT_ASSERT_EQUAL( 5., histogram->area() ); 218 218 Histogram::samples_t more_values; 219 219 more_values += 1.75,2.5,3.; 220 Histogram otherhistogram(more_values, 3);220 Histogram otherhistogram(more_values, 1.75, .625); 221 221 CPPUNIT_ASSERT_EQUAL( 3., otherhistogram.area() ); 222 222 … … 230 230 Histogram::samples_t sampled_values; 231 231 sampled_values += 1.,2.,3.,4.; 232 histogram = new Histogram(sampled_values, 4);232 histogram = new Histogram(sampled_values, 1., 1.); 233 233 Histogram::samples_t more_values; 234 234 more_values += 1.75,2.5,3.; 235 Histogram otherhistogram(more_values, 3);235 Histogram otherhistogram(more_values, 1.75, .625); 236 236 237 237 // check that size increases … … 252 252 Histogram::samples_t sampled_values; 253 253 sampled_values += 1.,2.,3.,4.; 254 histogram = new Histogram(sampled_values, 4);254 histogram = new Histogram(sampled_values, 1., 1.); 255 255 256 256 // add upon larger … … 258 258 Histogram::samples_t more_values; 259 259 more_values += 0.5, 1.25, 2.5,3., 4.2; 260 Histogram otherhistogram(more_values, 5);260 Histogram otherhistogram(more_values, 0.5, .625); 261 261 const double areas = histogram->area() + otherhistogram.area(); 262 262 … … 271 271 Histogram::samples_t more_values; 272 272 more_values += 1.75,2.5,3.; 273 Histogram otherhistogram(more_values, 3);273 Histogram otherhistogram(more_values, 1.75, .625); 274 274 const double areas = histogram->area() + otherhistogram.area(); 275 275 … … 288 288 Histogram::samples_t sampled_values; 289 289 sampled_values += 1.,2.,3.,4.; 290 histogram = new Histogram(sampled_values, 4);290 histogram = new Histogram(sampled_values, 1., 1.); 291 291 292 292 // subtract smaller 293 293 { 294 294 Histogram::samples_t more_values; 295 more_values += 1.75,2.5,3.;296 Histogram otherhistogram(more_values, 3);295 more_values += 0.5, 1.25, 2.5,3., 4.2; 296 Histogram otherhistogram(more_values, 0.5, .625); 297 297 const double difference = otherhistogram.area() - histogram->area(); 298 298 … … 306 306 { 307 307 Histogram::samples_t more_values; 308 more_values += 0.5, 1.25, 2.5,3., 4.2;309 Histogram otherhistogram(more_values, 5);308 more_values += 1.75,2.5,3.; 309 Histogram otherhistogram(more_values, 1.75, .625); 310 310 const double difference = otherhistogram.area() - histogram->area(); 311 311
Note:
See TracChangeset
for help on using the changeset viewer.