source: src/FunctionApproximation/FunctionApproximation.hpp@ c62f96

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 c62f96 was 66cfc7, checked in by Frederik Heber <heber@…>, 12 years ago

Added new class FunctionApproximation that encapsulates the LevMar usage.

  • Property mode set to 100644
File size: 3.9 KB
Line 
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
20/** This class encapsulates the solution to approximating a high-dimensional
21 * function represented by two vectors of tuples, being input variables and
22 * output of the function via a model function, manipulated by a set of
23 * parameters.
24 *
25 * \note For this reason the input and output dimension has to be given in
26 * the constructor since these are fixed parameters to the problem as a
27 * whole and usually: a different input dimension means we have a completely
28 * different problem (and hence we may as well construct and new instance of
29 * this class).
30 *
31 * The "training data", i.e. the two sets of input and output values, is
32 * given extra.
33 *
34 * The problem is then that a given high-dimensional function is supplied,
35 * the "model", and we have to fit this function via its set of variable
36 * parameters. This fitting procedure is executed via a Levenberg-Marquardt
37 * algorithm as implemented in the
38 * <a href="http://www.ics.forth.gr/~lourakis/levmar/index.html">LevMar</a>
39 * package.
40 *
41 */
42class FunctionApproximation
43{
44public:
45 //!> typedef for a vector of input arguments
46 typedef std::vector<FunctionModel::arguments_t> inputs_t;
47 //!> typedef for a vector of output values
48 typedef std::vector<FunctionModel::results_t> outputs_t;
49public:
50 /** Constructor of the class FunctionApproximation.
51 *
52 * \param _input_dimension input dimension for this function approximation
53 * \param _output_dimension output dimension for this function approximation
54 */
55 FunctionApproximation(
56 const size_t &_input_dimension,
57 const size_t &_output_dimension,
58 FunctionModel &_model) :
59 input_dimension(_input_dimension),
60 output_dimension(_output_dimension),
61 model(_model)
62 {}
63 /** Destructor for class FunctionApproximation.
64 *
65 */
66 ~FunctionApproximation()
67 {}
68
69 /** Setter for the training data to be used.
70 *
71 * \param input vector of input tuples, needs to be of
72 * FunctionApproximation::input_dimension size
73 * \param output vector of output tuples, needs to be of
74 * FunctionApproximation::output_dimension size
75 */
76 void setTrainingData(const inputs_t &input, const outputs_t &output);
77
78 /** Setter for the model function to be used in the approximation.
79 *
80 */
81 void setModelFunction(FunctionModel &_model);
82
83 /** This starts the fitting process, resulting in the parameters to
84 * the model function being optimized with respect to the given training
85 * data.
86 */
87 void operator()();
88
89 /** Evaluates the model function for each pair of training tuple and returns
90 * the error between the output of the function and the expected output as a
91 * vector.
92 *
93 * This function as a signature compatible to the one required by the
94 * LevMar package (with double precision).
95 *
96 * \param *p array of parameters for the model function of dimension \a m
97 * \param *x array of result values of dimension \a n
98 * \param m parameter dimension
99 * \param n output dimension
100 * \param *data additional data, unused here
101 */
102 void evaluate(double *p, double *x, int m, int n, void *data);
103
104private:
105 static void LevMarCallback(double *p, double *x, int m, int n, void *data);
106
107private:
108 //!> input dimension (is fixed from construction)
109 const size_t input_dimension;
110 //!> output dimension (is fixed from construction)
111 const size_t output_dimension;
112
113 //!> current input set of training data
114 inputs_t input_data;
115 //!> current output set of training data
116 outputs_t output_data;
117
118 //!> the model function to be used in the high-dimensional approximation
119 FunctionModel &model;
120};
121
122#endif /* FUNCTIONAPPROXIMATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.