source: src/FunctionApproximation/TrainingData.cpp@ 31a2be

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 31a2be was 5aaa43, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Fixed new copyright line since start of 2013 in CodeChecks test.

  • we must look for either Uni Bonn or myself.
  • added second copyright line since from 1st of Jan 2013 I am not employed by University of Bonn anymore, hence changes to the code are my own copyright.
  • Property mode set to 100644
File size: 5.8 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
53void TrainingData::operator()(const range_t &range) {
54 for (HomologyContainer::const_iterator iter = range.first; iter != range.second; ++iter) {
55 // get distance out of Fragment
56 const Fragment &fragment = iter->second.first;
57 FunctionModel::arguments_t args = extractor(
58 fragment,
59 DistanceVector.size()
60 );
61 DistanceVector.push_back( args );
62 const double &energy = iter->second.second;
63 EnergyVector.push_back( FunctionModel::results_t(1, energy) );
64 }
65}
66
67const double TrainingData::getL2Error(const FunctionModel &model) const
68{
69 double L2sum = 0.;
70
71 FunctionApproximation::inputs_t::const_iterator initer = DistanceVector.begin();
72 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
73 for (; initer != DistanceVector.end(); ++initer, ++outiter) {
74 const FunctionModel::results_t result = model((*initer));
75 const double temp = fabs((*outiter)[0] - result[0]);
76 L2sum += temp*temp;
77 }
78 return L2sum;
79}
80
81const double TrainingData::getLMaxError(const FunctionModel &model) const
82{
83 double Lmax = 0.;
84 size_t maxindex = -1;
85 FunctionApproximation::inputs_t::const_iterator initer = DistanceVector.begin();
86 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
87 for (; initer != DistanceVector.end(); ++initer, ++outiter) {
88 const FunctionModel::results_t result = model((*initer));
89 const double temp = fabs((*outiter)[0] - result[0]);
90 if (temp > Lmax) {
91 Lmax = temp;
92 maxindex = std::distance(
93 const_cast<const FunctionApproximation::inputs_t &>(DistanceVector).begin(),
94 initer
95 );
96 }
97 }
98 return Lmax;
99}
100
101const TrainingData::DistanceEnergyTable_t TrainingData::getDistanceEnergyTable() const
102{
103 TrainingData::DistanceEnergyTable_t table;
104 const InputVector_t &DistanceVector = getTrainingInputs();
105 const OutputVector_t &EnergyVector = getTrainingOutputs();
106
107 /// extract distance member variable from argument_t and first value from results_t
108 OutputVector_t::const_iterator ergiter = EnergyVector.begin();
109 for (InputVector_t::const_iterator iter = DistanceVector.begin();
110 iter != DistanceVector.end(); ++iter, ++ergiter) {
111 ASSERT( ergiter != EnergyVector.end(),
112 "TrainingData::getDistanceEnergyTable() - less output than input values.");
113 std::vector< double > values(iter->size(), 0.);
114 // transform all distances
115 const FunctionModel::arguments_t &args = *iter;
116 std::transform(
117 args.begin(), args.end(),
118 values.begin(),
119 boost::bind(&argument_t::distance, _1));
120
121 // get first energy value
122 values.push_back((*ergiter)[0]);
123
124 // push as table row
125 table.push_back(values);
126 }
127
128 return table;
129}
130
131const FunctionModel::results_t TrainingData::getTrainingOutputAverage() const
132{
133 if (EnergyVector.size() != 0) {
134 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
135 FunctionModel::results_t result(*outiter);
136 for (++outiter; outiter != EnergyVector.end(); ++outiter)
137 for (size_t index = 0; index < (*outiter).size(); ++index)
138 result[index] += (*outiter)[index];
139 LOG(2, "DEBUG: Sum of EnergyVector is " << result << ".");
140 const double factor = 1./EnergyVector.size();
141 std::transform(result.begin(), result.end(), result.begin(),
142 boost::lambda::_1 * factor);
143 LOG(2, "DEBUG: Average EnergyVector is " << result << ".");
144 return result;
145 }
146 return FunctionModel::results_t();
147}
148
149std::ostream &operator<<(std::ostream &out, const TrainingData &data)
150{
151 const TrainingData::InputVector_t &DistanceVector = data.getTrainingInputs();
152 const TrainingData::OutputVector_t &EnergyVector = data.getTrainingOutputs();
153 out << "(" << DistanceVector.size()
154 << "," << EnergyVector.size() << ") data pairs: " << std::endl;
155 FunctionApproximation::inputs_t::const_iterator initer = DistanceVector.begin();
156 FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
157 for (; initer != DistanceVector.end(); ++initer, ++outiter) {
158 for (size_t index = 0; index < (*initer).size(); ++index)
159 out << "(" << (*initer)[index].indices.first << "," << (*initer)[index].indices.second
160 << ") " << (*initer)[index].distance;
161 out << " with energy ";
162 out << (*outiter);
163 out << std::endl;
164 }
165 return out;
166}
Note: See TracBrowser for help on using the repository browser.