Skip to content

Commit

Permalink
Refs #10623. Changed Poldi2DFunction to adjust weighting scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Dec 4, 2014
1 parent 974477e commit 3ef7a80
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Expand Up @@ -50,6 +50,10 @@ class MANTID_SINQ_DLL Poldi2DFunction : virtual public API::IFunction1DSpectrum,
virtual void functionDeriv(const API::FunctionDomain &domain, API::Jacobian &jacobian);

virtual void function1DSpectrum(const API::FunctionDomain1DSpectrum &domain, API::FunctionValues &values) const;

void iterationFinished();
private:
size_t m_iteration;
};


Expand Down
Expand Up @@ -8,7 +8,8 @@ using namespace API;

Poldi2DFunction::Poldi2DFunction() :
IFunction1DSpectrum(),
CompositeFunction()
CompositeFunction(),
m_iteration(0)
{
}

Expand All @@ -24,6 +25,12 @@ Poldi2DFunction::Poldi2DFunction() :
void Poldi2DFunction::function(const FunctionDomain &domain, FunctionValues &values) const
{
CompositeFunction::function(domain, values);

if(m_iteration > 0) {
for(size_t i = 0; i < values.size(); ++i) {
values.setFitWeight(i, 1.0/sqrt(values.getCalculated(i) + 0.1));
}
}
}

/**
Expand All @@ -50,6 +57,11 @@ void Poldi2DFunction::function1DSpectrum(const FunctionDomain1DSpectrum &domain,
UNUSED_ARG(values);
}

void Poldi2DFunction::iterationFinished()
{
++m_iteration;
}



} // namespace Poldi
Expand Down
33 changes: 33 additions & 0 deletions Code/Mantid/Framework/SINQ/test/Poldi2DFunctionTest.h
Expand Up @@ -56,6 +56,39 @@ class Poldi2DFunctionTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(values[9], 2.0);
}

void testIterationBehavior()
{
boost::shared_ptr<Poldi2DFunction> function2D(new Poldi2DFunction);

IFunction_sptr first(new SummingFunction);
IFunction_sptr second(new SummingFunction);

function2D->addFunction(first);
function2D->addFunction(second);

// x doesn't matter for that function
std::vector<double> x(10, 1.0);

FunctionDomain1DSpectrum domain(0, x);
FunctionValues values(domain);


function2D->function(domain, values);

for(size_t i = 0; i < values.size(); ++i) {
TS_ASSERT_THROWS(values.getFitWeight(i), std::runtime_error);
}

function2D->iterationFinished();

function2D->function(domain, values);

for(size_t i = 0; i < values.size(); ++i) {
TS_ASSERT_THROWS_NOTHING(values.getFitWeight(i));
TS_ASSERT_EQUALS(values.getFitWeight(i), 1.0/sqrt(fabs(values.getCalculated(i) + 0.1)));
}
}

private:
/* small test function that behaves like PoldiSpectrumDomainFunction
* in that it uses FunctionValues::addToCalculated.
Expand Down

0 comments on commit 3ef7a80

Please sign in to comment.