本文整理汇总了C++中Func::finiteHessian方法的典型用法代码示例。如果您正苦于以下问题:C++ Func::finiteHessian方法的具体用法?C++ Func::finiteHessian怎么用?C++ Func::finiteHessian使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func::finiteHessian方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: value
TEST(CentralDifference, Hessian){
// simple function y <- 3*a^2-a*b
class Func : public Problem<double> {
public:
double value(const Vector<double> &x) {
return 3*x[0]*x[0]-x[1]*x[0];
}
};
Vector<double> x0(2);
x0(0) = 0;
x0(1) = 0;
Func f;
Matrix<double> hessian(2,2);
// check using fast version
f.finiteHessian(x0, hessian);
EXPECT_NEAR(hessian(0,0), 6, PRECISION);
EXPECT_NEAR(hessian(1,0), -1, PRECISION);
EXPECT_NEAR(hessian(0,1), -1, PRECISION);
EXPECT_NEAR(hessian(1,1), 0, PRECISION);
// check using slow version
f.finiteHessian(x0, hessian,3);
EXPECT_NEAR(hessian(0,0), 6, PRECISION);
EXPECT_NEAR(hessian(1,0), -1, PRECISION);
EXPECT_NEAR(hessian(0,1), -1, PRECISION);
EXPECT_NEAR(hessian(1,1), 0, PRECISION);
}
示例2: value
TYPED_TEST(CentralDifference, Hessian){
// simple function y <- 3*a^2-a*b
class Func : public Problem<TypeParam, 2> {
public:
using typename Problem<TypeParam, 2>::TVector;
TypeParam value(const TVector &x) {
return 3*x[0]*x[0]-x[1]*x[0];
}
};
typename Func::TVector x0;
x0(0) = 0;
x0(1) = 0;
Func f;
typename Func::THessian hessian;
// check using fast version
f.finiteHessian(x0, hessian);
EXPECT_NEAR(hessian(0,0), 6, PRECISION);
EXPECT_NEAR(hessian(1,0), -1, PRECISION);
EXPECT_NEAR(hessian(0,1), -1, PRECISION);
EXPECT_NEAR(hessian(1,1), 0, PRECISION);
// check using slow version
f.finiteHessian(x0, hessian,3);
EXPECT_NEAR(hessian(0,0), 6, PRECISION);
EXPECT_NEAR(hessian(1,0), -1, PRECISION);
EXPECT_NEAR(hessian(0,1), -1, PRECISION);
EXPECT_NEAR(hessian(1,1), 0, PRECISION);
}