polyfit Reference Manual - Instituto Nacional de...

61
polyfit Reference Manual 0.0.1 Generated by Doxygen 1.4.7 Tue Oct 16 16:47:11 2007

Transcript of polyfit Reference Manual - Instituto Nacional de...

polyfit Reference Manual0.0.1

Generated by Doxygen 1.4.7

Tue Oct 16 16:47:11 2007

CONTENTS 1

Contents

1 polyfit Data Structure Documentation 1

2 polyfit File Documentation 36

1 polyfit Data Structure Documentation

1.1 Fitter< Real > Class Template Reference

The fitting class.

#include <Fitter.hpp>

Collaboration diagram for Fitter< Real >:

Fit ter< Real >

Real

valuespoints

fit t ingMatrixbasisWeights

sqrtSampleWeightssqrtBasisWeightssampleWeights

Public Member Functions

• Fitter (void)• virtual ∼Fitter (void)• void setDimension (unsigned int dimension)• void setSamples (unsigned int numberOfSamples, const Real ∗points, const Real ∗values=NULL,

const Real ∗sampleWeights=NULL)• void setBasis (const PolynomialBasis< Real > ∗basis, const Real ∗basisWeights=NULL)• virtual Polynomial< Real > ∗ fit (void)• template<> int gels (char trans, unsigned int m, unsigned int n, unsigned int nrhs, float ∗a, unsigned

int lda, float ∗b, unsigned int ldb, float ∗work, unsigned int lwork, int ∗info) const• template<> int gels (char trans, unsigned int m, unsigned int n, unsigned int nrhs, double ∗a, un-

signed int lda, double ∗b, unsigned int ldb, double ∗work, unsigned int lwork, int ∗info) const• template<> void gemm (const int order, const int transA, const int transB, const int m, const int n,

const int k, const float alpha, const float ∗a, const int lda, const float ∗b, const int ldb, const floatbeta, float ∗c, const int ldc) const

• template<> void gemm (const int order, const int transA, const int transB, const int m, const int n,const int k, const double alpha, const double ∗a, const int lda, const double ∗b, const int ldb, constdouble beta, double ∗c, const int ldc) const

• template<> int syevx (char jobz, char range, char uplo, unsigned int n, float ∗a, unsigned int lda,float vl, float vu, unsigned int il, unsigned int iu, float abstol, unsigned int ∗m, float ∗w, float ∗z__,unsigned int ldz, float ∗work, unsigned int lwork, long int ∗iwork, long int ∗ifail, int ∗info) const

• template<> int syevx (char jobz, char range, char uplo, unsigned int n, double ∗a, unsigned int lda,double vl, double vu, unsigned int il, unsigned int iu, double abstol, unsigned int ∗m, double ∗w,

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 2

double ∗z__, unsigned int ldz, double ∗work, unsigned int lwork, long int ∗iwork, long int ∗ifail, int∗info) const

Protected Member Functions

• virtual void buildFittingMatrix (void)• virtual Polynomial< Real > ∗ fitPolynomial (void)• virtual Polynomial< Real > ∗ fitZeroSet (void)• virtual int gels (char trans, unsigned int m, unsigned int n, unsigned int nrhs, Real ∗a, unsigned int

lda, Real ∗b, unsigned int ldb, Real ∗work, unsigned int lwork, int ∗info) const• virtual void gemm (const int order, const int transA, const int transB, const int m, const int n, const

int k, const Real alpha, const Real ∗a, const int lda, const Real ∗b, const int ldb, const Real beta,Real ∗c, const int ldc) const

• virtual int syevx (char jobz, char range, char uplo, unsigned int n, Real ∗a, unsigned int lda, Real vl,Real vu, unsigned int il, unsigned int iu, Real abstol, unsigned int ∗m, Real ∗w, Real ∗z__, unsignedint ldz, Real ∗work, unsigned int lwork, long int ∗iwork, long int ∗ifail, int ∗info) const

Protected Attributes

• unsigned int dimension• unsigned int numberOfSamples• const Real ∗ points• const Real ∗ values• const PolynomialBasis< Real > ∗ basis• bool weightSamples• const Real ∗ sampleWeights• Real ∗ sqrtSampleWeights• bool weightBasis• const Real ∗ basisWeights• Real ∗ sqrtBasisWeights• bool fitFromZeroSet• unsigned int m• unsigned int n• Real ∗ fittingMatrix

1.1.1 Detailed Description

template<typename Real = float> class Fitter< Real >

The fitting class.

Parameters:

Real {float} or double

This module encapsulates the fitting process and groups both inputs and intermediate data

Definition at line 30 of file Fitter.hpp.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 3

1.1.2 Constructor & Destructor Documentation

1.1.2.1 template<typename Real> Fitter< Real >::Fitter (void)

Class constructor

Definition at line 25 of file Fitter.cpp.

References Fitter< Real >::basis, Fitter< Real >::basisWeights, Fitter< Real >::dimension, Fitter< Real>::fitFromZeroSet, Fitter< Real >::fittingMatrix, Fitter< Real >::m, Fitter< Real >::n, Fitter< Real>::numberOfSamples, Fitter< Real >::points, Fitter< Real >::sampleWeights, Fitter< Real >::sqrtBasis-Weights, Fitter< Real >::sqrtSampleWeights, Fitter< Real >::values, Fitter< Real >::weightBasis, andFitter< Real >::weightSamples.

25 {26 this->dimension = 0;27 this->numberOfSamples = 0;28 this->points = NULL;29 this->values = NULL;30 this->basis = NULL;31 this->weightSamples = false;32 this->sampleWeights = NULL;33 this->sqrtSampleWeights = NULL;34 this->weightBasis = false;35 this->basisWeights = NULL;36 this->sqrtBasisWeights = NULL;37 this->fitFromZeroSet = false;38 this->m = 0;39 this->n = 0;40 this->fittingMatrix = NULL;41 }

1.1.2.2 template<typename Real> Fitter< Real >::∼Fitter (void) [virtual]

Class destructor

Definition at line 44 of file Fitter.cpp.

References Fitter< Real >::fittingMatrix, Fitter< Real >::sqrtBasisWeights, and Fitter< Real >::sqrt-SampleWeights.

44 {4546 if (this->fittingMatrix != NULL) {47 delete[] this->fittingMatrix;48 this->fittingMatrix = NULL;49 }505152 if (this->sqrtSampleWeights != NULL) {53 delete[] this->sqrtSampleWeights;54 this->sqrtSampleWeights = NULL;55 }565758 if (this->sqrtBasisWeights != NULL) {59 delete[] this->sqrtBasisWeights;60 this->sqrtBasisWeights = NULL;61 }6263 }

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 4

1.1.3 Member Function Documentation

1.1.3.1 template<typename Real> void Fitter< Real >::buildFittingMatrix (void)[protected, virtual]

Builds the fitting matrix of the corresponding fitting process

Definition at line 134 of file Fitter.cpp.

References Fitter< Real >::basis, Fitter< Real >::fittingMatrix, Fitter< Real >::m, Fitter< Real >::n,and Fitter< Real >::numberOfSamples.

Referenced by Fitter< Real >::fitPolynomial(), and Fitter< Real >::fitZeroSet().

134 {135 this->m = this->numberOfSamples;136 this->n = this->basis->getSize();137138 if (this->fittingMatrix == NULL) {139 this->fittingMatrix = new Real[this->m * this->n];140 }141142 this->basis->evaluate(this->numberOfSamples, this->points,143 this->fittingMatrix);144145 if (this->weightSamples) {146147 for (register unsigned int i = 0u; i < this->m; ++i) {148149 for (register unsigned int j = 0u; j < this->n; ++j) {150 this->fittingMatrix[j+i*this->n] *= this->sqrtSampleWeights[i];151 }152153 }154155 }156157 }

Here is the caller graph for this function:

Fit ter::buildFit t ingMatrix

Fit ter::fitPolynomial

Fit ter::fitZeroSet

Fit ter::fit main

1.1.3.2 template<typename Real> Polynomial< Real > ∗ Fitter< Real >::fit (void) [virtual]

Fits the provided data with a polynomial (if the values were not provided, the data is assumed to be asample from an isolevel and an eigenvalue problem is solved, otherwise, the data is fitted in the weightedlinear least squares sense with the standard algebraic distance functional)

Returns:

the fitted polynomial

Definition at line 121 of file Fitter.cpp.

References Fitter< Real >::fitPolynomial(), and Fitter< Real >::fitZeroSet().

Referenced by main().

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 5

121 {122 Polynomial<Real>* ret = NULL;123124 if (this->fitFromZeroSet) {125 ret = this->fitZeroSet();126 } else {127 ret = this->fitPolynomial();128 }129130 return ret;131 }

Here is the call graph for this function:

Fit ter::fit

Fit ter::fitPolynomial

Fit ter::fitZeroSet Fit ter::buildFit t ingMatrix

Fit ter::gels

Polynomial::setCoefficients

Fit ter::gemm

Fit ter::syevx

Here is the caller graph for this function:

Fit ter::fit main

1.1.3.3 template<typename Real> Polynomial< Real > ∗ Fitter< Real >::fitPolynomial (void)[protected, virtual]

Fits a polynomial to a list of (point, value) pairs

Returns:

the fitted polynomial

Definition at line 160 of file Fitter.cpp.

References Fitter< Real >::basis, Fitter< Real >::buildFittingMatrix(), Fitter< Real >::gels(), Fitter<Real >::m, Fitter< Real >::n, Fitter< Real >::numberOfSamples, and Polynomial< Real >::set-Coefficients().

Referenced by Fitter< Real >::fit().

