aboutsummaryrefslogtreecommitdiffstats
path: root/core/num_diff.hpp
diff options
context:
space:
mode:
authorastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-08-22 09:40:53 +0000
committerastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-08-22 09:40:53 +0000
commit4e6cebbb431222a5d8fa3bc62d5de44c93c8a93e (patch)
tree3800e20f0eaaa0b9dd88d8fafa21e18e747ca01b /core/num_diff.hpp
parent42ef6e5280c71ea770bf5a1a9bfb570d62b3c48e (diff)
downloadopt-utilities-4e6cebbb431222a5d8fa3bc62d5de44c93c8a93e.tar.bz2
git-svn-id: file:///home/svn/opt_utilities@48 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'core/num_diff.hpp')
-rw-r--r--core/num_diff.hpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/num_diff.hpp b/core/num_diff.hpp
index f9cf520..a6d9659 100644
--- a/core/num_diff.hpp
+++ b/core/num_diff.hpp
@@ -1,3 +1,8 @@
+/**
+ \file num_diff.hpp
+ */
+
+
#ifndef NUMDIFF_HPP
#define NUMDIFF_HPP
@@ -9,6 +14,12 @@
namespace opt_utilities
{
+
+ /**
+ differentiable function
+ \tparam rT the return type
+ \tparam the parameter type
+ */
template <typename rT,typename pT>
class dfunc_obj
:public func_obj<rT,pT>
@@ -17,12 +28,22 @@ namespace opt_utilities
virtual pT do_diff(const pT& p)=0;
public:
+ /**
+ calculate the differentiation
+ \param p the self-var
+ \return the gradient at p
+ */
pT diff(const pT& p)
{
return do_diff(p);
}
};
+
+ /**
+ When trying to diff an object function, when it is not differentiable,
+ this exception will be thrown.
+ */
class underivable
:public opt_exception
{
@@ -32,6 +53,9 @@ namespace opt_utilities
{}
};
+ /**
+ calculate the numerical differential of a func_obj
+ */
template <typename rT,typename pT>
pT numdiff(func_obj<rT,pT>& f,const pT& p)
{
@@ -68,6 +92,13 @@ namespace opt_utilities
return result;
}
+
+ /**
+ Help function to calculate the gradient of an objection function
+ func_obj, whether it is differentiable or not. If it is differentiable,
+ the gradient will be calculated by calling the diff member in the func_obj,
+ or a numerical calculation will be performed.
+ */
template <typename rT,typename pT>
pT diff(func_obj<rT,pT>& f,const pT& p)
{