From 9e69caaaac9c1563fe7a28c7a4490c0a2bc40e0c Mon Sep 17 00:00:00 2001 From: Roman Tolchenov <roman.tolchenov@stfc.ac.uk> Date: Tue, 17 Jul 2012 11:46:30 +0100 Subject: [PATCH] Re #5619. Do not do fitting if there are no active params --- .../inc/MantidCurveFitting/GSLVector.h | 20 +++++++++++++++---- .../Mantid/Framework/CurveFitting/src/Fit.cpp | 4 ++++ .../src/LevenbergMarquardtMDMinimizer.cpp | 15 +++++++------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/GSLVector.h b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/GSLVector.h index e40dec569f7..434eafedfaf 100644 --- a/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/GSLVector.h +++ b/Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/GSLVector.h @@ -127,14 +127,20 @@ namespace Mantid // Set all elements to zero void zero() { - gsl_vector_set_zero( m_vector ); + if ( m_vector ) + { + gsl_vector_set_zero( m_vector ); + } } /// Add a vector /// @param v :: The other vector GSLVector& operator+=(const GSLVector& v) { - gsl_vector_add(m_vector, v.gsl()); + if ( m_vector ) + { + gsl_vector_add(m_vector, v.gsl()); + } return *this; } @@ -142,7 +148,10 @@ namespace Mantid /// @param v :: The other vector GSLVector& operator-=(const GSLVector& v) { - gsl_vector_sub(m_vector, v.gsl()); + if ( m_vector ) + { + gsl_vector_sub(m_vector, v.gsl()); + } return *this; } @@ -150,7 +159,10 @@ namespace Mantid /// @param d :: The number GSLVector& operator*=(const double d) { - gsl_vector_scale(m_vector, d); + if ( m_vector ) + { + gsl_vector_scale(m_vector, d); + } return *this; } diff --git a/Code/Mantid/Framework/CurveFitting/src/Fit.cpp b/Code/Mantid/Framework/CurveFitting/src/Fit.cpp index 8f8e67481b6..00dc374994b 100644 --- a/Code/Mantid/Framework/CurveFitting/src/Fit.cpp +++ b/Code/Mantid/Framework/CurveFitting/src/Fit.cpp @@ -422,6 +422,10 @@ namespace CurveFitting { doCalcErrors = true; } + if ( costFunc->nParams() == 0 ) + { + doCalcErrors = false; + } GSLMatrix covar; if ( doCalcErrors ) diff --git a/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp b/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp index 27d4908e745..97f9fdc30ff 100644 --- a/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp +++ b/Code/Mantid/Framework/CurveFitting/src/LevenbergMarquardtMDMinimizer.cpp @@ -59,19 +59,20 @@ bool LevenbergMarquardtMDMinimizer::iterate() } size_t n = m_leastSquares->nParams(); - //if (m_der.size() == 0) - //{ - // m_der.resize(n); - // m_hessian.resize(n,n); - //} + if ( n == 0 ) + { + m_errorString = "No parameters to fit"; + return false; + } + // calculate the first and second derivatives of the cost function. if (m_mu == 0.0) {// first time calculate everything - m_F = m_leastSquares->valDerivHessian(/*m_der, m_hessian*/); + m_F = m_leastSquares->valDerivHessian(); } else if (m_rho > 0) {// last iteration was good: calculate new m_der and m_hessian, dont't recalculate m_F - m_leastSquares->valDerivHessian(/*m_der, m_hessian, */false); + m_leastSquares->valDerivHessian(false); } // else if m_rho < 0 last iteration was bad: reuse m_der and m_hessian -- GitLab