[91] | 1 | //#---------------------------------------------------------------------------
|
---|
[890] | 2 | //# Fitter.h: A Fitter class for spectra
|
---|
[91] | 3 | //#---------------------------------------------------------------------------
|
---|
| 4 | //# Copyright (C) 2004
|
---|
[125] | 5 | //# ATNF
|
---|
[91] | 6 | //#
|
---|
| 7 | //# This program is free software; you can redistribute it and/or modify it
|
---|
| 8 | //# under the terms of the GNU General Public License as published by the Free
|
---|
| 9 | //# Software Foundation; either version 2 of the License, or (at your option)
|
---|
| 10 | //# any later version.
|
---|
| 11 | //#
|
---|
| 12 | //# This program is distributed in the hope that it will be useful, but
|
---|
| 13 | //# WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
---|
| 15 | //# Public License for more details.
|
---|
| 16 | //#
|
---|
| 17 | //# You should have received a copy of the GNU General Public License along
|
---|
| 18 | //# with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
| 19 | //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
|
---|
| 20 | //#
|
---|
| 21 | //# Correspondence concerning this software should be addressed as follows:
|
---|
| 22 | //# Internet email: Malte.Marquarding@csiro.au
|
---|
| 23 | //# Postal address: Malte Marquarding,
|
---|
| 24 | //# Australia Telescope National Facility,
|
---|
| 25 | //# P.O. Box 76,
|
---|
| 26 | //# Epping, NSW, 2121,
|
---|
| 27 | //# AUSTRALIA
|
---|
| 28 | //#
|
---|
[1391] | 29 | //# $Id: STFitter.h 3106 2016-10-04 07:20:50Z TakeshiNakazato $
|
---|
[91] | 30 | //#---------------------------------------------------------------------------
|
---|
[1028] | 31 | #ifndef STFITTER_H
|
---|
| 32 | #define STFITTER_H
|
---|
[91] | 33 |
|
---|
| 34 | #include <string>
|
---|
| 35 | #include <vector>
|
---|
| 36 |
|
---|
| 37 | #include <casa/Arrays/Vector.h>
|
---|
| 38 | #include <casa/Containers/Block.h>
|
---|
| 39 | #include <scimath/Functionals/Function.h>
|
---|
| 40 | #include <scimath/Functionals/CompoundFunction.h>
|
---|
[2666] | 41 | #include <scimath/Fitting/GenericL2Fit.h>
|
---|
[91] | 42 |
|
---|
[2666] | 43 |
|
---|
[1932] | 44 | #include "STFitEntry.h"
|
---|
| 45 |
|
---|
[2666] | 46 |
|
---|
[91] | 47 | namespace asap {
|
---|
| 48 |
|
---|
[890] | 49 | class Fitter {
|
---|
[91] | 50 | public:
|
---|
[890] | 51 | Fitter();
|
---|
| 52 | virtual ~Fitter();
|
---|
[517] | 53 | // allowed "gauss" and "poly". ncomp is either numvber of gaussions
|
---|
| 54 | // or order of the polynomial
|
---|
| 55 | bool setExpression(const std::string& expr, int ncomp=1);
|
---|
| 56 | bool setData(std::vector<float> absc, std::vector<float> spec,
|
---|
| 57 | std::vector<bool> mask);
|
---|
| 58 | bool setParameters(std::vector<float> params);
|
---|
| 59 | bool setFixedParameters(std::vector<bool> fixed);
|
---|
[2666] | 60 | void addConstraint(const std::vector<float>& constraint);
|
---|
[1028] | 61 |
|
---|
[517] | 62 | std::vector<float> getResidual() const;
|
---|
| 63 | std::vector<float> getFit() const;
|
---|
| 64 | std::vector<float> getParameters() const;
|
---|
| 65 | std::vector<bool> getFixedParameters() const;
|
---|
[1028] | 66 |
|
---|
[517] | 67 | std::vector<float> getEstimate() const;
|
---|
| 68 | std::vector<float> getErrors() const;
|
---|
| 69 | float getChisquared() const;
|
---|
| 70 | void reset();
|
---|
| 71 | bool fit();
|
---|
[1391] | 72 | // Fit via linear method
|
---|
| 73 | bool lfit();
|
---|
[517] | 74 | bool computeEstimate();
|
---|
[1028] | 75 |
|
---|
[517] | 76 | std::vector<float> evaluate(int whichComp) const;
|
---|
[1932] | 77 |
|
---|
| 78 | STFitEntry getFitEntry() const;
|
---|
| 79 |
|
---|
[91] | 80 | private:
|
---|
[517] | 81 | void clear();
|
---|
[3106] | 82 | void applyConstraints(casacore::GenericL2Fit<casacore::Float>& fitter);
|
---|
| 83 | casacore::Vector<casacore::Float> x_;
|
---|
| 84 | casacore::Vector<casacore::Float> y_;
|
---|
| 85 | casacore::Vector<casacore::Bool> m_;
|
---|
| 86 | casacore::PtrBlock<casacore::Function<casacore::Float>* > funcs_;
|
---|
[1932] | 87 | std::vector<std::string> funcnames_;
|
---|
| 88 | std::vector<int> funccomponents_;
|
---|
| 89 |
|
---|
[517] | 90 | //Bool estimateSet_;
|
---|
[3106] | 91 | casacore::Float chisquared_;
|
---|
| 92 | casacore::Vector<casacore::Float> parameters_;
|
---|
| 93 | casacore::Vector<casacore::Bool> fixedpar_;
|
---|
[2666] | 94 | std::vector<std::vector<float> > constraints_;
|
---|
[1028] | 95 |
|
---|
[3106] | 96 | casacore::Vector<casacore::Float> error_;
|
---|
| 97 | casacore::Vector<casacore::Float> thefit_;
|
---|
| 98 | casacore::Vector<casacore::Float> residual_;
|
---|
| 99 | casacore::Vector<casacore::Float> estimate_;
|
---|
[91] | 100 | };
|
---|
| 101 |
|
---|
| 102 | } // namespace
|
---|
| 103 |
|
---|
| 104 | #endif
|
---|