Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing problem identifier as extra argument to QuadratureVec() instance

    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

    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])
    where
    1. I is the number of observations.
    2. delta is a J x 1 vector of parameters to be estimated.
    3. 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.
    4. 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.
    As you can see, the first two extra arguments, &delta and &casedata, are passed in a quite efficient way (which I would call vectorized) to the evaluator function (technically to the QuadratureVec() instance q). However, the way I pass the third extra argument (the observation number or integration problem identifier) is inefficient and can become quite wasteful with a large number of observations. This is why I would like to know whether there is a "vectorized" way of achieving the same, i. e., passing the integration problem identifier as an extra argument to the QuadratureVec() instance without looping over integration problems.

    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.
    Last edited by Pinjas Albagli; 03 May 2025, 17:34.
Working...
X