25 #include <queso/1D1DFunction.h>
26 #include <queso/1DQuadrature.h>
34 double minDomainValue,
35 double maxDomainValue)
37 m_minDomainValue(minDomainValue),
38 m_maxDomainValue(maxDomainValue)
64 queso_not_implemented();
66 if (resultWithMultiplicationByTAsWell) {
67 func.
value((
double) quadratureOrder);
77 double minDomainValue,
78 double maxDomainValue,
79 double (*valueRoutinePtr)(
double domainValue,
const void* routinesDataPtr),
80 double (*derivRoutinePtr)(
double domainValue,
const void* routinesDataPtr),
81 const void* routinesDataPtr)
84 m_valueRoutinePtr (valueRoutinePtr),
85 m_derivRoutinePtr (derivRoutinePtr),
86 m_routinesDataPtr (routinesDataPtr)
98 std::cerr <<
"In Generic1D1DFunction::value()"
99 <<
": requested x (" << domainValue
115 std::cerr <<
"In Generic1D1DFunction::deriv()"
116 <<
": requested x (" << domainValue
132 double minDomainValue,
133 double maxDomainValue,
134 double constantValue)
137 m_constantValue (constantValue)
149 std::cerr <<
"In Constant1D1DFunction::value()"
150 <<
": requested x (" << domainValue
166 std::cerr <<
"In Constant1D1DFunction::deriv()"
167 <<
": requested x (" << domainValue
183 double minDomainValue,
184 double maxDomainValue,
185 double referenceDomainValue,
186 double referenceImageValue,
190 m_referenceDomainValue (referenceDomainValue),
191 m_referenceImageValue (referenceImageValue),
192 m_rateValue (rateValue)
204 std::cerr <<
"In Linear1D1DFunction::value()"
205 <<
": requested x (" << domainValue
223 std::cerr <<
"In Linear1D1DFunction::deriv()"
224 <<
": requested x (" << domainValue
240 double minDomainValue,
241 double maxDomainValue,
242 const std::vector<double>& referenceDomainValues,
243 double referenceImageValue0,
244 const std::vector<double>& rateValues)
247 m_numRefValues (referenceDomainValues.
size()),
248 m_referenceDomainValues(referenceDomainValues),
249 m_rateValues (rateValues)
267 std::cout <<
"In PiecewiseLinear1D1DFunction::constructor():"
270 std::cout <<
"i = " << i
290 std::cerr <<
"In PiecewiseLinear1D1DFunction::value()"
291 <<
": requested x (" << domainValue
305 bool referenceDomainValueFound =
false;
306 while (referenceDomainValueFound ==
false) {
308 referenceDomainValueFound =
true;
313 referenceDomainValueFound =
true;
320 std::cout <<
"In PiecewiseLinear1D1DFunction::value()"
321 <<
": domainValue = " << domainValue
326 <<
", imageValue = " << imageValue
337 std::cerr <<
"In PiecewiseLinear1D1DFunction::deriv()"
338 <<
": requested x (" << domainValue
352 bool referenceDomainValueFound =
false;
353 while (referenceDomainValueFound ==
false) {
355 referenceDomainValueFound =
true;
371 double minDomainValue,
372 double maxDomainValue,
392 std::cerr <<
"In Quadratic1D1DFunction::value()"
393 <<
": requested x (" << domainValue
402 double imageValue =
m_a*domainValue*domainValue +
m_b*domainValue +
m_c;
411 std::cerr <<
"In Quadratic1D1DFunction::deriv()"
412 <<
": requested x (" << domainValue
421 return 2.*
m_a*domainValue +
m_b;
438 const std::vector<double>& domainValues,
439 const std::vector<double>& imageValues)
442 m_domainValues (domainValues.
size(),0.),
443 m_imageValues (imageValues.
size(), 0.)
446 for (
unsigned int i = 0; i < tmpSize; ++i) {
460 std::cerr <<
"In Sampled1D1DFunction::value()"
461 <<
": requested x (" << domainValue
470 double returnValue = 0.;
482 queso_require_greater_equal_msg(domainValue,
m_domainValues[0],
"domainValue < m_domainValues[0]");
484 queso_require_greater_equal_msg(
m_domainValues[tmpSize-1], domainValue,
"m_domainValues[max] < domainValue");
487 for (i = 0; i < tmpSize; ++i) {
508 std::cerr <<
"In Sampled1D1DFunction::deriv()"
509 <<
": requested x (" << domainValue
518 queso_error_msg(
"this function makes no sense for this class");
522 const std::vector<double>&
528 const std::vector<double>&
540 for (
unsigned int i = 0; i < tmpSize; ++i) {
552 const std::vector<double>& domainValues,
553 const std::vector<double>& imageValues)
558 unsigned int tmpSize = domainValues.size();
564 for (
unsigned int i = 0; i < tmpSize; ++i) {
575 std::ofstream& ofsvar,
576 const std::string& prefixName)
const
581 ofsvar <<
"\n" << prefixName <<
"Time_sub" << env.
subIdString() <<
" = zeros(" << tmpSize <<
",1);"
582 <<
"\n" << prefixName <<
"Value_sub" << env.
subIdString() <<
" = zeros(" << tmpSize <<
",1);";
585 ofsvar <<
"\n" << prefixName <<
"Time_sub" << env.
subIdString() <<
" = zeros(" << tmpSize <<
",1);"
586 <<
"\n" << prefixName <<
"Value_sub" << env.
subIdString() <<
" = zeros(" << tmpSize <<
",1);";
587 for (
unsigned int i = 0; i < tmpSize; ++i) {
629 std::cerr <<
"In ScalarTimes1D1DFunction::deriv()"
630 <<
": requested x (" << domainValue
639 queso_not_implemented();
651 Base1D1DFunction(std::max(func1.minDomainValue(),func2.minDomainValue()),std::min(func1.maxDomainValue(),func2.maxDomainValue())),
677 std::cerr <<
"In FuncTimes1D1DFunction::deriv()"
678 <<
": requested x (" << domainValue
687 queso_not_implemented();
699 Base1D1DFunction(std::max(func1.minDomainValue(),func2.minDomainValue()),std::min(func1.maxDomainValue(),func2.maxDomainValue())),
725 std::cerr <<
"In FuncPlus1D1DFunction::deriv()"
726 <<
": requested x (" << domainValue
735 queso_not_implemented();
744 const std::vector<double>& positionValues,
745 const std::vector<double>* functionValues)
748 m_positionValues(positionValues),
749 m_functionValues(positionValues.
size(),1.)
751 if (functionValues) {
767 double scaleFactor = 1.;
772 scaleFactor *= (domainValue-posJ)/(posK-posJ);
802 std::cerr <<
"In LagrangePolynomial1D1DFunction::deriv()"
803 <<
": requested x (" << domainValue
812 queso_not_implemented();
821 const std::vector<double>& positionValues,
822 unsigned int basisIndex)
825 m_positionValues(positionValues),
826 m_basisIndex (basisIndex)
838 double scaleFactor = 1.;
845 scaleFactor *= (domainValue-posJ)/(posK-posJ);
858 std::cerr <<
"In LagrangeBasis1D1DFunction::deriv()"
859 <<
": requested x (" << domainValue
868 queso_not_implemented();
877 unsigned int initialPos,
882 unsigned int quadratureOrder)
884 double resultValue = 0.;
890 const std::vector<double>& quadPositions = quadObj.positions();
891 const std::vector<double>& quadWeights = quadObj.weights ();
894 unsigned int numQuadraturePositions = quadPositions.size();
896 for (
unsigned int k = 0; k < dataSize; ++k) {
899 double x1k = scalarSeq1[k];
900 double x2k = scalarSeq2[k];
901 for (
unsigned int j = 0; j < numQuadraturePositions; ++j) {
902 value1 += func1.
value(scaleValue1*quadPositions[j]+x1k)*quadWeights[j];
903 value2 += func2.
value(scaleValue2*quadPositions[j]+x2k)*quadWeights[j];
905 resultValue += value1*value2;
907 resultValue *= 1./(2.*M_PI)/((
double) dataSize);
double deriv(double domainValue) const
Returns the value of the derivative of the linear function at point domainValue.
ScalarTimesFunc1D1DFunction(double scalar, const Base1D1DFunction &func)
Default constructor.
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the function func1 by another function func2 at the poin...
const Base1D1DFunction & m_func2
std::vector< double > m_rateValues
Rate value; in , for each =1 .. m_numRefValues.
~Constant1D1DFunction()
Destructor.
FuncTimesFunc1D1DFunction(const Base1D1DFunction &func1, const Base1D1DFunction &func2)
Default constructor.
LagrangePolynomial1D1DFunction(const std::vector< double > &positionValues, const std::vector< double > *functionValues)
Default constructor.
double value(double domainValue) const
Returns the value of the constant function at point domainValue.
double value(double domainValue) const
Returns the value of the multiplication of a function func1 by another function func2 at the point do...
double SubF1F2Gaussian2dKdeIntegral(const ScalarSequence< T > &scalarSeq1, const ScalarSequence< T > &scalarSeq2, unsigned int initialPos, double scaleValue1, double scaleValue2, const Base1D1DFunction &func1, const Base1D1DFunction &func2, unsigned int quadratureOrder)
Calculates the integral of a 2D Gaussian KDE.
Quadratic1D1DFunction(double minDomainValue, double maxDomainValue, double a, double b, double c)
Default constructor.
double value(double domainValue) const
Returns the value of the (one-dimensional) function at point domainValue, already multiplied by the s...
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
double value(double domainValue) const
Returns the value of the Lagrange polynomial at point domainValue.
virtual double value(double domainValue) const
Returns the value of the sampled function at point domainValue.
const void * m_routinesDataPtr
virtual void printForMatlab(const BaseEnvironment &env, std::ofstream &ofsvar, const std::string &prefixName) const
Prints the values of the function in Matlab/Octave format.
std::vector< double > m_domainValues
Array of the values in the domain of the function (values of the independent variable).
virtual double value(double domainValue) const =0
Returns the value of the (one-dimensional) function. See template specialization. ...
std::vector< double > m_imageValues
Array of the values in the image of the function (values of the dependent variable).
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix queso_require_not_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"))
PiecewiseLinear1D1DFunction(double minDomainValue, double maxDomainValue, const std::vector< double > &referenceDomainValues, double referenceImageValue0, const std::vector< double > &rateValues)
Default constructor.
Sampled1D1DFunction()
Default constructor. It should not be called by the user.
~Generic1D1DFunction()
Destructor.
std::vector< double > m_positionValues
void set(const std::vector< double > &domainValues, const std::vector< double > &imageValues)
Sets the values of the independent (domainValues) and dependent (imageValues) variables of this sampl...
const std::vector< double > & domainValues() const
Array of the domain values (values of the independent variable).
unsigned int m_numRefValues
Number of points which will be evaluated.
double m_b
'Linear' coefficient of the quadratic function; in .
double maxDomainValue() const
Returns the maximum value of the domain of the (one-dimensional) function.
const std::vector< double > & imageValues() const
Array of the image values (values of the dependent variable).
Class for Hermite-Gauss quadrature rule for one-dimensional functions.
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the addition of two functions.
double value(double domainValue) const
Returns the value of the addition of function func1 and func2 evaluated at the point domainValue...
double value(double domainValue) const
Returns the value of the (one-dimensional) function at point domainValue.
double minDomainValue() const
Returns the minimum value of the domain of the (one-dimensional) function.
~PiecewiseLinear1D1DFunction()
Destructor.
~ScalarTimesFunc1D1DFunction()
Destructor.
double m_referenceImageValue
Reference value in the function image; in .
Constant1D1DFunction(double minDomainValue, double maxDomainValue, double constantValue)
Default constructor.
Linear1D1DFunction(double minDomainValue, double maxDomainValue, double referenceDomainValue, double referenceImageValue, double rateValue)
Default constructor.
double m_referenceDomainValue
Reference value in the function domain; in .
Class for handling scalar samples.
double deriv(double domainValue) const
Returns the value of the derivative of the function at point domainValue.
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the Lagrange basis at point domainValue.
virtual ~Base1D1DFunction()
Destructor.
const Base1D1DFunction & m_func2
const Base1D1DFunction & m_func
~LagrangePolynomial1D1DFunction()
Destructor.
Base1D1DFunction(double minDomainValue, double maxDomainValue)
Default constructor.
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the function multiplied by the given scalar at point dom...
double deriv(double domainValue) const
Returns the value of the derivative of the piecewise-linear function at point domainValue.
double(* m_derivRoutinePtr)(double domainValue, const void *routinesDataPtr)
std::vector< double > m_functionValues
double(* m_valueRoutinePtr)(double domainValue, const void *routinesDataPtr)
std::vector< double > m_positionValues
double deriv(double domainValue) const
TODO: Returns the value of the derivative of the Lagrange polynomial at point domainValue.
double value(double domainValue) const
Returns the value of the quadratic function at point domainValue.
LagrangeBasis1D1DFunction(const std::vector< double > &positionValues, unsigned int basisIndex)
Default constructor.
std::vector< double > m_referenceDomainValues
Reference values in the piecewise-linear function domain; in , for each =1 .. m_numRefValues.
virtual double multiplyAndIntegrate(const Base1D1DFunction &func, unsigned int quadratureOrder, double *resultWithMultiplicationByTAsWell) const
TODO: Multiplies this function with function, and integrates it numerically. See template specializat...
const Base1D1DFunction & m_func1
double value(double domainValue) const
Returns the value of the linear function at point domainValue.
Generic1D1DFunction(double minDomainValue, double maxDomainValue, double(*valueRoutinePtr)(double domainValue, const void *routinesDataPtr), double(*derivRoutinePtr)(double domainValue, const void *routinesDataPtr), const void *routinesDataPtr)
Default constructor.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
~Quadratic1D1DFunction()
Destructor.
bool domainValueMatchesExactly(double domainValue) const
Checks whether the domain value domainValue matches exactly one of the values in the function domain ...
std::vector< double > m_referenceImageValues
Reference values in the piecewise-linear function image; in , for each =1 .. m_numRefValues.
const std::string & subIdString() const
Access to the attribute m_subIdString; which stores the string for the sub-environment, and it will be used, for instance, to create the output files for each sub-environment.
double value(double domainValue) const
Returns the value of the piecewise-linear function at point domainValue.
double deriv(double domainValue) const
Bogus: Derivative of the function.
~FuncTimesFunc1D1DFunction()
Destructor.
Class for one-dimensional functions.
~Linear1D1DFunction()
Destructor.
double value(double domainValue) const
Returns the value of the Lagrange basis at point domainValue.
double m_c
'Free' coefficient of the quadratic function; in .
virtual ~Sampled1D1DFunction()
Destructor.
double deriv(double domainValue) const
Returns the value of the derivative of the quadratic function at point domainValue.
unsigned int m_basisIndex
double deriv(double domainValue) const
Returns the value of the derivative of the constant function at point domainValue.
const Base1D1DFunction & m_func1
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
double m_a
'Quadratic' coefficient of the quadratic function; in .
~LagrangeBasis1D1DFunction()
Destructor.
FuncPlusFunc1D1DFunction(const Base1D1DFunction &func1, const Base1D1DFunction &func2)
Default constructor.
~FuncPlusFunc1D1DFunction()
Destructor.
double m_rateValue
Rate value; in .