Skip to content

Commit

Permalink
Re #10031. Throw exception if not converged.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Sep 30, 2014
1 parent 70ae491 commit a1c750e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
6 changes: 1 addition & 5 deletions Code/Mantid/Framework/CurveFitting/src/FABADAMinimizer.cpp
Expand Up @@ -105,6 +105,7 @@ FABADAMinimizer::~FABADAMinimizer()

if ( m_numberIterations > maxIterations )
{
g_log.warning() << "MaxIterations property reduces the required number of iterations (" << m_numberIterations << ")." << std::endl;
m_numberIterations = maxIterations;
}

Expand Down Expand Up @@ -362,11 +363,6 @@ FABADAMinimizer::~FABADAMinimizer()
{
return true;
}
else if (m_counter == m_numberIterations - 1)
{
m_converged = true;
return true;
}
// If there is not convergence, but it has been made convergenceMaxIterations iterations, stop and throw the error.
else
{
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/CurveFitting/src/Fit.cpp
Expand Up @@ -118,7 +118,7 @@ namespace CurveFitting
auto &properties = minimizer.getProperties();
for(auto prop = properties.begin(); prop != properties.end(); ++prop)
{
if ( (**prop).direction() == Kernel::Direction::Output )
if ( (**prop).direction() == Kernel::Direction::Output && (**prop).isValid() == "" )
{
Kernel::Property* property = (**prop).clone();
declareProperty( property );
Expand Down
33 changes: 29 additions & 4 deletions Code/Mantid/Framework/CurveFitting/test/FABADAMinimizerTest.h
Expand Up @@ -34,7 +34,7 @@ class FABADAMinimizerTest : public CxxTest::TestSuite
auto ws2 = createTestWorkspace(histogram);

API::IFunction_sptr fun(new ExpDecay);
fun->setParameter("Height",1.);
fun->setParameter("Height",8.);
fun->setParameter("Lifetime",1.0);

Fit fit;
Expand All @@ -46,13 +46,13 @@ class FABADAMinimizerTest : public CxxTest::TestSuite
fit.setProperty("WorkspaceIndex",0);
fit.setProperty("CreateOutput",true);
fit.setProperty("MaxIterations",100000);
fit.setProperty("Minimizer", "FABADA,ChainLength=5000,ConvergenceCriteria = 0.01, OutputWorkspaceConverged=conv");
fit.setProperty("Minimizer", "FABADA,ChainLength=5000,ConvergenceCriteria = 0.1, OutputWorkspaceConverged=conv");

TS_ASSERT_THROWS_NOTHING( fit.execute() );

TS_ASSERT(fit.isExecuted());

TS_ASSERT_DELTA( fun->getParameter("Height"), 10.0, 1e-2);
TS_ASSERT_DELTA( fun->getParameter("Height"), 10.0, 1e-1);
TS_ASSERT_DELTA( fun->getParameter("Lifetime"), 0.5, 1e-2);

TS_ASSERT_EQUALS(fit.getPropertyValue("OutputStatus"), "success");
Expand Down Expand Up @@ -107,7 +107,7 @@ class FABADAMinimizerTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(wsChain->getNumberHistograms(),n+1);

const Mantid::MantidVec& Xchain = wsChain->dataX(0);
TS_ASSERT_EQUALS(Xchain.size(), 5001);
TS_ASSERT_EQUALS(Xchain.size(), 6881);
TS_ASSERT_EQUALS(Xchain[5000], 5000);

TS_ASSERT(Xconv.size() < Xchain.size());
Expand All @@ -132,6 +132,31 @@ class FABADAMinimizerTest : public CxxTest::TestSuite

}

void test_low_MaxIterations()
{
const bool histogram(false);
auto ws2 = createTestWorkspace(histogram);

API::IFunction_sptr fun(new ExpDecay);
fun->setParameter("Height",1.);
fun->setParameter("Lifetime",1.0);

Fit fit;
fit.initialize();

fit.setRethrows(true);
fit.setProperty("Function",fun);
fit.setProperty("InputWorkspace",ws2);
fit.setProperty("WorkspaceIndex",0);
fit.setProperty("CreateOutput",true);
fit.setProperty("MaxIterations",10);
fit.setProperty("Minimizer", "FABADA,ChainLength=5000,ConvergenceCriteria = 0.01, OutputWorkspaceConverged=conv");

TS_ASSERT_THROWS( fit.execute(), std::runtime_error );

TS_ASSERT( !fit.isExecuted() );

}
private:

API::MatrixWorkspace_sptr createTestWorkspace(const bool histogram)
Expand Down

0 comments on commit a1c750e

Please sign in to comment.