Mantid
Loading...
Searching...
No Matches
Jacobian.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
10
11#include <vector>
12
13namespace Mantid {
14namespace CurveFitting {
21class Jacobian : public API::Jacobian {
23 size_t m_ny;
25 size_t m_np;
27 std::vector<double> m_data;
28
29public:
33 Jacobian(size_t ny, size_t np) : m_ny(ny), m_np(np) { m_data.resize(ny * np, 0.0); }
39 void addNumberToColumn(const double &value, const size_t &iP) override {
40 if (iP < m_np) {
41 // add penalty to first and last point and every 10th point in between
42 m_data[iP] += value;
43 m_data[(m_ny - 1) * m_np + iP] += value;
44 for (size_t iY = 9; iY < m_ny; iY += 10)
45 m_data[iY * m_np + iP] += value;
46 } else {
47 throw std::runtime_error("Try to add number to column of Jacobian matrix "
48 "which does not exist.");
49 }
50 }
52 void set(size_t iY, size_t iP, double value) override {
53 if (iY >= m_ny) {
54 throw std::out_of_range("Data index in Jacobian is out of range");
55 }
56 if (iP >= m_np) {
58 }
59 m_data[iY * m_np + iP] = value;
60 }
62 double get(size_t iY, size_t iP) override {
63 if (iY >= m_ny) {
64 throw std::out_of_range("Data index in Jacobian is out of range");
65 }
66 if (iP >= m_np) {
68 }
69 return m_data[iY * m_np + iP];
70 }
72 void zero() override { m_data.assign(m_data.size(), 0.0); }
73};
74
75} // namespace CurveFitting
76} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
const std::vector< Type > & m_data
Definition: TableColumn.h:417
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
size_t m_ny
Number of data points.
Definition: Jacobian.h:23
double get(size_t iY, size_t iP) override
overwrite base method
Definition: Jacobian.h:62
Jacobian(size_t ny, size_t np)
Constructor.
Definition: Jacobian.h:33
void zero() override
overwrite base method
Definition: Jacobian.h:72
std::vector< double > m_data
Storage for the derivatives.
Definition: Jacobian.h:27
void set(size_t iY, size_t iP, double value) override
overwrite base method
Definition: Jacobian.h:52
size_t m_np
Number of parameters in a function (== IFunction::nParams())
Definition: Jacobian.h:25
void addNumberToColumn(const double &value, const size_t &iP) override
overwrite base method
Definition: Jacobian.h:39
Exception thrown when a fitting function changes number of parameters during fit.
Definition: Exception.h:336
Helper class which provides the Collimation Length for SANS instruments.