Hello,
I would like to know whether it is possible to pass the problem identifier as an extra argument to an instance of class QuadratureVec() in Mata. I am currently using Stata version 18, but I am open to the possibility that such a feature became available in Stata version 19.
For context, I am programming a minorize-maximize algorithm in Mata. My algorithm requires numerical integration of a common evaluator function for each observation in the sample, where some extra arguments depend on the particular observation (think of an individual likelihood contribution to be computed numerically). I am currently using the QuadratureVec() class to compute these integrals in (what I think is) a vectorized way. For concreteness, consider the following Mata code
where
From the examples in the documentation, I get the impression this is not the way QuadratureVec() was intended to be used. However, I think similar setups are quite common in numerical methods, and I would like to make my code as efficient as possible without needing to look elsewhere (i.e., outside Stata + Mata). Any suggestions for setting up the integration problems, even if not in the way I am originally asking, are more than welcome. Many thanks.
I would like to know whether it is possible to pass the problem identifier as an extra argument to an instance of class QuadratureVec() in Mata. I am currently using Stata version 18, but I am open to the possibility that such a feature became available in Stata version 19.
For context, I am programming a minorize-maximize algorithm in Mata. My algorithm requires numerical integration of a common evaluator function for each observation in the sample, where some extra arguments depend on the particular observation (think of an individual likelihood contribution to be computed numerically). I am currently using the QuadratureVec() class to compute these integrals in (what I think is) a vectorized way. For concreteness, consider the following Mata code
Code:
cases = &(1::I) q = QuadratureVec() q.setEvaluator(&fcn()) q.setLimits((0,1)) q.setArgument(*cases, 1, &delta) q.setArgument(*cases, 2, &casedata) for (i = 1; i <= I; i++) q.setArgument(i, 3, (*cases)[i])
- I is the number of observations.
- delta is a J x 1 vector of parameters to be estimated.
- casedata is an I x 1 vector of pointers, where element i = 1, ..., I is a pointer to a subvector of (1::J) corresponding to the elements of delta to which observation i contributes.
- The evaluator function fcn() takes as extra arguments pointers to delta and case data, and the observation number (which coincides with the integration problem identifier). It uses the argument i (observation number/problem identifier) to access the corresponding element of pointer vector casedata in order to use the corresponding subvector of delta in some computations to evaluate the integrand.
From the examples in the documentation, I get the impression this is not the way QuadratureVec() was intended to be used. However, I think similar setups are quite common in numerical methods, and I would like to make my code as efficient as possible without needing to look elsewhere (i.e., outside Stata + Mata). Any suggestions for setting up the integration problems, even if not in the way I am originally asking, are more than welcome. Many thanks.