160 {161 Polynomial<Real>* ret = new Polynomial<Real>(this->basis);162 this->buildFittingMatrix();163164 // Lapack uses column-major ordering for matrices ...165 unsigned int m = this->n;166 unsigned int n = this->m;167 unsigned int minMN = (m < n) ? m : n;168 unsigned int maxMN = (m > n) ? m : n;169 unsigned int lwork = 2u * minMN;170 Real* a = new Real[m * n];

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 6

171 Real* b = new Real[maxMN];172 Real* work = new Real[lwork];173174 std::memcpy(a, this->fittingMatrix, m * n * sizeof(Real));175176 if (this->weightSamples) {177178 for (register unsigned int i = 0u; i < this->numberOfSamples; ++i) {179 b[i] = this->values[i] * this->sqrtSampleWeights[i];180 }181182 } else {183 std::memcpy(b, this->values, this->numberOfSamples * sizeof(Real));184 }185186 int info = 0;187 // int gelsret = this->gels(’T’, m, n, 1, a, m, b,188 // maxMN, work, lwork, &info);189 this->gels(’T’, m, n, 1, a, m, b, maxMN, work, lwork, &info);190191 delete[] work; work = NULL;192 delete[] a ; a = NULL;193194 ret->setCoefficients(b);195196 delete[] b; b = NULL;197198 return ret;199 }

Here is the call graph for this function:

Fit ter::fitPolynomial

Fit ter::buildFit t ingMatrix

Fit ter::gels

Polynomial::setCoefficients

Here is the caller graph for this function:

Fit ter::fitPolynomial Fit ter::fit main

1.1.3.4 template<typename Real> Polynomial< Real > ∗ Fitter< Real >::fitZeroSet (void)[protected, virtual]

Fits a polynomial to a set of points sampled from a zero set

Returns:

the fitted polynomial

Definition at line 202 of file Fitter.cpp.

References Fitter< Real >::basis, Fitter< Real >::buildFittingMatrix(), Fitter< Real >::fittingMatrix,Fitter< Real >::gemm(), Fitter< Real >::m, Fitter< Real >::n, Polynomial< Real >::setCoefficients(),and Fitter< Real >::syevx().

Referenced by Fitter< Real >::fit().

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 7

202 {203 Polynomial<Real>* ret = new Polynomial<Real>(this->basis);204 this->buildFittingMatrix();205206 if (this->weightBasis) {207208 for (register unsigned int i = 0u; i < this->m; ++i) {209210 for (register unsigned int j = 0u; j < this->n; ++j) {211 this->fittingMatrix[j+i*this->n] /= this->sqrtBasisWeights[j];212 }213214 }215216 }217218 Real* c = new Real[this->n * this->n];219220 {221 int order = static_cast<int>(CblasColMajor);222 int transA = static_cast<int>(CblasNoTrans);223 int transB = static_cast<int>(CblasTrans);224 int m = static_cast<int>(this->n);225 int n = static_cast<int>(this->n);226 int k = static_cast<int>(this->m);227 int lda = m;228 int ldb = n;229 int ldc = m;230 Real alpha = static_cast<Real>(1.0f);231 Real beta = static_cast<Real>(0.0f);232 Real* a = this->fittingMatrix;233 Real* b = a;234235 this->gemm(order, transA, transB, m, n, k,236 alpha, a, lda, b, ldb, beta, c, ldc);237 }238239 {240 char jobz = ’V’;241 char range = ’I’;242 char uplo = ’U’;243 unsigned int n = this->n;244 unsigned int lda = n;245 unsigned int il = 1u;246 unsigned int iu = 1u;247 unsigned int m = 1u;248 unsigned int ldz = n;249 unsigned int lwork = 8u * n;250 long int* iwork = new long int[5u * n];251 long int* ifail = new long int[n];252 Real vl = static_cast<Real>(0.0f);253 Real vu = static_cast<Real>(0.0f);254 Real abstol = static_cast<Real>(0.0f);255 Real* a = c;256 Real* w = new Real[n];257 Real* z__ = new Real[n * m];258 Real* work = new Real[lwork];259260 int info = 0;261 // int syevxret = this->syevx(jobz, range, uplo, n, a, lda, vl, vu, il, iu,262 // abstol, &m, w, z__, ldz, work, lwork, iwork, ifail, &info);263 this->syevx(jobz, range, uplo, n, a, lda, vl, vu, il, iu,264 abstol, &m, w, z__, ldz, work, lwork, iwork, ifail, &info);265266 delete[] work;267 delete[] w;268 delete[] ifail;

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 8

269 delete[] iwork;270271 if (this->weightBasis) {272273 for (register unsigned int i = 0u; i < n; ++i) {274 z__[i] *= this->sqrtBasisWeights[i];275 }276277 }278279 ret->setCoefficients(z__);280281 delete[] z__;282 }283284 delete[] c;285286 return ret;287 }

Here is the call graph for this function:

Fit ter::fitZeroSet

Fit ter::buildFit t ingMatrix

Fit ter::gemm

Polynomial::setCoefficients

Fit ter::syevx

Here is the caller graph for this function:

Fit ter::fitZeroSet Fit ter::fit main

1.1.3.5 template<> int Fitter< double >::gels (char trans, unsigned int m, unsigned int n, unsignedint nrhs, double ∗ a, unsigned int lda, double ∗ b, unsigned int ldb, double ∗ work, unsigned int lwork,int ∗ info) const

Definition at line 313 of file Fitter.cpp.

315 {316 char TRANS = trans;317 integer M = m;318 integer N = n;319 integer NRHS = nrhs;320 doublereal* A = a;321 integer LDA = lda;322 doublereal* B = b;323 integer LDB = ldb;324 doublereal* WORK = work;325 integer LWORK = lwork;326 integer INFO = 0;327328 int ret = dgels_(&TRANS, &M, &N, &NRHS, A, &LDA,329 B, &LDB, WORK, &LWORK, &INFO);330 *info = INFO;331332 return ret;333 }

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 9

1.1.3.6 template<> int Fitter< float >::gels (char trans, unsigned int m, unsigned int n, unsignedint nrhs, float ∗ a, unsigned int lda, float ∗ b, unsigned int ldb, float ∗ work, unsigned int lwork, int ∗info) const

Definition at line 290 of file Fitter.cpp.

292 {293 char TRANS = trans;294 integer M = m;295 integer N = n;296 integer NRHS = nrhs;297 real* A = a;298 integer LDA = lda;299 real* B = b;300 integer LDB = ldb;301 real* WORK = work;302 integer LWORK = lwork;303 integer INFO = 0;304305 int ret = sgels_(&TRANS, &M, &N, &NRHS, A, &LDA,306 B, &LDB, WORK, &LWORK, &INFO);307 *info = INFO;308309 return ret;310 }

1.1.3.7 template<typename Real = float> virtual int Fitter< Real >::gels (char trans, unsigned intm, unsigned int n, unsigned int nrhs, Real ∗ a, unsigned int lda, Real ∗ b, unsigned int ldb, Real ∗work, unsigned int lwork, int ∗ info) const [protected, virtual]

Encapsulates the functionality of the {s|d}gels_ functions from netlib’s clapack library

See also:

LAPACK - Linear Algebra PACKage

Referenced by Fitter< Real >::fitPolynomial().

Here is the caller graph for this function:

Fit ter::gels Fit ter::fitPolynomial Fit ter::fit main

1.1.3.8 template<> void Fitter< double >::gemm (const int order, const int transA, const int trans-B, const int m, const int n, const int k, const double alpha, const double ∗ a, const int lda, const double∗ b, const int ldb, const double beta, double ∗ c, const int ldc) const

Definition at line 359 of file Fitter.cpp.

362 {363 enum CBLAS_ORDER Order = static_cast<enum CBLAS_ORDER>(order);364 enum CBLAS_TRANSPOSE TransA = static_cast<enum CBLAS_TRANSPOSE>(transA);365 enum CBLAS_TRANSPOSE TransB = static_cast<enum CBLAS_TRANSPOSE>(transB);366 int M = m;367 int N = n;368 int K = k;369 int LDA = lda;370 int LDB = ldb;

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 10

371 int LDC = ldc;372 const double* A = a;373 const double* B = b;374 double* C = c;375 double Alpha = alpha;376 double Beta = beta;377 cblas_dgemm(Order, TransA, TransB, M, N, K,378 Alpha, A, LDA, B, LDB, Beta, C, LDC);379 }

1.1.3.9 template<> void Fitter< float >::gemm (const int order, const int transA, const int transB,const int m, const int n, const int k, const float alpha, const float ∗ a, const int lda, const float ∗ b, constint ldb, const float beta, float ∗ c, const int ldc) const

Definition at line 336 of file Fitter.cpp.

339 {340 enum CBLAS_ORDER Order = static_cast<enum CBLAS_ORDER>(order);341 enum CBLAS_TRANSPOSE TransA = static_cast<enum CBLAS_TRANSPOSE>(transA);342 enum CBLAS_TRANSPOSE TransB = static_cast<enum CBLAS_TRANSPOSE>(transB);343 int M = m;344 int N = n;345 int K = k;346 int LDA = lda;347 int LDB = ldb;348 int LDC = ldc;349 const float* A = a;350 const float* B = b;351 float* C = c;352 float Alpha = alpha;353 float Beta = beta;354 cblas_sgemm(Order, TransA, TransB, M, N, K,355 Alpha, A, LDA, B, LDB, Beta, C, LDC);356 }

1.1.3.10 template<typename Real = float> virtual void Fitter< Real >::gemm (const int order,const int transA, const int transB, const int m, const int n, const int k, const Real alpha, constReal ∗ a, const int lda, const Real ∗ b, const int ldb, const Real beta, Real ∗ c, const int ldc) const[protected, virtual]

Encapsulates the functionality of the {s|d}gemm functions from netlib’s ATLAS implementation of thecblas library

See also:

Automatically Tuned Linear Algebra Software (ATLAS)BLAS (Basic Linear Algebra Subprograms)

Referenced by Fitter< Real >::fitZeroSet().

Here is the caller graph for this function:

Fit ter::gemm Fit ter::fitZeroSet Fit ter::fit main

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 11

1.1.3.11 template<typename Real> void Fitter< Real >::setBasis (const PolynomialBasis< Real> ∗ basis, const Real ∗ basisWeights = NULL)

Sets the basis for the space used in the fitting process as well as its (optional) corresponding weighting

Parameters:

basis The basis

basisWeights (Optional) The POSITIVE basis’ weights

Definition at line 100 of file Fitter.cpp.

References Fitter< Real >::basis, Fitter< Real >::sqrtBasisWeights, and Fitter< Real >::weightBasis.

Referenced by main().

101 {102 this->basis = basis;103104 if (basisWeights != NULL) {105 this->weightBasis = true;106 this->basisWeights = basisWeights;107 this->sqrtBasisWeights = new Real[this->basis->getSize()];108109 for (register unsigned int i = 0u; i < this->basis->getSize(); ++i) {110 this->sqrtBasisWeights[i] =111 static_cast<Real>(std::sqrt(this->basisWeights[i]));112 }113114 } else {115 this->weightBasis = false;116 }117118 }

Here is the caller graph for this function:

Fit ter::setBasis main

1.1.3.12 template<typename Real> void Fitter< Real >::setDimension (unsigned int dimension)

Sets the dimension of the space of samples

Parameters:

dimension A positive integer

Definition at line 66 of file Fitter.cpp.

Referenced by main().

66 {67 this->dimension = dimension;68 }

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 12

Here is the caller graph for this function:

Fit ter::setDimension main

1.1.3.13 template<typename Real> void Fitter< Real >::setSamples (unsigned int numberOf-Samples, const Real ∗ points, const Real ∗ values = NULL, const Real ∗ sampleWeights = NULL)

Sets the basis for the space used in the fitting process as well as its (optional) corresponding weighting

Parameters:

numberOfSamples The number of samples

points The sample points

values (Optional) The samples’ values

sampleWeights (Optional) The POSITIVE samples’ weights

Definition at line 71 of file Fitter.cpp.

References Fitter< Real >::fitFromZeroSet, Fitter< Real >::sqrtSampleWeights, and Fitter< Real>::weightSamples.

Referenced by main().

72 {73 this->numberOfSamples = numberOfSamples;74 this->points = points;7576 if (values != NULL) {77 this->fitFromZeroSet = false;78 this->values = values;79 } else {80 this->fitFromZeroSet = true;81 }8283 if (sampleWeights != NULL) {84 this->weightSamples = true;85 this->sampleWeights = sampleWeights;86 this->sqrtSampleWeights = new Real[this->numberOfSamples];8788 for (register unsigned int i = 0u; i < this->numberOfSamples; ++i) {89 this->sqrtSampleWeights[i] =90 static_cast<Real>(std::sqrt(this->sampleWeights[i]));91 }9293 } else {94 this->weightSamples = false;95 }9697 }

Here is the caller graph for this function:

Fit ter::setSamples main

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 13

1.1.3.14 template<> int Fitter< double >::syevx (char jobz, char range, char uplo, unsigned intn, double ∗ a, unsigned int lda, double vl, double vu, unsigned int il, unsigned int iu, double abstol,unsigned int ∗ m, double ∗ w, double ∗ z__, unsigned int ldz, double ∗ work, unsigned int lwork, longint ∗ iwork, long int ∗ ifail, int ∗ info) const

Definition at line 417 of file Fitter.cpp.

421 {422 char JOBZ = jobz;423 char RANGE = range;424 char UPLO = uplo;425 integer N = n;426 integer LDA = lda;427 integer IL = il;428 integer IU = iu;429 integer M = *m;430 integer LDZ = ldz;431 integer LWORK = lwork;432 integer* IWORK = iwork;433 integer* IFAIL = ifail;434 doublereal VL = vl;435 doublereal VU = vu;436 doublereal ABSTOL = abstol;437 doublereal* A = a;438 doublereal* W = w;439 doublereal* Z = z__;440 doublereal* WORK = work;441442 integer INFO = 0;443 int ret = dsyevx_(&JOBZ, &RANGE, &UPLO, &N, A, &LDA, &VL, &VU, &IL, &IU,444 &ABSTOL, &M, W, Z, &LDZ, WORK, &LWORK, IWORK, IFAIL, &INFO);445 *m = M;446 *info = INFO;447448 return ret;449 }

1.1.3.15 template<> int Fitter< float >::syevx (char jobz, char range, char uplo, unsigned int n,float ∗ a, unsigned int lda, float vl, float vu, unsigned int il, unsigned int iu, float abstol, unsigned int ∗m, float ∗ w, float ∗ z__, unsigned int ldz, float ∗ work, unsigned int lwork, long int ∗ iwork, long int ∗ifail, int ∗ info) const

Definition at line 382 of file Fitter.cpp.

386 {387 char JOBZ = jobz;388 char RANGE = range;389 char UPLO = uplo;390 integer N = n;391 integer LDA = lda;392 integer IL = il;393 integer IU = iu;394 integer M = *m;395 integer LDZ = ldz;396 integer LWORK = lwork;397 integer* IWORK = iwork;398 integer* IFAIL = ifail;399 real VL = vl;400 real VU = vu;401 real ABSTOL = abstol;402 real* A = a;403 real* W = w;404 real* Z = z__;

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 14

405 real* WORK = work;406407 integer INFO = 0;408 int ret = ssyevx_(&JOBZ, &RANGE, &UPLO, &N, A, &LDA, &VL, &VU, &IL, &IU,409 &ABSTOL, &M, W, Z, &LDZ, WORK, &LWORK, IWORK, IFAIL, &INFO);410 *m = M;411 *info = INFO;412413 return ret;414 }

1.1.3.16 template<typename Real = float> virtual int Fitter< Real >::syevx (char jobz, char range,char uplo, unsigned int n, Real ∗ a, unsigned int lda, Real vl, Real vu, unsigned int il, unsigned int iu,Real abstol, unsigned int ∗ m, Real ∗ w, Real ∗ z__, unsigned int ldz, Real ∗ work, unsigned int lwork,long int ∗ iwork, long int ∗ ifail, int ∗ info) const [protected, virtual]

Encapsulates the functionality of the {s|d}syevx_ functions from netlib’s clapack library

See also:

LAPACK - Linear Algebra PACKage

Referenced by Fitter< Real >::fitZeroSet().

Here is the caller graph for this function:

Fit ter::syevx Fit ter::fitZeroSet Fit ter::fit main

1.1.4 Field Documentation

1.1.4.1 template<typename Real = float> const PolynomialBasis<Real>∗ Fitter< Real >::basis[protected]

A basis for the space used to choose the fitted polynomial

Definition at line 60 of file Fitter.hpp.

Referenced by Fitter< Real >::buildFittingMatrix(), Fitter< Real >::fitPolynomial(), Fitter< Real>::Fitter(), Fitter< Real >::fitZeroSet(), and Fitter< Real >::setBasis().

1.1.4.2 template<typename Real = float> const Real∗ Fitter< Real >::basisWeights[protected]

The basis’ POSITIVE weights

Definition at line 88 of file Fitter.hpp.

Referenced by Fitter< Real >::Fitter().

1.1.4.3 template<typename Real = float> unsigned int Fitter< Real >::dimension[protected]

The dimension of the space from which the points were sampled

Definition at line 38 of file Fitter.hpp.

Referenced by Fitter< Real >::Fitter().

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.1 Fitter< Real > Class Template Reference 15

1.1.4.4 template<typename Real = float> bool Fitter< Real >::fitFromZeroSet [protected]

A flag indicating the input data were sampled from an isolevel

Definition at line 100 of file Fitter.hpp.

Referenced by Fitter< Real >::Fitter(), and Fitter< Real >::setSamples().

1.1.4.5 template<typename Real = float> Real∗ Fitter< Real >::fittingMatrix [protected]

The fitting matrix (used in intermediate computations)

Definition at line 117 of file Fitter.hpp.

Referenced by Fitter< Real >::buildFittingMatrix(), Fitter< Real >::Fitter(), Fitter< Real >::fitZeroSet(),and Fitter< Real >::∼Fitter().

1.1.4.6 template<typename Real = float> unsigned int Fitter< Real >::m [protected]

The number of rows of the fitting matrix

Definition at line 106 of file Fitter.hpp.

Referenced by Fitter< Real >::buildFittingMatrix(), Fitter< Real >::fitPolynomial(), Fitter< Real>::Fitter(), and Fitter< Real >::fitZeroSet().

1.1.4.7 template<typename Real = float> unsigned int Fitter< Real >::n [protected]

The number of columns of the fitting matrix

Definition at line 111 of file Fitter.hpp.

Referenced by Fitter< Real >::buildFittingMatrix(), Fitter< Real >::fitPolynomial(), Fitter< Real>::Fitter(), and Fitter< Real >::fitZeroSet().

1.1.4.8 template<typename Real = float> unsigned int Fitter< Real >::numberOfSamples[protected]

The number of input samples

Definition at line 43 of file Fitter.hpp.

Referenced by Fitter< Real >::buildFittingMatrix(), Fitter< Real >::fitPolynomial(), and Fitter< Real>::Fitter().

1.1.4.9 template<typename Real = float> const Real∗ Fitter< Real >::points [protected]

The locations of the input samples

Definition at line 48 of file Fitter.hpp.

Referenced by Fitter< Real >::Fitter().

1.1.4.10 template<typename Real = float> const Real∗ Fitter< Real >::sampleWeights[protected]

The samples’ POSITIVE weights

Definition at line 71 of file Fitter.hpp.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 16

Referenced by Fitter< Real >::Fitter().

1.1.4.11 template<typename Real = float> Real∗ Fitter< Real >::sqrtBasisWeights[protected]

The square roots of the basis’ weights (used in intermediate computations)

Definition at line 94 of file Fitter.hpp.

Referenced by Fitter< Real >::Fitter(), Fitter< Real >::setBasis(), and Fitter< Real >::∼Fitter().

1.1.4.12 template<typename Real = float> Real∗ Fitter< Real >::sqrtSampleWeights[protected]

The square roots of the samples’ weights (used in intermediate computations)

Definition at line 77 of file Fitter.hpp.

Referenced by Fitter< Real >::Fitter(), Fitter< Real >::setSamples(), and Fitter< Real >::∼Fitter().

1.1.4.13 template<typename Real = float> const Real∗ Fitter< Real >::values [protected]

The expected values of the fitted polynomial when evaluated at the input points

Definition at line 54 of file Fitter.hpp.

Referenced by Fitter< Real >::Fitter().

1.1.4.14 template<typename Real = float> bool Fitter< Real >::weightBasis [protected]

A flag indicating a request to weight the basis’ elements

Definition at line 83 of file Fitter.hpp.

Referenced by Fitter< Real >::Fitter(), and Fitter< Real >::setBasis().

1.1.4.15 template<typename Real = float> bool Fitter< Real >::weightSamples [protected]

A flag indicating a request to weight the input samples

Definition at line 66 of file Fitter.hpp.

Referenced by Fitter< Real >::Fitter(), and Fitter< Real >::setSamples().

The documentation for this class was generated from the following files:

• Fitter.hpp• Fitter.cpp

1.2 MonomialBasis< Real > Class Template Reference

The monomial basis to spaces of polynomial functions.

#include <MonomialBasis.hpp>

Inheritance diagram for MonomialBasis< Real >:

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 17

MonomialBasis< Real >

PolynomialBasis< double >

Collaboration diagram for MonomialBasis< Real >:

MonomialBasis< Real >

PolynomialBasis< double > Real

monomials

Public Member Functions

• MonomialBasis (unsigned int dimension, unsigned int degree)• virtual ∼MonomialBasis (void)• virtual Real evaluatePolynomial (const Real ∗coefficients, const Real ∗point) const• virtual void evaluate (unsigned int numberOfPoints, const Real ∗points, Real ∗matrix) const• unsigned int getDimension (void) const• unsigned int getDegree (void) const• unsigned int getSize (void) const

Static Public Member Functions

• static unsigned int getPolynomialBasisSize (unsigned int dimension, unsigned int degree)

Protected Member Functions

• void evaluateMonomials (const Real ∗point, Real ∗monomials) const• Real evaluateMonomial (const Real ∗monomials, const unsigned int ∗multiIndex) const• void zeroMultiIndex (unsigned int ∗multiIndex) const• void nextMultiIndex (unsigned int ∗multiIndex) const

Protected Attributes

• Real ∗ monomials• unsigned int ∗ multiIndex• unsigned int dimension• unsigned int degree• unsigned int size

1.2.1 Detailed Description

template<typename Real = float> class MonomialBasis< Real >

The monomial basis to spaces of polynomial functions.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 18

Parameters:

Real {float} or double

The basis formed by monomials to finite-dimensional linear spaces of multivariate polynomials over thefield of real numbers

Definition at line 30 of file MonomialBasis.hpp.

1.2.2 Constructor & Destructor Documentation

1.2.2.1 template<typename Real> MonomialBasis< Real >::MonomialBasis (unsigned int dimen-sion, unsigned int degree)

Class constructor

Parameters:

dimension Dimension of the real space in which the polynomials are defined

degree (Maximum) Degree of the polynomials

Definition at line 19 of file MonomialBasis.cpp.

References MonomialBasis< Real >::monomials, and MonomialBasis< Real >::multiIndex.

20 : PolynomialBasis<Real>(dimension, degree) {21 this->monomials = new Real[this->dimension * (this->degree + 1u)];22 this->multiIndex = new unsigned int[this->dimension];23 }

1.2.2.2 template<typename Real> MonomialBasis< Real >::∼MonomialBasis (void)[virtual]

Class destructor

Definition at line 26 of file MonomialBasis.cpp.

References MonomialBasis< Real >::monomials, and MonomialBasis< Real >::multiIndex.

26 {27 delete[] this->multiIndex;28 delete[] this->monomials;29 }

1.2.3 Member Function Documentation

1.2.3.1 template<typename Real> void MonomialBasis< Real >::evaluate (unsigned int number-OfPoints, const Real ∗ points, Real ∗ matrix) const [virtual]

Evaluates each one of the elements in this basis at the given points and build a matrix (in C++’s column-major order) with the computed values (analogously to the Vandermonde matrix)

Parameters:

numberOfPoints The number of points to evaluate

points An array with the points’ coordinates

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 19

matrix A pointer to a pre-allocated array

Returns:

The matrix computed is written to the array ’matrix’

Implements PolynomialBasis< Real >.

Definition at line 55 of file MonomialBasis.cpp.

References MonomialBasis< Real >::evaluateMonomial(), PolynomialBasis< Real >::getSize(),MonomialBasis< Real >::monomials, MonomialBasis< Real >::multiIndex, and MonomialBasis< Real>::zeroMultiIndex().

56 {57 unsigned int m = numberOfPoints;58 unsigned int n = this->getSize();5960 // Real* monomials = new Real[this->dimension * (this->degree + 1u)];61 // unsigned int* multiIndex = new unsigned int[this->dimension];6263 register unsigned int r, c;64 const Real* point;65 Real* basis;6667 for (r = 0u; r < m; ++r) {68 point = &points[r * this->dimension];69 basis = &matrix[r * n];7071 this->evaluateMonomials(point, monomials);72 this->zeroMultiIndex(multiIndex);73 basis[0] = static_cast<Real>(1.0f);7475 for (c = 1u; c < n; ++c) {76 this->nextMultiIndex(multiIndex);77 basis[c] = this->evaluateMonomial(monomials, multiIndex);78 }7980 }8182 // delete[] multiIndex; multiIndex = NULL;83 // delete[] monomials; monomials = NULL;84 }

Here is the call graph for this function:

MonomialBasis::evaluate

MonomialBasis::evaluateMonomial

PolynomialBasis::getSize

MonomialBasis::zeroMult iIndex

1.2.3.2 template<typename Real> Real MonomialBasis< Real >::evaluateMonomial (const Real∗ monomials, const unsigned int ∗ multiIndex) const [protected]

Evaluates the monomial represented by the multi-index at the given point (with the aid of the computed 1Dmonomials)

Parameters:

monomials The 1D monomials evaluated at the point

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 20

multiIndex The multi-index which represents the evaluated monomial

Returns:

The value of the monomial at the given point

Definition at line 105 of file MonomialBasis.cpp.

References PolynomialBasis< Real >::dimension.

Referenced by MonomialBasis< Real >::evaluate(), and MonomialBasis< Real >::evaluatePolynomial().

106 {107 Real ret = static_cast<Real>(1.0f);108 const Real* monomials1D;109110 for (register unsigned int i = 0; i < this->dimension; ++i) {111 monomials1D = &monomials[i * (this->degree + 1u)];112 ret *= monomials1D[multiIndex[i]];113 }114115 return ret;116 }

Here is the caller graph for this function:

MonomialBasis::evaluateMonomial

MonomialBasis::evaluate

MonomialBasis::evaluatePolynomial

1.2.3.3 template<typename Real> void MonomialBasis< Real >::evaluateMonomials (const Real∗ point, Real ∗ monomials) const [protected]

Evaluates the 1D monomials of degree at most ’degree’ at each of the given point’s coordinates

Parameters:

point An array with the point’s coordinates

monomials A pointer to a pre-allocated array

Returns:

The value of the 1D monomials overwrite ’monomials’

Definition at line 87 of file MonomialBasis.cpp.

References PolynomialBasis< Real >::degree, and PolynomialBasis< Real >::dimension.

Referenced by MonomialBasis< Real >::evaluatePolynomial().

88 {89 register unsigned int i, j;90 register Real* monomials1D;9192 for (i = 0u; i < this->dimension; ++i) {93 monomials1D = &monomials[i * (this->degree + 1u)];94 monomials1D[0] = static_cast<Real>(1.0f);

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 21

9596 for (j = 0u; j < this->degree; ++j) {97 monomials1D[j+1u] = monomials1D[j] * point[i];98 }99100 }101102 }

Here is the caller graph for this function:

MonomialBasis::evaluateMonomials MonomialBasis::evaluatePolynomial

1.2.3.4 template<typename Real> Real MonomialBasis< Real >::evaluatePolynomial (const Real∗ coefficients, const Real ∗ point) const [virtual]

Evaluates a polynomial represented as a linear combination of the elements of this basis at the given point

Parameters:

coefficients The coefficients which represent the evaluated polynomial in this basis

point An array with the point’s coordinates

Returns:

The value of the polynomial at the given point

Implements PolynomialBasis< Real >.

Definition at line 32 of file MonomialBasis.cpp.

References MonomialBasis< Real >::evaluateMonomial(), MonomialBasis< Real >::evaluate-Monomials(), PolynomialBasis< Real >::getSize(), MonomialBasis< Real >::monomials, Monomial-Basis< Real >::multiIndex, and MonomialBasis< Real >::zeroMultiIndex().

33 {34 Real ret = static_cast<Real>(0.0f);3536 // Real* monomials = new Real[this->dimension * (this->degree + 1u)];37 // unsigned int* multiIndex = new unsigned int[this->dimension];3839 this->evaluateMonomials(point, monomials);40 this->zeroMultiIndex(multiIndex);41 ret = coefficients[0];4243 for (register unsigned int i = 1u; i < this->getSize(); ++i) {44 this->nextMultiIndex(multiIndex);45 ret += coefficients[i] * evaluateMonomial(monomials, multiIndex);46 }4748 // delete[] multiIndex; multiIndex = NULL;49 // delete[] monomials; monomials = NULL;5051 return ret;52 }

Here is the call graph for this function:

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 22

MonomialBasis::evaluatePolynomial

MonomialBasis::evaluateMonomial

MonomialBasis::evaluateMonomials

PolynomialBasis::getSize

MonomialBasis::zeroMult iIndex

1.2.3.5 template<typename Real> unsigned int PolynomialBasis< Real >::getDegree (void) const[inherited]

Returns the (maximum) degree of the polynomials in this basis

Returns:

the (maximum) degree of the polynomials

Definition at line 35 of file PolynomialBasis.cpp.

References PolynomialBasis< Real >::degree.

35 {36 return this->degree;37 }

1.2.3.6 template<typename Real> unsigned int PolynomialBasis< Real >::getDimension (void)const [inherited]

Returns the dimension of the space in which the basis is defined

Returns:

the dimension of the domain

Definition at line 30 of file PolynomialBasis.cpp.

References PolynomialBasis< Real >::dimension.

30 {31 return this->dimension;32 }

1.2.3.7 template<typename Real> unsigned int PolynomialBasis< Real >::getPolynomialBasis-Size (unsigned int dimension, unsigned int degree) [static, inherited]

Computes the dimension of the linear space of polynomials defined on a real space of dimension ’dimen-sion’ whose maximum degree is ’degree’

Parameters:

dimension The dimension of the polynomials’ domain

degree The (maximum) degree of the polynomials

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 23

Returns:

the dimension of this space of polynomials

Definition at line 45 of file PolynomialBasis.cpp.

References combination().

Referenced by PolynomialBasis< Real >::PolynomialBasis().

46 {4748 if (dimension <= degree) {49 return combination(dimension + degree, dimension);50 } else {51 return combination(dimension + degree, degree);52 }5354 }

Here is the call graph for this function:

PolynomialBasis::getPolynomialBasisSize combinat ion

Here is the caller graph for this function:

PolynomialBasis::getPolynomialBasisSize PolynomialBasis::PolynomialBasis

1.2.3.8 template<typename Real> unsigned int PolynomialBasis< Real >::getSize (void) const[inherited]

Returns the dimension of the linear space spanned by this basis

Returns:

the dimension of the space spanned by this basis

Definition at line 40 of file PolynomialBasis.cpp.

References PolynomialBasis< Real >::size.

Referenced by MonomialBasis< Real >::evaluate(), MonomialBasis< Real >::evaluatePolynomial(), andmain().

40 {41 return this->size;42 }

Here is the caller graph for this function:

PolynomialBasis::getSize

MonomialBasis::evaluate

MonomialBasis::evaluatePolynomial

main

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 24

1.2.3.9 template<typename Real> void MonomialBasis< Real >::nextMultiIndex (unsigned int ∗multiIndex) const [protected]

Computes the next multi-index whose elements sum up to ’degree’

Parameters:

multiIndex The current multi-index

Returns:

The next multi-index overwrites the array ’multiIndex’

Definition at line 128 of file MonomialBasis.cpp.

References PolynomialBasis< Real >::dimension, and nexcom().

128 {129 static unsigned int currentDegree;130 static int mtc;131132 register unsigned int i = 0;133 while ((i < this->dimension) && (multiIndex[i] == 0u)) {134 i = i + 1u;135 }136137 if ((i == this->dimension) || (i == (this->dimension-1u))) {138 currentDegree = (multiIndex[this->dimension-1]+1u) % (this->degree+1u);139 mtc = 0;140 }141142 nexcom(currentDegree, this->dimension, multiIndex, &mtc);143 }

Here is the call graph for this function:

MonomialBasis::nextMult iIndex nexcom

1.2.3.10 template<typename Real> void MonomialBasis< Real >::zeroMultiIndex (unsigned int∗ multiIndex) const [protected]

Sets the given multi-index to an all-zero vector

Parameters:

multiIndex An array with the multi-index

Returns:

The zeroed multi-index overwrites ’multiIndex’

Definition at line 119 of file MonomialBasis.cpp.

References PolynomialBasis< Real >::dimension.

Referenced by MonomialBasis< Real >::evaluate(), and MonomialBasis< Real >::evaluatePolynomial().

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.2 MonomialBasis< Real > Class Template Reference 25

119 {120121 for (register unsigned int i = 0; i < this->dimension; ++i) {122 multiIndex[i] = 0u;123 }124125 }

Here is the caller graph for this function:

MonomialBasis::zeroMult iIndex

MonomialBasis::evaluate

MonomialBasis::evaluatePolynomial

1.2.4 Field Documentation

1.2.4.1 template<typename Real = float> unsigned int PolynomialBasis< Real >::degree[protected, inherited]

(Maximum) Degree of the polynomials

Definition at line 40 of file PolynomialBasis.hpp.

Referenced by MonomialBasis< Real >::evaluateMonomials(), and PolynomialBasis< Real >::get-Degree().

1.2.4.2 template<typename Real = float> unsigned int PolynomialBasis< Real >::dimension[protected, inherited]

Dimension of the real space in which the polynomials are defined

Definition at line 35 of file PolynomialBasis.hpp.

Referenced by MonomialBasis< Real >::evaluateMonomial(), MonomialBasis< Real >::evaluate-Monomials(), PolynomialBasis< Real >::getDimension(), MonomialBasis< Real >::nextMultiIndex(),and MonomialBasis< Real >::zeroMultiIndex().

1.2.4.3 template<typename Real = float> Real∗ MonomialBasis< Real >::monomials[protected]

The 1D monomials evaluated at each coordinate of a given point (used in intermediate computations)

Definition at line 39 of file MonomialBasis.hpp.

Referenced by MonomialBasis< Real >::evaluate(), MonomialBasis< Real >::evaluatePolynomial(),MonomialBasis< Real >::MonomialBasis(), and MonomialBasis< Real >::∼MonomialBasis().

1.2.4.4 template<typename Real = float> unsigned int∗ MonomialBasis< Real >::multiIndex[protected]

A multi-index representing powers of some multivariate monomial (used in intermediate computations)

Definition at line 45 of file MonomialBasis.hpp.

Referenced by MonomialBasis< Real >::evaluate(), MonomialBasis< Real >::evaluatePolynomial(),MonomialBasis< Real >::MonomialBasis(), and MonomialBasis< Real >::∼MonomialBasis().

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.3 Polynomial< Real > Class Template Reference 26

1.2.4.5 template<typename Real = float> unsigned int PolynomialBasis< Real >::size[protected, inherited]

Dimension of the linear space spanned by this basis

Definition at line 45 of file PolynomialBasis.hpp.

Referenced by PolynomialBasis< Real >::getSize(), and PolynomialBasis< Real >::PolynomialBasis().

The documentation for this class was generated from the following files:

• MonomialBasis.hpp• MonomialBasis.cpp

1.3 Polynomial< Real > Class Template Reference

A polynomial function.

#include <Polynomial.hpp>

Collaboration diagram for Polynomial< Real >:

Polynomial< Real >

Real

coefficients

Public Member Functions

• Polynomial (const PolynomialBasis< Real > ∗basis, const Real ∗coefficients=NULL)• Polynomial (const Polynomial< Real > &polynomial)• virtual ∼Polynomial (void)• void setCoefficients (const Real ∗coefficients)• Real ∗ getCoefficients (void) const• Real ∗ getCoefficients (void)• unsigned int getNumberOfCoefficients (void) const• Real evaluate (const Real ∗point) const• virtual Polynomial< Real > & operator= (const Polynomial< Real > &polynomial)

Protected Attributes

• const PolynomialBasis< Real > ∗ basis• Real ∗ coefficients

1.3.1 Detailed Description

template<typename Real = float> class Polynomial< Real >

A polynomial function.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.3 Polynomial< Real > Class Template Reference 27

Parameters:

Real {float} or double

A polynomial function represented as the linear combination of the elements from a given basis to a finite-dimensional linear space of functions over the field of real numbers

Definition at line 31 of file Polynomial.hpp.

1.3.2 Constructor & Destructor Documentation

1.3.2.1 template<typename Real> Polynomial< Real >::Polynomial (const PolynomialBasis<Real > ∗ basis, const Real ∗ coefficients = NULL)

Class constructor

Parameters:

basis A basis to some polynomial space

coefficients (Optional) The coefficients of the polynomial with respect to the basis

Definition at line 16 of file Polynomial.cpp.

References Polynomial< Real >::basis, and Polynomial< Real >::setCoefficients().

17 {18 this->basis = basis;19 this->coefficients = new Real[this->basis->getSize()];20 this->setCoefficients(coefficients);21 }

Here is the call graph for this function:

Polynomial::Polynomial Polynomial::setCoefficients

1.3.2.2 template<typename Real> Polynomial< Real >::Polynomial (const Polynomial< Real >& polynomial)

Copy constructor

Parameters:

polynomial A polynomial

Definition at line 24 of file Polynomial.cpp.

24 {25 (*this) = polynomial;26 }

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.3 Polynomial< Real > Class Template Reference 28

1.3.2.3 template<typename Real> Polynomial< Real >::∼Polynomial (void) [virtual]

Class destructor

Definition at line 29 of file Polynomial.cpp.

References Polynomial< Real >::coefficients.

29 {30 delete[] this->coefficients;31 this->coefficients = NULL;32 }

1.3.3 Member Function Documentation

1.3.3.1 template<typename Real> Real Polynomial< Real >::evaluate (const Real ∗ point) const

Evaluates this polynomial at the given point

Parameters:

point An array with the point’s coordinates

Returns:

The value of this polynomial at the given point

Definition at line 69 of file Polynomial.cpp.

References Polynomial< Real >::basis.

Referenced by main().

69 {70 return this->basis->evaluatePolynomial(this->coefficients, point);71 }

Here is the caller graph for this function:

Polynomial::evaluate main

1.3.3.2 template<typename Real> Real ∗ Polynomial< Real >::getCoefficients (void)

Returns the coefficients of this polynomial

Returns:

A pointer to the array of coefficients of this object

Definition at line 59 of file Polynomial.cpp.

References Polynomial< Real >::coefficients.

59 {60 return this->coefficients;61 }

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.3 Polynomial< Real > Class Template Reference 29

1.3.3.3 template<typename Real> Real ∗ Polynomial< Real >::getCoefficients (void) const

Returns the coefficients of this polynomial

Returns:

A pointer to the array of coefficients of this object

Definition at line 54 of file Polynomial.cpp.

References Polynomial< Real >::coefficients.

54 {55 return this->coefficients;56 }

1.3.3.4 template<typename Real> unsigned int Polynomial< Real >::getNumberOfCoefficients(void) const

Returns the dimension of the linear space spanned by basis

Returns:

The number of coefficients of this polynomial

Definition at line 64 of file Polynomial.cpp.

References Polynomial< Real >::basis.

64 {65 return this->basis->getSize();66 }

1.3.3.5 template<typename Real> Polynomial< Real > & Polynomial< Real >::operator= (constPolynomial< Real > & polynomial) [virtual]

Assignment operator

Parameters:

polynomial A polynomial

Returns:

A reference to this polynomial with members copied from the parameter

Definition at line 74 of file Polynomial.cpp.

References Polynomial< Real >::basis, Polynomial< Real >::coefficients, and Polynomial< Real >::set-Coefficients().

74 {7576 if (this->basis->getSize() != polynomial.basis->getSize()) {77 delete[] this->coefficients;78 this->coefficients = new Real[polynomial.basis->getSize()];79 }

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.3 Polynomial< Real > Class Template Reference 30

8081 this->basis = polynomial.basis;82 this->setCoefficients(polynomial.coefficients);83 return (*this);84 }

Here is the call graph for this function:

Polynomial::operator= Polynomial::setCoefficients

1.3.3.6 template<typename Real> void Polynomial< Real >::setCoefficients (const Real ∗ coeffi-cients)

Sets the coefficients of this polynomial

Parameters:

coefficients The array of coefficients to be copied

Definition at line 35 of file Polynomial.cpp.

References Polynomial< Real >::basis.

Referenced by Fitter< Real >::fitPolynomial(), Fitter< Real >::fitZeroSet(), Polynomial< Real>::operator=(), and Polynomial< Real >::Polynomial().

35 {3637 if (coefficients != NULL) {3839 for (register unsigned int i = 0; i < this->basis->getSize(); ++i) {40 this->coefficients[i] = coefficients[i];41 }4243 } else {4445 for (register unsigned int i = 0; i < this->basis->getSize(); ++i) {46 this->coefficients[i] = static_cast<Real>(0.0f);47 }4849 }5051 }

Here is the caller graph for this function:

Polynomial::setCoefficients

Fit ter::fitPolynomial

Fit ter::fitZeroSet

Polynomial::operator=

Polynomial::Polynomial

Fit ter::fit main

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.4 PolynomialBasis< Real > Class Template Reference 31

1.3.4 Field Documentation

1.3.4.1 template<typename Real = float> const PolynomialBasis<Real>∗ Polynomial< Real>::basis [protected]

A basis to some polynomial space

Definition at line 39 of file Polynomial.hpp.

Referenced by Polynomial< Real >::evaluate(), Polynomial< Real >::getNumberOfCoefficients(),Polynomial< Real >::operator=(), Polynomial< Real >::Polynomial(), and Polynomial< Real >::set-Coefficients().

1.3.4.2 template<typename Real = float> Real∗ Polynomial< Real >::coefficients[protected]

An array of coefficients which represent this polynomial in the space spanned by the given basis

Definition at line 45 of file Polynomial.hpp.

Referenced by Polynomial< Real >::getCoefficients(), Polynomial< Real >::operator=(), andPolynomial< Real >::∼Polynomial().

The documentation for this class was generated from the following files:

• Polynomial.hpp• Polynomial.cpp

1.4 PolynomialBasis< Real > Class Template Reference

A basis to a space of polynomial functions.

#include <PolynomialBasis.hpp>

Inheritance diagram for PolynomialBasis< Real >:

PolynomialBasis< Real >

MonomialBasis< double > PolynomialBasis< double >

< double >

Public Member Functions

• virtual ∼PolynomialBasis (void)• unsigned int getDimension (void) const• unsigned int getDegree (void) const• unsigned int getSize (void) const• virtual Real evaluatePolynomial (const Real ∗coefficients, const Real ∗point) const =0• virtual void evaluate (unsigned int numberOfPoints, const Real ∗points, Real ∗matrix) const =0

Static Public Member Functions

• static unsigned int getPolynomialBasisSize (unsigned int dimension, unsigned int degree)

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.4 PolynomialBasis< Real > Class Template Reference 32

Protected Member Functions

• PolynomialBasis (unsigned int dimension, unsigned int degree)

Protected Attributes

• unsigned int dimension• unsigned int degree• unsigned int size

1.4.1 Detailed Description

template<typename Real = float> class PolynomialBasis< Real >

A basis to a space of polynomial functions.

Parameters:

Real {float} or double

A basis to a finite-dimensional linear space of multivariate polynomials over the field of real numbers

Definition at line 27 of file PolynomialBasis.hpp.

1.4.2 Constructor & Destructor Documentation

1.4.2.1 template<typename Real> PolynomialBasis< Real >::PolynomialBasis (unsigned int di-mension, unsigned int degree) [protected]

Class constructor

Parameters:

dimension Dimension of the real space in which the polynomials are defined

degree (Maximum) Degree of the polynomials

Definition at line 17 of file PolynomialBasis.cpp.

References PolynomialBasis< Real >::getPolynomialBasisSize(), and PolynomialBasis< Real >::size.

18 {19 this->dimension = dimension;20 this->degree = degree;21 this->size = getPolynomialBasisSize(dimension, degree);22 }

Here is the call graph for this function:

PolynomialBasis::PolynomialBasis PolynomialBasis::getPolynomialBasisSize combinat ion

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.4 PolynomialBasis< Real > Class Template Reference 33

1.4.2.2 template<typename Real> PolynomialBasis< Real >::∼PolynomialBasis (void)[virtual]

Class destructor

Definition at line 25 of file PolynomialBasis.cpp.

25 {26 // Do nothing ...27 }

1.4.3 Member Function Documentation

1.4.3.1 template<typename Real = float> virtual void PolynomialBasis< Real >::evaluate (un-signed int numberOfPoints, const Real ∗ points, Real ∗ matrix) const [pure virtual]

Evaluates each one of the elements in this basis at the given points and build a matrix (in C++’s column-major order) with the computed values (analogously to the Vandermonde matrix)

Parameters:

numberOfPoints The number of points to evaluate

points An array with the points’ coordinates

matrix A pointer to a pre-allocated array

Returns:

The matrix computed is written to the array ’matrix’

Implemented in MonomialBasis< Real >.

1.4.3.2 template<typename Real = float> virtual Real PolynomialBasis< Real >::evaluate-Polynomial (const Real ∗ coefficients, const Real ∗ point) const [pure virtual]

Evaluates a polynomial represented as a linear combination of the elements of this basis at the given point

Parameters:

coefficients The coefficients which represent the evaluated polynomial in this basis

point An array with the point’s coordinates

Returns:

The value of the polynomial at the given point

Implemented in MonomialBasis< Real >.

1.4.3.3 template<typename Real> unsigned int PolynomialBasis< Real >::getDegree (void) const

Returns the (maximum) degree of the polynomials in this basis

Returns:

the (maximum) degree of the polynomials

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.4 PolynomialBasis< Real > Class Template Reference 34

Definition at line 35 of file PolynomialBasis.cpp.

References PolynomialBasis< Real >::degree.

35 {36 return this->degree;37 }

1.4.3.4 template<typename Real> unsigned int PolynomialBasis< Real >::getDimension (void)const

Returns the dimension of the space in which the basis is defined

Returns:

the dimension of the domain

Definition at line 30 of file PolynomialBasis.cpp.

References PolynomialBasis< Real >::dimension.

30 {31 return this->dimension;32 }

1.4.3.5 template<typename Real> unsigned int PolynomialBasis< Real >::getPolynomialBasis-Size (unsigned int dimension, unsigned int degree) [static]

Computes the dimension of the linear space of polynomials defined on a real space of dimension ’dimen-sion’ whose maximum degree is ’degree’

Parameters:

dimension The dimension of the polynomials’ domain

degree The (maximum) degree of the polynomials

Returns:

the dimension of this space of polynomials

Definition at line 45 of file PolynomialBasis.cpp.

References combination().

Referenced by PolynomialBasis< Real >::PolynomialBasis().

46 {4748 if (dimension <= degree) {49 return combination(dimension + degree, dimension);50 } else {51 return combination(dimension + degree, degree);52 }5354 }

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

1.4 PolynomialBasis< Real > Class Template Reference 35

Here is the call graph for this function:

PolynomialBasis::getPolynomialBasisSize combinat ion

Here is the caller graph for this function:

PolynomialBasis::getPolynomialBasisSize PolynomialBasis::PolynomialBasis

1.4.3.6 template<typename Real> unsigned int PolynomialBasis< Real >::getSize (void) const

Returns the dimension of the linear space spanned by this basis

Returns:

the dimension of the space spanned by this basis

Definition at line 40 of file PolynomialBasis.cpp.

References PolynomialBasis< Real >::size.

Referenced by MonomialBasis< Real >::evaluate(), MonomialBasis< Real >::evaluatePolynomial(), andmain().

40 {41 return this->size;42 }

Here is the caller graph for this function:

PolynomialBasis::getSize

MonomialBasis::evaluate

MonomialBasis::evaluatePolynomial

main

1.4.4 Field Documentation

1.4.4.1 template<typename Real = float> unsigned int PolynomialBasis< Real >::degree[protected]

(Maximum) Degree of the polynomials

Definition at line 40 of file PolynomialBasis.hpp.

Referenced by MonomialBasis< Real >::evaluateMonomials(), and PolynomialBasis< Real >::get-Degree().

1.4.4.2 template<typename Real = float> unsigned int PolynomialBasis< Real >::dimension[protected]

Dimension of the real space in which the polynomials are defined

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2 polyfit File Documentation 36

Definition at line 35 of file PolynomialBasis.hpp.

Referenced by MonomialBasis< Real >::evaluateMonomial(), MonomialBasis< Real >::evaluate-Monomials(), PolynomialBasis< Real >::getDimension(), MonomialBasis< Real >::nextMultiIndex(),and MonomialBasis< Real >::zeroMultiIndex().

1.4.4.3 template<typename Real = float> unsigned int PolynomialBasis< Real >::size[protected]

Dimension of the linear space spanned by this basis

Definition at line 45 of file PolynomialBasis.hpp.

Referenced by PolynomialBasis< Real >::getSize(), and PolynomialBasis< Real >::PolynomialBasis().

The documentation for this class was generated from the following files:

• PolynomialBasis.hpp• PolynomialBasis.cpp

2 polyfit File Documentation

2.1 ellipse.cpp File Reference

Fitting an ellipse.

#include <iostream>

#include "polyfit.h"

Include dependency graph for ellipse.cpp:

ellipse.cpp

iostream

polyfit .h

PolynomialBasis.hpp

Polynomial.hpp

Fit ter.hpp

MonomialBasis.hpp

numerics.hpp

Functions

• int main (int argc, char ∗argv[ ])

2.1.1 Detailed Description

Fitting an ellipse.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.1 ellipse.cpp File Reference 37

Version:

0.0.1

Date:

16/10/2007

Definition in file ellipse.cpp.

2.1.2 Function Documentation

2.1.2.1 int main (int argc, char ∗ argv[ ])

Definition at line 24 of file ellipse.cpp.

References Polynomial< Real >::evaluate(), Fitter< Real >::fit(), Fitter< Real >::setBasis(), Fitter< Real>::setDimension(), and Fitter< Real >::setSamples().

24 {25 double points[] = { 1.0, 0.0,26 0.0, 1.0,27 -1.0, 0.0,28 0.0, -1.0,29 1.0, 1.0,30 -1.0, -1.0};3132 Fitter<double> fitter;33 MonomialBasis<double> basis(2, 2);3435 fitter.setDimension(2);36 fitter.setBasis(&basis);37 fitter.setSamples(6, points);3839 Polynomial<double>* ellipse = fitter.fit();4041 int n = 32;42 double point[2];4344 for (register int i = 0; i < n; ++i) {45 point[0] = ((i * 3.0) / (n - 1)) - 1.5;4647 for (register int j = 0; j < n; ++j) {48 point[1] = ((j * 3.0) / (n - 1)) - 1.5;49 std::cout << point[0] << ’\t’ << point[1] << ’\t’50 << ellipse->evaluate(point) << std::endl;51 }5253 }5455 delete ellipse;56 return 0;57 }

Here is the call graph for this function:

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.2 Fitter.cpp File Reference 38

main

Polynomial::evaluate

Fit ter::fit

Fit ter::setBasis

Fit ter::setDimension

Fit ter::setSamples

Fit ter::fitPolynomial

Fit ter::fitZeroSet Fit ter::buildFit t ingMatrix

Fit ter::gels

Polynomial::setCoefficients

Fit ter::gemm

Fit ter::syevx

2.2 Fitter.cpp File Reference

Polynomial fitting.

#include <cstring>

#include <cmath>

#include <cblas.h>

#include <f2c.h>

#include <clapack.h>

Include dependency graph for Fitter.cpp:

Fit ter.cpp

cstring

cmath

cblas.h

f2c.h

clapack.h

This graph shows which files directly or indirectly include this file:

Fit ter.cpp Fit ter.hpp polyfit .h

ellipse.cpp

parabola.cpp

polyfit .cpp

2.2.1 Detailed Description

Polynomial fitting.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.3 Fitter.hpp File Reference 39

Version:

0.0.1

Date:

14/10/2007

Definition in file Fitter.cpp.

2.3 Fitter.hpp File Reference

Polynomial fitting.

#include "Polynomial.hpp"

#include "PolynomialBasis.hpp"

#include "Fitter.cpp"

Include dependency graph for Fitter.hpp:

Fit ter.hpp

Polynomial.hpp

PolynomialBasis.hpp

Fit ter.cpp

cstddef

Polynomial.cpp

PolynomialBasis.cpp numerics.hpp numerics.cpp

cstring

cmath

cblas.h

f2c.h

clapack.h

This graph shows which files directly or indirectly include this file:

Fit ter.hpp polyfit .h

ellipse.cpp

parabola.cpp

polyfit .cpp

Data Structures

• class Fitter< Real >

The fitting class.

2.3.1 Detailed Description

Polynomial fitting.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.4 MonomialBasis.cpp File Reference 40

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file Fitter.hpp.

2.4 MonomialBasis.cpp File Reference

Representation and evaluation of linear spaces of polynomials spanned by monomials.

#include <cstddef>

#include "numerics.hpp"

Include dependency graph for MonomialBasis.cpp:

MonomialBasis.cpp

cstddef

numerics.hpp numerics.cpp

This graph shows which files directly or indirectly include this file:

MonomialBasis.cpp MonomialBasis.hpp polyfit .h

ellipse.cpp

parabola.cpp

polyfit .cpp

2.4.1 Detailed Description

Representation and evaluation of linear spaces of polynomials spanned by monomials.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file MonomialBasis.cpp.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.5 MonomialBasis.hpp File Reference 41

2.5 MonomialBasis.hpp File Reference

Representation and evaluation of linear spaces of polynomials spanned by monomials.

#include "PolynomialBasis.hpp"

#include "MonomialBasis.cpp"

Include dependency graph for MonomialBasis.hpp:

MonomialBasis.hpp

PolynomialBasis.hpp

MonomialBasis.cpp

PolynomialBasis.cpp

numerics.hpp numerics.cpp

cstddef

This graph shows which files directly or indirectly include this file:

MonomialBasis.hpp polyfit .h

ellipse.cpp

parabola.cpp

polyfit .cpp

Data Structures

• class MonomialBasis< Real >

The monomial basis to spaces of polynomial functions.

2.5.1 Detailed Description

Representation and evaluation of linear spaces of polynomials spanned by monomials.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file MonomialBasis.hpp.

2.6 numerics.cpp File Reference

Numerical / combinatorial functions.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.6 numerics.cpp File Reference 42

This graph shows which files directly or indirectly include this file:

numerics.cpp numerics.hpp PolynomialBasis.cpp polyfit .h

MonomialBasis.cpp

PolynomialBasis.hpp

MonomialBasis.hpp

Functions

• unsigned long int combination (unsigned long int n, unsigned long int k)• void nexcom (unsigned int n, unsigned int k, unsigned int ∗r, int ∗mtc)

2.6.1 Detailed Description

Numerical / combinatorial functions.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file numerics.cpp.

2.6.2 Function Documentation

2.6.2.1 unsigned long int combination (unsigned long int n, unsigned long int k) [inline]

Computes the binomial coefficient C(n,k) := n!/(k!(n-k)!)

Parameters:

n A non-negative integer

k A non-negative integer smaller than, or equals to, n

Returns:

C(n,k)

Definition at line 29 of file numerics.cpp.

Referenced by PolynomialBasis< Real >::getPolynomialBasisSize().

29 {3031 if (k > n) {

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.6 numerics.cpp File Reference 43

32 return 0u;33 }3435 if (k > (n >> 1u)) {36 k = n - k;37 }3839 if (k == 0u) {40 return 1u;41 } else if (k == 1u) {42 return n;43 } else {44 register unsigned long int cnk = ((n - k) + 1u), i, j;4546 for (i = (n - k) + 2u, j = 2u; j <= k; ++i, ++j) {47 cnk *= i;48 cnk /= j;49 }5051 return cnk;52 }5354 }

Here is the caller graph for this function:

combinat ion PolynomialBasis::getPolynomialBasisSize PolynomialBasis::PolynomialBasis

2.6.2.2 void nexcom (unsigned int n, unsigned int k, unsigned int ∗ r, int ∗ mtc) [inline]

Computes the next composition of n into k parts

Parameters:

n A non-negative integer whose compositions are desired

k A non-negative integer indicating the number of parts of desired composition

r A pointer to the current composition of n into k parts, where r[i] is the (i+1)-th part of the outputcomposition

mtc A pointer to a flag indicating if the current composition is NOT the last (it is zero if the current isthe last)

Returns:

On output, r is overwritten with the next composition of n into k parts and mtc is set zero if r is the lastcomposition

Definition at line 56 of file numerics.cpp.

Referenced by MonomialBasis< Real >::nextMultiIndex().

56 {57 // Combinatorial Algorithms: For Computers and Calculators, Second Edition58 // Albert Nijenhuis and Herbert S. Wilf59 // Chapter 5: Next Composition of n into k Parts (NEXCOM)60 static unsigned int t;61 static int h;62

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.7 numerics.hpp File Reference 44

63 --r;6465 if (*mtc != 0) {6667 if (t > 1) {68 h = 0;69 }7071 h = h + 1;72 t = r[h];73 r[h] = 0;74 r[1] = t - 1;75 r[h+1] = r[h+1] + 1;76 } else {77 register unsigned int i;78 r[1] = n;79 t = n;80 h = 0;8182 for (i = 2; i <= k; ++i) {83 r[i] = 0;84 }8586 }8788 *mtc = (r[k] != n);8990 ++r;91 }

Here is the caller graph for this function:

nexcom MonomialBasis::nextMult iIndex

2.7 numerics.hpp File Reference

Numerical / combinatorial functions.

#include "numerics.cpp"

Include dependency graph for numerics.hpp:

numerics.hpp numerics.cpp

This graph shows which files directly or indirectly include this file:

numerics.hpp PolynomialBasis.cpp

polyfit .h

MonomialBasis.cpp

PolynomialBasis.hpp

Polynomial.hpp

Fit ter.hpp

MonomialBasis.hpp

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.7 numerics.hpp File Reference 45

Functions

• unsigned long int combination (unsigned long int n, unsigned long int k)• void nexcom (unsigned int n, unsigned int k, unsigned int ∗r, int ∗mtc)

2.7.1 Detailed Description

Numerical / combinatorial functions.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file numerics.hpp.

2.7.2 Function Documentation

2.7.2.1 unsigned long int combination (unsigned long int n, unsigned long int k) [inline]

Computes the binomial coefficient C(n,k) := n!/(k!(n-k)!)

Parameters:

n A non-negative integer

k A non-negative integer smaller than, or equals to, n

Returns:

C(n,k)

Definition at line 29 of file numerics.cpp.

Referenced by PolynomialBasis< Real >::getPolynomialBasisSize().

29 {3031 if (k > n) {32 return 0u;33 }3435 if (k > (n >> 1u)) {36 k = n - k;37 }3839 if (k == 0u) {40 return 1u;41 } else if (k == 1u) {42 return n;43 } else {

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.7 numerics.hpp File Reference 46

44 register unsigned long int cnk = ((n - k) + 1u), i, j;4546 for (i = (n - k) + 2u, j = 2u; j <= k; ++i, ++j) {47 cnk *= i;48 cnk /= j;49 }5051 return cnk;52 }5354 }

Here is the caller graph for this function:

combinat ion PolynomialBasis::getPolynomialBasisSize PolynomialBasis::PolynomialBasis

2.7.2.2 void nexcom (unsigned int n, unsigned int k, unsigned int ∗ r, int ∗ mtc) [inline]

Computes the next composition of n into k parts

Parameters:

n A non-negative integer whose compositions are desired

k A non-negative integer indicating the number of parts of desired composition

r A pointer to the current composition of n into k parts, where r[i] is the (i+1)-th part of the outputcomposition

mtc A pointer to a flag indicating if the current composition is NOT the last (it is zero if the current isthe last)

Returns:

On output, r is overwritten with the next composition of n into k parts and mtc is set zero if r is the lastcomposition

Definition at line 56 of file numerics.cpp.

Referenced by MonomialBasis< Real >::nextMultiIndex().

56 {57 // Combinatorial Algorithms: For Computers and Calculators, Second Edition58 // Albert Nijenhuis and Herbert S. Wilf59 // Chapter 5: Next Composition of n into k Parts (NEXCOM)60 static unsigned int t;61 static int h;6263 --r;6465 if (*mtc != 0) {6667 if (t > 1) {68 h = 0;69 }7071 h = h + 1;72 t = r[h];73 r[h] = 0;74 r[1] = t - 1;

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.8 parabola.cpp File Reference 47

75 r[h+1] = r[h+1] + 1;76 } else {77 register unsigned int i;78 r[1] = n;79 t = n;80 h = 0;8182 for (i = 2; i <= k; ++i) {83 r[i] = 0;84 }8586 }8788 *mtc = (r[k] != n);8990 ++r;91 }

Here is the caller graph for this function:

nexcom MonomialBasis::nextMult iIndex

2.8 parabola.cpp File Reference

Fitting a parabola.

#include <iostream>

#include "polyfit.h"

Include dependency graph for parabola.cpp:

parabola.cpp

iostream

polyfit .h

PolynomialBasis.hpp

Polynomial.hpp

Fit ter.hpp

MonomialBasis.hpp

numerics.hpp

Functions

• int main (int argc, char ∗argv[ ])

2.8.1 Detailed Description

Fitting a parabola.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.9 polyfit.cpp File Reference 48

Version:

0.0.1

Date:

16/10/2007

Definition in file parabola.cpp.

2.8.2 Function Documentation

2.8.2.1 int main (int argc, char ∗ argv[ ])

Definition at line 24 of file parabola.cpp.

References Polynomial< Real >::evaluate(), Fitter< Real >::fit(), Fitter< Real >::setBasis(), Fitter< Real>::setDimension(), and Fitter< Real >::setSamples().

24 {25 double points[] = {-1.0, 0.0, 1.0};26 double values[] = { 1.0, 0.0, 1.0};2728 Fitter<double> fitter;29 MonomialBasis<double> basis(1, 2);3031 fitter.setDimension(1);32 fitter.setBasis(&basis);33 fitter.setSamples(3, points, values);3435 Polynomial<double>* parabola = fitter.fit();3637 int n = 32;38 double x;3940 for (register int i = 0; i < n; ++i) {41 x = ((i * 2.0) / (n - 1)) - 1.0;42 std::cout << x << ’\t’ << parabola->evaluate(&x) << std::endl;43 }4445 delete parabola;46 return 0;47 }

Here is the call graph for this function:

main

Polynomial::evaluate

Fit ter::fit

Fit ter::setBasis

Fit ter::setDimension

Fit ter::setSamples

Fit ter::fitPolynomial

Fit ter::fitZeroSet Fit ter::buildFit t ingMatrix

Fit ter::gels

Polynomial::setCoefficients

Fit ter::gemm

Fit ter::syevx

2.9 polyfit.cpp File Reference

Polynomial fitting.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.9 polyfit.cpp File Reference 49

#include <iostream>

#include <cstdlib>

#include "polyfit.h"

Include dependency graph for polyfit.cpp:

polyfit .cpp

iostream

cstdlib

polyfit .h

PolynomialBasis.hpp

Polynomial.hpp

Fit ter.hpp

MonomialBasis.hpp

numerics.hpp

Typedefs

• typedef double Real

Functions

• Real absolute (const Real x)• int main (int argc, char ∗argv[ ])

Variables

• const Real EPSILON = static_cast<Real>(1.0e-6)• const Real zero = static_cast<Real>(0.0f)• const Real one = static_cast<Real>(1.0f)

2.9.1 Detailed Description

Polynomial fitting.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

This is a test program for the polynomial fitting library. It takes from the standard input a description forthe fitting process and writes to the standard output samples of the fitted polynomial as a list of (point,value) pairs. The output is a sample from the [-1,1]∧{dimension} hypercube, where each dimension issampled with a default number of points of 32 (which can be altered by passing a positive integer in thecommand-line which runs this program).

Definition in file polyfit.cpp.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.9 polyfit.cpp File Reference 50

2.9.2 Typedef Documentation

2.9.2.1 typedef double Real

Definition at line 31 of file polyfit.cpp.

2.9.3 Function Documentation

2.9.3.1 Real absolute (const Real x) [inline]

Definition at line 37 of file polyfit.cpp.

37 {38 return (((x) > 0.0f) ? (x) : (-x));39 }

2.9.3.2 int main (int argc, char ∗ argv[ ])

Definition at line 41 of file polyfit.cpp.

References Polynomial< Real >::evaluate(), Fitter< Real >::fit(), PolynomialBasis< Real >::getSize(),one, Fitter< Real >::setBasis(), Fitter< Real >::setDimension(), Fitter< Real >::setSamples(), and zero.

41 {42 unsigned int N = 32u;4344 if (argc == 2) {45 N = std::atoi(argv[1]);46 }4748 unsigned int dimension, numberOfSamples, degree;49 Real *points, *values, *sampleWeights, *basisWeights;50 PolynomialBasis<Real>* polynomialBasis;5152 std::string fitting, basis, sampleWeighting, basisWeighting;5354 std::cin >> fitting;55 std::cin >> basis;56 std::cin >> sampleWeighting;57 std::cin >> basisWeighting;5859 std::cin >> dimension;60 std::cin >> numberOfSamples;61 std::cin >> degree;6263 register unsigned int i, j;6465 points = new Real[dimension * numberOfSamples];6667 bool fitPolynomial, weightSamples, weightBasis;6869 fitPolynomial = (fitting.compare("fitPolynomial") == 0);7071 if (fitPolynomial) {72 values = new Real[numberOfSamples];73 } else {74 values = NULL;75 }7677 if (basis.compare("MonomialBasis") == 0) {78 polynomialBasis = new MonomialBasis<Real>(dimension, degree);79 } else {

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.9 polyfit.cpp File Reference 51

80 std::cerr << "WARNING: The only basis available"81 << " is the ’MonomialBasis’ !!!" << std::endl;82 polynomialBasis = new MonomialBasis<Real>(dimension, degree);83 }8485 weightSamples = (sampleWeighting.compare("weightSamples") == 0);8687 if (weightSamples) {88 sampleWeights = new Real[numberOfSamples];89 } else {90 sampleWeights = NULL;91 }9293 for (i = 0u; i < numberOfSamples; ++i) {9495 for (j = 0u; j < dimension; ++j) {96 std::cin >> points[j + i * dimension];97 }9899 if (fitPolynomial) {100 std::cin >> values[i];101 }102103 if (weightSamples) {104 std::cin >> sampleWeights[i];105 }106107 }108109 weightBasis = (basisWeighting.compare("weightBasis") == 0);110111 if (weightBasis) {112 unsigned int size = polynomialBasis->getSize();113 basisWeights = new Real[size];114115 for (i = 0u; i < size; ++i) {116 std::cin >> basisWeights[i];117 }118119 } else {120 basisWeights = NULL;121 }122123 Fitter<Real> fitter;124 fitter.setDimension(dimension);125 fitter.setSamples(numberOfSamples, points, values, sampleWeights);126 fitter.setBasis(polynomialBasis, basisWeights);127 Polynomial<Real>* polynomial = fitter.fit();128129 unsigned int size = 1u;130 unsigned int* index = new unsigned int[dimension];131 Real* point = new Real[dimension];132133 for (i = 0u; i < dimension; ++i) {134 size = size * N;135 index[i] = 0u;136 point[i] = zero;137 }138139 Real s = 1.0f;140 Real x = -one * s, y = one * s;141 Real h = (y - x) / (N - one);142143 for (i = 0u; i < size; ++i) {144145 for (j = 0u; j < dimension; ++j) {146 point[j] = x + index[j] * h;

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.9 polyfit.cpp File Reference 52

147 std::cout << point[j] << ’\t’;148 }149150 std::cout << polynomial->evaluate(point) << std::endl;151152 bool incremented = false;153 j = 0u;154155 while ((j < dimension) && !incremented) {156 index[j] = index[j] + 1u;157158 if (index[j] == N) {159 index[j] = 0u;160 incremented = ((j + 1u) == dimension);161 } else {162 incremented = true;163 }164165 j = j + 1u;166 }167168 }169170 delete[] point;171 point = NULL;172173 delete[] index;174 index = NULL;175176 delete polynomial;177 polynomial = NULL;178179 if (weightBasis) {180 delete[] basisWeights;181 basisWeights = NULL;182 }183184 if (weightSamples) {185 delete[] sampleWeights;186 sampleWeights = NULL;187 }188189 if (fitPolynomial) {190 delete[] values;191 values = NULL;192 }193194 delete[] points;195 points = NULL;196197 delete polynomialBasis;198 polynomialBasis = NULL;199200 return EXIT_SUCCESS;201 }

Here is the call graph for this function:

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.10 polyfit.h File Reference 53

main

Polynomial::evaluate

Fit ter::fit

PolynomialBasis::getSize

Fit ter::setBasis

Fit ter::setDimension

Fit ter::setSamples

Fit ter::fitPolynomial

Fit ter::fitZeroSet Fit ter::buildFit t ingMatrix

Fit ter::gels

Polynomial::setCoefficients

Fit ter::gemm

Fit ter::syevx

2.9.4 Variable Documentation

2.9.4.1 const Real EPSILON = static_cast<Real>(1.0e-6)

Definition at line 33 of file polyfit.cpp.

2.9.4.2 const Real one = static_cast<Real>(1.0f)

Definition at line 35 of file polyfit.cpp.

Referenced by main().

2.9.4.3 const Real zero = static_cast<Real>(0.0f)

Definition at line 34 of file polyfit.cpp.

Referenced by main().

2.10 polyfit.h File Reference

polyfit’s main header

#include "PolynomialBasis.hpp"

#include "Polynomial.hpp"

#include "Fitter.hpp"

#include "MonomialBasis.hpp"

#include "numerics.hpp"

Include dependency graph for polyfit.h:

polyfit .h

PolynomialBasis.hpp

Polynomial.hpp

Fit ter.hpp

MonomialBasis.hpp

numerics.hpp

This graph shows which files directly or indirectly include this file:

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.11 Polynomial.cpp File Reference 54

polyfit .h

ellipse.cpp

parabola.cpp

polyfit .cpp

2.10.1 Detailed Description

polyfit’s main header

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file polyfit.h.

2.11 Polynomial.cpp File Reference

Polynomial representation and evaluation.

This graph shows which files directly or indirectly include this file:

Polynomial.cpp Polynomial.hpp

Fit ter.hpp

polyfit .h

ellipse.cpp

parabola.cpp

polyfit .cpp

2.11.1 Detailed Description

Polynomial representation and evaluation.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file Polynomial.cpp.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.12 Polynomial.hpp File Reference 55

2.12 Polynomial.hpp File Reference

Polynomial representation and evaluation.

#include <cstddef>

#include "PolynomialBasis.hpp"

#include "Polynomial.cpp"

Include dependency graph for Polynomial.hpp:

Polynomial.hpp

cstddef

PolynomialBasis.hpp

Polynomial.cpp

PolynomialBasis.cpp numerics.hpp numerics.cpp

This graph shows which files directly or indirectly include this file:

Polynomial.hpp

Fit ter.hpp

polyfit .h

ellipse.cpp

parabola.cpp

polyfit .cpp

Data Structures

• class Polynomial< Real >

A polynomial function.

2.12.1 Detailed Description

Polynomial representation and evaluation.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file Polynomial.hpp.

2.13 PolynomialBasis.cpp File Reference

Representation and evaluation of linear spaces of polynomials.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.14 PolynomialBasis.hpp File Reference 56

#include "numerics.hpp"

Include dependency graph for PolynomialBasis.cpp:

PolynomialBasis.cpp numerics.hpp numerics.cpp

This graph shows which files directly or indirectly include this file:

PolynomialBasis.cpp PolynomialBasis.hpp

Polynomial.hpp

Fit ter.hpp

polyfit .h

MonomialBasis.hpp

ellipse.cpp

parabola.cpp

polyfit .cpp

2.13.1 Detailed Description

Representation and evaluation of linear spaces of polynomials.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file PolynomialBasis.cpp.

2.14 PolynomialBasis.hpp File Reference

Representation and evaluation of linear spaces of polynomials.

#include "PolynomialBasis.cpp"

Include dependency graph for PolynomialBasis.hpp:

PolynomialBasis.hpp PolynomialBasis.cpp numerics.hpp numerics.cpp

This graph shows which files directly or indirectly include this file:

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

2.14 PolynomialBasis.hpp File Reference 57

PolynomialBasis.hpp

Polynomial.hpp

Fit ter.hpp

polyfit .h

MonomialBasis.hpp

ellipse.cpp

parabola.cpp

polyfit .cpp

Data Structures

• class PolynomialBasis< Real >

A basis to a space of polynomial functions.

2.14.1 Detailed Description

Representation and evaluation of linear spaces of polynomials.

Author:

Ives Macêdo <[email protected]>Instituto Nacional de Matemática Pura e Aplicada

Version:

0.0.1

Date:

14/10/2007

Definition in file PolynomialBasis.hpp.

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

Index∼Fitter

Fitter, 3∼MonomialBasis

MonomialBasis, 18∼Polynomial

Polynomial, 27∼PolynomialBasis

PolynomialBasis, 32

absolutepolyfit.cpp, 50

basisFitter, 14Polynomial, 31

basisWeightsFitter, 14

buildFittingMatrixFitter, 4

coefficientsPolynomial, 31

combinationnumerics.cpp, 42numerics.hpp, 45

degreeMonomialBasis, 25PolynomialBasis, 35

dimensionFitter, 14MonomialBasis, 25PolynomialBasis, 35

ellipse.cpp, 36main, 37

EPSILONpolyfit.cpp, 53

evaluateMonomialBasis, 18Polynomial, 28PolynomialBasis, 33

evaluateMonomialMonomialBasis, 19

evaluateMonomialsMonomialBasis, 20

evaluatePolynomialMonomialBasis, 21PolynomialBasis, 33

fitFitter, 4

fitFromZeroSetFitter, 14

fitPolynomialFitter, 5

Fitter, 1∼Fitter, 3basis, 14basisWeights, 14buildFittingMatrix, 4dimension, 14fit, 4fitFromZeroSet, 14fitPolynomial, 5Fitter, 3fittingMatrix, 15fitZeroSet, 6gels, 8, 9gemm, 9, 10m, 15n, 15numberOfSamples, 15points, 15sampleWeights, 15setBasis, 10setDimension, 11setSamples, 12sqrtBasisWeights, 16sqrtSampleWeights, 16syevx, 12–14values, 16weightBasis, 16weightSamples, 16

Fitter.cpp, 38Fitter.hpp, 39fittingMatrix

Fitter, 15fitZeroSet

Fitter, 6

gelsFitter, 8, 9

gemmFitter, 9, 10

getCoefficientsPolynomial, 28

getDegreeMonomialBasis, 22PolynomialBasis, 33

getDimensionMonomialBasis, 22PolynomialBasis, 34

INDEX 59

getNumberOfCoefficientsPolynomial, 29

getPolynomialBasisSizeMonomialBasis, 22PolynomialBasis, 34

getSizeMonomialBasis, 23PolynomialBasis, 35

mFitter, 15

mainellipse.cpp, 37parabola.cpp, 48polyfit.cpp, 50

MonomialBasis, 16MonomialBasis, 18

MonomialBasis∼MonomialBasis, 18degree, 25dimension, 25evaluate, 18evaluateMonomial, 19evaluateMonomials, 20evaluatePolynomial, 21getDegree, 22getDimension, 22getPolynomialBasisSize, 22getSize, 23MonomialBasis, 18monomials, 25multiIndex, 25nextMultiIndex, 23size, 25zeroMultiIndex, 24

MonomialBasis.cpp, 40MonomialBasis.hpp, 41monomials

MonomialBasis, 25multiIndex

MonomialBasis, 25

nFitter, 15

nexcomnumerics.cpp, 43numerics.hpp, 46

nextMultiIndexMonomialBasis, 23

numberOfSamplesFitter, 15

numerics.cpp, 41combination, 42nexcom, 43

numerics.hpp, 44combination, 45nexcom, 46

onepolyfit.cpp, 53

operator=Polynomial, 29

parabola.cpp, 47main, 48

pointsFitter, 15

polyfit.cpp, 48absolute, 50EPSILON, 53main, 50one, 53Real, 50zero, 53

polyfit.h, 53Polynomial, 26

∼Polynomial, 27basis, 31coefficients, 31evaluate, 28getCoefficients, 28getNumberOfCoefficients, 29operator=, 29Polynomial, 27setCoefficients, 30

Polynomial.cpp, 54Polynomial.hpp, 55PolynomialBasis, 31

PolynomialBasis, 32PolynomialBasis

∼PolynomialBasis, 32degree, 35dimension, 35evaluate, 33evaluatePolynomial, 33getDegree, 33getDimension, 34getPolynomialBasisSize, 34getSize, 35PolynomialBasis, 32size, 36

PolynomialBasis.cpp, 55PolynomialBasis.hpp, 56

Realpolyfit.cpp, 50

sampleWeights

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen

INDEX 60

Fitter, 15setBasis

Fitter, 10setCoefficients

Polynomial, 30setDimension

Fitter, 11setSamples

Fitter, 12size

MonomialBasis, 25PolynomialBasis, 36

sqrtBasisWeightsFitter, 16

sqrtSampleWeightsFitter, 16

syevxFitter, 12–14

valuesFitter, 16

weightBasisFitter, 16

weightSamplesFitter, 16

zeropolyfit.cpp, 53

zeroMultiIndexMonomialBasis, 24

Generated on Tue Oct 16 16:47:11 2007 for polyfit by Doxygen