-
Notifications
You must be signed in to change notification settings - Fork 122
/
LorentzianFamily.cpp
93 lines (72 loc) · 2.3 KB
/
LorentzianFamily.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "MantidCurveFitting/LorentzianFamily.h"
namespace Mantid
{
namespace CurveFitting
{
namespace Lorentzians {
using namespace API;
void LorentzianHandCoded::function1D(double *out, const double *xValues, const size_t nData) const
{
double h = getParameter("Height");
double x0 = getParameter("Centre");
double s = getParameter("Gamma");
for(size_t i = 0; i < nData; ++i) {
double diff = xValues[i] - x0;
out[i] = h * s * s / (diff*diff + s * s);
}
}
void LorentzianHandCoded::functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData)
{
double h = getParameter("Height");
double x0 = getParameter("Centre");
double s = getParameter("Gamma");
for(size_t i = 0; i < nData; ++i) {
double diff = xValues[i] - x0;
double num = diff*diff + s * s;
double ssquared = s * s;
out->set(i, 0, 2 * h * ssquared * diff / (num * num));
out->set(i, 1, ssquared / (num));
out->set(i, 2, 2 * h * s / num * (1 - ssquared / num));
}
}
void LorentzianHandCoded::init()
{
declareParameter("Centre");
declareParameter("Height");
declareParameter("Gamma");
}
void LorentzianNumDiff::function1D(double *out, const double *xValues, const size_t nData) const
{
double h = getParameter("Height");
double x0 = getParameter("Centre");
double s = getParameter("Gamma");
for(size_t i = 0; i < nData; ++i) {
double diff = xValues[i] - x0;
out[i] = h * s * s / (diff*diff + s * s);
}
}
void LorentzianNumDiff::init()
{
declareParameter("Centre");
declareParameter("Height");
declareParameter("Gamma");
}
void LorentzianAutoDiff::function1DAutoDiff(const FunctionDomain1D &domain, std::vector<adept::adouble> &y, const AutoDiffParameterAdapter ¶meters) const
{
adept::adouble h = parameters.getParameter("Height");
adept::adouble x0 = parameters.getParameter("Centre");
adept::adouble s = parameters.getParameter("Gamma");
for(size_t i = 0; i < y.size(); ++i) {
adept::adouble diff = domain[i] - x0;
y[i] = h * s * s / (diff*diff + s * s);
}
}
void LorentzianAutoDiff::init()
{
declareParameter("Centre");
declareParameter("Height");
declareParameter("Gamma");
}
}
} // namespace CurveFitting
} // namespace Mantid