Dear Statalisters,
I’m learning MATA function optimisation, and run into a problem.
In short, I have two identical functions, but MATA can only optimise one of them.
I demonstrate the problem by a simple example.
MATA works well with a function like this:
However, MATA doesn't work with a function like this:
The only difference between the two functions is that n=189 and r=59 are defined outside the function 2.
I've tried to deal with this problem by using optimize_init_argument, but MATA still returns the same error message: "initial values not feasible."
I'd like to know why this difference matters, and how to deal with this problem, if I really need to define something outside the function. Thank you very much.
Best,
Kirin
I’m learning MATA function optimisation, and run into a problem.
In short, I have two identical functions, but MATA can only optimise one of them.
I demonstrate the problem by a simple example.
MATA works well with a function like this:
Code:
mata:
mata clear
void FN1(todo, b, lnf, g, H) {
lnf = ln( binomialp(189, 59, invlogit(b) ))
}
S1 = optimize_init()
optimize_init_evaluator(S1, &FN1())
optimize_init_params(S1, (0))
optimize(S1)
end
Code:
mata:
mata clear
n = 189
r = 59
void FN2(todo, b, lnf, g, H) {
lnf = ln( binomialp(n, r, invlogit(b) ))
}
S2 = optimize_init()
optimize_init_evaluator(S2, &FN2())
optimize_init_params(S2, (0))
optimize(S2)
end
I've tried to deal with this problem by using optimize_init_argument, but MATA still returns the same error message: "initial values not feasible."
Code:
mata:
mata clear
n = 189
r = 59
void FN2(todo, b, lnf, n, r, g, H) {
lnf = ln( binomialp(n, r, invlogit(b) ))
}
S2 = optimize_init()
optimize_init_evaluator(S2, &FN2())
optimize_init_params(S2, (0))
optimize_init_argument(S2, 1, n)
optimize_init_argument(S2, 2, r)
optimize(S2)
end
Best,
Kirin

Comment