本文整理汇总了C++中QualityMetric::get_negate_flag方法的典型用法代码示例。如果您正苦于以下问题:C++ QualityMetric::get_negate_flag方法的具体用法?C++ QualityMetric::get_negate_flag怎么用?C++ QualityMetric::get_negate_flag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QualityMetric
的用法示例。
在下文中一共展示了QualityMetric::get_negate_flag方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evaluate_with_gradient
bool LPtoPTemplate::evaluate_with_gradient( EvalType type,
PatchData& pd,
double& OF_val,
std::vector<Vector3D>& grad_out,
MsqError& err )
{
QualityMetric* qm = get_quality_metric();
qm->get_evaluations( pd, qmHandles, OF_FREE_EVALS_ONLY, err ); MSQ_ERRFALSE(err);
// zero gradient
grad_out.clear();
grad_out.resize( pd.num_free_vertices(), Vector3D(0.0,0.0,0.0) );
bool qm_bool=true;
double QM_val;
OF_val = 0.;
int p1;
// calculate OF value and gradient for just the patch
std::vector<size_t>::const_iterator i;
for (i = qmHandles.begin(); i != qmHandles.end(); ++i)
{
qm_bool = qm->evaluate_with_gradient( pd, *i, QM_val, mIndices, mGradient, err );
if (MSQ_CHKERR(err) || !qm_bool)
return false;
QM_val = fabs(QM_val);
double QM_pow = 1.0;
double factor = qm->get_negate_flag();
if (pVal == 1)
QM_pow = 1.0;
else {
QM_pow = QM_val;
for (p1 = 2; p1 < pVal; ++p1)
QM_pow *= QM_val;
factor *= QM_pow * pVal;
}
OF_val += QM_pow * QM_val;
for (size_t j = 0; j < mIndices.size(); ++j) {
mGradient[j] *= factor;
grad_out[mIndices[j]] += mGradient[j];
}
}
// get overall OF value, update member data, etc.
size_t global_count;
OF_val = qm->get_negate_flag() * get_value( OF_val, qmHandles.size(), type, global_count, err );
// if (!global_count)
// return false; // invalid mesh
if (dividingByN && global_count) {
const double inv_n = 1.0/global_count;
std::vector<Vector3D>::iterator g;
for (g = grad_out.begin(); g != grad_out.end(); ++g)
*g *= inv_n;
}
return true;
}
示例2: evaluate
bool LInfTemplate::evaluate( EvalType type,
PatchData& pd,
double& value_out,
bool free,
MsqError& err )
{
if (type != ObjectiveFunction::CALCULATE) {
MSQ_SETERR(err)(
"LInfTemplate does not support block coodinate descent algoritms",
MsqError::INVALID_STATE );
return false;
}
QualityMetric* qm = get_quality_metric();
qm->get_evaluations( pd, qmHandles, free, err ); MSQ_ERRFALSE(err);
const double negate = qm->get_negate_flag();
// calculate OF value for just the patch
std::vector<size_t>::const_iterator i;
double value;
value_out = -HUGE_VAL;
for (i = qmHandles.begin(); i != qmHandles.end(); ++i)
{
bool result = qm->evaluate( pd, *i, value, err );
if (MSQ_CHKERR(err) || !result)
return false;
value = negate * fabs(value);
if (value > value_out)
value_out = value;
}
return true;
}
示例3: evaluate
bool PMeanPTemplate::evaluate( EvalType type,
PatchData& pd,
double& value_out,
bool free,
MsqError& err )
{
QualityMetric* qm = get_quality_metric();
if (type == ObjectiveFunction::ACCUMULATE)
qm->get_single_pass( pd, qmHandles, free, err );
else
qm->get_evaluations( pd, qmHandles, free, err );
MSQ_ERRFALSE(err);
// calculate OF value for just the patch
std::vector<size_t>::const_iterator i;
double value, working_sum = 0.0;
for (i = qmHandles.begin(); i != qmHandles.end(); ++i)
{
bool result = qm->evaluate( pd, *i, value, err );
if (MSQ_CHKERR(err) || !result)
return false;
working_sum += mPower.raise( value );
}
// get overall OF value, update member data, etc.
size_t global_count;
value_out = qm->get_negate_flag()
* get_value( working_sum, qmHandles.size(), type, global_count );
return true;
}
示例4: evaluate_with_gradient
bool PMeanPTemplate::evaluate_with_gradient( EvalType type,
PatchData& pd,
double& value_out,
std::vector<Vector3D>& grad_out,
MsqError& err )
{
QualityMetric* qm = get_quality_metric();
qm->get_evaluations( pd, qmHandles, OF_FREE_EVALS_ONLY, err ); MSQ_ERRFALSE(err);
// zero gradient
grad_out.clear();
grad_out.resize( pd.num_free_vertices(), Vector3D(0.0,0.0,0.0) );
// calculate OF value and gradient for just the patch
std::vector<size_t>::const_iterator i;
double value, working_sum = 0.0;
const double f = qm->get_negate_flag() * mPower.value();
for (i = qmHandles.begin(); i != qmHandles.end(); ++i)
{
bool result = qm->evaluate_with_gradient( pd, *i, value, mIndices, mGradient, err );
if (MSQ_CHKERR(err) || !result)
return false;
if (fabs(value) < DBL_EPSILON)
continue;
const double r1 = mPowerMinus1.raise( value );
const double qmp = r1 * value;
working_sum += qmp;
value = f * r1;
for (size_t j = 0; j < mIndices.size(); ++j) {
mGradient[j] *= value;
grad_out[mIndices[j]] += mGradient[j];
}
}
// get overall OF value, update member data, etc.
size_t global_count;
value_out = qm->get_negate_flag()
* get_value( working_sum, qmHandles.size(), type, global_count );
const double inv_n = 1.0 / global_count;
std::vector<Vector3D>::iterator g;
for (g = grad_out.begin(); g != grad_out.end(); ++g)
*g *= inv_n;
return true;
}
示例5: evaluate_with_Hessian
bool PMeanPTemplate::evaluate_with_Hessian( EvalType type,
PatchData& pd,
double& value_out,
std::vector<Vector3D>& grad_out,
MsqHessian& Hessian_out,
MsqError& err )
{
QualityMetric* qm = get_quality_metric();
qm->get_evaluations( pd, qmHandles, OF_FREE_EVALS_ONLY, err ); MSQ_ERRFALSE(err);
// zero gradient and hessian
grad_out.clear();
grad_out.resize( pd.num_free_vertices(), 0.0 );
Hessian_out.zero_out();
// calculate OF value and gradient for just the patch
std::vector<size_t>::const_iterator i;
size_t j, k, n;
double value, working_sum = 0.0;
const double f1 = qm->get_negate_flag() * mPower.value();
const double f2 = f1 * (mPower.value() - 1);
Matrix3D m;
for (i = qmHandles.begin(); i != qmHandles.end(); ++i)
{
bool result = qm->evaluate_with_Hessian( pd, *i, value, mIndices, mGradient, mHessian, err );
if (MSQ_CHKERR(err) || !result)
return false;
if (fabs(value) < DBL_EPSILON)
continue;
const size_t nfree = mIndices.size();
n = 0;
if (mPower.value() == 1.0) {
working_sum += mPower.raise( value );
for (j = 0; j < nfree; ++j) {
mGradient[j] *= f1;
grad_out[mIndices[j]] += mGradient[j];
for (k = j; k < nfree; ++k) {
mHessian[n] *= f1;
Hessian_out.add( mIndices[j], mIndices[k], mHessian[n], err ); MSQ_ERRFALSE(err);
++n;
}
}
}
else {
const double r2 = mPowerMinus2.raise( value );
const double r1 = r2 * value;
working_sum += r1 * value;
const double hf = f2 * r2;
const double gf = f1 * r1;
for (j = 0; j < nfree; ++j) {
for (k = j; k < nfree; ++k) {
m.outer_product( mGradient[j], mGradient[k] );
m *= hf;
mHessian[n] *= gf;
m += mHessian[n];
Hessian_out.add( mIndices[j], mIndices[k], m, err ); MSQ_ERRFALSE(err);
++n;
}
}
for (j = 0; j < nfree; ++j) {
mGradient[j] *= gf;
grad_out[mIndices[j]] += mGradient[j];
}
}
}
// get overall OF value, update member data, etc.
size_t global_count;
value_out = qm->get_negate_flag()
* get_value( working_sum, qmHandles.size(), type, global_count );
const double inv_n = 1.0 / global_count;
std::vector<Vector3D>::iterator g;
for (g = grad_out.begin(); g != grad_out.end(); ++g)
*g *= inv_n;
Hessian_out.scale( inv_n );
return true;
}
示例6: evaluate_with_Hessian_diagonal
bool PMeanPTemplate::evaluate_with_Hessian_diagonal( EvalType type,
PatchData& pd,
double& value_out,
std::vector<Vector3D>& grad_out,
std::vector<SymMatrix3D>& hess_diag_out,
MsqError& err )
{
QualityMetric* qm = get_quality_metric();
qm->get_evaluations( pd, qmHandles, OF_FREE_EVALS_ONLY, err ); MSQ_ERRFALSE(err);
// zero gradient and hessian
const size_t s = pd.num_free_vertices();
grad_out.clear();
grad_out.resize( s, 0.0 );
hess_diag_out.clear();
hess_diag_out.resize( s, 0.0 );
// calculate OF value and gradient for just the patch
std::vector<size_t>::const_iterator i;
size_t j;
double value, working_sum = 0.0;
const double f1 = qm->get_negate_flag() * mPower.value();
const double f2 = f1 * (mPower.value() - 1);
for (i = qmHandles.begin(); i != qmHandles.end(); ++i)
{
bool result = qm->evaluate_with_Hessian_diagonal( pd, *i, value, mIndices, mGradient, mDiag, err );
if (MSQ_CHKERR(err) || !result)
return false;
if (fabs(value) < DBL_EPSILON)
continue;
const size_t nfree = mIndices.size();
if (mPower.value() == 1.0) {
working_sum += mPower.raise( value );
for (j = 0; j < nfree; ++j) {
const size_t idx = mIndices[j];
hess_diag_out[idx] += f1 * mDiag[j];
mGradient[j] *= f1;
grad_out[idx] += mGradient[j];
}
}
else {
const double r2 = mPowerMinus2.raise( value );
const double r1 = r2 * value;
working_sum += r1 * value;
const double hf = f2 * r2;
const double gf = f1 * r1;
for (j = 0; j < nfree; ++j) {
const size_t idx = mIndices[j];
hess_diag_out[idx] += hf * outer( mGradient[j] );
hess_diag_out[idx] += gf * mDiag[j];
mGradient[j] *= gf;
grad_out[idx] += mGradient[j];
}
}
}
// get overall OF value, update member data, etc.
size_t global_count;
value_out = qm->get_negate_flag()
* get_value( working_sum, qmHandles.size(), type, global_count );
const double inv_n = 1.0 / global_count;
for (j = 0; j < s; ++j) {
grad_out[j] *= inv_n;
hess_diag_out[j] *= inv_n;
}
return true;
}
示例7: function
/*\ For each element, each entry to be accumulated in the Hessian for
this objective function (\f$ \sum_{e \in E} Q(e)^p \f$ where \f$ E \f$
is the set of all elements in the patch) has the form:
\f$ pQ(e)^{p-1} \nabla^2 Q(e) + p(p-1)Q(e)^{p-2} \nabla Q(e) [\nabla Q(e)]^T \f$.
For \f$ p=2 \f$, this simplifies to
\f$ 2Q(e) \nabla^2 Q(e) + 2 \nabla Q(e) [\nabla Q(e)]^T \f$.
For \f$ p=1 \f$, this simplifies to \f$ \nabla^2 Q(e) \f$.
The \f$ p=1 \f$ simplified version is implemented directly
to speed up computation.
This function does not support vertex-based metrics.
\param pd The PatchData object for which the objective function
hessian is computed.
\param hessian this object must have been previously initialized.
*/
bool LPtoPTemplate::evaluate_with_Hessian( EvalType type,
PatchData& pd,
double& OF_val,
std::vector<Vector3D>& grad,
MsqHessian& hessian,
MsqError& err )
{
QualityMetric* qm = get_quality_metric();
qm->get_evaluations( pd, qmHandles, OF_FREE_EVALS_ONLY, err ); MSQ_ERRFALSE(err);
double negate_flag = qm->get_negate_flag();
// zero gradient and hessian
grad.clear();
grad.resize( pd.num_free_vertices(), 0.0 );
hessian.zero_out();
double QM_val, QM_pow = 1.0;
double fac1, fac2;
Matrix3D elem_outer_product;
bool qm_bool;
size_t i, j, n;
short p;
// Loops over all elements in the patch.
OF_val = 0.0;
std::vector<size_t>::const_iterator k;
for (k = qmHandles.begin(); k != qmHandles.end(); ++k)
{
// Computes \nabla^2 Q(e). Only the free vertices will have non-zero entries.
qm_bool = qm->evaluate_with_Hessian( pd, *k, QM_val, mIndices, mGradient, mHessian, err );
if (MSQ_CHKERR(err) || !qm_bool)
return false;
QM_val = fabs(QM_val);
// **** Computes Hessian ****
const size_t nve = mIndices.size();
if (pVal == 1) {
QM_pow = 1.0;
n=0;
for (i=0; i<nve; ++i) {
for (j=i; j<nve; ++j) {
//negate if necessary
mHessian[n] *= negate_flag;
hessian.add( mIndices[i], mIndices[j], mHessian[n], err ); MSQ_ERRFALSE(err);
++n;
}
}
fac1 = 1;
}
else if (pVal >= 2) {
// Computes the coefficients:
QM_pow = 1.0;
for (p=0; p<pVal-2; ++p)
QM_pow *= QM_val;
// 1 - computes p(p-1)Q(e)^{p-2}
fac2 = pVal* (pVal-1) * QM_pow;
// 2 - computes pQ(e)^{p-1}
QM_pow *= QM_val;
fac1 = pVal * QM_pow;
//fac1 *= qm->get_negate_flag();
//fac2 *= qm->get_negate_flag();
n=0;
for (i=0; i<nve; ++i) {
for (j=i; j<nve; ++j) {
elem_outer_product.outer_product(mGradient[i], mGradient[j]);
elem_outer_product *= fac2;
mHessian[n] *= fac1;
mHessian[n] += elem_outer_product;
mHessian[n] *= negate_flag;
hessian.add( mIndices[i], mIndices[j], mHessian[n], err ); MSQ_ERRFALSE(err);
++n;
}
}
} else {
MSQ_SETERR(err)(" invalid P value.", MsqError::INVALID_STATE);
return false;
}
//.........这里部分代码省略.........
示例8: get_negate_flag
int CompareMetric::get_negate_flag() const
{
assert(metric1->get_negate_flag() == metric2->get_negate_flag());
return metric1->get_negate_flag();
}