本文整理汇总了C++中api::IFunction_sptr::getParameterNames方法的典型用法代码示例。如果您正苦于以下问题:C++ IFunction_sptr::getParameterNames方法的具体用法?C++ IFunction_sptr::getParameterNames怎么用?C++ IFunction_sptr::getParameterNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::IFunction_sptr
的用法示例。
在下文中一共展示了IFunction_sptr::getParameterNames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hasParameter
/** Find out whether a function has a certain parameter
*/
bool GeneratePeaks::hasParameter(API::IFunction_sptr function,
std::string paramname) {
std::vector<std::string> parnames = function->getParameterNames();
std::vector<std::string>::iterator piter;
piter = std::find(parnames.begin(), parnames.end(), paramname);
return piter != parnames.end();
}
示例2: fitBackgroundFunction
/** Fit background function
*/
void ProcessBackground::fitBackgroundFunction(std::string bkgdfunctiontype) {
// Get background type and create bakground function
BackgroundFunction_sptr bkgdfunction =
createBackgroundFunction(bkgdfunctiontype);
int bkgdorder = getProperty("OutputBackgroundOrder");
bkgdfunction->setAttributeValue("n", bkgdorder);
if (bkgdfunctiontype == "Chebyshev") {
double xmin = m_outputWS->readX(0).front();
double xmax = m_outputWS->readX(0).back();
g_log.information() << "Chebyshev Fit range: " << xmin << ", " << xmax
<< "\n";
bkgdfunction->setAttributeValue("StartX", xmin);
bkgdfunction->setAttributeValue("EndX", xmax);
}
g_log.information() << "Fit selected background " << bkgdfunctiontype
<< " to data workspace with "
<< m_outputWS->getNumberHistograms() << " spectra."
<< "\n";
// Fit input (a few) background pionts to get initial guess
API::IAlgorithm_sptr fit;
try {
fit = this->createChildAlgorithm("Fit", 0.9, 1.0, true);
} catch (Exception::NotFoundError &) {
g_log.error() << "Requires CurveFitting library." << std::endl;
throw;
}
g_log.information() << "Fitting background function: "
<< bkgdfunction->asString() << "\n";
double startx = m_lowerBound;
double endx = m_upperBound;
fit->setProperty("Function",
boost::dynamic_pointer_cast<API::IFunction>(bkgdfunction));
fit->setProperty("InputWorkspace", m_outputWS);
fit->setProperty("WorkspaceIndex", 0);
fit->setProperty("MaxIterations", 500);
fit->setProperty("StartX", startx);
fit->setProperty("EndX", endx);
fit->setProperty("Minimizer", "Levenberg-MarquardtMD");
fit->setProperty("CostFunction", "Least squares");
fit->executeAsChildAlg();
// Get fit status and chi^2
std::string fitStatus = fit->getProperty("OutputStatus");
bool allowedfailure = (fitStatus.find("cannot") < fitStatus.size()) &&
(fitStatus.find("tolerance") < fitStatus.size());
if (fitStatus.compare("success") != 0 && !allowedfailure) {
g_log.error() << "ProcessBackground: Fit Status = " << fitStatus
<< ". Not to update fit result" << std::endl;
throw std::runtime_error("Bad Fit");
}
const double chi2 = fit->getProperty("OutputChi2overDoF");
g_log.information() << "Fit background: Fit Status = " << fitStatus
<< ", chi2 = " << chi2 << "\n";
// Get out the parameter names
API::IFunction_sptr funcout = fit->getProperty("Function");
TableWorkspace_sptr outbkgdparws = boost::make_shared<TableWorkspace>();
outbkgdparws->addColumn("str", "Name");
outbkgdparws->addColumn("double", "Value");
TableRow typerow = outbkgdparws->appendRow();
typerow << bkgdfunctiontype << 0.;
vector<string> parnames = funcout->getParameterNames();
size_t nparam = funcout->nParams();
for (size_t i = 0; i < nparam; ++i) {
TableRow newrow = outbkgdparws->appendRow();
newrow << parnames[i] << funcout->getParameter(i);
}
TableRow chi2row = outbkgdparws->appendRow();
chi2row << "Chi-square" << chi2;
g_log.information() << "Set table workspace (#row = "
<< outbkgdparws->rowCount()
<< ") to OutputBackgroundParameterTable. "
<< "\n";
setProperty("OutputBackgroundParameterWorkspace", outbkgdparws);
// Set output workspace
const MantidVec &vecX = m_outputWS->readX(0);
const MantidVec &vecY = m_outputWS->readY(0);
FunctionDomain1DVector domain(vecX);
FunctionValues values(domain);
funcout->function(domain, values);
MantidVec &dataModel = m_outputWS->dataY(1);
MantidVec &dataDiff = m_outputWS->dataY(2);
for (size_t i = 0; i < dataModel.size(); ++i) {
//.........这里部分代码省略.........