21#ifndef JKQTPSTATPOLY_H_INCLUDED
22#define JKQTPSTATPOLY_H_INCLUDED
37#include "jkqtmath/jkqtmath_imexport.h"
38#include "jkqtmath/jkqtplinalgtools.h"
39#include "jkqtmath/jkqtparraytools.h"
40#include "jkqtcommon/jkqtpdebuggingtools.h"
68template <
class InputItX,
class InputItY,
class OutputItP>
69inline void jkqtpstatPolyFit(InputItX firstX, InputItX lastX, InputItY firstY, InputItY lastY,
size_t P, OutputItP firstRes) {
71 const int Nx=std::distance(firstX,lastX);
72 const int Ny=std::distance(firstY,lastY);
78 std::vector<double> X,Y;
81 for (; itX!=lastX && itY!=lastY; ++itX, ++itY) {
92 std::vector<double> V;
94 for (
size_t l=0; l<N; l++) {
98 for (
size_t c=1; c<P+1; c++) {
103#ifdef STATISTICS_TOOLS_DEBUG_statisticsPolyFit
110 std::vector<double> VT=V;
113#ifdef STATISTICS_TOOLS_DEBUG_statisticsPolyFit
114 std::cout<<
"V^T = \n";
120 std::vector<double> VTV;
121 VTV.resize((P+1)*(P+1));
122 jkqtplinalgMatrixProduct(VT.data(),
static_cast<long>(P+1),
static_cast<long>(N), V.data(),
static_cast<long>(N),
static_cast<long>(P+1), VTV.data());
124#ifdef STATISTICS_TOOLS_DEBUG_statisticsPolyFit
125 std::cout<<
"V^T*V = \n";
131 std::vector<double> VTY;
133 jkqtplinalgMatrixProduct(VT.data(),
static_cast<long>(P+1),
static_cast<long>(N), Y.data(),
static_cast<long>(N), 1, VTY.data());
135#ifdef STATISTICS_TOOLS_DEBUG_statisticsPolyFit
136 std::cout<<
"V^T*y = \n";
146 for (
size_t p=0; p<P+1; p++) {
151 throw std::runtime_error(
"jkqtplinalgLinSolve() didn't return a result!");
154#ifdef STATISTICS_TOOLS_DEBUG_statisticsPolyFit
155 std::cout<<
"result_out = \n";