I'm working with the integrate() function with a uni and multivariate example given here:
However, I need to have the returned function accept and perform a calculation based on more than just one input (in this case theta). These don't need to all be estimated parameters, but I am unsure of the syntax for correctly writing this. I've created a dummy example based on the above, wherein I am hoping to compute the integral using function f based on not only theta but a data input called "m". Ultimately I'd like to be able to calculate quantities within my objective function and pass them to integrate(). Currentlywhen compiling the error "no match for call to '(univariate)..." comes up.
I'd appreciate some guidance!
(BTW, I am aware that hard-coding a number in lieu of "m" seems to work, but since the value I plan to input here will change on the fly I'd like it to take a variable).
Thanks!
#include <TMB.hpp>
template<class Type>
struct univariate {
Type theta; // Parameter in integrand
univariate(Type theta_, Type m_) // Constructor of integrand -- how do I get this to anticipate more values than theta and x?
: theta (theta_) {} // Initializer list
Type operator()(Type x, Type m){ // Evaluate integrand, unsure about this syntax
return exp( -theta * m * (x * x) ); // I want to be able to have several values in this equation, some parameters and some calculated previously
}
};
template<class Type>
Type objective_function<Type>::operator() () {
DATA_SCALAR(a);
DATA_SCALAR(b);
DATA_INTEGER(m); // testing
PARAMETER(theta);
univariate<Type> f(theta, m); // unsure about this syntax
Type res = romberg::integrate(f, a, b);
return res;
}