Skip to content

Commit

Permalink
Re #4158. Changed the way active parameters are indexed.
Browse files Browse the repository at this point in the history
They are indexed from 0 to nParams(). Any fitting code will have to check if they are actually active
with isActive() method. isActive() could be not equal to !isFixed() if active parameters are overriden.
  • Loading branch information
mantid-roman committed Apr 2, 2012
1 parent cd16b57 commit 18d2aa5
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 399 deletions.
38 changes: 19 additions & 19 deletions Code/Mantid/Framework/API/inc/MantidAPI/CompositeFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MANTID_API_DLL CompositeFunction : public virtual IFunction
{
public:
/// Default constructor
CompositeFunction():m_nActive(0),m_nParams(0){}
CompositeFunction():/*m_nActive(0),*/m_nParams(0){}
/// Copy contructor
CompositeFunction(const CompositeFunction&);
///Assignment operator
Expand Down Expand Up @@ -84,8 +84,13 @@ class MANTID_API_DLL CompositeFunction : public virtual IFunction
/// Checks if a parameter has been set explicitly
bool isExplicitlySet(size_t i)const;

/// Number of active (in terms of fitting) parameters
size_t nActive()const;
/// Check if a parameter is active
bool isFixed(size_t i)const;
/// Removes a parameter from the list of active
void fix(size_t i);
/// Restores a declared parameter i to the active status
void unfix(size_t i);

/// Value of i-th active parameter. Override this method to make fitted parameters different from the declared
double activeParameter(size_t i)const;
/// Set new value of i-th active parameter. Override this method to make fitted parameters different from the declared
Expand All @@ -96,13 +101,8 @@ class MANTID_API_DLL CompositeFunction : public virtual IFunction
std::string nameOfActive(size_t i)const;
/// Returns the name of active parameter i
std::string descriptionOfActive(size_t i)const;

/// Check if a parameter is active
bool isFixed(size_t i)const;
/// Removes a parameter from the list of active
void fix(size_t i);
/// Restores a declared parameter i to the active status
void unfix(size_t i);
/// Check if an active parameter i is actually active
bool isActive(size_t i)const;

/// Return parameter index from a parameter reference.
size_t getParameterIndex(const ParameterReference& ref)const;
Expand Down Expand Up @@ -148,7 +148,7 @@ class MANTID_API_DLL CompositeFunction : public virtual IFunction
/// Get the function index
std::size_t functionIndex(std::size_t i)const;
/// Get the function index
std::size_t functionIndexActive(std::size_t i)const;
//std::size_t functionIndexActive(std::size_t i)const;
/// Returns the index of parameter i as it declared in its function
size_t parameterLocalIndex(size_t i)const;
/// Returns the name of parameter i as it declared in its function
Expand All @@ -165,7 +165,7 @@ class MANTID_API_DLL CompositeFunction : public virtual IFunction
virtual void addTie(ParameterTie* tie);

size_t paramOffset(size_t i)const{return m_paramOffsets[i];}
size_t activeOffset(size_t i)const{return m_activeOffsets[i];}
//size_t activeOffset(size_t i)const{return m_activeOffsets[i];}

private:

Expand All @@ -176,16 +176,16 @@ class MANTID_API_DLL CompositeFunction : public virtual IFunction
std::vector<IFunction_sptr> m_functions;
/// Individual function parameter offsets (function index in m_functions)
/// e.g. m_functions[i]->activeParameter(m_activeOffsets[i]+1) gives second active parameter of i-th function
std::vector<size_t> m_activeOffsets;
//std::vector<size_t> m_activeOffsets;
/// Individual function parameter offsets (function index in m_functions)
/// e.g. m_functions[i]->parameter(m_paramOffsets[i]+1) gives second declared parameter of i-th function
std::vector<size_t> m_paramOffsets;
/// Keeps the function index for each declared parameter (parameter declared index)
std::vector<size_t> m_IFunction;
/// Keeps the function index for each active parameter (parameter active index)
std::vector<size_t> m_IFunctionActive;
//std::vector<size_t> m_IFunctionActive;
/// Number of active parameters
size_t m_nActive;
//size_t m_nActive;
/// Total number of parameters
size_t m_nParams;
/// Function counter to be used in nextConstraint
Expand All @@ -204,14 +204,14 @@ class PartialJacobian: public Jacobian
{
Jacobian* m_J; ///< pointer to the overall Jacobian
size_t m_iP0; ///< offset in the overall Jacobian for a particular function
size_t m_iaP0; ///< offset in the active Jacobian for a particular function
//size_t m_iaP0; ///< offset in the active Jacobian for a particular function
public:
/** Constructor
* @param J :: A pointer to the overall Jacobian
* @param iP0 :: The parameter index (declared) offset for a particular function
* @param iap0 :: The active parameter index (declared) offset for a particular function
*/
PartialJacobian(Jacobian* J,size_t iP0, size_t iap0):m_J(J),m_iP0(iP0),m_iaP0(iap0)
PartialJacobian(Jacobian* J,size_t iP0):m_J(J),m_iP0(iP0)//,m_iaP0(iap0)
{}
/**
* Overridden Jacobian::set(...).
Expand All @@ -236,9 +236,9 @@ class PartialJacobian: public Jacobian
* @param value :: Value to add
* @param iActiveP :: The index of an active parameter.
*/
virtual void addNumberToColumn(const double& value, const size_t& iActiveP)
virtual void addNumberToColumn(const double& value, const size_t& iP)
{
m_J->addNumberToColumn(value,m_iaP0+iActiveP);
m_J->addNumberToColumn(value,m_iP0+iP);
}
};

Expand Down
35 changes: 20 additions & 15 deletions Code/Mantid/Framework/API/inc/MantidAPI/IFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,12 @@ class MANTID_API_DLL IFunction

/// Function you want to fit to.
/// @param domain :: The buffer for writing the calculated values. Must be big enough to accept dataSize() values
virtual void function(const FunctionDomain& domain,FunctionValues& values)const = 0;
virtual void function(const FunctionDomain& domain, FunctionValues& values)const = 0;
/// Derivatives of function with respect to active parameters
virtual void functionDeriv(const FunctionDomain& domain, Jacobian& jacobian);

/** @name Function parameters */
//@{
/// Set i-th parameter
virtual void setParameter(size_t, const double& value, bool explicitlySet = true) = 0;
/// Set i-th parameter description
Expand All @@ -274,28 +276,31 @@ class MANTID_API_DLL IFunction
/// Checks if a parameter has been set explicitly
virtual bool isExplicitlySet(size_t i)const = 0;

/// Number of active (in terms of fitting) parameters
virtual size_t nActive()const = 0;
/// Value of i-th active parameter. Override this method to make fitted parameters different from the declared
virtual double activeParameter(size_t i)const = 0;
/// Set new value of i-th active parameter. Override this method to make fitted parameters different from the declared
virtual void setActiveParameter(size_t i, double value) = 0;
/// Returns the name of active parameter i
virtual std::string nameOfActive(size_t 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
/// Check if a declared parameter i is fixed
virtual bool isFixed(size_t i)const = 0;
/// Get active index for a declared parameter i
//virtual size_t activeIndex(size_t i)const = 0;
/// Removes a declared parameter i from the list of active
virtual void fix(size_t i) = 0;
/// Restores a declared parameter i to the active status
virtual void unfix(size_t i) = 0;

/// Return parameter index from a parameter reference. Usefull for constraints and ties in composite functions
virtual size_t getParameterIndex(const ParameterReference& ref)const = 0;
//@}

/** @name Active parameters */
//@{
/// Value of i-th active parameter. Override this method to make fitted parameters different from the declared
virtual double activeParameter(size_t i)const;
/// Set new value of i-th active parameter. Override this method to make fitted parameters different from the declared
virtual void setActiveParameter(size_t i, double value);
/// Returns the name of active parameter i
virtual std::string nameOfActive(size_t i)const;
/// Returns the name of active parameter i
virtual std::string descriptionOfActive(size_t i)const;
/// Check if an active parameter i is actually active
virtual bool isActive(size_t i)const {return !isFixed(i);}
//@}


/// Tie a parameter to other parameters (or a constant)
virtual ParameterTie* tie(const std::string& parName, const std::string& expr);
Expand Down
13 changes: 1 addition & 12 deletions Code/Mantid/Framework/API/inc/MantidAPI/ParamFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,6 @@ class MANTID_API_DLL ParamFunction : public virtual IFunction
/// Checks if a parameter has been set explicitly
virtual bool isExplicitlySet(size_t i)const;

/// Number of active (in terms of fitting) parameters
virtual size_t nActive()const{return m_indexMap.size();}
/// Value of i-th active parameter. Override this method to make fitted parameters different from the declared
virtual double activeParameter(size_t i)const;
/// Set new value of i-th active parameter. Override this method to make fitted parameters different from the declared
virtual void setActiveParameter(size_t i, double value);
/// Returns the name of active parameter i
virtual std::string nameOfActive(size_t i)const;
/// Returns the name of active parameter i
virtual std::string descriptionOfActive(size_t i)const;

/// Check if a declared parameter i is active
virtual bool isFixed(size_t i)const;
/// Removes a declared parameter i from the list of active
Expand Down Expand Up @@ -155,7 +144,7 @@ class MANTID_API_DLL ParamFunction : public virtual IFunction

private:
/// The index map. m_indexMap[i] gives the total index for active parameter i
std::vector<size_t> m_indexMap;
std::vector<bool> m_isFixed;
/// Keeps parameter names
std::vector<std::string> m_parameterNames;
/// Keeps parameter values
Expand Down

0 comments on commit 18d2aa5

Please sign in to comment.