OpenMD
3.2
Molecular Dynamics in the Open
Toggle main menu visibility
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 Cesare
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
29
#include "
math/DynamicVector.hpp
"
30
31
using namespace
OpenMD
;
32
namespace
QuantLib {
33
34
//! Objective function abstract class for optimization problem
35
class
ObjectiveFunction
{
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
43
virtual
void
gradient
(
DynamicVector<RealType>
& grad,
44
const
DynamicVector<RealType>
& x) {
45
RealType eps =
finiteDifferenceEpsilon
(), fp, fm;
46
DynamicVector<RealType>
xx(x);
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
60
virtual
RealType
valueAndGradient
(
DynamicVector<RealType>
& grad,
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
70
class
ParametersTransformation
{
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
DynamicVector.hpp
OpenMD::DynamicVector
Dynamically-sized vector class.
Definition
DynamicVector.hpp:74
QuantLib::ObjectiveFunction
Objective function abstract class for optimization problem.
Definition
ObjectiveFunction.hpp:35
QuantLib::ObjectiveFunction::finiteDifferenceEpsilon
virtual RealType finiteDifferenceEpsilon() const
Default epsilon for finite difference method :
Definition
ObjectiveFunction.hpp:67
QuantLib::ObjectiveFunction::value
virtual RealType value(const DynamicVector< RealType > &x)=0
method to overload to compute the objective function value in x
QuantLib::ObjectiveFunction::valueAndGradient
virtual RealType valueAndGradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative
Definition
ObjectiveFunction.hpp:60
QuantLib::ObjectiveFunction::gradient
virtual void gradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative of
Definition
ObjectiveFunction.hpp:43
QuantLib::ParametersTransformation
Definition
ObjectiveFunction.hpp:70
OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Definition
ActionCorrFunc.cpp:63
optimization
ObjectiveFunction.hpp
Generated on
for OpenMD by
1.17.0