Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #9782. Added gaussian with hand-coded derivatives
- Loading branch information
Michael Wedel
committed
Aug 13, 2014
1 parent
dc8c0c8
commit 1538ab6
Showing
5 changed files
with
218 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/GaussianHandCoded.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef MANTID_CURVEFITTING_GAUSSIANHANDCODED_H_ | ||
#define MANTID_CURVEFITTING_GAUSSIANHANDCODED_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/IFunction1D.h" | ||
#include "MantidAPI/ParamFunction.h" | ||
|
||
|
||
namespace Mantid | ||
{ | ||
namespace CurveFitting | ||
{ | ||
|
||
/** GaussianHandCoded : TODO: DESCRIPTION | ||
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport GaussianHandCoded : public API::IFunction1D, public API::ParamFunction | ||
{ | ||
public: | ||
GaussianHandCoded(); | ||
virtual ~GaussianHandCoded(); | ||
std::string name() const { return "GaussianHandCoded"; } | ||
|
||
void function1D(double *out, const double *xValues, const size_t nData) const; | ||
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData); | ||
|
||
protected: | ||
void init(); | ||
|
||
}; | ||
|
||
|
||
} // namespace CurveFitting | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_CURVEFITTING_GAUSSIANHANDCODED_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Code/Mantid/Framework/CurveFitting/src/GaussianHandCoded.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "MantidCurveFitting/GaussianHandCoded.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace CurveFitting | ||
{ | ||
|
||
using namespace API; | ||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
GaussianHandCoded::GaussianHandCoded() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
GaussianHandCoded::~GaussianHandCoded() | ||
{ | ||
} | ||
|
||
void GaussianHandCoded::function1D(double *out, const double *xValues, const size_t nData) const | ||
{ | ||
double height = getParameter("Height"); | ||
double centre = getParameter("PeakCentre"); | ||
double sigma = getParameter("Sigma"); | ||
|
||
for(size_t i = 0; i < nData; ++i) { | ||
out[i] = height * exp(-0.5 * pow( (xValues[i] - centre)/sigma, 2.0) ); | ||
} | ||
} | ||
|
||
void GaussianHandCoded::functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData) | ||
{ | ||
double height = getParameter("Height"); | ||
double centre = getParameter("PeakCentre"); | ||
double sigma = getParameter("Sigma"); | ||
|
||
for(size_t i = 0; i < nData; ++i) { | ||
double xDiff = xValues[i] - centre; | ||
double expTerm = exp(-0.5 * pow( (xDiff)/sigma, 2.0)); | ||
|
||
out->set(i, 0, expTerm); | ||
out->set(i, 1, (height*expTerm*(2 * xDiff))/(2*pow(sigma, 2))); | ||
out->set(i, 2, (height*expTerm*pow(xDiff, 2))/pow(sigma, 3)); | ||
} | ||
} | ||
|
||
void GaussianHandCoded::init() { | ||
declareParameter("Height"); | ||
declareParameter("PeakCentre"); | ||
declareParameter("Sigma"); | ||
} | ||
|
||
|
||
|
||
} // namespace CurveFitting | ||
} // namespace Mantid |
29 changes: 29 additions & 0 deletions
29
Code/Mantid/Framework/CurveFitting/test/GaussianHandCodedTest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef MANTID_CURVEFITTING_GAUSSIANHANDCODEDTEST_H_ | ||
#define MANTID_CURVEFITTING_GAUSSIANHANDCODEDTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
#include "MantidCurveFitting/GaussianHandCoded.h" | ||
|
||
using Mantid::CurveFitting::GaussianHandCoded; | ||
using namespace Mantid::API; | ||
|
||
class GaussianHandCodedTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
// This pair of boilerplate methods prevent the suite being created statically | ||
// This means the constructor isn't called when running other tests | ||
static GaussianHandCodedTest *createSuite() { return new GaussianHandCodedTest(); } | ||
static void destroySuite( GaussianHandCodedTest *suite ) { delete suite; } | ||
|
||
|
||
void test_Something() | ||
{ | ||
TSM_ASSERT( "You forgot to write a test!", 0); | ||
} | ||
|
||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_CURVEFITTING_GAUSSIANHANDCODEDTEST_H_ */ |