OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
ObjectiveFunction.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2001, 2002, 2003 Nicolas Di C�sar�
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file ObjectiveFunction.hpp
21 \brief Optimization objective function class
22*/
23
24#ifndef optimization_objectivefunction_h
25#define optimization_objectivefunction_h
26
27#include <config.h>
28
30
31using namespace OpenMD;
32namespace QuantLib {
33
34 //! Objective function abstract class for optimization problem
36 public:
37 virtual ~ObjectiveFunction() {}
38 //! method to overload to compute the objective function value in x
39 virtual RealType value(const DynamicVector<RealType>& x) = 0;
40
41 //! method to overload to compute grad_f, the first derivative of
42 // the objective function with respect to x
44 const DynamicVector<RealType>& x) {
45 RealType eps = finiteDifferenceEpsilon(), fp, fm;
47 for (size_t i = 0; i < x.size(); i++) {
48 xx[i] += eps;
49 fp = value(xx);
50 xx[i] -= 2.0 * eps;
51 fm = value(xx);
52 grad[i] = 0.5 * (fp - fm) / eps;
53 xx[i] = x[i];
54 }
55 }
56
57 //! method to overload to compute grad_f, the first derivative
58 // of the objective function with respect to x and also the
59 // objective function
61 const DynamicVector<RealType>& x) {
62 gradient(grad, x);
63 return value(x);
64 }
65
66 //! Default epsilon for finite difference method :
67 virtual RealType finiteDifferenceEpsilon() const { return 1e-8; }
68 };
69
71 public:
72 virtual ~ParametersTransformation() {}
73 virtual DynamicVector<RealType> direct(
74 const DynamicVector<RealType>& x) const = 0;
75 virtual DynamicVector<RealType> inverse(
76 const DynamicVector<RealType>& x) const = 0;
77 };
78} // namespace QuantLib
79
80#endif
Dynamically-sized vector class.
Objective function abstract class for optimization problem.
virtual RealType finiteDifferenceEpsilon() const
Default epsilon for finite difference method :
virtual RealType value(const DynamicVector< RealType > &x)=0
method to overload to compute the objective function value in x
virtual RealType valueAndGradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative
virtual void gradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative of
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.