本文整理汇总了C++中Constraint::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ Constraint::empty方法的具体用法?C++ Constraint::empty怎么用?C++ Constraint::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Constraint
的用法示例。
在下文中一共展示了Constraint::empty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calibrate
void CalibratedModel::calibrate(
const vector<shared_ptr<CalibrationHelper> >& instruments,
OptimizationMethod& method,
const EndCriteria& endCriteria,
const Constraint& additionalConstraint,
const vector<Real>& weights,
const vector<bool>& fixParameters) {
QL_REQUIRE(weights.empty() || weights.size() == instruments.size(),
"mismatch between number of instruments (" <<
instruments.size() << ") and weights(" <<
weights.size() << ")");
Constraint c;
if (additionalConstraint.empty())
c = *constraint_;
else
c = CompositeConstraint(*constraint_,additionalConstraint);
vector<Real> w =
weights.empty() ? vector<Real>(instruments.size(), 1.0): weights;
Array prms = params();
vector<bool> all(prms.size(), false);
Projection proj(prms,fixParameters.size()>0 ? fixParameters : all);
CalibrationFunction f(this,instruments,w,proj);
ProjectedConstraint pc(c,proj);
Problem prob(f, pc, proj.project(prms));
shortRateEndCriteria_ = method.minimize(prob, endCriteria);
Array result(prob.currentValue());
setParams(proj.include(result));
problemValues_ = prob.values(result);
notifyObservers();
}
示例2: calibrate
void CalibratedModel::calibrate(
const std::vector<boost::shared_ptr<CalibrationHelper> >& instruments,
OptimizationMethod& method,
const EndCriteria& endCriteria,
const Constraint& additionalConstraint,
const std::vector<Real>& weights) {
QL_REQUIRE(weights.empty() ||
weights.size() == instruments.size(),
"mismatch between number of instruments and weights");
Constraint c;
if (additionalConstraint.empty())
c = *constraint_;
else
c = CompositeConstraint(*constraint_,additionalConstraint);
std::vector<Real> w = weights.empty() ?
std::vector<Real>(instruments.size(), 1.0):
weights;
CalibrationFunction f(this, instruments, w);
Problem prob(f, c, params());
shortRateEndCriteria_ = method.minimize(prob, endCriteria);
Array result(prob.currentValue());
setParams(result);
Array shortRateProblemValues_ = prob.values(result);
notifyObservers();
}
示例3: test
int test(OptimizationMethod& method, CostFunction& f, const EndCriteria& endCriteria,
const Array& start, const Constraint& constraint = Constraint(),
const Array& optimum = Array()) {
QL_REQUIRE(start.size() > 0, "Input size needs to be at least 1");
std::cout << "Starting point: ";
Constraint c;
if (!constraint.empty())
c = constraint;
Problem p(f, c, start);
printFunction(p, start);
method.minimize(p, endCriteria);
std::cout << "End point: ";
Real val = printFunction(p, p.currentValue());
if(!optimum.empty())
{
std::cout << "Global optimium: ";
Real optimVal = printFunction(p, optimum);
if(std::abs(optimVal) < 1e-13)
return std::abs(val-optimVal) < 1e-6;
else
return std::abs((val-optimVal)/optimVal) < 1e-6;
}
return 1;
}