50 : _pointDim(pv._pointDim),
51 _polyCoeffs(pv._polyCoeffs.num_row(), pv._polyCoeffs.num_col(), 0.) {
57 : _pointDim(numberOfInputVariables), _polyCoeffs(polynomialCoefficients) {
62 : _pointDim(0), _polyCoeffs() {
79 for (
unsigned int i = 0; i < coeff.size(); i++) {
80 int polyOrder = coeff[i].InVariables().size();
81 for (
unsigned int j = 0; j < coeff[i].InVariables().size(); j++)
83 if (coeff[i].OutVariable() > valueDim) valueDim = coeff[i].OutVariable();
84 if (polyOrder > maxPolyOrder) maxPolyOrder = polyOrder;
95 for (
unsigned int j = 0; j < coeff.size(); j++)
97 int dim = coeff[j].OutVariable();
98 _polyCoeffs(dim + 1, i + 1) = coeff[j].Coefficient();
112 pointV(i + 1) = point[i];
115 value[i] = valueV(i + 1);
123 value(i + 1) = answer(i + 1);
129 polyVector(i + 1) = 1.;
146 std::vector<int> check,
size_t check_index,
size_t poly_power,
147 std::vector<std::vector<int> >& nearby_points) {
148 check[check_index] = poly_power;
149 nearby_points.push_back(check);
150 if (check_index + 1 == check.size())
return;
151 for (
int i = 1; i < int(poly_power); ++i)
153 for (
int i = 0; i <= int(poly_power); ++i) {
154 check[check_index] = i;
162 "SquarePolynomialVector::IndexByPower",
"Point dimension must be > 0"));
168 std::vector<std::vector<int> > nearby_points(1, std::vector<int>(point_dim, 0));
170 int this_poly_order = 0;
171 while (
int(nearby_points.size()) < index + 1) {
173 this_poly_order += 1;
201 int pointDimension,
int order) {
203 for (
int i = 0; i < pointDimension; ++i)
215 std::ostream& out,
char int_separator,
char str_separator,
int length,
216 bool pad_at_start)
const {
218 PrintContainer<std::vector<int> >(
220 length - 1, pad_at_start);
227 template <
class Container>
229 std::ostream& out,
const Container& container,
char T_separator,
char str_separator,
230 int length,
bool pad_at_start) {
232 std::stringstream strstr1(
"");
233 std::stringstream strstr2(
"");
234 typename Container::const_iterator it1 = container.begin();
235 typename Container::const_iterator it2 = it1;
236 while (it1 != container.end()) {
238 if (it1 != container.end() && it2 != container.end())
239 strstr1 << (*it1) << T_separator;
245 if (
int(strstr1.str().size()) > length && length > 0)
246 strstr2 << strstr1.str().substr(1, length);
248 strstr2 << strstr1.str();
250 if (!pad_at_start) out << strstr2.str();
251 for (
int i = 0; i < length - int(strstr2.str().size()); i++)
252 out << str_separator;
253 if (pad_at_start) out << strstr2.str();
258 size_t maxPower = *std::max_element(index.begin(), index.end());
263 if (derivPower ==
nullptr) {
265 "SquarePolynomialVector::Deriv",
"Derivative points to nullptr"));
270 std::vector<int> thisPower = powerKey[j];
276 double newCoeff = 1.;
278 for (
size_t k = 0; k < thisPower.size(); ++k) {
279 newPower[k] = thisPower[k] - derivPower[k];
280 if (newPower[k] < 0) {
287 for (
size_t k = 0; k < powerKey.size(); ++k) {
289 for (
size_t l = 0; l < powerKey[k].size(); ++l) {
290 if (powerKey[k][l] != newPower[l]) {
297 newPolyCoeffs(i + 1, k + 1) = newCoeff *
_polyCoeffs(i + 1, j + 1);
double gsl_sf_fact(unsigned int n)
Factorial (computed via for large ).
size_t num_col() const
returns number of columns in the matrix
size_t num_row() const
returns number of rows in the matrix
SquarePolynomialVector describes a vector of multivariate polynomials.
unsigned int PointDimension() const
static std::vector< std::vector< std::vector< int > > > _polyKeyByVector
static unsigned int NumberOfPolynomialCoefficients(int pointDimension, int order)
void SetCoefficients(int pointDim, MMatrix< double > coeff)
MVector< double > & MakePolyVector(const MVector< double > &point, MVector< double > &polyVector) const
static std::vector< std::vector< std::vector< int > > > _polyKeyByPower
unsigned int PolynomialOrder() const
static std::vector< int > IndexByPower(int index, int nInputVariables)
static void PrintContainer(std::ostream &out, const Container &container, char T_separator, char str_separator, int length, bool pad_at_start)
unsigned int ValueDimension() const
MMatrix< double > GetCoefficientsAsMatrix() const
static bool _printHeaders
MMatrix< double > _polyCoeffs
SquarePolynomialVector Deriv(const int *derivPower) const
void PrintHeader(std::ostream &out, char int_separator='.', char str_separator=' ', int length=14, bool pad_at_start=true) const
void F(const double *point, double *value) const
static std::vector< int > IndexByVector(int index, int nInputVariables)
friend std::ostream & operator<<(std::ostream &, const SquarePolynomialVector &)
static void IndexByPowerRecursive(std::vector< int > check, size_t check_index, size_t poly_power, std::vector< std::vector< int > > &nearby_points)