2 #include "Validator/ObjectRequirement.h"
3 #include "Drivers/DriverException.h"
11 auto type = json.get(
"type",
"none").asString();
12 if(type ==
"Legendre")
14 else if (type ==
"Chebyshev")
16 else if (type ==
"Fourier")
19 throw std::invalid_argument(
"Invalid basis set type \"" + type +
"\".");
23 const std::string& path,
28 Json::CharReaderBuilder rbuilder;
29 Json::CharReader* reader = rbuilder.newCharReader();
31 reader->parse(JsonSchema::ChebyshevBasis.c_str(),
32 JsonSchema::ChebyshevBasis.c_str() + JsonSchema::ChebyshevBasis.size(),
34 validator.
Parse(schema, path);
42 json[
"polynomial_order"].asInt(),
43 json[
"lower_bound"].asDouble(),
44 json[
"upper_bound"].asDouble(),
50 const std::string& path,
55 Json::CharReaderBuilder rbuilder;
56 Json::CharReader* reader = rbuilder.newCharReader();
58 reader->parse(JsonSchema::FourierBasis.c_str(),
59 JsonSchema::FourierBasis.c_str() + JsonSchema::FourierBasis.size(),
61 validator.
Parse(schema, path);
69 json[
"polynomial_order"].asInt(),
70 json[
"lower_bound"].asDouble(),
71 json[
"upper_bound"].asDouble(),
76 const std::string& path,
81 Json::CharReaderBuilder rbuilder;
82 Json::CharReader* reader = rbuilder.newCharReader();
84 reader->parse(JsonSchema::LegendreBasis.c_str(),
85 JsonSchema::LegendreBasis.c_str() + JsonSchema::LegendreBasis.size(),
87 validator.
Parse(schema, path);
95 json[
"polynomial_order"].asInt(),
102 double coeff_size = 1;
110 Map temp_map(jdx,0.0);
112 for(
size_t i = 0; i < coeff_size; ++i)
114 for(
size_t j = 0; j < jdx.size(); ++j)
116 if(jdx[j] > 0 && jdx[j] % (
functions_[j]->GetOrder()+1) == 0)
124 temp_map.
map[j] = jdx[j];
127 coeff_.push_back(temp_map);
136 unsigned int poly =
functions_[i]->GetOrder()+1;
138 std::vector<double> dervs(nbin*poly,0);
139 std::vector<double> vals(nbin*poly,0);
141 for (
size_t j=0; j<poly; j++) {
142 for(
size_t k=0; k<nbin; k++) {
145 vals[k+j*nbin] =
functions_[i]->Evaluate(x,j);
146 dervs[k+j*nbin] =
functions_[i]->EvalGrad(x,j);
163 std::vector<double> tmp_grad (
functions_.size(),0);
165 for (
size_t i = 1; i <
coeff_.size(); ++i)
168 for (
size_t l = 0; l <
functions_.size(); l++)
173 for (
size_t k = 0; k <
functions_.size(); k++)
179 tmp_grad[l] -=
coeff_[i].value * temp;
181 basis *=
lookup_[l].values[it.index(l) +
coeff_[i].map[l]*nbins];
184 tmp_bias +=
coeff_[i].value * basis;
187 grad->at(it.coordinates()) = tmp_grad;
196 double coeffTemp = 0;
203 coeffTemp = coeff.value;
208 double weight = std::pow(2.0,
functions_.size());
213 if( it2.index(k) == 0 ||
225 basis *=
lookup_[l].values[it2.index(l) + coeff.map[l]*nbins]*
functions_[l]->GetRange()/nbins;
229 coeff.value += basis * array[j] * weight/std::pow(2.0,
functions_.size());
231 coeffTemp -= coeff.value;
233 sum += fabs(coeffTemp);
Requirements on an object.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.
std::vector< std::string > GetErrors()
Get list of error messages.
bool HasErrors()
Check if errors have occured.
std::vector< BasisLUT > lookup_
Lookup table for basis functions.
std::vector< Map > coeff_
Vector of basis function coefficients.
void BasisInit()
Creates lookup table for basis functions.
void UpdateBias(Grid< double > *bias, Grid< std::vector< double >> *grad)
Outputs the basis projection at a specific coordinate.
double UpdateCoeff(const std::vector< double > &array, Grid< unsigned int > *hist)
std::vector< BasisFunction * > functions_
Vector of basis functions.
void CoeffInit()
Initializes coefficient lookup vector.
Abstract class for all BasisFunction inheritance.
static BasisFunction * Build(const Json::Value &json, const std::string &path, unsigned int nbins)
Build BasisFunction from JSON value.
Exception to be thrown when building the Driver fails.
Defines the class of Chebyshev polynomials.
Chebyshev(unsigned int polyOrd, double boundLow, double boundUp, unsigned int nbins)
Constructor.
static Chebyshev * Build(const Json::Value &json, const std::string &path, unsigned int nbins)
Build BasisFunction from JSON value.
Defines the class of Fourier polynomials.
Fourier(unsigned int polyOrd, double boundLow, double boundUp, unsigned int nbins)
Constructor.
static Fourier * Build(const Json::Value &json, const std::string &path, unsigned int nbins)
Build BasisFunction from JSON value.
const std::vector< double > GetLower() const
Return the lower edges of the Grid.
const std::vector< double > GetUpper() const
Return the upper edges of the Grid.
const std::vector< int > GetNumPoints() const
Get the number of points for all dimensions.
iterator begin()
Return iterator at first grid point.
iterator end()
Return iterator after last valid grid point.
Defines the class of Legendre polynomials.
static Legendre * Build(const Json::Value &json, const std::string &path, unsigned int nbins)
Build BasisFunction from JSON value.
Legendre(unsigned int polyOrd, unsigned int nbins)
Constructor.
Look-up table for basis functions.
Map for histogram and coefficients.
double value
The coefficient value.
std::vector< int > map
The mapping in an array of integers.