Mantid
Loading...
Searching...
No Matches
TableWorkspaceDomainCreator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 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// Includes
8//----------------------------------------------------------------------
9
11
15#include "MantidAPI/TableRow.h"
16#include "MantidAPI/TextAxis.h"
19
25
27
32
33#include <boost/math/distributions/students_t.hpp>
34
35namespace Mantid::CurveFitting {
36
37namespace {
38
42struct RangePoint {
43 enum Kind : char { Opening, Closing };
45 Kind kind;
47 double value;
50 bool operator<(const RangePoint &point) const {
51 if (this->value == point.value) {
52 // If an Opening and Closing points have the same value
53 // the Opening one should go first (be "smaller").
54 // This way the procedure of joinOverlappingRanges will join
55 // the ranges that meet at these points.
56 return this->kind == Opening;
57 }
58 return this->value < point.value;
59 }
60};
61
66void joinOverlappingRanges(std::vector<double> &exclude) {
67 if (exclude.empty()) {
68 return;
69 }
70 // The situation here is similar to matching brackets in an expression.
71 // If we sort all the points in the input vector remembering their kind
72 // then a separate exclusion region starts with the first openning bracket
73 // and ends with the matching closing bracket. All brackets (points) inside
74 // them can be dropped.
75
76 // Wrap the points into helper struct RangePoint
77 std::vector<RangePoint> points;
78 points.reserve(exclude.size());
79 for (auto point = exclude.begin(); point != exclude.end(); point += 2) {
80 points.emplace_back(RangePoint{RangePoint::Opening, *point});
81 points.emplace_back(RangePoint{RangePoint::Closing, *(point + 1)});
82 }
83 // Sort the points according to the operator defined in RangePoint.
84 std::sort(points.begin(), points.end());
85
86 // Clear the argument vector.
87 exclude.clear();
88 // Start the level counter which shows the number of unmatched openning
89 // brackets.
90 size_t level(0);
91 for (auto &point : points) {
92 if (point.kind == RangePoint::Opening) {
93 if (level == 0) {
94 // First openning bracket starts a new exclusion range.
95 exclude.emplace_back(point.value);
96 }
97 // Each openning bracket increases the level
98 ++level;
99 } else {
100 if (level == 1) {
101 // The bracket that makes level 0 is an end of a range.
102 exclude.emplace_back(point.value);
103 }
104 // Each closing bracket decreases the level
105 --level;
106 }
107 }
108}
109
110bool greaterIsLess(double x1, double x2) { return x1 > x2; }
111} // namespace
112
113using namespace Kernel;
114
123 const std::string &workspacePropertyName,
125 : IDomainCreator(fit, std::vector<std::string>(1, workspacePropertyName), domainType), m_startX(EMPTY_DBL()),
126 m_endX(EMPTY_DBL()), m_maxSize(0), m_noErrCol(false) {
127 if (m_workspacePropertyNames.empty()) {
128 throw std::runtime_error("Cannot create FitMW: no workspace given");
129 }
131}
132
139 : IDomainCreator(nullptr, std::vector<std::string>(), domainType), m_startX(EMPTY_DBL()), m_endX(EMPTY_DBL()),
140 m_maxSize(10), m_noErrCol(false) {}
141
148void TableWorkspaceDomainCreator::declareDatasetProperties(const std::string &suffix, bool addProp) {
149
150 m_startXPropertyName = "StartX" + suffix;
151 m_endXPropertyName = "EndX" + suffix;
152 m_maxSizePropertyName = "MaxSize" + suffix;
153 m_excludePropertyName = "Exclude" + suffix;
154 m_xColumnPropertyName = "XColumn" + suffix;
155 m_yColumnPropertyName = "YColumn" + suffix;
156 m_errorColumnPropertyName = "ErrColumn" + suffix;
157
158 if (addProp) {
160 "A value of x in, or on the low x boundary of, the first bin to "
161 "include in\n"
162 "the fit (default lowest value of x)");
164 "A value in, or on the high x boundary of, the last bin the fitting "
165 "range\n"
166 "(default the highest value of x)");
168 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
169 mustBePositive->setLower(0);
171 "The maximum number of values per a simple domain.");
172 }
174 auto mustBeOrderedPairs = std::make_shared<ArrayOrderedPairsValidator<double>>();
176 "A list of pairs of doubles that specify ranges that must be "
177 "excluded from fit.");
178 }
179 declareProperty(new PropertyWithValue<std::string>(m_xColumnPropertyName, ""), "The name of the X column.");
180 declareProperty(new PropertyWithValue<std::string>(m_yColumnPropertyName, ""), "The name of the Y column.");
181 declareProperty(new PropertyWithValue<std::string>(m_errorColumnPropertyName, ""), "The name of the error column.");
182 }
183}
184
186void TableWorkspaceDomainCreator::createDomain(std::shared_ptr<API::FunctionDomain> &domain,
187 std::shared_ptr<API::FunctionValues> &values, size_t i0) {
188
190
191 auto rowCount = m_tableWorkspace->rowCount();
192 if (rowCount == 0) {
193 throw std::runtime_error("Workspace contains no data.");
194 }
195
196 auto X = m_tableWorkspace->getColumn(m_xColName);
197 std::vector<double> xData;
198 xData.reserve(m_tableWorkspace->rowCount());
199 for (size_t i = 0; i < m_tableWorkspace->rowCount(); ++i) {
200 xData.emplace_back(X->toDouble(i));
201 }
202
203 // find the fitting interval: from -> to
204 size_t endRowNo = 0;
205 std::tie(m_startRowNo, endRowNo) = getXInterval(xData);
206 auto from = xData.begin() + m_startRowNo;
207 auto to = xData.begin() + endRowNo;
208 auto n = endRowNo - m_startRowNo;
209
210 if (m_domainType != Simple) {
211 if (m_maxSize < n) {
213 domain.reset(seqDomain);
214 size_t m = 0;
215 while (m < n) {
216 // create a simple creator
217 auto creator = new TableWorkspaceDomainCreator;
219 creator->setColumnNames(m_xColName, m_yColName, m_errColName);
220 size_t k = m + m_maxSize;
221 if (k > n)
222 k = n;
223 creator->setRange(*(from + m), *(from + k - 1));
224 seqDomain->addCreator(API::IDomainCreator_sptr(creator));
225 m = k;
226 }
227 values.reset();
228 return;
229 }
230 // else continue with simple domain
231 }
232
233 // set function domain
234 domain.reset(new API::FunctionDomain1DVector(from, to));
235
236 if (!values) {
237 values.reset(new API::FunctionValues(*domain));
238 } else {
239 values->expand(i0 + domain->size());
240 }
241
242 // set the data to fit to
243 assert(n == domain->size());
244 auto Y = m_tableWorkspace->getColumn(m_yColName);
245 if (endRowNo > Y->size()) {
246 throw std::runtime_error("TableWorkspaceDomainCreator: Inconsistent TableWorkspace");
247 }
248
249 // Helps find points excluded form fit.
250 ExcludeRangeFinder excludeFinder(m_exclude, xData.front(), xData.back());
251
252 auto errors = m_tableWorkspace->getColumn(m_errColName);
253 for (size_t i = m_startRowNo; i < endRowNo; ++i) {
254 size_t j = i - m_startRowNo + i0;
255 auto y = Y->toDouble(i);
256 auto error = errors->toDouble(i);
257 double weight = 0.0;
258
259 if (excludeFinder.isExcluded(xData[i])) {
260 weight = 0.0;
261 } else if (!std::isfinite(y)) {
262 // nan or inf data
264 throw std::runtime_error("Infinte number or NaN found in input data.");
265 y = 0.0; // leaving inf or nan would break the fit
266 } else if (m_noErrCol) {
267 weight = 1.0;
268 } else if (!std::isfinite(error)) {
269 // nan or inf error
271 throw std::runtime_error("Infinte number or NaN found in input data.");
272 } else if (error <= 0) {
274 weight = 1.0;
275 } else {
276 weight = 1.0 / error;
277 if (!std::isfinite(weight)) {
279 throw std::runtime_error("Error of a data point is probably too small.");
280 weight = 0.0;
281 }
282 }
283
284 values->setFitData(j, y);
285 values->setFitWeight(j, weight);
286 }
287 m_domain = std::dynamic_pointer_cast<API::FunctionDomain1D>(domain);
288 m_values = values;
289}
290
300 const std::string &baseName, API::IFunction_sptr function, std::shared_ptr<API::FunctionDomain> domain,
301 std::shared_ptr<API::FunctionValues> values, const std::string &outputWorkspacePropertyName) {
302
303 if (!values) {
304 throw std::logic_error("FunctionValues expected");
305 }
306
307 // Compile list of functions to output. The top-level one is first
308 std::list<API::IFunction_sptr> functionsToDisplay(1, function);
310 appendCompositeFunctionMembers(functionsToDisplay, function);
311 }
312
313 // Nhist = Data histogram, Difference Histogram + nfunctions
314 const size_t nhistograms = functionsToDisplay.size() + 2;
315 const size_t nyvalues = values->size();
316 auto ws = createEmptyResultWS(nhistograms, nyvalues);
317 // The workspace was constructed with a TextAxis
318 API::TextAxis *textAxis = static_cast<API::TextAxis *>(ws->getAxis(1));
319 textAxis->setLabel(0, "Data");
320 textAxis->setLabel(1, "Calc");
321 textAxis->setLabel(2, "Diff");
322
323 // Add each calculated function
324 auto iend = functionsToDisplay.end();
325 size_t wsIndex(1); // Zero reserved for data
326 for (auto it = functionsToDisplay.begin(); it != iend; ++it) {
327 if (wsIndex > 2)
328 textAxis->setLabel(wsIndex, (*it)->name());
329 addFunctionValuesToWS(*it, ws, wsIndex, domain, values);
330 if (it == functionsToDisplay.begin())
331 wsIndex += 2; // Skip difference histogram for now
332 else
333 ++wsIndex;
334 }
335
336 // Set the difference spectrum
337 const auto &Ycal = ws->y(1);
338 auto &Diff = ws->mutableY(2);
339 const size_t nData = values->size();
340 for (size_t i = 0; i < nData; ++i) {
341 if (values->getFitWeight(i) != 0.0) {
342 Diff[i] = values->getFitData(i) - Ycal[i];
343 } else {
344 Diff[i] = 0.0;
345 }
346 }
347
348 if (!outputWorkspacePropertyName.empty()) {
350 new API::WorkspaceProperty<API::MatrixWorkspace>(outputWorkspacePropertyName, "", Direction::Output),
351 "Name of the output Workspace holding resulting simulated spectrum");
352 m_manager->setPropertyValue(outputWorkspacePropertyName, baseName + "Workspace");
353 m_manager->setProperty(outputWorkspacePropertyName, ws);
354 }
355
356 return ws;
357}
358
363void TableWorkspaceDomainCreator::appendCompositeFunctionMembers(std::list<API::IFunction_sptr> &functionList,
364 const API::IFunction_sptr &function) const {
365 // if function is a Convolution then output of convolved model's members may
366 // be required
367 if (m_convolutionCompositeMembers && std::dynamic_pointer_cast<Functions::Convolution>(function)) {
368 appendConvolvedCompositeFunctionMembers(functionList, function);
369 } else {
370 const auto compositeFn = std::dynamic_pointer_cast<API::CompositeFunction>(function);
371 if (!compositeFn)
372 return;
373
374 const size_t nlocals = compositeFn->nFunctions();
375 for (size_t i = 0; i < nlocals; ++i) {
376 auto localFunction = compositeFn->getFunction(i);
377 auto localComposite = std::dynamic_pointer_cast<API::CompositeFunction>(localFunction);
378 if (localComposite)
379 appendCompositeFunctionMembers(functionList, localComposite);
380 else
381 functionList.insert(functionList.end(), localFunction);
382 }
383 }
384}
385
399void TableWorkspaceDomainCreator::appendConvolvedCompositeFunctionMembers(std::list<API::IFunction_sptr> &functionList,
400 const API::IFunction_sptr &function) const {
401 std::shared_ptr<Functions::Convolution> convolution = std::dynamic_pointer_cast<Functions::Convolution>(function);
402
403 const auto compositeFn = std::dynamic_pointer_cast<API::CompositeFunction>(convolution->getFunction(1));
404 if (!compositeFn) {
405 functionList.insert(functionList.end(), convolution);
406 } else {
407 auto resolution = convolution->getFunction(0);
408 const size_t nlocals = compositeFn->nFunctions();
409 for (size_t i = 0; i < nlocals; ++i) {
410 auto localFunction = compositeFn->getFunction(i);
411 std::shared_ptr<Functions::Convolution> localConvolution = std::make_shared<Functions::Convolution>();
412 localConvolution->addFunction(resolution);
413 localConvolution->addFunction(localFunction);
414 functionList.insert(functionList.end(), localConvolution);
415 }
416 }
417}
418
429 const API::IFunction_sptr &function, std::shared_ptr<API::MatrixWorkspace> &ws, const size_t wsIndex,
430 const std::shared_ptr<API::FunctionDomain> &domain,
431 const std::shared_ptr<API::FunctionValues> &resultValues) const {
432 const size_t nData = resultValues->size();
433 resultValues->zeroCalculated();
434 // Confidence bands are calculated based on the example in
435 // www.astro.rug.nl/software/kapteyn/kmpfittutorial.html#confidence-and-prediction-intervals,
436 // which references J.Wolberg, Data Analysis Using the Method of Least
437 // Squares, 2006, Springer.
438 // Here we asusme a confidence band of 1 sigma
439 double sigma = 1;
440 double prob = std::erf(sigma / sqrt(2));
441 // critical value for t distribution
442 double alpha = (1 + prob) / 2;
443
444 // Function value
445 function->function(*domain, *resultValues);
446
447 size_t nParams = function->nParams();
448
449 // the function should contain the parameter's covariance matrix
450 auto covar = function->getCovarianceMatrix();
451 bool hasErrors = false;
452 if (!covar) {
453 for (size_t j = 0; j < nParams; ++j) {
454 if (function->getError(j) != 0.0) {
455 hasErrors = true;
456 break;
457 }
458 }
459 }
460
461 if (covar || hasErrors) {
462 // and errors
463 Jacobian J(nData, nParams);
464 try {
465 function->functionDeriv(*domain, J);
466 } catch (...) {
467 function->calNumericalDeriv(*domain, J);
468 }
469 if (covar) {
470 // if the function has a covariance matrix attached - use it for the
471 // errors
472 const Kernel::Matrix<double> &C = *covar;
473 // The formula is E = J * C * J^T
474 // We don't do full 3-matrix multiplication because we only need the
475 // diagonals of E
476 std::vector<double> E(nData);
477 for (size_t k = 0; k < nData; ++k) {
478 double s = 0.0;
479 for (size_t i = 0; i < nParams; ++i) {
480 double tmp = J.get(k, i);
481 s += C[i][i] * tmp * tmp;
482 for (size_t j = i + 1; j < nParams; ++j) {
483 s += J.get(k, i) * C[i][j] * J.get(k, j) * 2;
484 }
485 }
486 E[k] = s;
487 }
488
489 size_t dof = nData - nParams;
490 auto &yValues = ws->mutableY(wsIndex);
491 auto &eValues = ws->mutableE(wsIndex);
492 double T = 1.0;
493 if (dof != 0) {
494 boost::math::students_t dist(static_cast<double>(dof));
495 T = boost::math::quantile(dist, alpha);
496 }
497 for (size_t i = 0; i < nData; i++) {
498 yValues[i] = resultValues->getCalculated(i);
499 eValues[i] = T * std::sqrt(E[i]);
500 }
501
502 } else {
503 // otherwise use the parameter errors which is OK for uncorrelated
504 // parameters
505 auto &yValues = ws->mutableY(wsIndex);
506 auto &eValues = ws->mutableE(wsIndex);
507 for (size_t i = 0; i < nData; i++) {
508 yValues[i] = resultValues->getCalculated(i);
509 double err = 0.0;
510 for (size_t j = 0; j < nParams; ++j) {
511 double d = J.get(i, j) * function->getError(j);
512 err += d * d;
513 }
514 eValues[i] = std::sqrt(err);
515 }
516 }
517 } else {
518 // No errors
519 auto &yValues = ws->mutableY(wsIndex);
520 for (size_t i = 0; i < nData; i++) {
521 yValues[i] = resultValues->getCalculated(i);
522 }
523 }
524}
525
534 const size_t nyvalues) {
535 size_t nxvalues(nyvalues);
537 API::WorkspaceFactory::Instance().create("Workspace2D", nhistograms, nxvalues, nyvalues);
538 ws->setTitle(m_tableWorkspace->getTitle());
539 auto tAxis = std::make_unique<API::TextAxis>(nhistograms);
540 ws->replaceAxis(1, std::move(tAxis));
541
542 auto inputX = m_tableWorkspace->getColumn(m_xColName);
543 auto inputY = m_tableWorkspace->getColumn(m_yColName);
544 auto inputE = m_tableWorkspace->getColumn(m_errColName);
545
546 std::vector<double> xData;
547 std::vector<double> yData;
548 std::vector<double> eData;
549 xData.reserve(m_tableWorkspace->rowCount());
550 yData.reserve(m_tableWorkspace->rowCount());
551 eData.reserve(m_tableWorkspace->rowCount());
552
553 for (size_t i = 0; i < m_tableWorkspace->rowCount(); ++i) {
554 xData.emplace_back(inputX->toDouble(i));
555 yData.emplace_back(inputY->toDouble(i));
556 eData.emplace_back(inputE->toDouble(i));
557 }
558
559 // X values for all
560 for (size_t i = 0; i < nhistograms; i++) {
561 ws->mutableX(i).assign(xData.begin() + m_startRowNo, xData.begin() + m_startRowNo + nxvalues);
562 }
563 // Data values for the first histogram
564 ws->mutableY(0).assign(yData.begin() + m_startRowNo, yData.begin() + m_startRowNo + nyvalues);
565 ws->mutableE(0).assign(eData.begin() + m_startRowNo, eData.begin() + m_startRowNo + nyvalues);
566
567 return ws;
568}
569
575 auto X = m_tableWorkspace->getColumn(m_xColName);
576 std::vector<double> xData;
577 xData.reserve(m_tableWorkspace->rowCount());
578 for (size_t i = 0; i < m_tableWorkspace->rowCount(); ++i) {
579 xData.emplace_back(X->toDouble(i));
580 }
581 size_t startIndex, endIndex;
582 std::tie(startIndex, endIndex) = getXInterval(xData);
583 return endIndex - startIndex;
584}
585
592 if (!function) {
593 throw std::runtime_error("Cannot initialize empty function.");
594 }
595 function->setWorkspace(m_tableWorkspace);
596 setInitialValues(*function);
597}
598
604 auto domain = m_domain.lock();
605 auto values = m_values.lock();
606 if (domain && values) {
607 ParameterEstimator::estimate(function, *domain, *values);
608 }
609}
610
615std::pair<size_t, size_t> TableWorkspaceDomainCreator::getXInterval(std::vector<double> xData) const {
616 const auto sizeOfData = xData.size();
617 if (sizeOfData == 0) {
618 throw std::runtime_error("Workspace contains no data.");
619 }
620
622
623 // From points to the first occurrence of StartX in the workspace interval.
624 // End points to the last occurrence of EndX in the workspace interval.
625 // Find the fitting interval: from -> to
626 Mantid::MantidVec::iterator from;
627 Mantid::MantidVec::iterator to;
628
629 bool isXAscending = xData.front() < xData.back();
630
631 if (m_startX == EMPTY_DBL() && m_endX == EMPTY_DBL()) {
632 m_startX = xData.front();
633 from = xData.begin();
634 m_endX = xData.back();
635 to = xData.end();
636 } else if (m_startX == EMPTY_DBL() || m_endX == EMPTY_DBL()) {
637 throw std::invalid_argument("Both StartX and EndX must be given to set fitting interval.");
638 } else if (isXAscending) {
639 if (m_startX > m_endX) {
640 std::swap(m_startX, m_endX);
641 }
642 from = std::lower_bound(xData.begin(), xData.end(), m_startX);
643 to = std::upper_bound(from, xData.end(), m_endX);
644 } else { // x is descending
645 if (m_startX < m_endX) {
646 std::swap(m_startX, m_endX);
647 }
648 from = std::lower_bound(xData.begin(), xData.end(), m_startX, greaterIsLess);
649 to = std::upper_bound(from, xData.end(), m_endX, greaterIsLess);
650 }
651
652 // Check whether the fitting interval defined by StartX and EndX is 0.
653 // This occurs when StartX and EndX are both less than the minimum workspace
654 // x-value or greater than the maximum workspace x-value.
655 if (to - from == 0) {
656 throw std::invalid_argument("StartX and EndX values do not capture a range "
657 "within the workspace interval.");
658 }
659
660 return std::make_pair(std::distance(xData.begin(), from), std::distance(xData.begin(), to));
661}
662
669 // if property manager is set overwrite any set parameters
670 if (m_manager) {
671 // get the workspace
674 if (m_domainType != Simple) {
675 const int maxSizeInt = m_manager->getProperty(m_maxSizePropertyName);
676 m_maxSize = static_cast<size_t>(maxSizeInt);
677 }
679 if (m_exclude.size() % 2 != 0) {
680 throw std::runtime_error("Exclude property has an odd number of entries. "
681 "It has to be even as each pair specifies a "
682 "start and an end of an interval to exclude.");
683 }
686 joinOverlappingRanges(m_exclude);
687 }
688}
689
702
703 auto columnNames = ws->getColumnNames();
704
705 std::string xColName = m_manager->getProperty(m_xColumnPropertyName);
706 if (xColName != "") {
707 auto column = ws->getColumn(xColName);
708 if (!column->isNumber()) {
709 throw std::invalid_argument(xColName + " does not contain numbers");
710 }
711 }
712
713 std::string yColName = m_manager->getProperty(m_yColumnPropertyName);
714 if (yColName != "") {
715 auto column = ws->getColumn(yColName);
716 if (!column->isNumber()) {
717 throw std::invalid_argument(yColName + " does not contain numbers");
718 }
719 }
720
721 std::string eColName = m_manager->getProperty(m_errorColumnPropertyName);
722 if (eColName != "") {
723 auto column = ws->getColumn(eColName);
724 if (!column->isNumber()) {
725 throw std::invalid_argument(eColName + " does not contain numbers");
726 }
727 }
728
729 // get the column name from plot type
730 for (const auto &name : columnNames) {
731 auto column = ws->getColumn(name);
732 if (xColName == "" && column->getPlotType() == 1) {
733 xColName = column->name();
734 }
735 if (yColName == "" && column->getPlotType() == 2) {
736 yColName = column->name();
737 }
738 if (eColName == "" && column->getPlotType() == 5) {
739 eColName = column->name();
740 }
741 }
742
743 if (xColName != "" && yColName != "") {
744 setColumnNames(xColName, yColName, eColName);
745 } else {
746 throw std::invalid_argument("No valid input for X or Y column names");
747 }
748}
749
757 auto tableWorkspace = std::dynamic_pointer_cast<API::ITableWorkspace>(ws);
758 if (!tableWorkspace) {
759 throw std::invalid_argument("InputWorkspace must be a TableWorkspace.");
760 }
761 setXYEColumnNames(tableWorkspace);
762 std::vector<std::string> columnNames;
763 columnNames.emplace_back(m_xColName);
764 columnNames.emplace_back(m_yColName);
765 if (m_errColName != "")
766 columnNames.emplace_back(m_errColName);
767 // table workspace is cloned so it can be changed within the domain
768 m_tableWorkspace = tableWorkspace->cloneColumns(columnNames);
769
770 // if no error column has been found a column is added with 0 errors
771 if (columnNames.size() == 2) {
772 m_errColName = "AddedErrorColumn";
773 m_noErrCol = true;
774 auto columnAdded = m_tableWorkspace->addColumn("double", m_errColName);
775 if (!columnAdded)
776 throw std::invalid_argument("No error column provided.");
777 }
778
779 if (m_tableWorkspace->columnCount() != 3) {
780 throw std::invalid_argument("X or Y Columns not found");
781 }
782}
783} // namespace Mantid::CurveFitting
gsl_vector * tmp
Kind kind
The kind of the point: either openning or closing the range.
Definition: FitMW.cpp:49
double value
The value of the point.
Definition: FitMW.cpp:51
double sigma
Definition: GetAllEi.cpp:156
double error
Definition: IndexPeaks.cpp:133
Implements FunctionDomain1D with its own storage in form of a std::vector.
A class to store values calculated by a function.
An base class for domain creators for use in Fit.
DomainType
Type of domain to create.
bool m_convolutionCompositeMembers
Perform convolution of output composite components.
bool m_outputCompositeMembers
Output separate composite function values.
std::vector< std::string > m_workspacePropertyNames
Property names for workspaces to get the data from.
Kernel::IPropertyManager * m_manager
Pointer to a property manager.
bool m_ignoreInvalidData
Flag to ignore nans, infinities and zero errors.
void declareProperty(Kernel::Property *prop, const std::string &doc)
Declare a property to the algorithm.
DomainType m_domainType
Domain type.
This is an interface to a fitting function - a semi-abstarct class.
Definition: IFunction.h:163
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
virtual double get(size_t iY, size_t iP)=0
Get the value to a Jacobian matrix element.
Class to represent a text axis of a workspace.
Definition: TextAxis.h:36
void setLabel(const std::size_t &index, const std::string &lbl)
Set the label at the given index.
Definition: TextAxis.cpp:104
A property class for workspaces.
ExcludeRangeFinder : Helper clss that finds if a point should be excluded from fit.
bool isExcluded(double value)
Check if an x-value lies in an exclusion range.
An implementation of CompositeDomain.
Definition: SeqDomain.h:30
void addCreator(const API::IDomainCreator_sptr &creator)
Add new domain creator.
Definition: SeqDomain.cpp:48
static SeqDomain * create(API::IDomainCreator::DomainType type)
Create an instance of SeqDomain in one of two forms: either SeqDomain for sequential domain creation ...
Definition: SeqDomain.cpp:60
void setXYEColumnNames(const API::ITableWorkspace_sptr &ws) const
Set the names of the X, Y and Error columns.
std::shared_ptr< API::Workspace > createOutputWorkspace(const std::string &baseName, API::IFunction_sptr function, std::shared_ptr< API::FunctionDomain > domain, std::shared_ptr< API::FunctionValues > values, const std::string &outputWorkspacePropertyName) override
Create an output workspace with the calculated values.
std::string m_startXPropertyName
Store startX property name.
size_t m_startRowNo
Store number of the first row used in fitting.
std::string m_workspacePropertyName
Store workspace property name.
void addFunctionValuesToWS(const API::IFunction_sptr &function, std::shared_ptr< API::MatrixWorkspace > &ws, const size_t wsIndex, const std::shared_ptr< API::FunctionDomain > &domain, const std::shared_ptr< API::FunctionValues > &resultValues) const
Add the calculated function values to the workspace.
std::string m_maxSizePropertyName
Store maxSize property name.
std::weak_ptr< API::FunctionDomain1D > m_domain
Store the created domain and values.
void setInitialValues(API::IFunction &function)
Set initial values for parameters with default values.
void setWorkspace(API::ITableWorkspace_sptr ws)
Set the workspace.
std::pair< size_t, size_t > getXInterval(std::vector< double > XData) const
Calculate size and starting iterator in the X array.
bool m_noErrCol
Flag to indicate if no error column was found.
TableWorkspaceDomainCreator(Kernel::IPropertyManager *fit, const std::string &workspacePropertyName, DomainType domainType=Simple)
Constructor.
std::vector< double > m_exclude
Ranges that must be excluded from fit.
std::string m_yColumnPropertyName
Store YColumnName property name.
std::string m_xColumnPropertyName
Store XColumnName property name.
std::string m_errColName
Store the Y Error column name.
void declareDatasetProperties(const std::string &suffix="", bool addProp=true) override
Declare properties that specify the dataset within the workspace to fit to.
void appendCompositeFunctionMembers(std::list< API::IFunction_sptr > &functionList, const API::IFunction_sptr &function) const
std::shared_ptr< API::MatrixWorkspace > createEmptyResultWS(const size_t nhistograms, const size_t nyvalues)
Creates the blank output workspace of the correct size.
std::string m_excludePropertyName
Store the Exclude property name.
void setColumnNames(const std::string &xColName, const std::string &yColName, const std::string &errColName) const
Set the names Of the x, y and error columns.
void setAndValidateWorkspace(const API::Workspace_sptr &ws) const
Check workspace is in the correct form.
void appendConvolvedCompositeFunctionMembers(std::list< API::IFunction_sptr > &functionList, const API::IFunction_sptr &function) const
If the fit function is Convolution and flag m_convolutionCompositeMembers is set and Convolution's se...
API::ITableWorkspace_sptr m_tableWorkspace
The input TableWorkspace.
void initFunction(API::IFunction_sptr function) override
Initialize the function with the workspace.
void createDomain(std::shared_ptr< API::FunctionDomain > &domain, std::shared_ptr< API::FunctionValues > &values, size_t i0=0) override
Create a domain from the input workspace.
std::string m_errorColumnPropertyName
Store errorColumnName property name.
size_t getDomainSize() const override
Return the size of the domain to be created.
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
Interface to PropertyManager.
virtual void setPropertyValue(const std::string &name, const std::string &value)=0
Sets property value from a string.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
virtual bool existsProperty(const std::string &name) const =0
Checks whether the named property is already in the list of managed property.
virtual TypedValue getProperty(const std::string &name) const =0
Get the value of a property.
Numerical Matrix class.
Definition: Matrix.h:42
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
std::shared_ptr< IDomainCreator > IDomainCreator_sptr
Typedef for a shared pointer to IDomainCreator.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
void MANTID_CURVEFITTING_DLL estimate(API::IFunction &function, const API::FunctionDomain1D &domain, const API::FunctionValues &values)
ParameterEstimator estimates parameter values of some fitting functions from fitting data.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43
STL namespace.
constexpr bool operator<(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
@ Output
An output workspace.
Definition: Property.h:54