本文整理汇总了C++中ParameterList::hasParameter方法的典型用法代码示例。如果您正苦于以下问题:C++ ParameterList::hasParameter方法的具体用法?C++ ParameterList::hasParameter怎么用?C++ ParameterList::hasParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterList
的用法示例。
在下文中一共展示了ParameterList::hasParameter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_parameter
void Alignment::set_parameter(string name, double value) {
ParameterList pl;
enum class THING{LIKELIHOOD, RATES, MODEL}; // The 'thing' to update after setting parameter
THING thing;
if (likelihood) {
pl = likelihood->getParameters();
thing = THING::LIKELIHOOD;
}
else if (rates) {
pl = rates->getIndependentParameters();
thing = THING::RATES;
}
else if (model) {
pl = model->getIndependentParameters();
thing = THING::MODEL;
}
else {
throw Exception("Could not retrieve parameter list");
}
if (pl.hasParameter(name)) {
pl.setParameterValue(name, value);
switch (thing) {
case THING::LIKELIHOOD:
likelihood->setParametersValues(pl);
break;
case THING::RATES:
rates->setParametersValues(pl);
rates->fireParameterChanged(pl);
break;
case THING::MODEL:
model->setParametersValues(pl);
model->fireParameterChanged(pl);
break;
}
}
else {
throw Exception("Could not find that parameter");
}
}
示例2: get_parameter
double Alignment::get_parameter(string name) {
ParameterList pl;
if (likelihood) {
pl = likelihood->getParameters();
}
else if (rates) {
pl = rates->getIndependentParameters();
}
else if (model) {
pl = model->getIndependentParameters();
}
else {
throw Exception("Could not retrieve parameter list");
}
if (pl.hasParameter(name)) {
return pl.getParameterValue(name);
}
else {
throw Exception("Could not find that parameter");
}
}
示例3: updateDerivatives
void ThreePointsNumericalDerivative::updateDerivatives(const ParameterList & parameters)
throw (ParameterNotFoundException, ConstraintException)
{
if(computeD1_ && variables_.size() > 0)
{
if(function1_) function1_->enableFirstOrderDerivatives(false);
if(function2_) function2_->enableSecondOrderDerivatives(false);
function_->setParameters(parameters);
f2_ = function_->getValue();
string lastVar;
ParameterList p;
for(unsigned int i = 0; i < variables_.size(); i++)
{
string var = variables_[i];
if (!parameters.hasParameter(var)) continue;
if(i > 0)
{
vector<string> vars(2);
vars[0] = var;
vars[1] = lastVar;
p = parameters.subList(vars);
}
else
{
p = parameters.subList(var);
}
lastVar = var;
double value = function_->getParameterValue(var);
double h = (1. + std::abs(value)) * h_;
//Compute one other point:
try
{
p[0]->setValue(value - h);
function_->setParameters(p); //also reset previous parameter...
p = p.subList(0);
f1_ = function_->getValue();
try
{
p[0]->setValue(value + h);
function_->setParameters(p);
f3_ = function_->getValue();
//No limit raised, use central approximation:
der1_[i] = (-f1_ + f3_) / (2.*h);
der2_[i] = (f1_ -2*f2_ + f3_) / (h*h);
}
catch(ConstraintException & ce)
{
//Right limit raised, use backward approximation:
p[0]->setValue(value - h);
function_->setParameters(p);
f1_ = function_->getValue();
p[0]->setValue(value - 2*h);
function_->setParameters(p);
f3_ = function_->getValue();
der1_[i] = (f2_ - f1_) / h;
der2_[i] = (f2_ - 2.*f1_ + f3_) / (h*h);
}
}
catch(ConstraintException & ce)
{
//Left limit raised, use forward approximation:
p[0]->setValue(value + h);
function_->setParameters(p);
f3_ = function_->getValue();
p[0]->setValue(value + 2*h);
function_->setParameters(p);
f1_ = function_->getValue();
der1_[i] = (f3_ - f2_) / h;
der2_[i] = (f1_ - 2.*f3_ + f2_) / (h*h);
}
}
if(computeCrossD2_)
{
string lastVar1, lastVar2;
for(unsigned int i = 0; i < variables_.size(); i++)
{
string var1 = variables_[i];
if(!parameters.hasParameter(var1)) continue;
for(unsigned int j = 0; j < variables_.size(); j++)
{
if(j==i)
{
crossDer2_(i,j) = der2_[i];
continue;
}
string var2 = variables_[j];
if (!parameters.hasParameter(var2)) continue;
vector<string> vars(2);
vars[0] = var1;
vars[1] = var2;
if(i > 0 && j > 0)
{
if(lastVar1 != var1 && lastVar1 != var2) vars.push_back(lastVar1);
if(lastVar2 != var1 && lastVar2 != var2) vars.push_back(lastVar2);
}
p = parameters.subList(vars);
double value1 = function_->getParameterValue(var1);
//.........这里部分代码省略.........
示例4: updateDerivatives
void ThreePointsNumericalDerivative::updateDerivatives(const ParameterList parameters)
throw (ParameterNotFoundException, ConstraintException)
{
if (computeD1_ && variables_.size() > 0)
{
if (function1_)
function1_->enableFirstOrderDerivatives(false);
if (function2_)
function2_->enableSecondOrderDerivatives(false);
function_->setParameters(parameters);
f2_ = function_->getValue();
if ((abs(f2_) >= NumConstants::VERY_BIG()) || std::isnan(f2_))
{
for (size_t i = 0; i < variables_.size(); ++i)
{
der1_[i] = log(-1);
der2_[i] = log(-1);
}
return;
}
string lastVar;
bool functionChanged = false;
ParameterList p;
bool start = true;
for (size_t i = 0; i < variables_.size(); ++i)
{
string var = variables_[i];
if (!parameters.hasParameter(var))
continue;
if (!start)
{
vector<string> vars(2);
vars[0] = var;
vars[1] = lastVar;
p = parameters.subList(vars);
}
else
{
p = parameters.subList(var);
start = false;
}
lastVar = var;
functionChanged = true;
double value = function_->getParameterValue(var);
double h = -(1. + std::abs(value)) * h_;
if (abs(h) < p[0].getPrecision())
h = h < 0 ? -p[0].getPrecision() : p[0].getPrecision();
double hf1(0), hf3(0);
unsigned int nbtry = 0;
// Compute f1_
while (hf1 == 0)
{
try
{
p[0].setValue(value + h);
function_->setParameters(p); // also reset previous parameter...
p = p.subList(0);
f1_ = function_->getValue();
if ((abs(f1_) >= NumConstants::VERY_BIG()) || std::isnan(f1_))
throw ConstraintException("f1_ too large", &p[0], f1_);
else
hf1 = h;
}
catch (ConstraintException& ce)
{
if (++nbtry == 10) // no possibility to compute derivatives
break;
else if (h < 0)
h = -h; // try on the right
else
h /= -2; // try again on the left with smaller interval
}
}
if (hf1 != 0)
{
// Compute f3_
if (h < 0)
h = -h; // on the right
else
h /= 2; // on the left with smaller interval
nbtry = 0;
while (hf3 == 0)
{
try
{
p[0].setValue(value + h);
function_->setParameters(p); // also reset previous parameter...
p = p.subList(0);
f3_ = function_->getValue();
if ((abs(f3_) >= NumConstants::VERY_BIG()) || std::isnan(f3_))
throw ConstraintException("f3_ too large", &p[0], f3_);
else
hf3 = h;
}
//.........这里部分代码省略.........
示例5: updateDerivatives
void TwoPointsNumericalDerivative::updateDerivatives(const ParameterList parameters)
throw (ParameterNotFoundException, ConstraintException)
{
if (computeD1_ && variables_.size() > 0)
{
if (function1_)
function1_->enableFirstOrderDerivatives(false);
if (function2_)
function2_->enableSecondOrderDerivatives(false);
function_->setParameters(parameters);
f1_ = function_->getValue();
string lastVar;
bool functionChanged = false;
bool start = true;
for (unsigned int i = 0; i < variables_.size(); i++)
{
string var = variables_[i];
if (!parameters.hasParameter(var))
continue;
ParameterList p;
if (!start)
{
vector<string> vars(2);
vars[0] = var;
vars[1] = lastVar;
lastVar = var;
functionChanged = true;
p = parameters.subList(vars);
}
else
{
p = parameters.subList(var);
lastVar = var;
functionChanged = true;
start = false;
}
double value = function_->getParameterValue(var);
double h = (1 + std::abs(value)) * h_;
// Compute one other point:
try
{
p[0].setValue(value + h);
function_->setParameters(p);
f2_ = function_->getValue();
}
catch (ConstraintException& ce1)
{
// Right limit raised, use backward approximation:
try
{
p[0].setValue(value - h);
function_->setParameters(p);
f2_ = function_->getValue();
der1_[i] = (f1_ - f2_) / h;
}
catch (ConstraintException& ce2)
{
// PB: can't compute derivative, because of a two narrow interval (lower than h)
throw ce2;
}
}
// No limit raised, use forward approximation:
der1_[i] = (f2_ - f1_) / h;
}
// Reset last parameter and compute analytical derivatives if any:
if (function1_)
function1_->enableFirstOrderDerivatives(computeD1_);
if (functionChanged)
function_->setParameters(parameters.subList(lastVar));
}
else
{
// Reset initial value and compute analytical derivatives if any.
if (function1_)
function1_->enableFirstOrderDerivatives(computeD1_);
if (function2_)
function2_->enableSecondOrderDerivatives(computeD2_);
// Just in case derivatives are not computed:
function_->setParameters(parameters);
f1_ = function_->getValue();
}
}
示例6: main
//.........这里部分代码省略.........
unsigned int optVerbose = ApplicationTools::getParameter<unsigned int>("optimization.verbose", bppdist.getParams(), 2);
string mhPath = ApplicationTools::getAFilePath("optimization.message_handler", bppdist.getParams(), false, false);
OutputStream* messenger =
(mhPath == "none") ? 0 :
(mhPath == "std") ? ApplicationTools::message :
new StlOutputStream(new ofstream(mhPath.c_str(), ios::out));
ApplicationTools::displayResult("Message handler", mhPath);
string prPath = ApplicationTools::getAFilePath("optimization.profiler", bppdist.getParams(), false, false);
OutputStream* profiler =
(prPath == "none") ? 0 :
(prPath == "std") ? ApplicationTools::message :
new StlOutputStream(new ofstream(prPath.c_str(), ios::out));
if(profiler) profiler->setPrecision(20);
ApplicationTools::displayResult("Profiler", prPath);
// Should I ignore some parameters?
ParameterList allParameters = model->getParameters();
allParameters.addParameters(rDist->getParameters());
ParameterList parametersToIgnore;
string paramListDesc = ApplicationTools::getStringParameter("optimization.ignore_parameter", bppdist.getParams(), "", "", true, false);
bool ignoreBrLen = false;
StringTokenizer st(paramListDesc, ",");
while (st.hasMoreToken())
{
try
{
string param = st.nextToken();
if (param == "BrLen")
ignoreBrLen = true;
else
{
if (allParameters.hasParameter(param))
{
Parameter* p = &allParameters.getParameter(param);
parametersToIgnore.addParameter(*p);
}
else ApplicationTools::displayWarning("Parameter '" + param + "' not found.");
}
}
catch (ParameterNotFoundException& pnfe)
{
ApplicationTools::displayError("Parameter '" + pnfe.getParameter() + "' not found, and so can't be ignored!");
}
}
unsigned int nbEvalMax = ApplicationTools::getParameter<unsigned int>("optimization.max_number_f_eval", bppdist.getParams(), 1000000);
ApplicationTools::displayResult("Max # ML evaluations", TextTools::toString(nbEvalMax));
double tolerance = ApplicationTools::getDoubleParameter("optimization.tolerance", bppdist.getParams(), .000001);
ApplicationTools::displayResult("Tolerance", TextTools::toString(tolerance));
//Here it is:
ofstream warn("warnings", ios::out);
ApplicationTools::warning = new StlOutputStreamWrapper(&warn);
tree = OptimizationTools::buildDistanceTree(distEstimation, *distMethod, parametersToIgnore, !ignoreBrLen, type, tolerance, nbEvalMax, profiler, messenger, optVerbose);
warn.close();
delete ApplicationTools::warning;
ApplicationTools::warning = ApplicationTools::message;
string matrixPath = ApplicationTools::getAFilePath("output.matrix.file", bppdist.getParams(), false, false, "", false);
if (matrixPath != "none")
{
ApplicationTools::displayResult("Output matrix file", matrixPath);
string matrixFormat = ApplicationTools::getAFilePath("output.matrix.format", bppdist.getParams(), false, false, "", false);