source: src/FunctionApproximation/TrainingData.cpp@ 76096d

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
Last change on this file since 76096d was bf1d1b, checked in by Frederik Heber <heber@…>, 11 years ago

HomologyContainer now stores full struct as value to HomologyGraph key.

  • this structure does not only contain fragment and energy but also the sampled charge and potential distribution.
  • added version handling to HomologyContainer::value_t serialization.
  • added option "store-grids" to AnalyseFragmentationResultsAction.
  • TESTFIX: adapted HomologyContainerUnitTest such that new values are correctly constructed.
  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
7 *
8 *
9 * This file is part of MoleCuilder.
10 *
11 * MoleCuilder is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * MoleCuilder is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25/*
26 * TrainingData.cpp
27 *
28 * Created on: 15.10.2012
29 * Author: heber
30 */
31
32// include config.h
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include "CodePatterns/MemDebug.hpp"
38
39#include "TrainingData.hpp"
40
41#include <algorithm>
42#include <boost/bind.hpp>
43#include <boost/lambda/lambda.hpp>
44#include <iostream>
45
46#include "CodePatterns/Assert.hpp"
47#include "CodePatterns/Log.hpp"
48#include "CodePatterns/toString.hpp"
49
50#include "Fragmentation/Summation/SetValues/Fragment.hpp"
51#include "FunctionApproximation/FunctionModel.hpp"
52#include "FunctionApproximation/Extractors.hpp"
53
54void TrainingData::operator()(const range_t &range) {
55 for (HomologyContainer::const_iterator iter = range.first; iter != range.second; ++iter) {
56 const Fragment &fragment = iter->second.fragment;
57 // create internal list of arguments
58 FunctionModel::arguments_t all_args = Extractors::gatherAllSymmetricDistances(
59 fragment.getPositions(),
60 fragment.getCharges(),
61 DistanceVector.size()
62 );
63 DistanceVector.push_back( all_args );
64 const double &energy = iter->second.energy;
65 EnergyVector.push_back( FunctionModel::results_t(1, energy) );
66 // filter distances out of list of all arguments
67 FunctionModel::arguments_t args = filter(all_args);
68 LOG(3, "DEBUG: Filtered arguments are " << args << ".");
69 ArgumentVector.push_back( args );
70 }
71}
72
73const double TrainingData::getL2Error(const FunctionModel &model) const
74{
75 double L2sum = 0.;
76
77 FunctionApproximation::inputs_t::const_iterator initer = ArgumentVector.begin();
78 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
79 for (; initer != ArgumentVector.end(); ++initer, ++outiter) {
80 const FunctionModel::results_t result = model((*initer));
81 const double temp = fabs((*outiter)[0] - result[0]);
82 L2sum += temp*temp;
83 }
84 return L2sum;
85}
86
87const double TrainingData::getLMaxError(const FunctionModel &model) const
88{
89 double Lmax = 0.;
90// size_t maxindex = -1;
91 FunctionApproximation::inputs_t::const_iterator initer = ArgumentVector.begin();
92 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
93 for (; initer != ArgumentVector.end(); ++initer, ++outiter) {
94 const FunctionModel::results_t result = model((*initer));
95 const double temp = fabs((*outiter)[0] - result[0]);
96 if (temp > Lmax) {
97 Lmax = temp;
98// maxindex = std::distance(
99// const_cast<const FunctionApproximation::inputs_t &>(ArgumentVector).begin(),
100// initer
101// );
102 }
103 }
104 return Lmax;
105}
106
107const TrainingData::DistanceEnergyTable_t TrainingData::getDistanceEnergyTable() const
108{
109 TrainingData::DistanceEnergyTable_t table;
110
111 /// extract distance member variable from argument_t and first value from results_t
112 OutputVector_t::const_iterator ergiter = EnergyVector.begin();
113 for (InputVector_t::const_iterator iter = ArgumentVector.begin();
114 iter != ArgumentVector.end(); ++iter, ++ergiter) {
115 ASSERT( ergiter != EnergyVector.end(),
116 "TrainingData::getDistanceEnergyTable() - less output than input values.");
117 std::vector< double > values(iter->size(), 0.);
118 // transform all distances
119 const FunctionModel::arguments_t &args = *iter;
120 std::transform(
121 args.begin(), args.end(),
122 values.begin(),
123 boost::bind(&argument_t::distance, _1));
124
125 // get first energy value
126 values.push_back((*ergiter)[0]);
127
128 // push as table row
129 table.push_back(values);
130 }
131
132 return table;
133}
134
135const FunctionModel::results_t TrainingData::getTrainingOutputAverage() const
136{
137 if (EnergyVector.size() != 0) {
138 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
139 FunctionModel::results_t result(*outiter);
140 for (++outiter; outiter != EnergyVector.end(); ++outiter)
141 for (size_t index = 0; index < (*outiter).size(); ++index)
142 result[index] += (*outiter)[index];
143 LOG(2, "DEBUG: Sum of EnergyVector is " << result << ".");
144 const double factor = 1./EnergyVector.size();
145 std::transform(result.begin(), result.end(), result.begin(),
146 boost::lambda::_1 * factor);
147 LOG(2, "DEBUG: Average EnergyVector is " << result << ".");
148 return result;
149 }
150 return FunctionModel::results_t();
151}
152
153std::ostream &operator<<(std::ostream &out, const TrainingData &data)
154{
155 const TrainingData::InputVector_t &DistanceVector = data.getAllArguments();
156 const TrainingData::OutputVector_t &EnergyVector = data.getTrainingOutputs();
157 out << "(" << DistanceVector.size()
158 << "," << EnergyVector.size() << ") data pairs: " << std::endl;
159 FunctionApproximation::inputs_t::const_iterator initer = DistanceVector.begin();
160 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
161 for (; initer != DistanceVector.end(); ++initer, ++outiter) {
162 for (size_t index = 0; index < (*initer).size(); ++index)
163 out << "(" << (*initer)[index].indices.first << "," << (*initer)[index].indices.second
164 << ") " << (*initer)[index].distance;
165 out << " with energy ";
166 out << (*outiter);
167 out << std::endl;
168 }
169 return out;
170}
Note: See TracBrowser for help on using the repository browser.