I have a question that I bet any of you can answer, especially if your name is Jeff Pitblado.
I am writing something to bootstrap results from an moptimize() model fit. The individual estimates run pretty fast, but I'm doing millions of them, in Monte Carlo simulations, so speed matters.
In each estimation the only thing that changes is a column of data stored in a Mata matrix, which is passed to the likelihood evaluator via moptimize's userinfo facility. So (very cleverly, I thought), I constructed a loop something like this:
I like this because it minimizes housekeeping in each iteration.
At first it seemed to be working fine, but eventually I realized that there was some hysteresis, that two fits to the same data matrix x might produce different results, at least in that one would converge and one not, depending on the order in which I ran various simulations. So it seems that I am being too clever, that I need to do more to reset the search process before I call _moptimize() again on an already-fitted model.
So my question is, if I want to efficiently re-fit a model after making a change, what are the steps to take to make sure I don't confuse moptimize()?
--David
I am writing something to bootstrap results from an moptimize() model fit. The individual estimates run pretty fast, but I'm doing millions of them, in Monte Carlo simulations, so speed matters.
In each estimation the only thing that changes is a column of data stored in a Mata matrix, which is passed to the likelihood evaluator via moptimize's userinfo facility. So (very cleverly, I thought), I constructed a loop something like this:
Code:
bhat = J(reps, K, .) // will hold estimates of K parameters, from reps replications for (i=reps; i; i--) { [code to generate random data matrix x for this replication] moptimize_init_userinfo(M, 1, x) // store the new data matrix in M, an existing moptimize() model object (void) _moptimize(M) // optimize if (moptimize_result_converged(M)) bhat[i,] = moptimize_result_coefs(M) }
At first it seemed to be working fine, but eventually I realized that there was some hysteresis, that two fits to the same data matrix x might produce different results, at least in that one would converge and one not, depending on the order in which I ran various simulations. So it seems that I am being too clever, that I need to do more to reset the search process before I call _moptimize() again on an already-fitted model.
So my question is, if I want to efficiently re-fit a model after making a change, what are the steps to take to make sure I don't confuse moptimize()?
--David
Comment