[66cfc7] | 1 | /*
|
---|
| 2 | * FunctionModel.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: 02.10.2012
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef FUNCTIONMODEL_HPP_
|
---|
| 9 | #define FUNCTIONMODEL_HPP_
|
---|
| 10 |
|
---|
| 11 | // include config.h
|
---|
| 12 | #ifdef HAVE_CONFIG_H
|
---|
| 13 | #include <config.h>
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
[7b019a] | 16 | #include <boost/function.hpp>
|
---|
[e1fe7e] | 17 | #include <list>
|
---|
[66cfc7] | 18 | #include <vector>
|
---|
| 19 |
|
---|
| 20 | #include "FunctionApproximation/FunctionArgument.hpp"
|
---|
| 21 |
|
---|
[7b019a] | 22 | class Fragment;
|
---|
[d52819] | 23 | class TrainingData;
|
---|
[7b019a] | 24 |
|
---|
[66cfc7] | 25 | /** This class represents the interface for a given function to model a
|
---|
| 26 | * high-dimensional data set in FunctionApproximation.
|
---|
| 27 | *
|
---|
| 28 | * As the parameters may be stored differently, the interface functions for
|
---|
| 29 | * getting and setting them are as light-weight (and not speed-optimized)
|
---|
| 30 | * as possible.
|
---|
| 31 | *
|
---|
[0f5d38] | 32 | * We always work in distances, i.e. pairs of atoms and the distance in between.
|
---|
| 33 | * As fragments do not contain these distances directly but the atomic positions
|
---|
| 34 | * (and charges) instead, we need to extract these from the fragment. For this
|
---|
| 35 | * purpose we need a bound function, termed an 'Extractor'. However, this is only
|
---|
| 36 | * required when one wants to use a FunctionModel directly on a given fragment.
|
---|
| 37 | * In FunctionApproximation we instead have TrainingData generate automatically
|
---|
| 38 | * a list of all pair-wise distances. The FunctionModel's Extractor may however
|
---|
| 39 | * create a more specific (and tighter) list of arguments, which however can
|
---|
| 40 | * then only be used with this specific FunctionModel.
|
---|
| 41 | *
|
---|
| 42 | * Furthermore, the underlying function to fit may require these distances, or
|
---|
| 43 | * arguments (termed so if paired with charges and atomic indices), to be in a
|
---|
| 44 | * certain order or does need only a subset. For this purpose we need another
|
---|
| 45 | * bound function, called a 'Filter'.
|
---|
| 46 | *
|
---|
| 47 | * As a fragment may contain multiple sets of arguments or distances that serve
|
---|
| 48 | * as valid function arguments, we need to split these sets up, such that they
|
---|
| 49 | * can be served one by one to the function. For this purpose we need a function
|
---|
| 50 | * that gives the number of arguments per set. (note that the Filter is supposed
|
---|
| 51 | * to place related arguments consecutively.
|
---|
| 52 | *
|
---|
[66cfc7] | 53 | */
|
---|
| 54 | class FunctionModel
|
---|
| 55 | {
|
---|
| 56 | public:
|
---|
| 57 | //!> typedef for a single parameter degree of freedom of the function
|
---|
| 58 | typedef double parameter_t;
|
---|
| 59 | //!> typedef for the whole set of parameters of the function
|
---|
| 60 | typedef std::vector<parameter_t> parameters_t;
|
---|
[e1fe7e] | 61 | //!> typedef for the argument vector as input to the function (subset of distances)
|
---|
[66cfc7] | 62 | typedef std::vector<argument_t> arguments_t;
|
---|
[e1fe7e] | 63 | //!> typedef for a list of argument vectors as input to the function (list of subsets)
|
---|
| 64 | typedef std::list<arguments_t> list_of_arguments_t;
|
---|
[66cfc7] | 65 | //!> typedef for a single result degree of freedom
|
---|
| 66 | typedef double result_t;
|
---|
| 67 | //!> typedef for the result vector as returned by the function
|
---|
| 68 | typedef std::vector<result_t> results_t;
|
---|
[7b019a] | 69 | //!> typedef for a function containing how to extract required information from a Fragment.
|
---|
[e1fe7e] | 70 | typedef boost::function< list_of_arguments_t (const Fragment &, const size_t)> extractor_t;
|
---|
[0f5d38] | 71 | //!> typedef for a function containing how to filter required distances from a full argument list.
|
---|
[e1fe7e] | 72 | typedef boost::function< list_of_arguments_t (const arguments_t &)> filter_t;
|
---|
[e36ba2] | 73 | //!> typedef for the magic triple function that gets the other two distances for a given argument
|
---|
| 74 | typedef boost::function< std::vector<arguments_t>(const argument_t &, const double)> triplefunction_t;
|
---|
[7b019a] | 75 |
|
---|
[66cfc7] | 76 | public:
|
---|
| 77 | FunctionModel() {}
|
---|
| 78 | virtual ~FunctionModel() {}
|
---|
| 79 |
|
---|
| 80 | /** Setter for the parameters of the model function.
|
---|
| 81 | *
|
---|
| 82 | * \param params set of parameters to set
|
---|
| 83 | */
|
---|
| 84 | virtual void setParameters(const parameters_t ¶ms)=0;
|
---|
| 85 |
|
---|
| 86 | /** Getter for the parameters of this model function.
|
---|
| 87 | *
|
---|
| 88 | * \return current set of parameters of the model function
|
---|
| 89 | */
|
---|
| 90 | virtual parameters_t getParameters() const=0;
|
---|
| 91 |
|
---|
[d52819] | 92 | /** Sets the parameter randomly within the sensible range of each parameter.
|
---|
| 93 | *
|
---|
| 94 | * \param data container with training data for guesstimating range
|
---|
| 95 | */
|
---|
| 96 | virtual void setParametersToRandomInitialValues(const TrainingData &data)=0;
|
---|
[7b019a] | 97 |
|
---|
[66cfc7] | 98 | /** Getter for the number of parameters of this model function.
|
---|
| 99 | *
|
---|
| 100 | * \return number of parameters
|
---|
| 101 | */
|
---|
| 102 | virtual size_t getParameterDimension() const=0;
|
---|
| 103 |
|
---|
[e36ba2] | 104 | /** Sets the magic triple function that we use for getting angle distances.
|
---|
| 105 | *
|
---|
| 106 | * @param _triplefunction function that returns a list of triples (i.e. the
|
---|
| 107 | * two remaining distances) to a given pair of points (contained as
|
---|
| 108 | * indices within the argument)
|
---|
| 109 | */
|
---|
| 110 | virtual void setTriplefunction(triplefunction_t &_triplefunction)
|
---|
| 111 | {}
|
---|
| 112 |
|
---|
[66cfc7] | 113 | /** Evaluates the function with the given \a arguments and the current set of
|
---|
| 114 | * parameters.
|
---|
| 115 | *
|
---|
| 116 | * \param arguments set of arguments as input variables to the function
|
---|
| 117 | * \return result of the function
|
---|
| 118 | */
|
---|
[e1fe7e] | 119 | virtual results_t operator()(const list_of_arguments_t &arguments) const=0;
|
---|
[66cfc7] | 120 |
|
---|
| 121 | /** Evaluates the derivative of the function with the given \a arguments
|
---|
[3ccea3] | 122 | * with respect to a specific parameter indicated by \a index.
|
---|
[66cfc7] | 123 | *
|
---|
| 124 | * \param arguments set of arguments as input variables to the function
|
---|
[3ccea3] | 125 | * \param index derivative of which parameter
|
---|
| 126 | * \return result vector containing the derivative with respect to the given
|
---|
| 127 | * input
|
---|
[66cfc7] | 128 | */
|
---|
[e1fe7e] | 129 | virtual results_t parameter_derivative(const list_of_arguments_t &arguments, const size_t index) const=0;
|
---|
[d03292] | 130 |
|
---|
| 131 | /** States whether lower and upper boundaries should be used to constraint
|
---|
| 132 | * the parameter search for this function model.
|
---|
| 133 | *
|
---|
| 134 | * \return true - constraints should be used, false - else
|
---|
| 135 | */
|
---|
| 136 | virtual bool isBoxConstraint() const=0;
|
---|
| 137 |
|
---|
| 138 | /** Returns a vector which are the lower boundaries for each parameter_t
|
---|
| 139 | * of this FunctionModel.
|
---|
| 140 | *
|
---|
| 141 | * \return vector of parameter_t resembling lowest allowed values
|
---|
| 142 | */
|
---|
| 143 | virtual parameters_t getLowerBoxConstraints() const=0;
|
---|
| 144 |
|
---|
| 145 | /** Returns a vector which are the upper boundaries for each parameter_t
|
---|
| 146 | * of this FunctionModel.
|
---|
| 147 | *
|
---|
| 148 | * \return vector of parameter_t resembling highest allowed values
|
---|
| 149 | */
|
---|
| 150 | virtual parameters_t getUpperBoxConstraints() const=0;
|
---|
[7b019a] | 151 |
|
---|
[0f5d38] | 152 | /** Returns a bound function to be used with TrainingData, extracting distances
|
---|
| 153 | * from a Fragment.
|
---|
| 154 | *
|
---|
| 155 | * \return bound function extracting distances from a fragment
|
---|
| 156 | */
|
---|
| 157 | virtual filter_t getSpecificFilter() const=0;
|
---|
| 158 |
|
---|
| 159 | /** Returns the number of arguments the underlying function requires.
|
---|
| 160 | *
|
---|
| 161 | * \return number of arguments of the function
|
---|
| 162 | */
|
---|
| 163 | virtual size_t getSpecificArgumentCount() const=0;
|
---|
[66cfc7] | 164 | };
|
---|
| 165 |
|
---|
| 166 | #endif /* FUNCTIONMODEL_HPP_ */
|
---|