|
|
|
//
|
|
|
|
// $filename
|
|
|
|
// $projectname
|
|
|
|
//
|
|
|
|
// Created by Joshua moerman on $TODAY.
|
|
|
|
// Copyright 2010 Joshua Moerman. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Polynomial.hpp"
|
|
|
|
#include <algorithm>
|
|
|
|
//#include <iostream>
|
|
|
|
|
|
|
|
Polynomial::Polynomial():
|
|
|
|
KernelBasicParameter(0),
|
|
|
|
KernelBasicVector(3),
|
|
|
|
orde(2){
|
|
|
|
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Polynomial::Polynomial(const unsigned int dimension, const unsigned int orde):
|
|
|
|
KernelBasicParameter(0),
|
|
|
|
KernelBasicVector(dimension),
|
|
|
|
orde(orde) {
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Polynomial::init() {
|
|
|
|
const unsigned int number = calculateNumberOfParameters();
|
|
|
|
KernelBasicParameter::resetNumberOfParameters(number);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Polynomial::calculateNumberOfParameters() {
|
|
|
|
double n_coef = orde + 1;
|
|
|
|
for (unsigned int i = 2; i <= myDimension; i++) {
|
|
|
|
n_coef = n_coef*(orde + i)/(i - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned int output = (unsigned int) n_coef;
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Polynomial::operator()() {
|
|
|
|
std::swap(vectorNew, vectorOld);
|
|
|
|
|
|
|
|
unsigned int m = 0;
|
|
|
|
for ( unsigned int i = 0; i < myDimension; i++ ) {
|
|
|
|
|
|
|
|
#ifdef HARDDEBUG
|
|
|
|
cout << "Entering new dimension: " << i << " With m = " << m << endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vectorNew[i] = parameters[m];
|
|
|
|
m++;
|
|
|
|
recur(i, 0, 1, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Polynomial::recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product) {
|
|
|
|
double product;
|
|
|
|
for (unsigned int i = prev_i; i < myDimension; i++) {
|
|
|
|
|
|
|
|
#ifdef HARDDEBUG
|
|
|
|
for ( unsigned int j = 0; j < n; j++ )
|
|
|
|
cout << " ";
|
|
|
|
cout << "Calculation in dimension: " << i << " With m = " << m << " And depth = " << n << endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
product = prev_product * vectorOld[i];
|
|
|
|
vectorNew[curr_dimension] += parameters[m] * product;
|
|
|
|
m++;
|
|
|
|
if (n < orde) {
|
|
|
|
recur(curr_dimension, i, n+1, m, product);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|