Skip to content

Commit

Permalink
Refs #9782. Comparison capability on AutoDiffTestAlg
Browse files Browse the repository at this point in the history
Roman's changes to make a comparison possible between numerical and auto diff.
  • Loading branch information
Michael Wedel committed Jul 31, 2014
1 parent 1fbcda1 commit 8054491
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Expand Up @@ -46,11 +46,13 @@ namespace CurveFitting
void init();
void exec();

std::string m_derType;


};


} // namespace CurveFitting
} // namespace Mantid

#endif /* MANTID_CURVEFITTING_AUTODIFFTESTALG_H_ */
#endif /* MANTID_CURVEFITTING_AUTODIFFTESTALG_H_ */
38 changes: 35 additions & 3 deletions Code/Mantid/Framework/CurveFitting/src/AutoDiffTestAlg.cpp
@@ -1,8 +1,10 @@
#include "MantidCurveFitting/AutoDiffTestAlg.h"
#include "MantidCurveFitting/Gaussian.h"
#include "MantidCurveFitting/GaussianNumDiff.h"

#include "MantidCurveFitting/GaussianAutoDiff.h"
#include "MantidAPI/CompositeFunction.h"
#include "MantidKernel/Timer.h"
#include "MantidKernel/Logger.h"

namespace Mantid
{
Expand Down Expand Up @@ -53,15 +55,42 @@ void AutoDiffTestAlg::init()
declareProperty(new WorkspaceProperty<MatrixWorkspace>("InputWorkspace","",Direction::Input), "Data with 20 gaussian peaks.");
declareProperty(new WorkspaceProperty<ITableWorkspace>("OutputWorkspace","",Direction::Output), "Data with 20 gaussian peaks.");
declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspacePlot","",Direction::Output), "Data with 20 gaussian peaks.");
declareProperty("DerivativeType","adept","How to calculate derivatives.");

}

//----------------------------------------------------------------------------------------------
namespace
{

// Logger
Kernel::Logger g_log("AutoDiffTestAlg");

IFunction_sptr getFunction(const std::string& type)
{
if ( type == "adept" )
{
return IFunction_sptr(new GaussianAutoDiff);
}
/*
API::CompositeFunction_sptr comp(new API::CompositeFunction);
auto gauss = IFunction_sptr(new GaussianNumDiff);
gauss->initialize();
comp->addFunction( gauss );
comp->setAttributeValue("NumDeriv",true);
return comp;
*/
return IFunction_sptr(new GaussianNumDiff);
}
}

//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void AutoDiffTestAlg::exec()
{
MatrixWorkspace_sptr fitData = getProperty("InputWorkspace");
m_derType = getPropertyValue("DerivativeType");

// reference positions
std::vector<double> peakPos;
Expand Down Expand Up @@ -130,11 +159,10 @@ void AutoDiffTestAlg::exec()
sigma.push_back(12.065185190743160);
sigma.push_back(5.657079363007425);


// make composite function
CompositeFunction_sptr bigFunction(new CompositeFunction);
for(size_t i = 0; i < 20; ++i) {
IFunction_sptr g(new GaussianAutoDiff);
IFunction_sptr g = getFunction(m_derType);
g->initialize();
g->setParameter(0, peakHeight[i] * 1.1);
g->setParameter(2, sigma[i] * 1.15);
Expand All @@ -145,6 +173,8 @@ void AutoDiffTestAlg::exec()
bigFunction->addFunction(g);
}

Kernel::Timer timer;

IAlgorithm_sptr fitAlgorithm = createChildAlgorithm("Fit", -1, -1, true);
fitAlgorithm->setProperty("CreateOutput", true);
fitAlgorithm->setProperty("Output", "FitPeaks1D");
Expand All @@ -155,6 +185,8 @@ void AutoDiffTestAlg::exec()

fitAlgorithm->execute();

g_log.warning() << "Fit took " << timer.elapsed() << " seconds to complete" << std::endl;

ITableWorkspace_sptr t = fitAlgorithm->getProperty("OutputParameters");
MatrixWorkspace_sptr mw = fitAlgorithm->getProperty("OutputWorkspace");

Expand Down

0 comments on commit 8054491

Please sign in to comment.