本文整理汇总了C++中eigen::VectorXd::squaredNorm方法的典型用法代码示例。如果您正苦于以下问题:C++ VectorXd::squaredNorm方法的具体用法?C++ VectorXd::squaredNorm怎么用?C++ VectorXd::squaredNorm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::VectorXd
的用法示例。
在下文中一共展示了VectorXd::squaredNorm方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
double L2R_Huber_SVC::get_func(const Eigen::VectorXd &w) {
z = y * (X * w).array();
int indexD2 = 0;
double zi, tmp;
double f = 0;
indexs_D1.clear();
indexs_D2.clear();
XD2w_yD2 = Eigen::VectorXd::Zero(l);
for (int i = 0; i < l; ++i) {
zi = z.coeffRef(i);
tmp = 1 - zi;
if (zi <= 0) {
indexs_D1.push_back(i);
f += (tmp - 0.5);
} else if (zi < 1) {
indexs_D2.push_back(i);
f += tmp * tmp * 0.5;
XD2w_yD2.coeffRef(indexD2) = -y.coeffRef(i) * tmp;
++indexD2;
}
}
f *= C;
f += w.squaredNorm() / 2.0;
return f;
}
示例2:
double l2r_l1hinge_spdc::get_primal_func(const Eigen::VectorXd &w) const {
Eigen::ArrayXd wx = y_ * (x_ * w).array();
double tmp = 0.0;
for (int i = 0; i < num_ins_; ++i)
tmp += std::max(0.0, 1.0 - wx[i]);
return 0.5 * w.squaredNorm() + C * tmp;
}
示例3: gradientStep
double SmoothDualDecompositionFistaDescent::gradientStep(double rho,
const Eigen::VectorXd& lambda,
double& obj_lambda,
Eigen::VectorXd& gradient,
double& gradient_norm_squared,
Eigen::VectorXd& y, double& omega)
{
double obj_new;
double obj_approx;
// evaluate objective, gradient and gradient norm
obj_lambda = computeObjectiveAndGradient(rho, gradient, lambda);
gradient_norm_squared = gradient.squaredNorm();
// backtracking
do {
y = lambda + gradient*(1.0/omega);
obj_new = computeObjective(rho, y);
obj_approx = obj_lambda+1/(2.0*omega)*gradient_norm_squared;
if (obj_new < obj_approx) {
omega *= _lipschitz_inc_u;
}
} while(obj_new < obj_approx);
omega = std::max(_lipschitz_constant_optimistic, omega/_lipschitz_inc_d);
return obj_new;
}
示例4: determineNewTimeStep
bool AdaptiveTimeStepper::determineNewTimeStep(
const Eigen::VectorXd & errorEstimate,
const Eigen::VectorXd & solution,
const double computedTimeStep,
double & newTimeStep
)
{
assert( endTime > 0 );
scalarList squaredNorm( Pstream::nProcs(), scalar( 0 ) );
squaredNorm[Pstream::myProcNo()] = errorEstimate.squaredNorm();
reduce( squaredNorm, sumOp<scalarList>() );
double error = std::sqrt( sum( squaredNorm ) );
squaredNorm = 0;
squaredNorm[Pstream::myProcNo()] = solution.squaredNorm();
reduce( squaredNorm, sumOp<scalarList>() );
error /= std::sqrt( sum( squaredNorm ) );
return determineNewTimeStep( error, computedTimeStep, newTimeStep );
}
示例5: CalcObjVal
double cIKSolver::CalcObjVal(const Eigen::MatrixXd &joint_desc, const Eigen::VectorXd& pose, const Eigen::MatrixXd& cons_desc)
{
// objective function is the 2-norm of the constraint violations
double obj_val = 0;
Eigen::VectorXd err;
for (int c = 0; c < cons_desc.rows(); ++c)
{
const tConsDesc& curr_cons = cons_desc.row(c);
double weight = curr_cons(eConsDesc::eConsDescWeight);
err = BuildErr(joint_desc, pose, curr_cons);
obj_val += weight * err.squaredNorm();
}
return obj_val;
}
示例6: option_value
SimuEuro(const option & o, long path, const std::vector<double> & RN){
opt=o;
N= path;
asset_price.resize(N);
asset_price.setZero();
option_value= asset_price;
for (long i=0; i< N; i++) {
asset_price(i)=opt.S* exp((opt.r- opt.q)*opt.T-.5*opt.sigma*opt.sigma*opt.T+ opt.sigma* sqrt(opt.T)* RN[i]);
if(opt.Call) option_value(i)= fmax(asset_price(i)- opt.K,0.0);
else option_value(i)= fmax(-asset_price(i)+opt.K, 0.0);
}
mean= option_value.sum()/ option_value.size() * exp(-opt.T*opt.r);
stdiv= option_value.squaredNorm()/ option_value.size()* exp(-opt.r*opt.T *2);
stdiv= stdiv- pow(mean,2.0);
stdiv= sqrt(stdiv/ N);
};