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
397void TableWorkspaceDomainCreator::appendConvolvedCompositeFunctionMembers(std::list<API::IFunction_sptr> &functionList,
398 const API::IFunction_sptr &function) const {
399 std::shared_ptr<Functions::Convolution> convolution = std::dynamic_pointer_cast<Functions::Convolution>(function);
400
401 const auto compositeFn = std::dynamic_pointer_cast<API::CompositeFunction>(convolution->getFunction(1));
402 if (!compositeFn) {
403 functionList.insert(functionList.end(), convolution);
404 } else {
405 auto resolution = convolution->getFunction(0);
406 const size_t nlocals = compositeFn->nFunctions();
407 for (size_t i = 0; i < nlocals; ++i) {
408 auto localFunction = compositeFn->getFunction(i);
409 std::shared_ptr<Functions::Convolution> localConvolution = std::make_shared<Functions::Convolution>();
410 localConvolution->addFunction(resolution);
411 localConvolution->addFunction(localFunction);
412 functionList.insert(functionList.end(), localConvolution);
413 }
414 }
415}
416
427 const API::IFunction_sptr &function, std::shared_ptr<API::MatrixWorkspace> &ws, const size_t wsIndex,
428 const std::shared_ptr<API::FunctionDomain> &domain,
429 const std::shared_ptr<API::FunctionValues> &resultValues) const {
430 const size_t nData = resultValues->size();
431 resultValues->zeroCalculated();
432 // Confidence bands are calculated based on the example in
433 // www.astro.rug.nl/software/kapteyn/kmpfittutorial.html#confidence-and-prediction-intervals,
434 // which references J.Wolberg, Data Analysis Using the Method of Least
435 // Squares, 2006, Springer.
436 // Here we asusme a confidence band of 1 sigma
437 double sigma = 1;
438 double prob = std::erf(sigma / sqrt(2));
439 // critical value for t distribution
440 double alpha = (1 + prob) / 2;
441
442 // Function value
443 function->function(*domain, *resultValues);
444
445 size_t nParams = function->nParams();
446
447 // the function should contain the parameter's covariance matrix
448 auto covar = function->getCovarianceMatrix();
449 bool hasErrors = false;
450 if (!covar) {
451 for (size_t j = 0; j < nParams; ++j) {
452 if (function->getError(j) != 0.0) {
453 hasErrors = true;
454 break;
455 }
456 }
457 }
458
459 if (covar || hasErrors) {
460 // and errors
461 Jacobian J(nData, nParams);
462 try {
463 function->functionDeriv(*domain, J);
464 } catch (...) {
465 function->calNumericalDeriv(*domain, J);
466 }
467 if (covar) {
468 // if the function has a covariance matrix attached - use it for the
469 // errors
470 const Kernel::Matrix<double> &C = *covar;
471 // The formula is E = J * C * J^T
472 // We don't do full 3-matrix multiplication because we only need the
473 // diagonals of E
474 std::vector<double> E(nData);
475 for (size_t k = 0; k < nData; ++k) {
476 double s = 0.0;
477 for (size_t i = 0; i < nParams; ++i) {
478 double tmp = J.get(k, i);
479 s += C[i][i] * tmp * tmp;
480 for (size_t j = i + 1; j < nParams; ++j) {
481 s += J.get(k, i) * C[i][j] * J.get(k, j) * 2;
482 }
483 }
484 E[k] = s;
485 }
486
487 size_t dof = nData - nParams;
488 auto &yValues = ws->mutableY(wsIndex);
489 auto &eValues = ws->mutableE(wsIndex);
490 double T = 1.0;
491 if (dof != 0) {
492 boost::math::students_t dist(static_cast<double>(dof));
493 T = boost::math::quantile(dist, alpha);
494 }
495 for (size_t i = 0; i < nData; i++) {
496 yValues[i] = resultValues->getCalculated(i);
497 eValues[i] = T * std::sqrt(E[i]);
498 }
499
500 } else {
501 // otherwise use the parameter errors which is OK for uncorrelated
502 // parameters
503 auto &yValues = ws->mutableY(wsIndex);
504 auto &eValues = ws->mutableE(wsIndex);
505 for (size_t i = 0; i < nData; i++) {
506 yValues[i] = resultValues->getCalculated(i);
507 double err = 0.0;
508 for (size_t j = 0; j < nParams; ++j) {
509 double d = J.get(i, j) * function->getError(j);
510 err += d * d;
511 }
512 eValues[i] = std::sqrt(err);
513 }
514 }
515 } else {
516 // No errors
517 auto &yValues = ws->mutableY(wsIndex);
518 for (size_t i = 0; i < nData; i++) {
519 yValues[i] = resultValues->getCalculated(i);
520 }
521 }
522}
523
532 const size_t nyvalues) {
533 size_t nxvalues(nyvalues);
535 API::WorkspaceFactory::Instance().create("Workspace2D", nhistograms, nxvalues, nyvalues);
536 ws->setTitle(m_tableWorkspace->getTitle());
537 auto tAxis = std::make_unique<API::TextAxis>(nhistograms);
538 ws->replaceAxis(1, std::move(tAxis));
539
540 auto inputX = m_tableWorkspace->getColumn(m_xColName);
541 auto inputY = m_tableWorkspace->getColumn(m_yColName);
542 auto inputE = m_tableWorkspace->getColumn(m_errColName);
543
544 std::vector<double> xData;
545 std::vector<double> yData;
546 std::vector<double> eData;
547 xData.reserve(m_tableWorkspace->rowCount());
548 yData.reserve(m_tableWorkspace->rowCount());
549 eData.reserve(m_tableWorkspace->rowCount());
550
551 for (size_t i = 0; i < m_tableWorkspace->rowCount(); ++i) {
552 xData.emplace_back(inputX->toDouble(i));
553 yData.emplace_back(inputY->toDouble(i));
554 eData.emplace_back(inputE->toDouble(i));
555 }
556
557 // X values for all
558 for (size_t i = 0; i < nhistograms; i++) {
559 ws->mutableX(i).assign(xData.begin() + m_startRowNo, xData.begin() + m_startRowNo + nxvalues);
560 }
561 // Data values for the first histogram
562 ws->mutableY(0).assign(yData.begin() + m_startRowNo, yData.begin() + m_startRowNo + nyvalues);
563 ws->mutableE(0).assign(eData.begin() + m_startRowNo, eData.begin() + m_startRowNo + nyvalues);
564
565 return ws;
566}
567
573 auto X = m_tableWorkspace->getColumn(m_xColName);
574 std::vector<double> xData;
575 xData.reserve(m_tableWorkspace->rowCount());
576 for (size_t i = 0; i < m_tableWorkspace->rowCount(); ++i) {
577 xData.emplace_back(X->toDouble(i));
578 }
579 size_t startIndex, endIndex;
580 std::tie(startIndex, endIndex) = getXInterval(xData);
581 return endIndex - startIndex;
582}
583
590 if (!function) {
591 throw std::runtime_error("Cannot initialize empty function.");
592 }
593 function->setWorkspace(m_tableWorkspace);
594 setInitialValues(*function);
595}
596
602 auto domain = m_domain.lock();
603 auto values = m_values.lock();
604 if (domain && values) {
605 ParameterEstimator::estimate(function, *domain, *values);
606 }
607}
608
613std::pair<size_t, size_t> TableWorkspaceDomainCreator::getXInterval(std::vector<double> xData) const {
614 const auto sizeOfData = xData.size();
615 if (sizeOfData == 0) {
616 throw std::runtime_error("Workspace contains no data.");
617 }
618
620
621 // From points to the first occurrence of StartX in the workspace interval.
622 // End points to the last occurrence of EndX in the workspace interval.
623 // Find the fitting interval: from -> to
624 Mantid::MantidVec::iterator from;
625 Mantid::MantidVec::iterator to;
626
627 bool isXAscending = xData.front() < xData.back();
628
629 if (m_startX == EMPTY_DBL() && m_endX == EMPTY_DBL()) {
630 m_startX = xData.front();
631 from = xData.begin();
632 m_endX = xData.back();
633 to = xData.end();
634 } else if (m_startX == EMPTY_DBL() || m_endX == EMPTY_DBL()) {
635 throw std::invalid_argument("Both StartX and EndX must be given to set fitting interval.");
636 } else if (isXAscending) {
637 if (m_startX > m_endX) {
638 std::swap(m_startX, m_endX);
639 }
640 from = std::lower_bound(xData.begin(), xData.end(), m_startX);
641 to = std::upper_bound(from, xData.end(), m_endX);
642 } else { // x is descending
643 if (m_startX < m_endX) {
644 std::swap(m_startX, m_endX);
645 }
646 from = std::lower_bound(xData.begin(), xData.end(), m_startX, greaterIsLess);
647 to = std::upper_bound(from, xData.end(), m_endX, greaterIsLess);
648 }
649
650 // Check whether the fitting interval defined by StartX and EndX is 0.
651 // This occurs when StartX and EndX are both less than the minimum workspace
652 // x-value or greater than the maximum workspace x-value.
653 if (to - from == 0) {
654 throw std::invalid_argument("StartX and EndX values do not capture a range "
655 "within the workspace interval.");
656 }
657
658 return std::make_pair(std::distance(xData.begin(), from), std::distance(xData.begin(), to));
659}
660
667 // if property manager is set overwrite any set parameters
668 if (m_manager) {
669 // get the workspace
672 if (m_domainType != Simple) {
673 const int maxSizeInt = m_manager->getProperty(m_maxSizePropertyName);
674 m_maxSize = static_cast<size_t>(maxSizeInt);
675 }
677 if (m_exclude.size() % 2 != 0) {
678 throw std::runtime_error("Exclude property has an odd number of entries. "
679 "It has to be even as each pair specifies a "
680 "start and an end of an interval to exclude.");
681 }
684 joinOverlappingRanges(m_exclude);
685 }
686}
687
698
699 auto columnNames = ws->getColumnNames();
700
701 std::string xColName = m_manager->getProperty(m_xColumnPropertyName);
702 if (xColName != "") {
703 auto column = ws->getColumn(xColName);
704 if (!column->isNumber()) {
705 throw std::invalid_argument(xColName + " does not contain numbers");
706 }
707 }
708
709 std::string yColName = m_manager->getProperty(m_yColumnPropertyName);
710 if (yColName != "") {
711 auto column = ws->getColumn(yColName);
712 if (!column->isNumber()) {
713 throw std::invalid_argument(yColName + " does not contain numbers");
714 }
715 }
716
717 std::string eColName = m_manager->getProperty(m_errorColumnPropertyName);
718 if (eColName != "") {
719 auto column = ws->getColumn(eColName);
720 if (!column->isNumber()) {
721 throw std::invalid_argument(eColName + " does not contain numbers");
722 }
723 }
724
725 // get the column name from plot type
726 for (const auto &name : columnNames) {
727 auto column = ws->getColumn(name);
728 if (xColName == "" && column->getPlotType() == 1) {
729 xColName = column->name();
730 }
731 if (yColName == "" && column->getPlotType() == 2) {
732 yColName = column->name();
733 }
734 if (eColName == "" && column->getPlotType() == 5) {
735 eColName = column->name();
736 }
737 }
738
739 if (xColName != "" && yColName != "") {
740 setColumnNames(xColName, yColName, eColName);
741 } else {
742 throw std::invalid_argument("No valid input for X or Y column names");
743 }
744}
745
753 auto tableWorkspace = std::dynamic_pointer_cast<API::ITableWorkspace>(ws);
754 if (!tableWorkspace) {
755 throw std::invalid_argument("InputWorkspace must be a TableWorkspace.");
756 }
757 setXYEColumnNames(tableWorkspace);
758 std::vector<std::string> columnNames;
759 columnNames.emplace_back(m_xColName);
760 columnNames.emplace_back(m_yColName);
761 if (m_errColName != "")
762 columnNames.emplace_back(m_errColName);
763 // table workspace is cloned so it can be changed within the domain
764 m_tableWorkspace = tableWorkspace->cloneColumns(columnNames);
765
766 // if no error column has been found a column is added with 0 errors
767 if (columnNames.size() == 2) {
768 m_errColName = "AddedErrorColumn";
769 m_noErrCol = true;
770 auto columnAdded = m_tableWorkspace->addColumn("double", m_errColName);
771 if (!columnAdded)
772 throw std::invalid_argument("No error column provided.");
773 }
774
775 if (m_tableWorkspace->columnCount() != 3) {
776 throw std::invalid_argument("X or Y Columns not found");
777 }
778}
779} // namespace Mantid::CurveFitting
std::string name
Definition Run.cpp:60
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
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:166
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:114
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.
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
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition IFunction.h:743
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:42
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