diff --git a/Framework/CurveFitting/CMakeLists.txt b/Framework/CurveFitting/CMakeLists.txt index 366cbcc0e3ef8676f4bca89f3c0b9799d2a56ab7..65770666d1efc315f6585a940a8d1979a6693d29 100644 --- a/Framework/CurveFitting/CMakeLists.txt +++ b/Framework/CurveFitting/CMakeLists.txt @@ -4,10 +4,10 @@ set ( SRC_FILES # src/ChebyshevPolynomialBackground.cpp #src/RefinePowderInstrumentParameters.cpp src/AugmentedLagrangianOptimizer.cpp - src/BoundaryConstraint.cpp src/CalculateChiSquared.cpp src/CalculateGammaBackground.cpp src/CalculateMSVesuvio.cpp + src/Constraints/BoundaryConstraint.cpp src/ConvertToYSpace.cpp src/ConvolveWorkspaces.cpp src/CostFunctions/CostFuncFitting.cpp @@ -125,10 +125,10 @@ set ( INC_FILES # inc/MantidCurveFitting/ChebyshevPolynomialBackground.h #inc/MantidCurveFitting/RefinePowderInstrumentParameters.h inc/MantidCurveFitting/AugmentedLagrangianOptimizer.h - inc/MantidCurveFitting/BoundaryConstraint.h inc/MantidCurveFitting/CalculateChiSquared.h inc/MantidCurveFitting/CalculateGammaBackground.h inc/MantidCurveFitting/CalculateMSVesuvio.h + inc/MantidCurveFitting/Constraints/BoundaryConstraint.h inc/MantidCurveFitting/ConvertToYSpace.h inc/MantidCurveFitting/ConvolveWorkspaces.h inc/MantidCurveFitting/CostFunctions/CostFuncFitting.h @@ -246,43 +246,21 @@ set ( TEST_FILES # ChebyshevPolynomialBackgroundTest.h # RefinePowderInstrumentParametersTest.h #SCDPanelErrorsTest.h - Functions/AbragamTest.h AugmentedLagrangianOptimizerTest.h - Functions/BSplineTest.h - Functions/BackToBackExponentialTest.h - Functions/BivariateNormalTest.h - Functions/Bk2BkExpConvPVTest.h - BoundaryConstraintTest.h + Constraints/BoundaryConstraintTest.h CalculateChiSquaredTest.h CalculateGammaBackgroundTest.h CalculateMSVesuvioTest.h - Functions/ChebfunBaseTest.h - Functions/ChebyshevTest.h CompositeFunctionTest.h - Functions/ComptonPeakProfileTest.h - Functions/ComptonProfileTest.h - Functions/ComptonScatteringCountRateTest.h ConvertToYSpaceTest.h - Functions/ConvolutionTest.h ConvolveWorkspacesTest.h CostFunctions/CostFuncUnweightedLeastSquaresTest.h CostFunctions/LeastSquaresTest.h - Functions/CubicSplineTest.h - Functions/DeltaFunctionTest.h - Functions/DiffRotDiscreteCircleTest.h - Functions/DiffSphereTest.h - Functions/DynamicKuboToyabeTest.h - Functions/EndErfcTest.h EstimatePeakErrorsTest.h EvaluateFunctionTest.h - Functions/ExpDecayMuonTest.h - Functions/ExpDecayOscTest.h - Functions/ExpDecayTest.h FitMWTest.h FitPowderDiffPeaksTest.h FitTest.h - Functions/FlatBackgroundTest.h - Functions/FullprofPolynomialTest.h FuncMinimizers/BFGSTest.h FuncMinimizers/DampingMinimizerTest.h FuncMinimizers/FABADAMinimizerTest.h @@ -294,34 +272,42 @@ set ( TEST_FILES FunctionDomain1DSpectrumCreatorTest.h FunctionFactoryConstraintTest.h FunctionParameterDecoratorFitTest.h - GSLMatrixTest.h - GSLVectorTest.h + Functions/AbragamTest.h + Functions/BSplineTest.h + Functions/BackToBackExponentialTest.h + Functions/BivariateNormalTest.h + Functions/Bk2BkExpConvPVTest.h + Functions/ChebfunBaseTest.h + Functions/ChebyshevTest.h + Functions/ComptonPeakProfileTest.h + Functions/ComptonProfileTest.h + Functions/ComptonScatteringCountRateTest.h + Functions/ConvolutionTest.h + Functions/CubicSplineTest.h + Functions/DeltaFunctionTest.h + Functions/DiffRotDiscreteCircleTest.h + Functions/DiffSphereTest.h + Functions/DynamicKuboToyabeTest.h + Functions/EndErfcTest.h + Functions/ExpDecayMuonTest.h + Functions/ExpDecayOscTest.h + Functions/ExpDecayTest.h + Functions/FlatBackgroundTest.h + Functions/FullprofPolynomialTest.h Functions/GausDecayTest.h Functions/GausOscTest.h Functions/GaussianComptonProfileTest.h Functions/GaussianTest.h Functions/GramCharlierComptonProfileTest.h - IPeakFunctionCentreParameterNameTest.h - IPeakFunctionIntensityTest.h Functions/IkedaCarpenterPVTest.h - LatticeDomainCreatorTest.h - LatticeFunctionTest.h - LeBailFitTest.h - LeBailFunctionTest.h Functions/LinearBackgroundTest.h Functions/LogNormalTest.h Functions/Lorentzian1DTest.h Functions/LorentzianTest.h - MultiDomainCreatorTest.h - MultiDomainFunctionTest.h Functions/MuonFInteractionTest.h Functions/NeutronBk2BkExpConvPVoigtTest.h - NormaliseByPeakAreaTest.h - ParameterEstimatorTest.h - PawleyFitTest.h Functions/PawleyFunctionTest.h Functions/PeakParameterFunctionTest.h - PlotPeakByLogValueTest.h Functions/PolynomialTest.h Functions/ProcessBackgroundTest.h Functions/ProductFunctionTest.h @@ -329,15 +315,9 @@ set ( TEST_FILES Functions/ProductQuadraticExpTest.h Functions/PseudoVoigtTest.h Functions/QuadraticTest.h - RefinePowderInstrumentParameters3Test.h Functions/ReflectivityMulfTest.h Functions/ResolutionTest.h - SeqDomainSpectrumCreatorTest.h Functions/SimpleChebfunTest.h - SpecialFunctionSupportTest.h - SplineBackgroundTest.h - SplineInterpolationTest.h - SplineSmoothingTest.h Functions/StaticKuboToyabeTest.h Functions/StaticKuboToyabeTimesExpDecayTest.h Functions/StaticKuboToyabeTimesGausDecayTest.h @@ -353,6 +333,26 @@ set ( TEST_FILES Functions/UserFunctionTest.h Functions/VesuvioResolutionTest.h Functions/VoigtTest.h + GSLMatrixTest.h + GSLVectorTest.h + IPeakFunctionCentreParameterNameTest.h + IPeakFunctionIntensityTest.h + LatticeDomainCreatorTest.h + LatticeFunctionTest.h + LeBailFitTest.h + LeBailFunctionTest.h + MultiDomainCreatorTest.h + MultiDomainFunctionTest.h + NormaliseByPeakAreaTest.h + ParameterEstimatorTest.h + PawleyFitTest.h + PlotPeakByLogValueTest.h + RefinePowderInstrumentParameters3Test.h + SeqDomainSpectrumCreatorTest.h + SpecialFunctionSupportTest.h + SplineBackgroundTest.h + SplineInterpolationTest.h + SplineSmoothingTest.h ) if (COVERALLS) diff --git a/Framework/CurveFitting/inc/MantidCurveFitting/BoundaryConstraint.h b/Framework/CurveFitting/inc/MantidCurveFitting/Constraints/BoundaryConstraint.h similarity index 98% rename from Framework/CurveFitting/inc/MantidCurveFitting/BoundaryConstraint.h rename to Framework/CurveFitting/inc/MantidCurveFitting/Constraints/BoundaryConstraint.h index 2b3301fa8ea844eea8951a2583b47df936d45c83..ef798c50e1afbe87ad21d94ee77fdd088c0bfa47 100644 --- a/Framework/CurveFitting/inc/MantidCurveFitting/BoundaryConstraint.h +++ b/Framework/CurveFitting/inc/MantidCurveFitting/Constraints/BoundaryConstraint.h @@ -8,6 +8,7 @@ namespace Mantid { namespace CurveFitting { +namespace Constraints { //---------------------------------------------------------------------- // Forward Declaration //---------------------------------------------------------------------- @@ -142,6 +143,7 @@ private: double m_upperBound; }; +} // namespace Constraints } // namespace CurveFitting } // namespace Mantid diff --git a/Framework/CurveFitting/inc/MantidCurveFitting/Functions/BivariateNormal.h b/Framework/CurveFitting/inc/MantidCurveFitting/Functions/BivariateNormal.h index 821eb0f3bbf18a631bec8a856184b07c39ab15d3..59fd0db97239581ebaa53d4a3a430e70b2536390 100644 --- a/Framework/CurveFitting/inc/MantidCurveFitting/Functions/BivariateNormal.h +++ b/Framework/CurveFitting/inc/MantidCurveFitting/Functions/BivariateNormal.h @@ -9,7 +9,7 @@ #include "MantidAPI/IFunction1D.h" #include "MantidAPI/ParamFunction.h" #include "MantidKernel/cow_ptr.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" namespace Mantid { namespace CurveFitting { diff --git a/Framework/CurveFitting/inc/MantidCurveFitting/RefinePowderInstrumentParameters3.h b/Framework/CurveFitting/inc/MantidCurveFitting/RefinePowderInstrumentParameters3.h index f60697f358590b6f1a45a561676230521fb90fd4..46cbed993a578cf530235ec39e26daff51c12d6b 100644 --- a/Framework/CurveFitting/inc/MantidCurveFitting/RefinePowderInstrumentParameters3.h +++ b/Framework/CurveFitting/inc/MantidCurveFitting/RefinePowderInstrumentParameters3.h @@ -10,7 +10,7 @@ #include "MantidCurveFitting/LeBailFit.h" #include "MantidCurveFitting/Functions/ThermalNeutronDtoTOFFunction.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" namespace Mantid { namespace CurveFitting { diff --git a/Framework/CurveFitting/src/BoundaryConstraint.cpp b/Framework/CurveFitting/src/Constraints/BoundaryConstraint.cpp similarity index 98% rename from Framework/CurveFitting/src/BoundaryConstraint.cpp rename to Framework/CurveFitting/src/Constraints/BoundaryConstraint.cpp index 6ecbe020e781f48f2adbc63862c2ddb45fd067e5..86f3f52be2a7fe4549198c0a4926b5a0c3d1074a 100644 --- a/Framework/CurveFitting/src/BoundaryConstraint.cpp +++ b/Framework/CurveFitting/src/Constraints/BoundaryConstraint.cpp @@ -1,7 +1,7 @@ //---------------------------------------------------------------------- // Includes //---------------------------------------------------------------------- -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidAPI/Expression.h" #include "MantidAPI/ConstraintFactory.h" #include "MantidKernel/Logger.h" @@ -10,6 +10,7 @@ namespace Mantid { namespace CurveFitting { +namespace Constraints { namespace { /// static logger Kernel::Logger g_log("BoundaryConstraint"); @@ -247,5 +248,6 @@ std::string BoundaryConstraint::asString() const { return ostr.str(); } +} // namespace Constraints } // namespace CurveFitting } // namespace Mantid diff --git a/Framework/CurveFitting/src/DampingMinimizer.cpp b/Framework/CurveFitting/src/DampingMinimizer.cpp deleted file mode 100644 index 01e3169ebba8d9a0d3587a6d30143796d1de82f0..0000000000000000000000000000000000000000 --- a/Framework/CurveFitting/src/DampingMinimizer.cpp +++ /dev/null @@ -1,125 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidCurveFitting/DampingMinimizer.h" -#include "MantidCurveFitting/CostFuncLeastSquares.h" - -#include "MantidAPI/CostFunctionFactory.h" -#include "MantidAPI/FuncMinimizerFactory.h" -#include "MantidAPI/IFunction.h" - -#include "MantidKernel/Logger.h" - -#include <boost/lexical_cast.hpp> -#include <gsl/gsl_blas.h> -#include <iostream> -#include <cmath> - -namespace Mantid { -namespace CurveFitting { -namespace { -/// static logger -Kernel::Logger g_log("DampingMinimizer"); -} - -DECLARE_FUNCMINIMIZER(DampingMinimizer, Damping) - -/// Constructor -DampingMinimizer::DampingMinimizer(double relTol) - : IFuncMinimizer(), m_relTol(relTol) { - declareProperty("Damping", 0.0, "The damping parameter."); -} - -/// Initialize minimizer, i.e. pass a function to minimize. -void DampingMinimizer::initialize(API::ICostFunction_sptr function, size_t) { - m_leastSquares = boost::dynamic_pointer_cast<CostFuncLeastSquares>(function); - if (!m_leastSquares) { - throw std::invalid_argument("Damping minimizer works only with least " - "squares. Different function was given."); - } -} - -/// Do one iteration. -bool DampingMinimizer::iterate(size_t) { - const bool debug = false; - - const double damping = getProperty("Damping"); - - if (!m_leastSquares) { - throw std::runtime_error("Cost function isn't set up."); - } - size_t n = m_leastSquares->nParams(); - - if (n == 0) { - m_errorString = "No parameters to fit"; - return false; - } - - // calculate the first and second derivatives of the cost function. - m_leastSquares->valDerivHessian(); - - // copy the hessian - GSLMatrix H(m_leastSquares->getHessian()); - GSLVector dd(m_leastSquares->getDeriv()); - - for (size_t i = 0; i < n; ++i) { - double tmp = H.get(i, i) + damping; - H.set(i, i, tmp); - } - - if (debug) { - std::cerr << "H:\n" << H; - std::cerr << "-----------------------------\n"; - for (size_t j = 0; j < n; ++j) { - std::cerr << dd.get(j) << ' '; - } - std::cerr << std::endl; - } - - /// Parameter corrections - GSLVector dx(n); - // To find dx solve the system of linear equations H * dx == -m_der - dd *= -1.0; - H.solve(dd, dx); - - if (debug) { - for (size_t j = 0; j < n; ++j) { - std::cerr << dx.get(j) << ' '; - } - std::cerr << std::endl - << std::endl; - } - - // Update the parameters of the cost function. - for (size_t i = 0; i < n; ++i) { - double d = m_leastSquares->getParameter(i) + dx.get(i); - m_leastSquares->setParameter(i, d); - if (debug) { - std::cerr << "P" << i << ' ' << d << std::endl; - } - } - m_leastSquares->getFittingFunction()->applyTies(); - - // --- prepare for the next iteration --- // - - // Try the stop condition - GSLVector p(n); - m_leastSquares->getParameters(p); - double dx_norm = gsl_blas_dnrm2(dx.gsl()); - if (dx_norm < m_relTol) { - return false; - } - - return true; -} - -/// Return current value of the cost function -double DampingMinimizer::costFunctionVal() { - if (!m_leastSquares) { - throw std::runtime_error("Cost function isn't set up."); - } - return m_leastSquares->val(); -} - -} // namespace CurveFitting -} // namespace Mantid diff --git a/Framework/CurveFitting/src/DerivMinimizer.cpp b/Framework/CurveFitting/src/DerivMinimizer.cpp deleted file mode 100644 index 57cbc5a122fcbce37b30629977b8cc9c6dcc0dc0..0000000000000000000000000000000000000000 --- a/Framework/CurveFitting/src/DerivMinimizer.cpp +++ /dev/null @@ -1,177 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidCurveFitting/DerivMinimizer.h" -#include "MantidCurveFitting/CostFuncFitting.h" - -namespace Mantid { -namespace CurveFitting { - -/** Used by the GSL to calculate the cost function. - * @param x :: Vector with parameters - * @param params :: Pointer to a DerivMinimizer - */ -double DerivMinimizer::fun(const gsl_vector *x, void *params) { - DerivMinimizer &minimizer = *static_cast<DerivMinimizer *>(params); - size_t n = minimizer.m_costFunction->nParams(); - for (size_t i = 0; i < n; ++i) { - minimizer.m_costFunction->setParameter(i, gsl_vector_get(x, i)); - } - boost::shared_ptr<CostFuncFitting> fitting = - boost::dynamic_pointer_cast<CostFuncFitting>(minimizer.m_costFunction); - if (fitting) { - fitting->getFittingFunction()->applyTies(); - } - return minimizer.m_costFunction->val(); -} - -/** Used by the GSL to calculate the derivatives. - * @param x :: Vector with parameters - * @param params :: Pointer to a DerivMinimizer - * @param g :: Buffer for the derivatives - */ -void DerivMinimizer::dfun(const gsl_vector *x, void *params, gsl_vector *g) { - DerivMinimizer &minimizer = *static_cast<DerivMinimizer *>(params); - size_t n = minimizer.m_costFunction->nParams(); - for (size_t i = 0; i < n; ++i) { - minimizer.m_costFunction->setParameter(i, gsl_vector_get(x, i)); - } - boost::shared_ptr<CostFuncFitting> fitting = - boost::dynamic_pointer_cast<CostFuncFitting>(minimizer.m_costFunction); - if (fitting) { - fitting->getFittingFunction()->applyTies(); - } - std::vector<double> der(n); - minimizer.m_costFunction->deriv(der); - for (size_t i = 0; i < n; ++i) { - gsl_vector_set(g, i, der[i]); - } -} - -/** Used by the GSL to calculate the cost function and the derivatives. - * @param x :: Vector with parameters - * @param params :: Pointer to a DerivMinimizer - * @param f :: Buffer for the fanction value - * @param g :: Buffer for the derivatives - */ -void DerivMinimizer::fundfun(const gsl_vector *x, void *params, double *f, - gsl_vector *g) { - DerivMinimizer &minimizer = *static_cast<DerivMinimizer *>(params); - size_t n = minimizer.m_costFunction->nParams(); - for (size_t i = 0; i < n; ++i) { - minimizer.m_costFunction->setParameter(i, gsl_vector_get(x, i)); - } - boost::shared_ptr<CostFuncFitting> fitting = - boost::dynamic_pointer_cast<CostFuncFitting>(minimizer.m_costFunction); - if (fitting) { - fitting->getFittingFunction()->applyTies(); - } - std::vector<double> der(n); - *f = minimizer.m_costFunction->valAndDeriv(der); - for (size_t i = 0; i < n; ++i) { - gsl_vector_set(g, i, der[i]); - } -} - -/// Constructor -DerivMinimizer::DerivMinimizer() - : m_gslSolver(NULL), m_x(NULL), m_stopGradient(1e-3), m_stepSize(0.1), - m_tolerance(0.0001) { - initGSLMMin(); -} - -/** - * Constructor. - * @param stepSize :: Initial step size. - * @param tolerance :: Tolerance. - */ -DerivMinimizer::DerivMinimizer(const double stepSize, const double tolerance) - : m_gslSolver(NULL), m_x(NULL), m_stopGradient(1e-3), m_stepSize(stepSize), - m_tolerance(tolerance) { - initGSLMMin(); -} - -void DerivMinimizer::initGSLMMin() { - m_gslMultiminContainer.f = NULL; - m_gslMultiminContainer.df = NULL; - m_gslMultiminContainer.fdf = NULL; - m_gslMultiminContainer.n = 0; - m_gslMultiminContainer.params = NULL; -} - -/** - * Destructor. - */ -DerivMinimizer::~DerivMinimizer() { - if (m_gslSolver != NULL) { - gsl_multimin_fdfminimizer_free(m_gslSolver); - gsl_vector_free(m_x); - } -} - -/** - * Initialize the minimizer. - * @param function :: A cost function to minimize. - * @param maxIterations :: Maximum number of iterations. - */ -void DerivMinimizer::initialize(API::ICostFunction_sptr function, - size_t maxIterations) { - UNUSED_ARG(maxIterations); - m_costFunction = function; - m_gslMultiminContainer.n = m_costFunction->nParams(); - m_gslMultiminContainer.f = &fun; - m_gslMultiminContainer.df = &dfun; - m_gslMultiminContainer.fdf = &fundfun; - m_gslMultiminContainer.params = this; - - m_gslSolver = gsl_multimin_fdfminimizer_alloc(getGSLMinimizerType(), - m_gslMultiminContainer.n); - - size_t nParams = m_costFunction->nParams(); - // Starting point - m_x = gsl_vector_alloc(nParams); - for (size_t i = 0; i < nParams; ++i) { - gsl_vector_set(m_x, i, m_costFunction->getParameter(i)); - } - - gsl_multimin_fdfminimizer_set(m_gslSolver, &m_gslMultiminContainer, m_x, - m_stepSize, m_tolerance); -} - -/** - * Perform one iteration. - * @return :: true to continue, false to stop. - */ -bool DerivMinimizer::iterate(size_t) { - if (m_gslSolver == NULL) { - throw std::runtime_error("Minimizer " + this->name() + - " was not initialized."); - } - int status = gsl_multimin_fdfminimizer_iterate(m_gslSolver); - if (status) { - m_errorString = gsl_strerror(status); - return false; - } - status = gsl_multimin_test_gradient(m_gslSolver->gradient, m_stopGradient); - if (status != GSL_CONTINUE) { - m_errorString = gsl_strerror(status); - return false; - } - return true; -} - -/** - * Set maximum value of the gradient at which iterations can stop - * @param value :: New value for the gradient, must be positive. - */ -void DerivMinimizer::setStopGradient(const double value) { - if (value <= 0) { - throw std::invalid_argument("Gradient norm must be a positive number"); - } - m_stopGradient = value; -} - -double DerivMinimizer::costFunctionVal() { return m_gslSolver->f; } - -} // namespace CurveFitting -} // namespace Mantid diff --git a/Framework/CurveFitting/src/FABADAMinimizer.cpp b/Framework/CurveFitting/src/FABADAMinimizer.cpp deleted file mode 100644 index 8e8f7e3d70838d4d8dfaa06d2010a61b5954d7bc..0000000000000000000000000000000000000000 --- a/Framework/CurveFitting/src/FABADAMinimizer.cpp +++ /dev/null @@ -1,645 +0,0 @@ -#include "MantidCurveFitting/FABADAMinimizer.h" -#include "MantidCurveFitting/CostFuncLeastSquares.h" -#include "MantidCurveFitting/BoundaryConstraint.h" - -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -#include "MantidAPI/CostFunctionFactory.h" -#include "MantidAPI/FuncMinimizerFactory.h" -#include "MantidAPI/IFunction.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/WorkspaceProperty.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/TableRow.h" -#include "MantidKernel/MersenneTwister.h" -#include "MantidKernel/PseudoRandomNumberGenerator.h" - -#include "MantidKernel/Logger.h" - -#include <boost/random/normal_distribution.hpp> -#include <boost/random/uniform_real.hpp> -#include <boost/random/mersenne_twister.hpp> -#include <boost/version.hpp> -#include <boost/math/special_functions/fpclassify.hpp> - -#include <iostream> -#include <ctime> - -namespace Mantid { -namespace CurveFitting { - -namespace { -// static logger object -Kernel::Logger g_log("FABADAMinimizer"); -// absolute maximum number of iterations when fit must converge -const size_t convergenceMaxIterations = 50000; -// number of iterations when convergence isn't expected -const size_t lowerIterationLimit = 350; -// very large number -const double largeNumber = 1e100; -// jump checking rate -const size_t jumpCheckingRate = 200; -// low jump limit -const double lowJumpLimit = 1e-25; -} - -DECLARE_FUNCMINIMIZER(FABADAMinimizer, FABADA) - -//---------------------------------------------------------------------------------------------- -/// Constructor -FABADAMinimizer::FABADAMinimizer() - : m_counter(0), m_numberIterations(0), m_changes(), m_jump(), - m_parameters(), m_chain(), m_chi2(0.), m_converged(false), - m_conv_point(0), m_par_converged(), m_lower(), m_upper(), m_bound(), - m_criteria(), m_max_iter(0) { - declareProperty("ChainLength", static_cast<size_t>(10000), - "Length of the converged chain."); - declareProperty("StepsBetweenValues", static_cast<size_t>(10), - "Steps realized between keeping each result."); - declareProperty( - "ConvergenceCriteria", 0.01, - "Variance in Cost Function for considering convergence reached."); - declareProperty("JumpAcceptanceRate", 0.6666666, - "Desired jumping acceptance rate"); - declareProperty( - new API::WorkspaceProperty<>("PDF", "PDF", Kernel::Direction::Output), - "The name to give the output workspace"); - declareProperty( - new API::WorkspaceProperty<>("Chains", "", Kernel::Direction::Output), - "The name to give the output workspace"); - declareProperty(new API::WorkspaceProperty<>("ConvergedChain", "", - Kernel::Direction::Output, - API::PropertyMode::Optional), - "The name to give the output workspace"); - declareProperty(new API::WorkspaceProperty<API::ITableWorkspace>( - "CostFunctionTable", "", Kernel::Direction::Output), - "The name to give the output workspace"); - declareProperty(new API::WorkspaceProperty<API::ITableWorkspace>( - "Parameters", "", Kernel::Direction::Output), - "The name to give the output workspace"); -} - -//---------------------------------------------------------------------------------------------- - -/// Destructor -FABADAMinimizer::~FABADAMinimizer() {} - -/// Initialize minimizer. Set initial values for all private members. -void FABADAMinimizer::initialize(API::ICostFunction_sptr function, - size_t maxIterations) { - - m_leastSquares = boost::dynamic_pointer_cast<CostFuncLeastSquares>(function); - if (!m_leastSquares) { - throw std::invalid_argument( - "FABADA works only with least squares. Different function was given."); - } - - m_counter = 0; - m_leastSquares->getParameters(m_parameters); - API::IFunction_sptr fun = m_leastSquares->getFittingFunction(); - - if (fun->nParams() == 0) { - throw std::invalid_argument("Function has 0 fitting parameters."); - } - - size_t n = getProperty("ChainLength"); - m_numberIterations = n / fun->nParams(); - - if (m_numberIterations > maxIterations) { - g_log.warning() - << "MaxIterations property reduces the required number of iterations (" - << m_numberIterations << ")." << std::endl; - m_numberIterations = maxIterations; - } - - for (size_t i = 0; i < m_leastSquares->nParams(); ++i) { - double p = m_parameters.get(i); - m_bound.push_back(false); - API::IConstraint *iconstr = fun->getConstraint(i); - if (iconstr) { - BoundaryConstraint *bcon = dynamic_cast<BoundaryConstraint *>(iconstr); - if (bcon) { - m_bound[i] = true; - if (bcon->hasLower()) { - m_lower.push_back(bcon->lower()); - } else { - m_lower.push_back(-largeNumber); - } - if (bcon->hasUpper()) { - m_upper.push_back(bcon->upper()); - } else { - m_upper.push_back(largeNumber); - } - if (p < m_lower[i]) { - p = m_lower[i]; - m_parameters.set(i, p); - } - if (p > m_upper[i]) { - p = m_upper[i]; - m_parameters.set(i, p); - } - } - } else { - m_lower.push_back(-largeNumber); - m_upper.push_back(largeNumber); - } - std::vector<double> v; - v.push_back(p); - m_chain.push_back(v); - m_max_iter = maxIterations; - m_changes.push_back(0); - m_par_converged.push_back(false); - m_criteria.push_back(getProperty("ConvergenceCriteria")); - if (p != 0.0) { - m_jump.push_back(std::abs(p / 10)); - } else { - m_jump.push_back(0.01); - } - } - m_chi2 = m_leastSquares->val(); - std::vector<double> v; - v.push_back(m_chi2); - m_chain.push_back(v); - m_converged = false; - m_max_iter = maxIterations; -} - -/// Do one iteration. Returns true if iterations to be continued, false if they -/// must stop. -bool FABADAMinimizer::iterate(size_t) { - - if (!m_leastSquares) { - throw std::runtime_error("Cost function isn't set up."); - } - - size_t nParams = m_leastSquares->nParams(); - size_t m = nParams; - - // Just for the last iteration. For doing exactly the indicated number of - // iterations. - if (m_converged && m_counter == m_numberIterations) { - size_t t = getProperty("ChainLength"); - m = t % nParams; - } - - // Do one iteration of FABADA's algorithm for each parameter. - for (size_t i = 0; i < m; i++) { - GSLVector new_parameters = m_parameters; - - // Calculate the step, depending on convergence reached or not - double step; - if (m_converged || m_bound[i]) { - boost::mt19937 mt; - mt.seed(123 * (int(m_counter) + - 45 * int(i))); // Numeros inventados para la seed - boost::normal_distribution<double> distr(0.0, std::abs(m_jump[i])); - boost::variate_generator<boost::mt19937, - boost::normal_distribution<double>> gen(mt, - distr); - step = gen(); - } else { - step = m_jump[i]; - } - - // Calculate the new value of the parameter - double new_value = m_parameters.get(i) + step; - - // Comproves if it is inside the boundary constrinctions. If not, changes - // it. - if (m_bound[i]) { - while (new_value < m_lower[i]) { - if (std::abs(step) > m_upper[i] - m_lower[i]) { - new_value = m_parameters.get(i) + step / 10.0; - step = step / 10; - m_jump[i] = m_jump[i] / 10; - } else { - new_value = - m_lower[i] + std::abs(step) - (m_parameters.get(i) - m_lower[i]); - } - } - while (new_value > m_upper[i]) { - if (std::abs(step) > m_upper[i] - m_lower[i]) { - new_value = m_parameters.get(i) + step / 10.0; - step = step / 10; - m_jump[i] = m_jump[i] / 10; - } else { - new_value = - m_upper[i] - (std::abs(step) + m_parameters.get(i) - m_upper[i]); - } - } - } - - // Set the new value in order to calculate the new Chi square value - if (boost::math::isnan(new_value)) { - throw std::runtime_error("Parameter value is NaN."); - } - new_parameters.set(i, new_value); - m_leastSquares->setParameter(i, new_value); - double chi2_new = m_leastSquares->val(); - - // If new Chi square value is lower, jumping directly to new parameter - if (chi2_new < m_chi2) { - for (size_t j = 0; j < nParams; j++) { - m_chain[j].push_back(new_parameters.get(j)); - } - m_chain[nParams].push_back(chi2_new); - m_parameters = new_parameters; - m_chi2 = chi2_new; - m_changes[i] += 1; - - } - - // If new Chi square value is higher, it depends on the probability - else { - // Calculate probability of change - double prob = exp((m_chi2 / 2.0) - (chi2_new / 2.0)); - - // Decide if changing or not - boost::mt19937 mt; - mt.seed(int(time_t()) + 48 * (int(m_counter) + 76 * int(i))); - boost::uniform_real<> distr(0.0, 1.0); - double p = distr(mt); - if (p <= prob) { - for (size_t j = 0; j < nParams; j++) { - m_chain[j].push_back(new_parameters.get(j)); - } - m_chain[nParams].push_back(chi2_new); - m_parameters = new_parameters; - m_chi2 = chi2_new; - m_changes[i] += 1; - } else { - for (size_t j = 0; j < nParams; j++) { - m_chain[j].push_back(m_parameters.get(j)); - } - m_chain[nParams].push_back(m_chi2); - m_leastSquares->setParameter(i, new_value - m_jump[i]); - m_jump[i] = -m_jump[i]; - } - } - - const double jumpAR = getProperty("JumpAcceptanceRate"); - - // Update the jump once each jumpCheckingRate iterations - if (m_counter % jumpCheckingRate == 150) // JUMP CHECKING RATE IS 200, BUT - // IS NOT CHECKED AT FIRST STEP, IT - // IS AT 150 - { - double jnew; - if (m_changes[i] == 0.0) { - jnew = m_jump[i] / - 10.0; // JUST FOR THE CASE THERE HAS NOT BEEN ANY CHANGE. - } else { - double f = m_changes[i] / double(m_counter); - jnew = m_jump[i] * f / jumpAR; - } - - m_jump[i] = jnew; - - // Check if the new jump is too small. It means that it has been a wrong - // convergence. - if (std::abs(m_jump[i]) < lowJumpLimit) { - API::IFunction_sptr fun = m_leastSquares->getFittingFunction(); - g_log.warning() - << "Wrong convergence for parameter " + fun->parameterName(i) + - ". Try to set a proper initial value for this parameter" - << std::endl; - } - } - - // Check if the Chi square value has converged for parameter i. - const size_t startingPoint = - 350; // The iteration since it starts to check if convergence is reached - if (!m_par_converged[i] && m_counter > startingPoint) { - if (chi2_new != m_chi2) { - double chi2_quotient = std::abs(chi2_new - m_chi2) / m_chi2; - if (chi2_quotient < m_criteria[i]) { - m_par_converged[i] = true; - } - } - } - } // for i - - // Update the counter, after finishing the iteration for each parameter - m_counter += 1; - - // Check if Chi square has converged for all the parameters. - if (m_counter > lowerIterationLimit && !m_converged) { - size_t t = 0; - for (size_t i = 0; i < nParams; i++) { - if (m_par_converged[i]) { - t += 1; - } - } - // If all parameters have converged: - // It set up both the counter and the changes' vector to 0, in order to - // consider only the data of the converged part of the chain, when updating - // the jump. - if (t == nParams) { - m_converged = true; - m_conv_point = m_counter * nParams + 1; - m_counter = 0; - for (size_t i = 0; i < nParams; ++i) { - m_changes[i] = 0; - } - } - } - - if (!m_converged) { - // If there is not convergence continue the iterations. - if (m_counter <= convergenceMaxIterations && - m_counter < m_numberIterations - 1) { - return true; - } - // If there is not convergence, but it has been made - // convergenceMaxIterations iterations, stop and throw the error. - else { - API::IFunction_sptr fun = m_leastSquares->getFittingFunction(); - std::string failed = ""; - for (size_t i = 0; i < nParams; ++i) { - if (!m_par_converged[i]) { - failed = failed + fun->parameterName(i) + ", "; - } - } - failed.replace(failed.end() - 2, failed.end(), "."); - throw std::runtime_error( - "Convegence NOT reached after " + - boost::lexical_cast<std::string>(m_max_iter) + - " iterations.\n Try to set better initial values for parameters: " + - failed); - } - } else { - // If convergence has been reached, continue untill complete the chain - // length. - if (m_counter <= m_numberIterations) { - return true; - } - // If convergence has been reached, but the maximum of iterations have been - // reached before finishing the chain, stop and throw the error. - if (m_counter >= m_max_iter) { - throw std::length_error("Convegence reached but Max Iterations parameter " - "insufficient for creating the whole chain.\n " - "Increase Max Iterations"); - } - // nothing else to do, stop interations - return false; - } - // can we even get here? - return true; -} - -double FABADAMinimizer::costFunctionVal() { return m_chi2; } - -/// When the all the iterations have been done, calculate and show all the -/// results. -void FABADAMinimizer::finalize() { - // Creating the reduced chain (considering only one each "Steps between - // values" values) - size_t cl = getProperty("ChainLength"); - size_t n_steps = getProperty("StepsBetweenValues"); - size_t conv_length = size_t(double(cl) / double(n_steps)); - std::vector<std::vector<double>> red_conv_chain; - size_t nParams = m_leastSquares->nParams(); - for (size_t e = 0; e <= nParams; ++e) { - std::vector<double> v; - v.push_back(m_chain[e][m_conv_point]); - red_conv_chain.push_back(v); - } - - // Calculate the red_conv_chain for the cost fuction. - auto first = m_chain[nParams].begin() + m_conv_point; - auto last = m_chain[nParams].end(); - std::vector<double> conv_chain(first, last); - for (size_t k = 1; k < conv_length; ++k) { - red_conv_chain[nParams].push_back(conv_chain[n_steps * k]); - } - - // Calculate the position of the minimum Chi square value - auto pos_min = std::min_element(red_conv_chain[nParams].begin(), - red_conv_chain[nParams].end()); - m_chi2 = *pos_min; - - std::vector<double> par_def(nParams); - std::vector<double> error_left(nParams); - std::vector<double> error_rigth(nParams); - API::IFunction_sptr fun = m_leastSquares->getFittingFunction(); - - // Do one iteration for each parameter. - for (size_t j = 0; j < nParams; ++j) { - // Calculate the parameter value and the errors - auto first = m_chain[j].begin() + m_conv_point; - auto last = m_chain[j].end(); - std::vector<double> conv_chain(first, last); - auto &rc_chain_j = red_conv_chain[j]; - for (size_t k = 0; k < conv_length; ++k) { - rc_chain_j.push_back(conv_chain[n_steps * k]); - } - par_def[j] = rc_chain_j[pos_min - red_conv_chain[nParams].begin()]; - std::sort(rc_chain_j.begin(), rc_chain_j.end()); - auto pos_par = std::find(rc_chain_j.begin(), rc_chain_j.end(), par_def[j]); - auto pos_left = rc_chain_j.begin(); - auto pos_right = rc_chain_j.end() - 1; - size_t sigma = static_cast<size_t>(0.34 * double(conv_length)); - if (pos_par == rc_chain_j.end()) { - error_left[j] = *(pos_right - sigma); - error_rigth[j] = *pos_right; - } else { - - if (sigma < static_cast<size_t>(std::distance(pos_left, pos_par))) { - pos_left = pos_par - sigma; - } - // make sure the iterator is valid in any case - if (sigma < static_cast<size_t>(std::distance(pos_par, pos_right))) { - pos_right = pos_par + sigma; - } - error_left[j] = *pos_left - *pos_par; - error_rigth[j] = *pos_right - *pos_par; - } - } - - const bool outputParametersTable = !getPropertyValue("Parameters").empty(); - - if (outputParametersTable) { - - // Create the workspace for the parameters' value and errors. - API::ITableWorkspace_sptr wsPdfE = - API::WorkspaceFactory::Instance().createTable("TableWorkspace"); - wsPdfE->addColumn("str", "Name"); - wsPdfE->addColumn("double", "Value"); - wsPdfE->addColumn("double", "Left's error"); - wsPdfE->addColumn("double", "Rigth's error"); - - for (size_t j = 0; j < nParams; ++j) { - API::TableRow row = wsPdfE->appendRow(); - row << fun->parameterName(j) << par_def[j] << error_left[j] - << error_rigth[j]; - } - // Set and name the Parameter Errors workspace. - setProperty("Parameters", wsPdfE); - } - - // Set the best parameter values - for (size_t j = 0; j < nParams; ++j) { - m_leastSquares->setParameter(j, par_def[j]); - } - - double mostPchi2; - - // Create the workspace for the Probability Density Functions - size_t pdf_length = 20; // histogram length for the PDF output workspace - API::MatrixWorkspace_sptr ws = API::WorkspaceFactory::Instance().create( - "Workspace2D", nParams + 1, pdf_length + 1, pdf_length); - - // Calculate the cost function Probability Density Function - std::sort(red_conv_chain[nParams].begin(), red_conv_chain[nParams].end()); - std::vector<double> pdf_y(pdf_length, 0); - double start = red_conv_chain[nParams][0]; - double bin = - (red_conv_chain[nParams][conv_length - 1] - start) / double(pdf_length); - size_t step = 0; - MantidVec &X = ws->dataX(nParams); - MantidVec &Y = ws->dataY(nParams); - X[0] = start; - for (size_t i = 1; i < pdf_length + 1; i++) { - double bin_end = start + double(i) * bin; - X[i] = bin_end; - while (step < conv_length && red_conv_chain[nParams][step] <= bin_end) { - pdf_y[i - 1] += 1; - ++step; - } - Y[i - 1] = pdf_y[i - 1] / (double(conv_length) * bin); - } - - std::vector<double>::iterator pos_MPchi2 = - std::max_element(pdf_y.begin(), pdf_y.end()); - - if (pos_MPchi2 - pdf_y.begin() == 0) { - // mostPchi2 = X[pos_MPchi2-pdf_y.begin()]; - mostPchi2 = *pos_min; - } else { - mostPchi2 = X[pos_MPchi2 - pdf_y.begin()] + (bin / 2.0); - } - - // Do one iteration for each parameter. - for (size_t j = 0; j < nParams; ++j) { - // Calculate the Probability Density Function - std::vector<double> pdf_y(pdf_length, 0); - double start = red_conv_chain[j][0]; - double bin = - (red_conv_chain[j][conv_length - 1] - start) / double(pdf_length); - size_t step = 0; - MantidVec &X = ws->dataX(j); - MantidVec &Y = ws->dataY(j); - X[0] = start; - for (size_t i = 1; i < pdf_length + 1; i++) { - double bin_end = start + double(i) * bin; - X[i] = bin_end; - while (step < conv_length && red_conv_chain[j][step] <= bin_end) { - pdf_y[i - 1] += 1; - ++step; - } - Y[i - 1] = pdf_y[i - 1] / (double(conv_length) * bin); - } - - // Calculate the most probable value, from the PDF. - std::vector<double>::iterator pos_MP = - std::max_element(pdf_y.begin(), pdf_y.end()); - double mostP = X[pos_MP - pdf_y.begin()] + (bin / 2.0); - m_leastSquares->setParameter(j, mostP); - } - - // Set and name the PDF workspace. - setProperty("PDF", ws); - - const bool outputChains = !getPropertyValue("Chains").empty(); - - if (outputChains) { - - // Create the workspace for the complete parameters' chain (the last - // histogram is for the Chi square). - size_t chain_length = m_chain[0].size(); - API::MatrixWorkspace_sptr wsC = API::WorkspaceFactory::Instance().create( - "Workspace2D", nParams + 1, chain_length, chain_length); - - // Do one iteration for each parameter plus one for Chi square. - for (size_t j = 0; j < nParams + 1; ++j) { - MantidVec &X = wsC->dataX(j); - MantidVec &Y = wsC->dataY(j); - for (size_t k = 0; k < chain_length; ++k) { - X[k] = double(k); - Y[k] = m_chain[j][k]; - } - } - - // Set and name the workspace for the complete chain - setProperty("Chains", wsC); - } - - // Read if necessary to show the workspace for the converged part of the - // chain. - const bool outputConvergedChains = - !getPropertyValue("ConvergedChain").empty(); - - if (outputConvergedChains) { - // Create the workspace for the converged part of the chain. - API::MatrixWorkspace_sptr wsConv = API::WorkspaceFactory::Instance().create( - "Workspace2D", nParams + 1, conv_length, conv_length); - - // Do one iteration for each parameter plus one for Chi square. - for (size_t j = 0; j < nParams + 1; ++j) { - std::vector<double>::const_iterator first = - m_chain[j].begin() + m_conv_point; - std::vector<double>::const_iterator last = m_chain[j].end(); - std::vector<double> conv_chain(first, last); - MantidVec &X = wsConv->dataX(j); - MantidVec &Y = wsConv->dataY(j); - for (size_t k = 0; k < conv_length; ++k) { - X[k] = double(k); - Y[k] = conv_chain[n_steps * k]; - } - } - - // Set and name the workspace for the converged part of the chain. - setProperty("ConvergedChain", wsConv); - } - - // Read if necessary to show the workspace for the Chi square values. - const bool outputCostFunctionTable = - !getPropertyValue("CostFunctionTable").empty(); - - if (outputCostFunctionTable) { - - // Create the workspace for the Chi square values. - API::ITableWorkspace_sptr wsChi2 = - API::WorkspaceFactory::Instance().createTable("TableWorkspace"); - wsChi2->addColumn("double", "Chi2min"); - wsChi2->addColumn("double", "Chi2MP"); - wsChi2->addColumn("double", "Chi2min_red"); - wsChi2->addColumn("double", "Chi2MP_red"); - - // Obtain the quantity of the initial data. - API::FunctionDomain_sptr domain = m_leastSquares->getDomain(); - size_t data_number = domain->size(); - - // Calculate the value for the reduced Chi square. - double Chi2min_red = - m_chi2 / (double(data_number - nParams)); // For de minimum value. - double mostPchi2_red = mostPchi2 / (double(data_number - nParams)); - - // Add the information to the workspace and name it. - API::TableRow row = wsChi2->appendRow(); - row << m_chi2 << mostPchi2 << Chi2min_red << mostPchi2_red; - setProperty("CostFunctionTable", wsChi2); - } - - // Set the best parameter values - for (size_t j = 0; j < nParams; ++j) { - m_leastSquares->setParameter(j, par_def[j]); - } -} - -} // namespace CurveFitting -} // namespace Mantid diff --git a/Framework/CurveFitting/src/FitPowderDiffPeaks.cpp b/Framework/CurveFitting/src/FitPowderDiffPeaks.cpp index e5ba3d3ff3ab98660df071c82ec9114d6c6b287e..4506e6acd5bfdfc82775d095840d43f2e1b00529 100644 --- a/Framework/CurveFitting/src/FitPowderDiffPeaks.cpp +++ b/Framework/CurveFitting/src/FitPowderDiffPeaks.cpp @@ -17,7 +17,7 @@ #include "MantidAPI/TextAxis.h" #include "MantidCurveFitting/Fit.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Functions/BackgroundFunction.h" #include "MantidCurveFitting/Functions/ThermalNeutronDtoTOFFunction.h" #include "MantidCurveFitting/Functions/Polynomial.h" @@ -52,6 +52,7 @@ using namespace Mantid::API; using namespace Mantid::Kernel; using namespace Mantid::DataObjects; using namespace Mantid::CurveFitting::Functions; +using namespace Mantid::CurveFitting::Constraints; using namespace std; @@ -1855,8 +1856,8 @@ bool FitPowderDiffPeaks::doFitGaussianPeak(DataObjects::Workspace2D_sptr dataws, // b) Constraint double centerleftend = in_center - leftfwhm * 0.5; double centerrightend = in_center + rightfwhm * 0.5; - CurveFitting::BoundaryConstraint *centerbound = - new CurveFitting::BoundaryConstraint(gaussianpeak.get(), "PeakCentre", + Constraints::BoundaryConstraint *centerbound = + new Constraints::BoundaryConstraint(gaussianpeak.get(), "PeakCentre", centerleftend, centerrightend, false); gaussianpeak->addConstraint(centerbound); diff --git a/Framework/CurveFitting/src/FuncMinimizers/FABADAMinimizer.cpp b/Framework/CurveFitting/src/FuncMinimizers/FABADAMinimizer.cpp index e1dbc421376cc372fe68e51078ba6078f90f5fa1..6e76be4520f4ff5fcbb3ce1cfe702702a01809d7 100644 --- a/Framework/CurveFitting/src/FuncMinimizers/FABADAMinimizer.cpp +++ b/Framework/CurveFitting/src/FuncMinimizers/FABADAMinimizer.cpp @@ -1,6 +1,6 @@ #include "MantidCurveFitting/FuncMinimizers/FABADAMinimizer.h" #include "MantidCurveFitting/CostFunctions/CostFuncLeastSquares.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting//Constraints/BoundaryConstraint.h" #include <stdio.h> #include <stdlib.h> @@ -122,7 +122,7 @@ void FABADAMinimizer::initialize(API::ICostFunction_sptr function, m_bound.push_back(false); API::IConstraint *iconstr = fun->getConstraint(i); if (iconstr) { - BoundaryConstraint *bcon = dynamic_cast<BoundaryConstraint *>(iconstr); + Constraints::BoundaryConstraint *bcon = dynamic_cast<Constraints::BoundaryConstraint *>(iconstr); if (bcon) { m_bound[i] = true; if (bcon->hasLower()) { diff --git a/Framework/CurveFitting/src/Functions/BivariateNormal.cpp b/Framework/CurveFitting/src/Functions/BivariateNormal.cpp index 3e290bbcae51b0c8d1102cf1bc972bf3af46e428..95749a228b72573bf36cbc76eb7637d677a9a89e 100644 --- a/Framework/CurveFitting/src/Functions/BivariateNormal.cpp +++ b/Framework/CurveFitting/src/Functions/BivariateNormal.cpp @@ -1,5 +1,5 @@ #include "MantidCurveFitting/Functions/BivariateNormal.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidKernel/PhysicalConstants.h" #include "MantidAPI/ParameterTie.h" @@ -20,8 +20,9 @@ using namespace Mantid::API; namespace Mantid { namespace CurveFitting { namespace Functions { - + using namespace CurveFitting; +using namespace Constraints; namespace { /// static logger diff --git a/Framework/CurveFitting/src/Functions/DiffRotDiscreteCircle.cpp b/Framework/CurveFitting/src/Functions/DiffRotDiscreteCircle.cpp index 80377a015d5afaf1e6a58b8d2b6bbf29bdcfb038..ab2f2402bd9ea069d8f8ee7dfd6ad177fd013667 100644 --- a/Framework/CurveFitting/src/Functions/DiffRotDiscreteCircle.cpp +++ b/Framework/CurveFitting/src/Functions/DiffRotDiscreteCircle.cpp @@ -6,7 +6,7 @@ #include "MantidAPI/FunctionFactory.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/ParameterTie.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidGeometry/IDetector.h" #include "MantidKernel/Exception.h" #include "MantidKernel/UnitConversion.h" @@ -21,8 +21,9 @@ Mantid::Kernel::Logger g_log("DiffSphere"); namespace Mantid { namespace CurveFitting { namespace Functions { - + using namespace CurveFitting; +using namespace Constraints; using namespace API; diff --git a/Framework/CurveFitting/src/Functions/DiffSphere.cpp b/Framework/CurveFitting/src/Functions/DiffSphere.cpp index 17e975a3796d36542377fc719bd8458346e15701..7cf48ca1c0ebbfab5d0a6ddb5a760f70cdb24e6f 100644 --- a/Framework/CurveFitting/src/Functions/DiffSphere.cpp +++ b/Framework/CurveFitting/src/Functions/DiffSphere.cpp @@ -6,7 +6,7 @@ #include "MantidAPI/FunctionFactory.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/ParameterTie.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidGeometry/IDetector.h" #include "MantidKernel/Exception.h" #include "MantidKernel/UnitConversion.h" @@ -23,8 +23,9 @@ Mantid::Kernel::Logger g_log("DiffSphere"); namespace Mantid { namespace CurveFitting { namespace Functions { - + using namespace CurveFitting; +using namespace Constraints; using namespace API; diff --git a/Framework/CurveFitting/src/Functions/IkedaCarpenterPV.cpp b/Framework/CurveFitting/src/Functions/IkedaCarpenterPV.cpp index 72a22b1a576efe345bd5fdda6d4a304e1b526d84..b74d920b0eae28a2cbffa31f5cf8d21f95053c5d 100644 --- a/Framework/CurveFitting/src/Functions/IkedaCarpenterPV.cpp +++ b/Framework/CurveFitting/src/Functions/IkedaCarpenterPV.cpp @@ -2,7 +2,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidCurveFitting/Functions/IkedaCarpenterPV.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/SpecialFunctionSupport.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/FunctionFactory.h" @@ -36,6 +36,7 @@ using namespace Kernel; using namespace SpecialFunctionSupport; using namespace Geometry; +using namespace Constraints; DECLARE_FUNCTION(IkedaCarpenterPV) diff --git a/Framework/CurveFitting/src/Functions/PawleyFunction.cpp b/Framework/CurveFitting/src/Functions/PawleyFunction.cpp index be3bb4fb202ef377c7f5082406ce18db37c9efa9..d1ee189b9d13a0fba8972f5ab5c6d09315f32d0c 100644 --- a/Framework/CurveFitting/src/Functions/PawleyFunction.cpp +++ b/Framework/CurveFitting/src/Functions/PawleyFunction.cpp @@ -3,7 +3,7 @@ #include "MantidAPI/FunctionFactory.h" #include "MantidAPI/MatrixWorkspace.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidKernel/UnitConversion.h" #include "MantidKernel/UnitFactory.h" @@ -14,8 +14,9 @@ namespace Mantid { namespace CurveFitting { namespace Functions { - + using namespace CurveFitting; +using namespace Constraints; DECLARE_FUNCTION(PawleyParameterFunction) diff --git a/Framework/CurveFitting/src/Functions/PseudoVoigt.cpp b/Framework/CurveFitting/src/Functions/PseudoVoigt.cpp index 1992434d583b0c999e85f44a380ff5f7cf58111a..86c80a034818e8e2972904da8e31ec352fc1753c 100644 --- a/Framework/CurveFitting/src/Functions/PseudoVoigt.cpp +++ b/Framework/CurveFitting/src/Functions/PseudoVoigt.cpp @@ -1,14 +1,15 @@ #include "MantidCurveFitting/Functions/PseudoVoigt.h" #include "MantidAPI/FunctionFactory.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include <cmath> namespace Mantid { namespace CurveFitting { namespace Functions { - + using namespace CurveFitting; +using namespace Constraints; using namespace API; diff --git a/Framework/CurveFitting/src/LeBailFunction.cpp b/Framework/CurveFitting/src/LeBailFunction.cpp index 7a47d8a012709196a3a60a00bba78fb05c8610da..6835b74fea4c67b9127fa0c8082e4c1cacbe2930 100644 --- a/Framework/CurveFitting/src/LeBailFunction.cpp +++ b/Framework/CurveFitting/src/LeBailFunction.cpp @@ -2,7 +2,7 @@ #include "MantidCurveFitting/LeBailFunction.h" #include "MantidKernel/System.h" #include "MantidAPI/FunctionFactory.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include <sstream> @@ -946,7 +946,7 @@ void LeBailFunction::setFitProfileParameter(string paramname, double minvalue, std::stringstream parss; parss << "f0." << paramname; string parnamef0 = parss.str(); - CurveFitting::BoundaryConstraint *bc = new BoundaryConstraint( + Constraints::BoundaryConstraint *bc = new Constraints::BoundaryConstraint( m_compsiteFunction.get(), parnamef0, minvalue, maxvalue); m_compsiteFunction->addConstraint(bc); diff --git a/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp b/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp deleted file mode 100644 index 11793321b58aa4f52d8d51db2238f6f28ab41022..0000000000000000000000000000000000000000 --- a/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp +++ /dev/null @@ -1,291 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidCurveFitting/LevenbergMarquardtMDMinimizer.h" -#include "MantidCurveFitting/CostFuncLeastSquares.h" - -#include "MantidAPI/CostFunctionFactory.h" -#include "MantidAPI/FuncMinimizerFactory.h" -#include "MantidAPI/IFunction.h" - -#include "MantidKernel/Logger.h" - -#include <boost/lexical_cast.hpp> -#include <gsl/gsl_blas.h> -#include <iostream> -#include <cmath> - -namespace Mantid { -namespace CurveFitting { -namespace { -/// static logger object -Kernel::Logger g_log("LevenbergMarquardMD"); -} - -// clang-format off -DECLARE_FUNCMINIMIZER(LevenbergMarquardtMDMinimizer, Levenberg-MarquardtMD) -// clang-format on - -/// Constructor -LevenbergMarquardtMDMinimizer::LevenbergMarquardtMDMinimizer() - : IFuncMinimizer(), m_tau(1e-6), m_mu(1e-6), m_nu(2.0), m_rho(1.0), - m_F(0.0) { - declareProperty("MuMax", 1e6, - "Maximum value of mu - a stopping parameter in failure."); - declareProperty("AbsError", 0.0001, "Absolute error allowed for parameters - " - "a stopping parameter in success."); - declareProperty("Debug", false, "Turn on the debug output."); -} - -/// Initialize minimizer, i.e. pass a function to minimize. -void LevenbergMarquardtMDMinimizer::initialize(API::ICostFunction_sptr function, - size_t) { - m_leastSquares = boost::dynamic_pointer_cast<CostFuncLeastSquares>(function); - if (!m_leastSquares) { - throw std::invalid_argument("Levenberg-Marquardt minimizer works only with " - "least squares. Different function was given."); - } - m_mu = 0; - m_nu = 2.0; - m_rho = 1.0; -} - -/// Do one iteration. -bool LevenbergMarquardtMDMinimizer::iterate(size_t) { - const bool debug = getProperty("Debug"); - const double muMax = getProperty("MuMax"); - const double absError = getProperty("AbsError"); - - if (!m_leastSquares) { - throw std::runtime_error("Cost function isn't set up."); - } - size_t n = m_leastSquares->nParams(); - - if (n == 0) { - m_errorString = "No parameters to fit."; - g_log.information(m_errorString); - return false; - } - - if (m_mu > muMax) { - // m_errorString = "Failed to converge, maximum mu reached"; - // g_log.warning() << m_errorString << std::endl; - return false; - } - - // calculate the first and second derivatives of the cost function. - if (m_mu == 0.0 || m_rho > 0) { - // calculate everything first time or - // if last iteration was good - m_F = m_leastSquares->valDerivHessian(); - } - // else if m_rho < 0 last iteration was bad: reuse m_der and m_hessian - - // Calculate damping to hessian - if (m_mu == 0) // first iteration or accidental zero - { - m_mu = m_tau; - m_nu = 2.0; - } - - if (debug) { - g_log.warning() - << "===========================================================" - << std::endl; - g_log.warning() << "mu=" << m_mu << std::endl - << std::endl; - } - - if (m_D.empty()) { - m_D.resize(n); - } - - // copy the hessian - GSLMatrix H(m_leastSquares->getHessian()); - GSLVector dd(m_leastSquares->getDeriv()); - - // scaling factors - std::vector<double> sf(n); - - for (size_t i = 0; i < n; ++i) { - double d = fabs(dd.get(i)); - if (m_D[i] > d) - d = m_D[i]; - m_D[i] = d; - double tmp = H.get(i, i) + m_mu * d; - H.set(i, i, tmp); - sf[i] = sqrt(tmp); - if (tmp == 0.0) { - m_errorString = "Singular matrix."; - g_log.information(m_errorString); - return false; - } - } - - // apply scaling - for (size_t i = 0; i < n; ++i) { - double d = dd.get(i); - dd.set(i, d / sf[i]); - for (size_t j = i; j < n; ++j) { - const double f = sf[i] * sf[j]; - double tmp = H.get(i, j); - H.set(i, j, tmp / f); - if (i != j) { - tmp = H.get(j, i); - H.set(j, i, tmp / f); - } - } - } - - if (debug && m_rho > 0) { - g_log.warning() << "Hessian:\n" << H; - g_log.warning() << "Right-hand side:\n"; - for (size_t j = 0; j < n; ++j) { - g_log.warning() << dd.get(j) << ' '; - } - g_log.warning() << std::endl; - g_log.warning() << "Determinant=" << H.det() << std::endl; - } - - // Parameter corrections - GSLVector dx(n); - // To find dx solve the system of linear equations H * dx == -m_der - dd *= -1.0; - H.solve(dd, dx); - - if (debug) { - g_log.warning() << "\nScaling factors:" << std::endl; - for (size_t j = 0; j < n; ++j) { - g_log.warning() << sf[j] << ' '; - } - g_log.warning() << std::endl; - g_log.warning() << "Corrections:" << std::endl; - for (size_t j = 0; j < n; ++j) { - g_log.warning() << dx.get(j) << ' '; - } - g_log.warning() << std::endl - << std::endl; - } - - // restore scaling - for (size_t i = 0; i < n; ++i) { - double d = dx.get(i); - dx.set(i, d / sf[i]); - d = dd.get(i); - dd.set(i, d * sf[i]); - } - - // save previous state - m_leastSquares->push(); - // Update the parameters of the cost function. - for (size_t i = 0; i < n; ++i) { - double d = m_leastSquares->getParameter(i) + dx.get(i); - m_leastSquares->setParameter(i, d); - if (debug) { - g_log.warning() << "Parameter(" << i << ")=" << d << std::endl; - } - } - m_leastSquares->getFittingFunction()->applyTies(); - - // --- prepare for the next iteration --- // - - double dL; - // der -> - der - 0.5 * hessian * dx - gsl_blas_dgemv(CblasNoTrans, -0.5, m_leastSquares->getHessian().gsl(), - dx.gsl(), 1., dd.gsl()); - // calculate the linear part of the change in cost function - // dL = - der * dx - 0.5 * dx * hessian * dx - gsl_blas_ddot(dd.gsl(), dx.gsl(), &dL); - - double F1 = m_leastSquares->val(); - if (debug) { - g_log.warning() << std::endl; - g_log.warning() << "Old cost function " << m_F << std::endl; - g_log.warning() << "New cost function " << F1 << std::endl; - g_log.warning() << "Linear part " << dL << std::endl; - } - - // Try the stop condition - if (m_rho >= 0) { - GSLVector p(n); - m_leastSquares->getParameters(p); - double dx_norm = gsl_blas_dnrm2(dx.gsl()); - if (dx_norm < absError) { - if (debug) { - g_log.warning() << "Successful fit, parameters changed by less than " - << absError << std::endl; - } - return false; - } - if (m_rho == 0) { - if (m_F != F1) { - this->m_errorString = "Failed to converge, rho == 0"; - g_log.warning() << m_errorString << std::endl; - } - if (debug) { - g_log.warning() << "Successful fit, cost function didn't change." - << std::endl; - } - return false; - } - } - - if (fabs(dL) == 0.0) { - if (m_F == F1) - m_rho = 1.0; - else - m_rho = 0; - } else { - m_rho = (m_F - F1) / dL; - if (m_rho == 0) { - return false; - } - } - if (debug) { - g_log.warning() << "rho=" << m_rho << std::endl; - } - - if (m_rho > 0) { // good progress, decrease m_mu but no more than by 1/3 - // rho = 1 - (2*rho - 1)^3 - m_rho = 2.0 * m_rho - 1.0; - m_rho = 1.0 - m_rho * m_rho * m_rho; - const double I3 = 1.0 / 3.0; - if (m_rho > I3) - m_rho = I3; - if (m_rho < 0.0001) - m_rho = 0.1; - m_mu *= m_rho; - m_nu = 2.0; - m_F = F1; - if (debug) { - g_log.warning() << "Good iteration, accept new parameters." << std::endl; - g_log.warning() << "rho=" << m_rho << std::endl; - } - // drop saved state, accept new parameters - m_leastSquares->drop(); - } else { // bad iteration. increase m_mu and revert changes to parameters - m_mu *= m_nu; - m_nu *= 2.0; - // undo parameter update - m_leastSquares->pop(); - m_F = m_leastSquares->val(); - if (debug) { - g_log.warning() - << "Bad iteration, increase mu and revert changes to parameters." - << std::endl; - } - } - - return true; -} - -/// Return current value of the cost function -double LevenbergMarquardtMDMinimizer::costFunctionVal() { - if (!m_leastSquares) { - throw std::runtime_error("Cost function isn't set up."); - } - return m_leastSquares->val(); -} - -} // namespace CurveFitting -} // namespace Mantid diff --git a/Framework/CurveFitting/src/LevenbergMarquardtMinimizer.cpp b/Framework/CurveFitting/src/LevenbergMarquardtMinimizer.cpp deleted file mode 100644 index 7e5614689298bb76705e4f6fed28472a1eab3ff5..0000000000000000000000000000000000000000 --- a/Framework/CurveFitting/src/LevenbergMarquardtMinimizer.cpp +++ /dev/null @@ -1,145 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidCurveFitting/LevenbergMarquardtMinimizer.h" -#include "MantidCurveFitting/CostFuncLeastSquares.h" - -#include "MantidAPI/CostFunctionFactory.h" -#include "MantidAPI/FuncMinimizerFactory.h" - -#include "MantidKernel/Exception.h" -#include "MantidKernel/Logger.h" -#include "MantidKernel/System.h" - -#include <boost/lexical_cast.hpp> -#include <gsl/gsl_blas.h> -#include <iostream> - -namespace Mantid { -namespace CurveFitting { -namespace { -// Get a reference to the logger -Kernel::Logger g_log("LevenbergMarquardtMinimizer"); -} - -// clang-format off -DECLARE_FUNCMINIMIZER(LevenbergMarquardtMinimizer, Levenberg-Marquardt) -// clang-format on - -LevenbergMarquardtMinimizer::LevenbergMarquardtMinimizer() - : m_data(NULL), gslContainer(), m_gslSolver(NULL), m_function(), - m_absError(1e-4), m_relError(1e-4) { - declareProperty("AbsError", m_absError, "Absolute error allowed for " - "parameters - a stopping parameter " - "in success."); - declareProperty("RelError", m_relError, "Relative error allowed for " - "parameters - a stopping parameter " - "in success."); -} - -void LevenbergMarquardtMinimizer::initialize( - API::ICostFunction_sptr costFunction, size_t) { - // set-up GSL container to be used with GSL simplex algorithm - auto leastSquares = - boost::dynamic_pointer_cast<CostFuncLeastSquares>(costFunction); - if (leastSquares) { - m_data = new GSL_FitData(leastSquares); - } else { - throw std::runtime_error("LevenbergMarquardt can only be used with Least " - "squares cost function."); - } - - // specify the type of GSL solver to use - const gsl_multifit_fdfsolver_type *T = gsl_multifit_fdfsolver_lmsder; - - // setup GSL container - gslContainer.f = &gsl_f; - gslContainer.df = &gsl_df; - gslContainer.fdf = &gsl_fdf; - gslContainer.n = m_data->n; - gslContainer.p = m_data->p; - gslContainer.params = m_data; - - // setup GSL solver - m_gslSolver = gsl_multifit_fdfsolver_alloc(T, m_data->n, m_data->p); - if (!m_gslSolver) { - throw std::runtime_error( - "Levenberg-Marquardt minimizer failed to initialize. \n" + - boost::lexical_cast<std::string>(m_data->n) + " data points, " + - boost::lexical_cast<std::string>(m_data->p) + " fitting parameters. "); - } - gsl_multifit_fdfsolver_set(m_gslSolver, &gslContainer, - m_data->initFuncParams); - - m_function = leastSquares->getFittingFunction(); -} - -LevenbergMarquardtMinimizer::~LevenbergMarquardtMinimizer() { - if (m_data) { - delete m_data; - } - if (m_gslSolver) { - gsl_multifit_fdfsolver_free(m_gslSolver); - } -} - -bool LevenbergMarquardtMinimizer::iterate(size_t) { - m_absError = getProperty("AbsError"); - m_relError = getProperty("RelError"); - - int retVal = gsl_multifit_fdfsolver_iterate(m_gslSolver); - - // From experience it is found that gsl_multifit_fdfsolver_iterate - // occasionally get - // stock - even after having achieved a sensible fit. This seem in particular - // to be a - // problem on Linux. However, to force GSL not to return ga ga have to do - // stuff in the - // if statement below - // GSL 1.14 changed return value from GSL_CONTINUE->GSL_ENOPROG for - // non-converging fits at 10 iterations - if (retVal == GSL_CONTINUE || retVal == GSL_ENOPROG) { - size_t ia = 0; - for (size_t i = 0; i < m_function->nParams(); i++) { - if (m_function->isActive(i)) { - m_function->setActiveParameter(i, gsl_vector_get(m_gslSolver->x, ia)); - ++ia; - } - } - m_function->applyTies(); - retVal = GSL_CONTINUE; - } - - if (retVal && retVal != GSL_CONTINUE) { - m_errorString = gsl_strerror(retVal); - return false; - } - - retVal = hasConverged(); - m_errorString = gsl_strerror(retVal); - - return retVal != GSL_SUCCESS; -} - -int LevenbergMarquardtMinimizer::hasConverged() { - return gsl_multifit_test_delta(m_gslSolver->dx, m_gslSolver->x, m_absError, - m_relError); -} - -double LevenbergMarquardtMinimizer::costFunctionVal() { - double chi = gsl_blas_dnrm2(m_gslSolver->f); - return chi * chi; -} - -/* Calculates covariance matrix - * - * @param epsrel :: Is used to remove linear-dependent columns - * @param covar :: Returned covariance matrix, here as - */ -void LevenbergMarquardtMinimizer::calCovarianceMatrix(double epsrel, - gsl_matrix *covar) { - gsl_multifit_covar(m_gslSolver->J, epsrel, covar); -} - -} // namespace CurveFitting -} // namespace Mantid diff --git a/Framework/CurveFitting/src/RefinePowderInstrumentParameters3.cpp b/Framework/CurveFitting/src/RefinePowderInstrumentParameters3.cpp index bfc7bc0984973a9ae965e369eb1058c0d617bf9a..22c96159ba9bcb39f9be9ed40b89532da6a62974 100644 --- a/Framework/CurveFitting/src/RefinePowderInstrumentParameters3.cpp +++ b/Framework/CurveFitting/src/RefinePowderInstrumentParameters3.cpp @@ -1267,7 +1267,7 @@ void RefinePowderInstrumentParameters3::setFunctionParameterFitSetups( double upperbound = param.maxvalue; if (lowerbound >= -DBL_MAX * 0.1 || upperbound <= DBL_MAX * 0.1) { // If there is a boundary - BoundaryConstraint *bc = new BoundaryConstraint( + Constraints::BoundaryConstraint *bc = new Constraints::BoundaryConstraint( function.get(), parname, lowerbound, upperbound, false); function->addConstraint(bc); } diff --git a/Framework/CurveFitting/test/BoundaryConstraintTest.h b/Framework/CurveFitting/test/Constraints/BoundaryConstraintTest.h similarity index 97% rename from Framework/CurveFitting/test/BoundaryConstraintTest.h rename to Framework/CurveFitting/test/Constraints/BoundaryConstraintTest.h index b4fe9bb2d011c0272f7bbd2a786dc5839bac92f5..d4d479b94a603df45163195d330ff99692d8d748 100644 --- a/Framework/CurveFitting/test/BoundaryConstraintTest.h +++ b/Framework/CurveFitting/test/Constraints/BoundaryConstraintTest.h @@ -3,7 +3,7 @@ #include <cxxtest/TestSuite.h> -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Functions/Gaussian.h" #include "MantidCurveFitting/Functions/Lorentzian.h" #include "MantidKernel/UnitFactory.h" @@ -16,6 +16,7 @@ using namespace Mantid::API; using namespace Mantid::CurveFitting; using namespace Mantid::CurveFitting::Functions; +using namespace Mantid::CurveFitting::Constraints; class BoundaryConstraintTest : public CxxTest::TestSuite { public: @@ -40,7 +41,7 @@ public: TS_ASSERT(bc.hasUpper()); BoundaryConstraint bc2; - ; + bc2.reset(&gaus, 2); bc2.setBounds(10, 20); diff --git a/Framework/CurveFitting/test/ConvertToYSpaceTest.h b/Framework/CurveFitting/test/ConvertToYSpaceTest.h index a3fed78b8baaa7c85c3ea0b918de70b4c4cc7fa3..c439658b075daf32105cdbadffb1c21f74eda4e0 100644 --- a/Framework/CurveFitting/test/ConvertToYSpaceTest.h +++ b/Framework/CurveFitting/test/ConvertToYSpaceTest.h @@ -4,7 +4,7 @@ #include <cxxtest/TestSuite.h> #include "MantidCurveFitting/ConvertToYSpace.h" -#include "ComptonProfileTestHelpers.h" +#include "Functions/ComptonProfileTestHelpers.h" using Mantid::CurveFitting::ConvertToYSpace; diff --git a/Framework/CurveFitting/test/FuncMinimizers/DampingMinimizerTest.h b/Framework/CurveFitting/test/FuncMinimizers/DampingMinimizerTest.h index 8e1ec30d01ac875a815c27554c3393b64bf9b3b5..1e8d08c13f590156ab50f463a09e6ea4e3714271 100644 --- a/Framework/CurveFitting/test/FuncMinimizers/DampingMinimizerTest.h +++ b/Framework/CurveFitting/test/FuncMinimizers/DampingMinimizerTest.h @@ -8,7 +8,7 @@ #include "MantidCurveFitting/Functions/UserFunction.h" #include "MantidAPI/FunctionDomain1D.h" #include "MantidAPI/FunctionValues.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include <sstream> @@ -16,6 +16,7 @@ using namespace Mantid; using namespace Mantid::CurveFitting; using namespace Mantid::CurveFitting::FuncMinimisers; using namespace Mantid::CurveFitting::CostFunctions; +using namespace Mantid::CurveFitting::Constraints; using namespace Mantid::CurveFitting::Functions; using namespace Mantid::API; diff --git a/Framework/CurveFitting/test/FuncMinimizers/LevenbergMarquardtMDTest.h b/Framework/CurveFitting/test/FuncMinimizers/LevenbergMarquardtMDTest.h index 49a24f2a9a00e496cf2552a1f6e80af7139f3766..edaeec639e087ddf475094d1d23c41b66cccb0ea 100644 --- a/Framework/CurveFitting/test/FuncMinimizers/LevenbergMarquardtMDTest.h +++ b/Framework/CurveFitting/test/FuncMinimizers/LevenbergMarquardtMDTest.h @@ -8,7 +8,7 @@ #include "MantidCurveFitting/Functions/UserFunction.h" #include "MantidAPI/FunctionDomain1D.h" #include "MantidAPI/FunctionValues.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include <sstream> @@ -16,6 +16,7 @@ using namespace Mantid; using namespace Mantid::CurveFitting; using namespace Mantid::CurveFitting::FuncMinimisers; using namespace Mantid::CurveFitting::CostFunctions; +using namespace Mantid::CurveFitting::Constraints; using namespace Mantid::CurveFitting::Functions; using namespace Mantid::API; diff --git a/Framework/CurveFitting/test/FuncMinimizers/LevenbergMarquardtTest.h b/Framework/CurveFitting/test/FuncMinimizers/LevenbergMarquardtTest.h index 7537ee88047cdbf1e201c0c6520f3c0fba2286bc..359712feb5f798bacd3398eb7e15d1193dac7f58 100644 --- a/Framework/CurveFitting/test/FuncMinimizers/LevenbergMarquardtTest.h +++ b/Framework/CurveFitting/test/FuncMinimizers/LevenbergMarquardtTest.h @@ -8,7 +8,7 @@ #include "MantidCurveFitting/Functions/UserFunction.h" #include "MantidAPI/FunctionDomain1D.h" #include "MantidAPI/FunctionValues.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include <sstream> @@ -16,6 +16,7 @@ using namespace Mantid; using namespace Mantid::CurveFitting; using namespace Mantid::CurveFitting::FuncMinimisers; using namespace Mantid::CurveFitting::CostFunctions; +using namespace Mantid::CurveFitting::Constraints; using namespace Mantid::CurveFitting::Functions; using namespace Mantid::API; diff --git a/Framework/CurveFitting/test/Functions/AbragamTest.h b/Framework/CurveFitting/test/Functions/AbragamTest.h index 1bea6f89482c2604d3207e2bd1e6008738a62c61..d103dfa360ed57fc1a60f7a2e8a8f357c79f71dc 100644 --- a/Framework/CurveFitting/test/Functions/AbragamTest.h +++ b/Framework/CurveFitting/test/Functions/AbragamTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/Abragam.h" #include "MantidAPI/CompositeFunction.h" #include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" diff --git a/Framework/CurveFitting/test/Functions/EndErfcTest.h b/Framework/CurveFitting/test/Functions/EndErfcTest.h index 7c9ad2d9ecdfece167bb8fdbcffe3726be3fc7be..5fe20acfd8e99905c50aca1c74e0ba9a838b2b9e 100644 --- a/Framework/CurveFitting/test/Functions/EndErfcTest.h +++ b/Framework/CurveFitting/test/Functions/EndErfcTest.h @@ -4,9 +4,6 @@ #include <cxxtest/TestSuite.h> #include "MantidCurveFitting/Functions/EndErfc.h" -#include "MantidAPI/CompositeFunction.h" -#include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/WorkspaceFactory.h" diff --git a/Framework/CurveFitting/test/Functions/ExpDecayMuonTest.h b/Framework/CurveFitting/test/Functions/ExpDecayMuonTest.h index 7171baaba31e31fb7eb16661f1fca62ce93cbeed..45561fcc3d1326c35d87105e6098aa05f29da5df 100644 --- a/Framework/CurveFitting/test/Functions/ExpDecayMuonTest.h +++ b/Framework/CurveFitting/test/Functions/ExpDecayMuonTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/ExpDecayMuon.h" #include "MantidAPI/CompositeFunction.h" #include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/WorkspaceFactory.h" diff --git a/Framework/CurveFitting/test/Functions/ExpDecayOscTest.h b/Framework/CurveFitting/test/Functions/ExpDecayOscTest.h index 67025d69e22a3f5a1371bf10ea6260b7a04a7136..cc87d09f6b5b2908c3407d53d9be690c3c6f70a9 100644 --- a/Framework/CurveFitting/test/Functions/ExpDecayOscTest.h +++ b/Framework/CurveFitting/test/Functions/ExpDecayOscTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/ExpDecayOsc.h" #include "MantidCurveFitting/Fit.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataObjects/Workspace2D.h" @@ -15,6 +15,7 @@ using namespace Mantid::Kernel; using namespace Mantid::API; using namespace Mantid::CurveFitting; using namespace Mantid::CurveFitting::Functions; +using namespace Mantid::CurveFitting::Constraints; using namespace Mantid::DataObjects; class ExpDecayOscTest : public CxxTest::TestSuite { diff --git a/Framework/CurveFitting/test/Functions/ExpDecayTest.h b/Framework/CurveFitting/test/Functions/ExpDecayTest.h index 243a2dd2ebe4e70c9f3f18051cc55e6fc2d58909..e5b3ff434c8b850ec7e7f672e50f2ed5286c9443 100644 --- a/Framework/CurveFitting/test/Functions/ExpDecayTest.h +++ b/Framework/CurveFitting/test/Functions/ExpDecayTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/ExpDecay.h" #include "MantidAPI/CompositeFunction.h" #include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" diff --git a/Framework/CurveFitting/test/Functions/GausDecayTest.h b/Framework/CurveFitting/test/Functions/GausDecayTest.h index 248fdd6cfb86960f10b9f0da11cef5a09e5fb74a..59df2188d75dd290dbac76646fd153cb545aa4e5 100644 --- a/Framework/CurveFitting/test/Functions/GausDecayTest.h +++ b/Framework/CurveFitting/test/Functions/GausDecayTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/GausDecay.h" #include "MantidAPI/CompositeFunction.h" #include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" diff --git a/Framework/CurveFitting/test/Functions/GausOscTest.h b/Framework/CurveFitting/test/Functions/GausOscTest.h index abdc63650ff49e63eca164d4ba4132f81b9432a7..fdd9b91bf366267ffbed186e20b18b338c34f16d 100644 --- a/Framework/CurveFitting/test/Functions/GausOscTest.h +++ b/Framework/CurveFitting/test/Functions/GausOscTest.h @@ -7,7 +7,7 @@ #include "MantidCurveFitting/Functions/GausOsc.h" #include "MantidAPI/CompositeFunction.h" #include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" diff --git a/Framework/CurveFitting/test/Functions/GaussianTest.h b/Framework/CurveFitting/test/Functions/GaussianTest.h index 903fdeb96efd799b8fb4d704ebc99d1d30a6583e..79c76ab0836973c8c75803cabf7a0dfe36be9d1b 100644 --- a/Framework/CurveFitting/test/Functions/GaussianTest.h +++ b/Framework/CurveFitting/test/Functions/GaussianTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/Gaussian.h" #include "MantidCurveFitting/Fit.h" #include "MantidAPI/CompositeFunction.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/InstrumentDataService.h" @@ -33,6 +33,7 @@ using namespace Mantid::API; using namespace Mantid::CurveFitting; using namespace Mantid::CurveFitting::Functions; using namespace Mantid::CurveFitting::CostFunctions; +using namespace Mantid::CurveFitting::Constraints; using namespace Mantid::DataObjects; using namespace Mantid::DataHandling; diff --git a/Framework/CurveFitting/test/Functions/LogNormalTest.h b/Framework/CurveFitting/test/Functions/LogNormalTest.h index 2d950578e8a7a2b3a9aaa261b03d118cddff623e..de8055bfb53da1d2a85cced1b8c7fd8c56b8d0ff 100644 --- a/Framework/CurveFitting/test/Functions/LogNormalTest.h +++ b/Framework/CurveFitting/test/Functions/LogNormalTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/LogNormal.h" #include "MantidAPI/CompositeFunction.h" #include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" diff --git a/Framework/CurveFitting/test/Functions/MuonFInteractionTest.h b/Framework/CurveFitting/test/Functions/MuonFInteractionTest.h index 61e05b91013887291e85fd2d468a538cacc86628..3e3e3ac7b52e9a102648c843b693de72215aba0e 100644 --- a/Framework/CurveFitting/test/Functions/MuonFInteractionTest.h +++ b/Framework/CurveFitting/test/Functions/MuonFInteractionTest.h @@ -4,9 +4,6 @@ #include <cxxtest/TestSuite.h> #include "MantidCurveFitting/Functions/MuonFInteraction.h" -#include "MantidAPI/CompositeFunction.h" -#include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" diff --git a/Framework/CurveFitting/test/Functions/StaticKuboToyabeTest.h b/Framework/CurveFitting/test/Functions/StaticKuboToyabeTest.h index 220de48b3252c2c464f1f59b264cc0220767a962..7cf2b5b478e3392952dd6509d35570141cf118ad 100644 --- a/Framework/CurveFitting/test/Functions/StaticKuboToyabeTest.h +++ b/Framework/CurveFitting/test/Functions/StaticKuboToyabeTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/StaticKuboToyabe.h" #include "MantidAPI/CompositeFunction.h" #include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" diff --git a/Framework/CurveFitting/test/Functions/StretchExpMuonTest.h b/Framework/CurveFitting/test/Functions/StretchExpMuonTest.h index d86db44ec7ab3101cfdc4c1998bfbef1a7002b8b..47c85a7e6818fc8e56a4019299147d47252253c4 100644 --- a/Framework/CurveFitting/test/Functions/StretchExpMuonTest.h +++ b/Framework/CurveFitting/test/Functions/StretchExpMuonTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/StretchExpMuon.h" #include "MantidAPI/CompositeFunction.h" #include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" diff --git a/Framework/CurveFitting/test/Functions/StretchExpTest.h b/Framework/CurveFitting/test/Functions/StretchExpTest.h index d25b966d7d2c8b04f97f279f9006ea8889cb332f..b90876d0e5be6b387c2d839a7adf6452763efb06 100644 --- a/Framework/CurveFitting/test/Functions/StretchExpTest.h +++ b/Framework/CurveFitting/test/Functions/StretchExpTest.h @@ -6,7 +6,7 @@ #include "MantidCurveFitting/Functions/StretchExp.h" #include "MantidAPI/CompositeFunction.h" #include "MantidCurveFitting/Functions/LinearBackground.h" -#include "MantidCurveFitting/BoundaryConstraint.h" +#include "MantidCurveFitting/Constraints/BoundaryConstraint.h" #include "MantidCurveFitting/Fit.h" #include "MantidKernel/UnitFactory.h" #include "MantidAPI/AnalysisDataService.h" diff --git a/Framework/SINQ/test/PoldiFitPeaks1D2Test.h b/Framework/SINQ/test/PoldiFitPeaks1D2Test.h index 4ced3e46bad5c158d1d9ef7f047fa179be817d44..35fbec1cc249f38f5f47758afc1a36845b5b3002 100644 --- a/Framework/SINQ/test/PoldiFitPeaks1D2Test.h +++ b/Framework/SINQ/test/PoldiFitPeaks1D2Test.h @@ -9,8 +9,7 @@ #include "MantidAPI/CompositeFunction.h" #include "MantidAPI/IPeakFunction.h" -#include "MantidCurveFitting/Gaussian.h" -#include "MantidCurveFitting/FlatBackground.h" +#include "MantidCurveFitting/Functions/FlatBackground.h" #include "MantidSINQ/PoldiUtilities/PoldiPeak.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" @@ -21,6 +20,7 @@ using Mantid::Poldi::PoldiFitPeaks1D2; using namespace Mantid::Poldi; using namespace Mantid::API; using namespace Mantid::CurveFitting; +using namespace Mantid::CurveFitting::Functions; using namespace Mantid::Kernel; using namespace Mantid::DataObjects; diff --git a/Framework/SINQ/test/PoldiFitPeaks1DTest.h b/Framework/SINQ/test/PoldiFitPeaks1DTest.h index a2158802104fad5391ed961eec6a2eced22c43b3..452d6472c3987e074ea2ba878042f6b2cca616c4 100644 --- a/Framework/SINQ/test/PoldiFitPeaks1DTest.h +++ b/Framework/SINQ/test/PoldiFitPeaks1DTest.h @@ -9,8 +9,7 @@ #include "MantidAPI/CompositeFunction.h" #include "MantidAPI/IPeakFunction.h" -#include "MantidCurveFitting/Gaussian.h" -#include "MantidCurveFitting/FlatBackground.h" +#include "MantidCurveFitting/Functions/FlatBackground.h" #include "MantidSINQ/PoldiUtilities/PoldiPeak.h" @@ -18,6 +17,7 @@ using Mantid::Poldi::PoldiFitPeaks1D; using namespace Mantid::Poldi; using namespace Mantid::API; using namespace Mantid::CurveFitting; +using namespace Mantid::CurveFitting::Functions; using namespace Mantid::Kernel; class TestablePoldiFitPeaks1D : public Mantid::Poldi::PoldiFitPeaks1D {