File: polynomialfitter.h

package info (click to toggle)
wsclean 2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,196 kB
  • sloc: cpp: 34,504; ansic: 234; python: 174; makefile: 10
file content (38 lines) | stat: -rw-r--r-- 683 bytes parent folder | download | duplicates (2)
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
#ifndef POLYNOMIAL_FITTER_H
#define POLYNOMIAL_FITTER_H

#include "uvector.h"

#include <array>

class PolynomialFitter
{
public:
	void Clear() { _dataPoints.clear(); }
	
	void AddDataPoint(double x, double y, double w)
	{
		_dataPoints.emplace_back(std::array<double,3>{{x, y, w}});
	}
	
	void Fit(ao::uvector<double>& terms, size_t nTerms);
	
	static double Evaluate(double x, const ao::uvector<double>& terms)
	{
		double val = terms[0];
		double f = 1.0;
		for(size_t i=1; i!=terms.size(); ++i)
		{
			f *= x;
			val += f * terms[i];
		}
		return val;
	}
	
	size_t size() const { return _dataPoints.size(); }
	
private:
	ao::uvector<std::array<double,3>> _dataPoints;
};

#endif