Commit 84d9ff41 authored by Anders Markvardsen's avatar Anders Markvardsen
Browse files

Rest of the code for allowing fitting parameter descriptions plus tests. re #2970

parent 78911ebc
......@@ -56,10 +56,14 @@ public:
/// Set i-th parameter
void setParameter(int, const double& value, bool explicitlySet = true);
/// Set i-th parameter description
void setParameterDescription(size_t, const std::string& description);
/// Get i-th parameter
double getParameter(int i)const;
/// Set parameter by name.
void setParameter(const std::string& name, const double& value, bool explicitlySet = true);
/// Set description of parameter by name.
void setParameterDescription(const std::string& name, const std::string& description);
/// Get parameter by name.
double getParameter(const std::string& name)const;
/// Total number of parameters
......@@ -70,6 +74,8 @@ public:
//int parameterIndex(const double* p)const;
/// Returns the name of parameter i
std::string parameterName(int i)const;
/// Returns the description of parameter i
std::string parameterDescription(size_t i)const;
/// Checks if a parameter has been set explicitly
bool isExplicitlySet(int i)const;
......@@ -85,6 +91,8 @@ public:
int indexOfActive(int i)const;
/// Returns the name of active parameter i
std::string nameOfActive(int i)const;
/// Returns the name of active parameter i
std::string descriptionOfActive(size_t i)const;
/// Check if a parameter is active
bool isActive(int i)const;
......
......@@ -251,10 +251,14 @@ public:
/// Set i-th parameter
virtual void setParameter(int, const double& value, bool explicitlySet = true) = 0;
/// Set i-th parameter description
virtual void setParameterDescription(size_t, const std::string& description) = 0;
/// Get i-th parameter
virtual double getParameter(int i)const = 0;
/// Set parameter by name.
virtual void setParameter(const std::string& name, const double& value, bool explicitlySet = true) = 0;
/// Set description of parameter by name.
virtual void setParameterDescription(const std::string& name, const std::string& description) = 0;
/// Get parameter by name.
virtual double getParameter(const std::string& name)const = 0;
/// Total number of parameters
......@@ -263,6 +267,8 @@ public:
virtual int parameterIndex(const std::string& name)const = 0;
/// Returns the name of parameter i
virtual std::string parameterName(int i)const = 0;
/// Returns the description of parameter i
virtual std::string parameterDescription(size_t i)const = 0;
/// Checks if a parameter has been set explicitly
virtual bool isExplicitlySet(int i)const = 0;
......@@ -278,6 +284,8 @@ public:
virtual int indexOfActive(int i)const = 0;
/// Returns the name of active parameter i
virtual std::string nameOfActive(int i)const = 0;
/// Returns the name of active parameter i
virtual std::string descriptionOfActive(size_t i)const = 0;
/// Check if a declared parameter i is active
virtual bool isActive(int i)const = 0;
......
......@@ -68,7 +68,7 @@ public:
/// Set i-th parameter
virtual void setParameter(int, const double& value, bool explicitlySet = true);
/// Set i-th parameter description
virtual void setParameterDescription(int, const std::string& description);
virtual void setParameterDescription(size_t, const std::string& description);
/// Get i-th parameter
virtual double getParameter(int i)const;
/// Set parameter by name.
......@@ -86,7 +86,7 @@ public:
/// Returns the name of parameter i
virtual std::string parameterName(int i)const;
/// Returns the description of parameter i
virtual std::string parameterDescription(int i)const;
virtual std::string parameterDescription(size_t i)const;
/// Checks if a parameter has been set explicitly
virtual bool isExplicitlySet(int i)const;
......@@ -97,7 +97,7 @@ public:
/// Returns the name of active parameter i
virtual std::string nameOfActive(int i)const;
/// Returns the name of active parameter i
virtual std::string descriptionOfActive(int i)const;
virtual std::string descriptionOfActive(size_t i)const;
/// Check if a declared parameter i is active
virtual bool isActive(int i)const;
......
......@@ -121,6 +121,16 @@ void CompositeFunction::setParameter(int i, const double& value, bool explicitly
m_functions[ iFun ]->setParameter(i - m_paramOffsets[iFun],value,explicitlySet);
}
/** Sets a new description to the i-th parameter.
* @param i :: The parameter index
* @param description :: The new description
*/
void CompositeFunction::setParameterDescription(size_t i, const std::string& description)
{
int iFun = functionIndex(i);
m_functions[ iFun ]->setParameterDescription(i - m_paramOffsets[iFun],description);
}
/** Get the i-th parameter.
* @param i :: The parameter index
* @return value of the requested parameter
......@@ -150,6 +160,24 @@ void CompositeFunction::setParameter(const std::string& name, const double& valu
}
}
/**
* Sets a new description to a parameter by name.
* @param name :: The name of the parameter.
* @param value :: The new description
*/
void CompositeFunction::setParameterDescription(const std::string& name, const std::string& description)
{
std::string pname;
int index;
parseName(name,index,pname);
if (index < 0)
throw std::invalid_argument("CompositeFunction::getParameter: parameter name must contain function index");
else
{
getFunction(index)->setParameterDescription(pname,description);
}
}
/**
* Parameters by name.
* @param name :: The name of the parameter.
......@@ -201,6 +229,17 @@ std::string CompositeFunction::parameterName(int i)const
return ostr.str();
}
/// Returns the description of parameter
/// @param i :: The index
/// @return The description of the parameter
std::string CompositeFunction::parameterDescription(size_t i)const
{
int iFun = functionIndex(i);
std::ostringstream ostr;
ostr << m_functions[ iFun ]->parameterDescription(i - m_paramOffsets[iFun]);
return ostr.str();
}
/// Number of active (in terms of fitting) parameters
int CompositeFunction::nActive()const
{
......@@ -247,6 +286,15 @@ std::string CompositeFunction::nameOfActive(int i)const
return ostr.str();
}
/// Returns the description of active parameter i
std::string CompositeFunction::descriptionOfActive(size_t i)const
{
int iFun = functionIndexActive(i);
std::ostringstream ostr;
ostr << m_functions[ iFun ]->descriptionOfActive(i - m_activeOffsets[iFun]);
return ostr.str();
}
/**
* query to see in the function is active
* @param i :: The index of a declared parameter
......
......@@ -72,7 +72,7 @@ void ParamFunction::setParameter(int i, const double& value, bool explicitlySet)
* @param i :: The parameter index
* @param description :: New parameter description
*/
void ParamFunction::setParameterDescription(int i, const std::string& description)
void ParamFunction::setParameterDescription(size_t i, const std::string& description)
{
if (i >= nParams() || i < 0)
{
......@@ -193,7 +193,7 @@ std::string ParamFunction::parameterName(int i)const
* @param i :: The index of a parameter
* @return the description of the parameter at the requested index
*/
std::string ParamFunction::parameterDescription(int i)const
std::string ParamFunction::parameterDescription(size_t i)const
{
if (i >= nParams() || i < 0)
{
......@@ -256,7 +256,7 @@ std::string ParamFunction::nameOfActive(int i)const
* @param i :: The index of an active parameter
* @return the description of the active parameter
*/
std::string ParamFunction::descriptionOfActive(int i)const
std::string ParamFunction::descriptionOfActive(size_t i)const
{
return m_parameterDescriptions[indexOfActive(i)];
}
......
......@@ -18,7 +18,7 @@ class IFT_Funct: public ParamFunction, public IFunctionMW
public:
IFT_Funct()
{
declareParameter("c0");
declareParameter("c0", 0.0, "this is the famous c0 blah...");
declareParameter("c1");
declareParameter("c2");
declareParameter("c3");
......@@ -60,11 +60,15 @@ public:
{
IFT_Funct f;
TS_ASSERT_EQUALS(f.parameterDescription(0),"this is the famous c0 blah...");
f.setParameter("c0",1.0);
f.setParameter("c1",1.1);
f.setParameter("c2",1.2);
f.setParameter("c3",1.3);
TS_ASSERT_EQUALS(f.parameterDescription(0),"this is the famous c0 blah...");
TS_ASSERT_EQUALS(f.nParams(),4);
TS_ASSERT_EQUALS(f.nActive(),4);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment