Skip to content
Snippets Groups Projects
Commit 87521c32 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Added more detail to Fit at information log level. Refs #7199

* The value of the cost function is printed after each iteration
* The Covariance & Hessian matrix are output at the end of the fit
parent 6e75e81e
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
namespace Mantid namespace Mantid
{ {
namespace Kernel
{
class Logger;
}
namespace CurveFitting namespace CurveFitting
{ {
class SeqDomain; class SeqDomain;
...@@ -44,7 +48,7 @@ class DLLExport CostFuncLeastSquares : public CostFuncFitting ...@@ -44,7 +48,7 @@ class DLLExport CostFuncLeastSquares : public CostFuncFitting
{ {
public: public:
/// Constructor /// Constructor
CostFuncLeastSquares():CostFuncFitting(),m_value(0),m_pushed(false){} CostFuncLeastSquares();
/// Virtual destructor /// Virtual destructor
virtual ~CostFuncLeastSquares() {} virtual ~CostFuncLeastSquares() {}
...@@ -103,6 +107,7 @@ private: ...@@ -103,6 +107,7 @@ private:
friend class SeqDomain; friend class SeqDomain;
friend class ParDomain; friend class ParDomain;
Kernel::Logger & m_log;
}; };
} // namespace CurveFitting } // namespace CurveFitting
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "MantidAPI/CompositeDomain.h" #include "MantidAPI/CompositeDomain.h"
#include "MantidAPI/FunctionValues.h" #include "MantidAPI/FunctionValues.h"
#include <iomanip>
namespace namespace
{ {
const bool debug = false; const bool debug = false;
...@@ -20,6 +22,12 @@ namespace CurveFitting ...@@ -20,6 +22,12 @@ namespace CurveFitting
DECLARE_COSTFUNCTION(CostFuncLeastSquares,Least squares) DECLARE_COSTFUNCTION(CostFuncLeastSquares,Least squares)
/**
* Constructor
*/
CostFuncLeastSquares::CostFuncLeastSquares() : CostFuncFitting(),m_value(0),m_pushed(false),
m_log(Kernel::Logger::get("CostFuncLeastSquares")) {}
/** Calculate value of cost function /** Calculate value of cost function
* @return :: The value of the function * @return :: The value of the function
*/ */
...@@ -452,8 +460,41 @@ void CostFuncLeastSquares::calActiveCovarianceMatrix(GSLMatrix& covar, double ep ...@@ -452,8 +460,41 @@ void CostFuncLeastSquares::calActiveCovarianceMatrix(GSLMatrix& covar, double ep
{ {
valDerivHessian(); valDerivHessian();
} }
if(m_log.is(Kernel::Logger::Priority::PRIO_INFORMATION))
{
m_log.information() << "== Hessian (H) ==\n";
std::ios::fmtflags prevState = m_log.information().flags();
m_log.information() << std::left << std::fixed;
for(size_t i = 0; i < m_hessian.size1(); ++i)
{
for(size_t j = 0; j < m_hessian.size2(); ++j)
{
m_log.information() << std::setw(10);
m_log.information() << m_hessian.get(i,j) << " ";
}
m_log.information() << "\n";
}
m_log.information().flags(prevState);
}
covar = m_hessian; covar = m_hessian;
covar.invert(); covar.invert();
if(m_log.is(Kernel::Logger::Priority::PRIO_INFORMATION))
{
m_log.information() << "== Covariance matrix (H^-1) ==\n";
std::ios::fmtflags prevState = m_log.information().flags();
m_log.information() << std::left << std::fixed;
for(size_t i = 0; i < covar.size1(); ++i)
{
for(size_t j = 0; j < covar.size2(); ++j)
{
m_log.information() << std::setw(10);
m_log.information() << covar.get(i,j) << " ";
}
m_log.information() << "\n";
}
m_log.information().flags(prevState);
}
} }
} // namespace CurveFitting } // namespace CurveFitting
......
...@@ -611,8 +611,6 @@ namespace CurveFitting ...@@ -611,8 +611,6 @@ namespace CurveFitting
size_t iter = 0; size_t iter = 0;
bool success = false; bool success = false;
std::string errorString; std::string errorString;
//double costFuncVal = 0;
//do
g_log.debug("Starting minimizer iteration\n"); g_log.debug("Starting minimizer iteration\n");
while (static_cast<int>(iter) < maxIterations) while (static_cast<int>(iter) < maxIterations)
{ {
...@@ -633,6 +631,10 @@ namespace CurveFitting ...@@ -633,6 +631,10 @@ namespace CurveFitting
} }
prog.report(); prog.report();
m_function->iterationFinished(); m_function->iterationFinished();
if(g_log.is(Kernel::Logger::Priority::PRIO_INFORMATION))
{
g_log.information() << "Iteration " << iter << ", cost function = " << minimizer->costFunctionVal() << "\n";
}
} }
g_log.information() << "Number of minimizer iterations=" << iter << "\n"; g_log.information() << "Number of minimizer iterations=" << iter << "\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment