本文整理汇总了C++中MsqHessian::get_block方法的典型用法代码示例。如果您正苦于以下问题:C++ MsqHessian::get_block方法的具体用法?C++ MsqHessian::get_block怎么用?C++ MsqHessian::get_block使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MsqHessian
的用法示例。
在下文中一共展示了MsqHessian::get_block方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compare_hessian_diagonal
void ObjectiveFunctionTests::compare_hessian_diagonal( ObjectiveFunction* of )
{
MsqPrintError err(std::cout);
PatchData pd;
create_twelve_hex_patch( pd, err );
ASSERT_NO_ERROR( err );
std::vector<Vector3D> diag_grad, hess_grad;
std::vector<SymMatrix3D> diag;
MsqHessian hess;
double diag_val, hess_val;
bool valid;
valid = of->evaluate_with_Hessian_diagonal( ObjectiveFunction::CALCULATE, pd, diag_val, diag_grad, diag, err );
ASSERT_NO_ERROR( err );
CPPUNIT_ASSERT(valid);
CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), diag_grad.size() );
CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), diag.size() );
hess.initialize( pd, err );
ASSERT_NO_ERROR( err );
valid = of->evaluate_with_Hessian( ObjectiveFunction::CALCULATE, pd, hess_val, hess_grad, hess, err );
ASSERT_NO_ERROR( err );
CPPUNIT_ASSERT(valid);
CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), hess_grad.size() );
CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), hess.size() );
CPPUNIT_ASSERT_DOUBLES_EQUAL( hess_val, diag_val, 1e-6 );
for (size_t i = 0; i < pd.num_free_vertices(); ++i) {
CPPUNIT_ASSERT_VECTORS_EQUAL( hess_grad[i], diag_grad[i], 1e-6 );
CPPUNIT_ASSERT_MATRICES_EQUAL( *hess.get_block(i,i), diag[i], 1e-6 );
}
}
示例2: evaluate_with_Hessian_diagonal
bool ObjectiveFunction::evaluate_with_Hessian_diagonal( EvalType type,
PatchData& pd,
double& value_out,
std::vector<Vector3D>& grad_out,
std::vector<SymMatrix3D>& hess_diag_out,
MsqError& err )
{
MsqHessian hess;
hess.initialize( pd, err ); MSQ_ERRZERO(err);
bool val = evaluate_with_Hessian( type, pd, value_out, grad_out, hess, err );
MSQ_ERRZERO(err);
hess_diag_out.resize( hess.size() );
for (size_t i = 0; i < hess.size(); ++i)
hess_diag_out[i] = hess.get_block(i,i)->upper();
return val;
}
示例3: test_compute_ana_hessian_tet_scaled
void ObjectiveFunctionTest::test_compute_ana_hessian_tet_scaled()
{
MsqPrintError err(cout);
PatchData tetPatch;
create_qm_two_tet_patch(tetPatch,err);
ASSERT_NO_ERROR(err);
// creates a mean ratio quality metric ...
IdealWeightInverseMeanRatio* mean_ratio = new IdealWeightInverseMeanRatio(err);
CPPUNIT_ASSERT(!err);
mean_ratio->set_averaging_method(QualityMetric::SUM);
// ... and builds an objective function with it
LPtoPTemplate LP2(mean_ratio, 2, err);
LP2.set_dividing_by_n(true);
MsqHessian H;
std::vector<Vector3D> g;
double dummy;
H.initialize(tetPatch, err);
CPPUNIT_ASSERT(!err);
LP2.evaluate_with_Hessian(ObjectiveFunction::CALCULATE, tetPatch, dummy, g, H, err);
CPPUNIT_ASSERT(!err);
CPPUNIT_ASSERT_EQUAL( tetPatch.num_free_vertices(), g.size() );
Matrix3D mat00(" 2.44444 0.2566 0.181444 "
" 0.2566 2.14815 0.104757 "
" 0.181444 0.104757 2.07407 ");
mat00*=.5;
Matrix3D mat13(" 5.47514 3.16659 9.83479 "
" -1.11704 -5.29718 -3.67406 "
" 10.3635 -13.5358 -15.5638 ");
mat13*=.5;
CPPUNIT_ASSERT_MATRICES_EQUAL( mat00, *H.get_block(0,0), 1e-4 );
CPPUNIT_ASSERT_MATRICES_EQUAL( mat13, *H.get_block(1,3), 1e-4 );
// cout << H <<endl;
delete mean_ratio;
}
示例4: compare_numerical_hessian
void ObjectiveFunctionTests::compare_numerical_hessian( ObjectiveFunction* of,
bool diagonal_only )
{
const double delta = 0.0001;
MsqPrintError err(std::cout);
PatchData pd;
create_qm_two_tet_patch( pd, err );
ASSERT_NO_ERROR( err );
CPPUNIT_ASSERT( pd.num_free_vertices() != 0 );
// get analytical Hessian from objective function
std::vector<Vector3D> grad;
std::vector<SymMatrix3D> diag;
MsqHessian hess;
hess.initialize( pd, err );
ASSERT_NO_ERROR( err );
double value;
bool valid;
if (diagonal_only)
valid = of->evaluate_with_Hessian_diagonal( ObjectiveFunction::CALCULATE, pd, value, grad, diag, err );
else
valid = of->evaluate_with_Hessian( ObjectiveFunction::CALCULATE, pd, value, grad, hess, err );
ASSERT_NO_ERROR(err); CPPUNIT_ASSERT(valid);
// do numerical approximation of each block and compare to analytical value
for (size_t i = 0; i < pd.num_free_vertices(); ++i) {
const size_t j_end = diagonal_only ? i+1 : pd.num_free_vertices();
for (size_t j = i; j < j_end; ++j) {
// do numerical approximation for block corresponding to
// coorindates for ith and jth vertices.
Matrix3D block;
for (int k = 0; k < 3; ++k) {
for (int m = 0; m < 3; ++m) {
double dk, dm, dkm;
Vector3D ik = pd.vertex_by_index(i);
Vector3D im = pd.vertex_by_index(j);
Vector3D delta_k(0.0); delta_k[k] = delta;
pd.move_vertex( delta_k, i, err ); ASSERT_NO_ERROR(err);
valid = of->evaluate( ObjectiveFunction::CALCULATE, pd, dk, true, err );
ASSERT_NO_ERROR(err); CPPUNIT_ASSERT(valid);
Vector3D delta_m(0.0); delta_m[m] = delta;
pd.move_vertex( delta_m, j, err ); ASSERT_NO_ERROR(err);
valid = of->evaluate( ObjectiveFunction::CALCULATE, pd, dkm, true, err );
ASSERT_NO_ERROR(err); CPPUNIT_ASSERT(valid);
// be careful here that we do the right thing if i==j
pd.set_vertex_coordinates( ik, i, err ); ASSERT_NO_ERROR(err);
pd.set_vertex_coordinates( im, j, err ); ASSERT_NO_ERROR(err);
pd.move_vertex( delta_m, j, err ); ASSERT_NO_ERROR(err);
valid = of->evaluate( ObjectiveFunction::CALCULATE, pd, dm, true, err );
ASSERT_NO_ERROR(err); CPPUNIT_ASSERT(valid);
pd.set_vertex_coordinates( ik, i, err ); ASSERT_NO_ERROR(err);
pd.set_vertex_coordinates( im, j, err ); ASSERT_NO_ERROR(err);
block[k][m] = (dkm - dk - dm + value)/(delta*delta);
}
}
// compare to analytical value
if (diagonal_only) {
CPPUNIT_ASSERT(i == j); // see j_end above
CPPUNIT_ASSERT(i < diag.size());
CHECK_EQUAL_MATRICES( block, Matrix3D(diag[i]) );
}
else {
Matrix3D* m = hess.get_block( i, j );
Matrix3D* mt = hess.get_block( j, i );
if (NULL != m) {
CHECK_EQUAL_MATRICES( block, *m );
}
if (NULL != mt) {
CHECK_EQUAL_MATRICES( transpose(block), *m );
}
if (NULL == mt && NULL == m) {
CHECK_EQUAL_MATRICES( Matrix3D(0.0), block );
}
}
}
}
}