I am doing an optimization problem with a likelihood function and when I start the optimization process I get the following error:
error G0525 : Argument contains NaNs
Given that for starting values there is no problem, meaning that the 0/0 or o*inf occurs when the optimization starts I am not sure how to go around it.
I would like to know if you guys have an idea of how to track down the place where this error comes up.
Thanks in advance.
You can track this down in the debugger. The trick in this case is that you do not know if it is on the second call to your likelihood function or the 200th and you don't want to have to keep stepping through your code until it errors out.
Let's work through a simple example. We will run this program file, which I named debug_proc.gss:
testProcedure(); proc (0) = testProcedure(); local a, iters, i, eig_vals; iters = 100; for i(1, iters, 1); //create random array a = areshape(rndn(24, 1), 6|2|2); //Set first element to be //missing value if it is less //than -1 if a[1,1,1] .< -1; a[1,1,1] = error(0); endif; eig_vals = eigh(a); endfor; endp;
When we run this file, we will get this error message:
G0525 : Argument contains NaNs [debug_proc.gss, line 19]
Click on the thumbnail image below to see a screenshot.
Based upon this information, we know that the error is happening in the call to the GAUSS function eigh. Since we do not know on which iteration the error is occuring, we will add an if statement that checks to see if our variable a, contains any NaNs with the GAUSS function isinfnanmiss. To accomplish this we will add this bit of code just before the call to eigh:
//check to see if 'a' contains NaNs if isinfnanmiss(a); a = a; endif;
The purpose of the line: a = a; is just to give us a line to place our breakpoint on. Click in the margin to the left of the line number on the line a = a; to set the breakpoint. Then start the debugger and run to that breakpoint. Click on the thumbnail below to see a screenshot with the breakpoint set and the debugger being started:
When you are in the debugger and have run to your breakpoint, you can examine the contents of any local variables by double-clicking them in the Local/Watch variable window (inside the yellow box in the image below), or by placing your cursor on a variable inside the code and using the hotkey CTRL+E.
so a follow up on this. It was perfectly clear the example you gave me and it works when I know where the NaNs are located.
But now the problem is that the like mentioned in the NaNs error is an empty one.
So at this point I am quite lost. The estimation runs for some time but after quite a number of iterations it gives the same NaNs error I cant locate.
Any ideas on this?
Thanks in advance.
Is this empty line in your code or in the code for Optmum? The error is most likely coming from a call to eigh. I would guess that unless your code has a call to eigh, the problem is that the return from your likelihood function contains NaNs.
What I would do is place an if check before any call to eigh that occurs in your code and I would also check the return from your likelihood function before you return it--something like:
proc (1) = myLikelihood(x); local out; . . . if isinfnanmiss(out); out = out; //put a breakpoint here endif; retp(out); endp;
This should find your problem.
Please login or Register to submit your answer