Skip to content

Commit

Permalink
Add active parameter support to Python fit functions.
Browse files Browse the repository at this point in the history
Also add some debug statements to the Fit iteration loop.Refs #970
  • Loading branch information
martyngigg committed Apr 17, 2013
1 parent d7d443b commit afe05e3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/CurveFitting/src/Fit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,16 @@ namespace CurveFitting
std::string errorString;
//double costFuncVal = 0;
//do
g_log.debug("Starting minimizer iteration\n");
while (static_cast<int>(iter) < maxIterations)
{
iter++;
g_log.debug() << "Starting iteration " << iter << "\n";
if ( !minimizer->iterate() )
{
errorString = minimizer->getError();
g_log.debug() << "Iteration stopped. Minimizer status string=" << errorString << "\n";

success = errorString.empty() || errorString == "success";
if (success)
{
Expand All @@ -562,7 +566,7 @@ namespace CurveFitting
}
prog.report();
}

g_log.information() << "Number of minimizer iterations=" << iter << "\n";

if (static_cast<int>(iter) >= maxIterations)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ namespace Mantid
this->declareFitParameter(name,0.0,"");
}

/// Override this method to make fitted parameters different from the declared
double activeParameter(size_t i)const;
/// Override this method to make fitted parameters different from the declared
void setActiveParameter(size_t i, double value);

protected:
/**
* Returns the PyObject that owns this wrapper, i.e. self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Mantid
namespace PythonInterface
{
using Mantid::PythonInterface::Environment::CallMethod0;
using Mantid::PythonInterface::Environment::CallMethod1;
using Mantid::PythonInterface::Environment::CallMethod2;
using namespace boost::python;

/**
Expand Down Expand Up @@ -73,5 +75,37 @@ namespace Mantid
return result;
}

/**
* Value of i-th active parameter. If this functions is overridden
* in Python then it returns the value of the ith active Parameter
* If not it simple returns the base class result
* @param i The index of the parameter
*/
double IFunctionAdapter::activeParameter(size_t i) const
{
return CallMethod1<double,size_t>::dispatchWithDefaultReturn(getSelf(), "activeParameter",
this->getParameter(i), i);
}

/**
* Sets the value of i-th active parameter. If this functions is overridden
* in Python then it should set the value of the ith active parameter
* If calls the base class function
* @param i The index of the parameter
*/
void IFunctionAdapter::setActiveParameter(size_t i, double value)
{
try
{
CallMethod2<void,size_t,double>::dispatchWithException(getSelf(), "setActiveParameter", i,value);
}
catch(std::runtime_error&)
{
IFunction::setActiveParameter(i,value);
}

}


}
}

0 comments on commit afe05e3

Please sign in to comment.