source: src/FunctionApproximation/FunctionApproximation.hpp@ 1ba8a1

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 1ba8a1 was 1ba8a1, checked in by Frederik Heber <heber@…>, 11 years ago

DOCU: Extended documentation on FunctionApproximation and potential fitting.

  • Property mode set to 100644
File size: 6.9 KB
RevLine 
[66cfc7]1/*
2 * FunctionApproximation.hpp
3 *
4 * Created on: 02.10.2012
5 * Author: heber
6 */
7
8#ifndef FUNCTIONAPPROXIMATION_HPP_
9#define FUNCTIONAPPROXIMATION_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <vector>
17
18#include "FunctionApproximation/FunctionModel.hpp"
19
[69ab84]20class TrainingData;
21
[66cfc7]22/** This class encapsulates the solution to approximating a high-dimensional
23 * function represented by two vectors of tuples, being input variables and
24 * output of the function via a model function, manipulated by a set of
25 * parameters.
26 *
27 * \note For this reason the input and output dimension has to be given in
28 * the constructor since these are fixed parameters to the problem as a
29 * whole and usually: a different input dimension means we have a completely
30 * different problem (and hence we may as well construct and new instance of
31 * this class).
32 *
33 * The "training data", i.e. the two sets of input and output values, is
34 * given extra.
35 *
36 * The problem is then that a given high-dimensional function is supplied,
37 * the "model", and we have to fit this function via its set of variable
38 * parameters. This fitting procedure is executed via a Levenberg-Marquardt
39 * algorithm as implemented in the
40 * <a href="http://www.ics.forth.gr/~lourakis/levmar/index.html">LevMar</a>
41 * package.
42 *
[1ba8a1]43 * \section FunctionApproximation-details Details on the inner workings.
44 *
45 * FunctionApproximation::operator() is the main function that performs the
46 * non-linear regression. It consists of the following steps:
47 * -# hand given (initial) parameters over to model.
48 * -# convert output vector to format suitable to levmar
49 * -# allocate memory for levmar to work in
50 * -# depending on whether the model is constrained or not and whether we
51 * have a derivative, we make use of various levmar functions with prepared
52 * parameters.
53 * -# memory is free'd and some final infos is given.
54 *
55 * levmar needs to evaluate the model. To this end, FunctionApproximation has
56 * two functions whose signatures is such as to match with the one required
57 * by the levmar package. Hence,
58 * -# FunctionApproximation::LevMarCallback()
59 * -# FunctionApproximation::LevMarDerivativeCallback()
60 * are used as callbacks by levmar only.
61 * These hand over the current set of parameters to the model, then both bind
62 * FunctionApproximation::evaluate() and
63 * FunctionApproximation::evaluateDerivative(), respectively, and execute
64 * FunctionModel::operator() or FunctionModel::parameter_derivative(),
65 * respectively.
66 *
[66cfc7]67 */
68class FunctionApproximation
69{
70public:
71 //!> typedef for a vector of input arguments
72 typedef std::vector<FunctionModel::arguments_t> inputs_t;
73 //!> typedef for a vector of output values
74 typedef std::vector<FunctionModel::results_t> outputs_t;
75public:
[69ab84]76 /** Constructor of the class FunctionApproximation.
77 *
78 * \param _data container with tuple of (input, output) values
79 * \param _model FunctionModel to use in approximation
80 */
81 FunctionApproximation(
82 const TrainingData &_data,
83 FunctionModel &_model);
84
[66cfc7]85 /** Constructor of the class FunctionApproximation.
86 *
87 * \param _input_dimension input dimension for this function approximation
88 * \param _output_dimension output dimension for this function approximation
[69ab84]89 * \param _model FunctionModel to use in approximation
[66cfc7]90 */
91 FunctionApproximation(
92 const size_t &_input_dimension,
93 const size_t &_output_dimension,
94 FunctionModel &_model) :
95 input_dimension(_input_dimension),
96 output_dimension(_output_dimension),
97 model(_model)
98 {}
99 /** Destructor for class FunctionApproximation.
100 *
101 */
102 ~FunctionApproximation()
103 {}
104
105 /** Setter for the training data to be used.
106 *
107 * \param input vector of input tuples, needs to be of
108 * FunctionApproximation::input_dimension size
109 * \param output vector of output tuples, needs to be of
110 * FunctionApproximation::output_dimension size
111 */
112 void setTrainingData(const inputs_t &input, const outputs_t &output);
113
114 /** Setter for the model function to be used in the approximation.
115 *
116 */
117 void setModelFunction(FunctionModel &_model);
118
[76e63d]119 /** This enum steers whether we use finite differences or
120 * FunctionModel::parameter_derivative to calculate the jacobian.
121 *
122 */
123 enum JacobianMode {
124 FiniteDifferences,
125 ParameterDerivative,
126 MAXMODE
127 };
128
[66cfc7]129 /** This starts the fitting process, resulting in the parameters to
130 * the model function being optimized with respect to the given training
131 * data.
[76e63d]132 *
133 * \param mode whether to use finite differences or the parameter derivative
134 * in calculating the jacobian
[66cfc7]135 */
[76e63d]136 void operator()(const enum JacobianMode mode = FiniteDifferences);
[66cfc7]137
138 /** Evaluates the model function for each pair of training tuple and returns
[5b5724]139 * the output of the function as a vector.
[66cfc7]140 *
141 * This function as a signature compatible to the one required by the
142 * LevMar package (with double precision).
143 *
144 * \param *p array of parameters for the model function of dimension \a m
145 * \param *x array of result values of dimension \a n
146 * \param m parameter dimension
147 * \param n output dimension
148 * \param *data additional data, unused here
149 */
150 void evaluate(double *p, double *x, int m, int n, void *data);
151
[5b5724]152 /** Evaluates the parameter derivative of the model function for each pair of
153 * training tuple and returns the output of the function as vector.
154 *
155 * This function as a signature compatible to the one required by the
156 * LevMar package (with double precision).
157 *
158 * \param *p array of parameters for the model function of dimension \a m
159 * \param *jac on output jacobian matrix of result values of dimension \a n times \a m
160 * \param m parameter dimension
161 * \param n output dimension times parameter dimension
162 * \param *data additional data, unused here
163 */
164 void evaluateDerivative(double *p, double *jac, int m, int n, void *data);
165
[371c8b]166 /** This functions checks whether the parameter derivative of the FunctionModel
167 * has been correctly implemented by validating against finite differences.
168 *
169 * We use LevMar's dlevmar_chkjac() function.
170 *
171 * \return true - gradients are ok (>0.5), false - else
172 */
173 bool checkParameterDerivatives();
174
[66cfc7]175private:
176 static void LevMarCallback(double *p, double *x, int m, int n, void *data);
177
[5b5724]178 static void LevMarDerivativeCallback(double *p, double *x, int m, int n, void *data);
179
180 void prepareModel(double *p, int m);
181
[63b9f7]182 void prepareParameters(double *&p, int &m) const;
183
184 void prepareOutput(double *&x, int &n) const;
185
[66cfc7]186private:
187 //!> input dimension (is fixed from construction)
188 const size_t input_dimension;
189 //!> output dimension (is fixed from construction)
190 const size_t output_dimension;
191
192 //!> current input set of training data
193 inputs_t input_data;
194 //!> current output set of training data
195 outputs_t output_data;
196
197 //!> the model function to be used in the high-dimensional approximation
198 FunctionModel &model;
199};
200
201#endif /* FUNCTIONAPPROXIMATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.