Skip to content

Commit

Permalink
Re #4158. Refactored function interfaces to use domains and Values.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 2, 2012
1 parent 125eb67 commit a5af579
Show file tree
Hide file tree
Showing 30 changed files with 1,051 additions and 786 deletions.
17 changes: 7 additions & 10 deletions Code/Mantid/Framework/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ set ( SRC_FILES
src/CloneableAlgorithm.cpp
src/Column.cpp
src/ColumnFactory.cpp
src/CompositeDomainMD.cpp
src/CompositeFunction.cpp
src/CompositeFunctionMD.cpp
src/CompositeFunctionMW.cpp
src/ConstraintFactory.cpp
src/CoordTransform.cpp
src/CostFunctionFactory.cpp
Expand All @@ -27,14 +26,14 @@ set ( SRC_FILES
src/FileFinder.cpp
src/FileProperty.cpp
src/FrameworkManager.cpp
src/FunctionDomain.cpp
src/FunctionDomain1D.cpp
src/FunctionDomainMD.cpp
src/FunctionFactory.cpp
src/FunctionProperty.cpp
src/FunctionValues.cpp
src/IDataFileChecker.cpp
src/IEventList.cpp
src/IEventWorkspace.cpp
src/IFitFunction.cpp
src/IFunction.cpp
src/IFunctionMD.cpp
src/IFunction1D.cpp
Expand Down Expand Up @@ -78,7 +77,6 @@ set ( SRC_FILES
src/SpectraAxis.cpp
src/SpectraDetectorMap.cpp
src/TableRow.cpp
src/TempFunction.cpp
src/TextAxis.cpp
src/Workspace.cpp
src/WorkspaceFactory.cpp
Expand Down Expand Up @@ -115,8 +113,8 @@ set ( INC_FILES
inc/MantidAPI/Column.h
inc/MantidAPI/ColumnFactory.h
inc/MantidAPI/CompositeFunction.h
inc/MantidAPI/CompositeFunctionMD.h
inc/MantidAPI/CompositeFunctionMW.h
inc/MantidAPI/CompositeDomain.h
inc/MantidAPI/CompositeDomainMD.h
inc/MantidAPI/ConstraintFactory.h
inc/MantidAPI/CoordTransform.h
inc/MantidAPI/CostFunctionFactory.h
Expand All @@ -131,8 +129,10 @@ set ( INC_FILES
inc/MantidAPI/FrameworkManager.h
inc/MantidAPI/FunctionDomain.h
inc/MantidAPI/FunctionDomain1D.h
inc/MantidAPI/FunctionDomainMD.h
inc/MantidAPI/FunctionFactory.h
inc/MantidAPI/FunctionProperty.h
inc/MantidAPI/FunctionValues.h
inc/MantidAPI/IAlgorithm.h
inc/MantidAPI/IArchiveSearch.h
inc/MantidAPI/IBackgroundFunction.h
Expand All @@ -143,7 +143,6 @@ set ( INC_FILES
inc/MantidAPI/IDataItem.h
inc/MantidAPI/IEventList.h
inc/MantidAPI/IEventWorkspace.h
inc/MantidAPI/IFitFunction.h
inc/MantidAPI/IFunction.h
inc/MantidAPI/IFunctionMD.h
inc/MantidAPI/IFunction1D.h
Expand Down Expand Up @@ -197,7 +196,6 @@ set ( INC_FILES
inc/MantidAPI/SpectraAxis.h
inc/MantidAPI/SpectraDetectorMap.h
inc/MantidAPI/TableRow.h
inc/MantidAPI/TempFunction.h
inc/MantidAPI/TextAxis.h
inc/MantidAPI/VectorParameter.h
inc/MantidAPI/VectorParameterParser.h
Expand Down Expand Up @@ -256,7 +254,6 @@ set ( TEST_FILES
test/SampleTest.h
test/SpectraAxisTest.h
test/SpectraDetectorMapTest.h
test/TempFunctionTest.h
test/TextAxisTest.h
test/VectorParameterParserTest.h
test/VectorParameterTest.h
Expand Down
57 changes: 57 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/CompositeDomain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef MANTID_API_COMPOSITEDOMAIN_H_
#define MANTID_API_COMPOSITEDOMAIN_H_

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/DllConfig.h"
#include "MantidAPI/FunctionDomain.h"

#include <stdexcept>

namespace Mantid
{
namespace API
{
/** Base class that represents the domain of a function.
A domain is a generalisation of x (argument) and y (value) arrays.
A domain consists at least of a list of function arguments for which a function should
be evaluated and a buffer for the calculated values. If used in fitting also contains
the fit data and weights.
@author Roman Tolchenov, Tessella plc
@date 15/11/2011
Copyright &copy; 2009 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL CompositeDomain: public FunctionDomain
{
public:
/// Return the number of parts in the domain
virtual size_t getNParts() const = 0;
/// Return i-th domain
virtual const FunctionDomain& getDomain(size_t i) const = 0;
};

} // namespace API
} // namespace Mantid

#endif /*MANTID_API_COMPOSITEDOMAIN_H_*/
67 changes: 67 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/CompositeDomainMD.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef MANTID_API_COMPOSITEDOMAINMD_H_
#define MANTID_API_COMPOSITEDOMAINMD_H_

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/CompositeDomain.h"
#include "MantidAPI/IMDWorkspace.h"

#include <vector>

namespace Mantid
{
namespace API
{
class FunctionDomainMD;

/** Base class that represents the domain of a function.
A domain is a generalisation of x (argument) and y (value) arrays.
A domain consists at least of a list of function arguments for which a function should
be evaluated and a buffer for the calculated values. If used in fitting also contains
the fit data and weights.
@author Roman Tolchenov, Tessella plc
@date 15/11/2011
Copyright &copy; 2009 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL CompositeDomainMD: public CompositeDomain
{
public:
CompositeDomainMD(IMDWorkspace_const_sptr ws, size_t maxDomainSize);
~CompositeDomainMD();
/// Return the total number of arguments in the domain
virtual size_t size() const {return m_totalSize;}
/// Return the number of parts in the domain
virtual size_t getNParts() const {return m_domains.size();}
/// Return i-th domain
virtual const FunctionDomain& getDomain(size_t i) const;
protected:
mutable IMDIterator* m_iterator; ///< IMDIterator
size_t m_totalSize; ///< The total size of the domain
mutable std::vector<FunctionDomainMD*> m_domains; ///< smaller parts of the domain
};

} // namespace API
} // namespace Mantid

#endif /*MANTID_API_COMPOSITEDOMAINMD_H_*/
22 changes: 12 additions & 10 deletions Code/Mantid/Framework/API/inc/MantidAPI/CompositeFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IFitFunction.h"
#include "MantidAPI/IFunction.h"
#include "MantidAPI/Jacobian.h"
#include <boost/shared_array.hpp>

namespace Mantid
{
namespace API
{
class MatrixWorkspace;
/** A composite function.
@author Roman Tolchenov, Tessella Support Services plc
Expand All @@ -38,7 +37,7 @@ namespace API
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL CompositeFunction : public virtual IFitFunction
class MANTID_API_DLL CompositeFunction : public virtual IFunction
{
public:
/// Default constructor
Expand All @@ -52,8 +51,15 @@ class MANTID_API_DLL CompositeFunction : public virtual IFitFunction

/* Overriden methods */

/// Returns the function's name
virtual std::string name()const {return "CompositeFunction";}
/// Writes itself into a string
std::string asString()const;
/// 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;
/// Derivatives of function with respect to active parameters
virtual void functionDeriv(const FunctionDomain& domain, Jacobian& jacobian);

/// Set i-th parameter
void setParameter(size_t, const double& value, bool explicitlySet = true);
Expand Down Expand Up @@ -86,21 +92,17 @@ class MANTID_API_DLL CompositeFunction : public virtual IFitFunction
void setActiveParameter(size_t i, double value);
/// Update parameters after a fitting iteration
void updateActive(const double* in);
/// Returns "global" index of active parameter i
size_t indexOfActive(size_t i)const;
/// Returns the name of active parameter i
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 isActive(size_t i)const;
/// Get active index for a declared parameter i
size_t activeIndex(size_t i)const;
bool isFixed(size_t i)const;
/// Removes a parameter from the list of active
void removeActive(size_t i);
void fix(size_t i);
/// Restores a declared parameter i to the active status
void restoreActive(size_t i);
void unfix(size_t i);

/// Return parameter index from a parameter reference.
size_t getParameterIndex(const ParameterReference& ref)const;
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/API/inc/MantidAPI/ConstraintFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace API
// More forward declarations
//----------------------------------------------------------------------
class IConstraint;
class IFitFunction;
class IFunction;
class Expression;

/** @class Mantid::API::ConstraintFactoryImpl
Expand Down Expand Up @@ -68,13 +68,13 @@ namespace API
* @param input :: The creation expression
* @return A pointer to the created Constraint
*/
IConstraint* createInitialized(IFitFunction* fun, const std::string& input) const;
IConstraint* createInitialized(IFunction* fun, const std::string& input) const;
/**Creates an instance of a Constraint
* @param fun :: The function
* @param expr :: The creation expression
* @return A pointer to the created Constraint
*/
IConstraint* createInitialized(IFitFunction* fun, const Expression& expr) const;
IConstraint* createInitialized(IFunction* fun, const Expression& expr) const;

private:
friend struct Mantid::Kernel::CreateUsingNew<ConstraintFactoryImpl>;
Expand Down
30 changes: 5 additions & 25 deletions Code/Mantid/Framework/API/inc/MantidAPI/FunctionDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/Exception.h"

#include <vector>
#include <stdexcept>

namespace Mantid
{
Expand Down Expand Up @@ -45,31 +44,12 @@ namespace API
class MANTID_API_DLL FunctionDomain
{
public:
/// Constructor.
FunctionDomain(size_t n);
/// Virtual destructor
virtual ~FunctionDomain(){}
/// Return the number of points, values, etc in the domain
virtual size_t size() const {return m_calculated.size();}
/// store i-th calculated value. 0 <= i < size()
virtual void setCalculated(size_t i,double value) {m_calculated[i] = value;}
/// get i-th calculated value. 0 <= i < size()
virtual double getCalculated(size_t i) const {return m_calculated[i];}
/// set a fitting data value
virtual void setFitData(size_t i,double value);
virtual void setFitData(const std::vector<double>& values);
/// get a fitting data value
virtual double getFitData(size_t i) const;
/// set a fitting weight
virtual void setFitWeight(size_t i,double value);
virtual void setFitWeights(const std::vector<double>& values);
/// get a fitting weight
virtual double getFitWeight(size_t i) const;
protected:
void setDataSize();
std::vector<double> m_calculated; ///< buffer for calculated values
std::vector<double> m_data; ///< buffer for fit data
std::vector<double> m_weights; ///< buffer for fitting weights (reciprocal errors)
/// Return the number of points in the domain
virtual size_t size() const = 0;
/// Reset the the domain so it can be reused. Implement this method for domains with a state.
virtual void reset() const {}
};

} // namespace API
Expand Down
6 changes: 4 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/FunctionDomain1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class MANTID_API_DLL FunctionDomain1D: public FunctionDomain
{
public:
FunctionDomain1D(const std::vector<double>& xvalues);
/// get an x value
/// Return the number of arguments in the domain
virtual size_t size() const {return m_X.size();}
/// Get an x value.
/// @param i :: Index
double getX(size_t i) const {return m_X.at(i);}
const double* operator[](size_t i) const {return &m_X.at(i);}
protected:
std::vector<double> m_X; ///< vector of function arguments
};
Expand Down

0 comments on commit a5af579

Please sign in to comment.