Go to the documentation of this file.
24 #ifndef _DERIVATIVETEST_HPP_
25 #define _DERIVATIVETEST_HPP_
38 namespace DerivativeTest {
48 template<
typename value_type>
55 virtual ublas::vector<value_type>
operator()(ublas::vector<double>
x)
const = 0;
59 std::ostream& os)
const;
66 template<
typename value_type>
69 ublas::matrix<value_type> result(argumentCount(), valueCount());
71 for (
unsigned int i=0; i<argumentCount(); i++)
73 ublas::vector<double> x2(
x);
75 row(result, i) = ((*this)(x2)-(*
this)(
x))/delta;
81 template<
typename value_type>
83 std::ostream& os)
const
87 for (
double delta=.1; delta>1e-9; delta/=10)
89 os << scientific << setprecision(1) <<
"[delta: " << delta <<
"] ";
90 os.unsetf(std::ios::scientific);
91 os << setprecision(8) << differenceQuotient(
x, delta) << endl;
100 template<
typename value_type>
111 virtual ublas::vector<value_type>
operator()(ublas::vector<double> p)
const
113 ublas::vector<value_type> result(1);
114 result(0) = f_(x_, p);
124 template<
typename value_type>
133 virtual unsigned int valueCount()
const {
return f_.parameterCount();}
135 virtual ublas::vector<value_type>
operator()(ublas::vector<double> p)
const
146 template<
typename value_type>
157 virtual ublas::vector<double>
operator()(ublas::vector<double> p)
const
159 ublas::vector<double> result(1);
169 template<
typename value_type>
178 virtual unsigned int valueCount()
const {
return e_.parameterCount();}
180 virtual ublas::vector<double>
operator()(ublas::vector<double> p)
const
193 template<
typename value_type>
196 const ublas::vector<double>& p,
197 std::ostream* os = 0,
205 *os <<
"x: " <<
x << endl;
206 *os <<
"p: " << p << endl;
209 if (os) *os <<
"f.dp: " << f.
dp(
x,p) << endl;
213 ublas::matrix<value_type> dp(f.
dp(
x,p).size(),1);
214 column(dp,0) = f.
dp(
x,p);
217 if (os) *os <<
"f.dp2: " << f.
dp2(
x,p) << endl;
225 template<
typename value_type>
227 const ublas::vector<double>& p,
228 std::ostream* os = 0,
234 if (os) *os <<
"p: " << p << endl;
236 if (os) *os <<
"e.dp: " << e.
dp(p) << endl;
240 ublas::matrix<value_type> dp(e.
dp(p).size(), 1);
241 column(dp,0) = e.
dp(p);
244 if (os) *os <<
"e.dp2: " << e.
dp2(p) << endl;
257 #endif // _DERIVATIVETEST_HPP_
virtual ublas::vector< double > operator()(ublas::vector< double > p) const
virtual unsigned int valueCount() const
virtual ublas::vector< double > operator()(ublas::vector< double > p) const
virtual unsigned int valueCount() const
virtual ~VectorFunction()
virtual unsigned int valueCount() const =0
ParametrizedDerivativeSlice(const ParametrizedFunction< value_type > &f, double x)
AdaptedErrorDerivative(const typename ParametrizedFunction< value_type >::ErrorFunction &e)
virtual unsigned int argumentCount() const =0
virtual ublas::vector< value_type > dp(double x, const ublas::vector< double > &p) const =0
ParametrizedFunctionSlice(const ParametrizedFunction< value_type > &f, double x)
virtual unsigned int argumentCount() const
ublas::matrix< value_type > differenceQuotient(ublas::vector< double > x, double delta) const
const ParametrizedFunction< value_type >::ErrorFunction & e_
virtual ublas::vector< value_type > operator()(ublas::vector< double > p) const
void printDifferenceQuotientSequence(ublas::vector< double > x, std::ostream &os) const
virtual ublas::vector< value_type > operator()(ublas::vector< double > x) const =0
virtual unsigned int argumentCount() const
AdaptedErrorFunction(const typename ParametrizedFunction< value_type >::ErrorFunction &e)
ublas::vector< double > dp(const ublas::vector< double > &p) const
virtual unsigned int argumentCount() const
const ParametrizedFunction< value_type > & f_
virtual unsigned int valueCount() const
ublas::matrix< double > dp2(const ublas::vector< double > &p) const
virtual ublas::vector< value_type > operator()(ublas::vector< double > p) const
KernelTraitsBase< Kernel >::space_type::abscissa_type x
const ParametrizedFunction< value_type > & f_
#define unit_assert_matrices_equal(A, B, epsilon)
virtual unsigned int argumentCount() const
virtual ublas::matrix< value_type > dp2(double x, const ublas::vector< double > &p) const =0
void testDerivatives(const ParametrizedFunction< value_type > &f, double x, const ublas::vector< double > &p, std::ostream *os=0, double delta=1e-7, double epsilon=1e-4)
virtual unsigned int valueCount() const
const ParametrizedFunction< value_type >::ErrorFunction & e_