-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
obj$fn() depends on starting values? #112
Comments
@James-Thorson pointed out a thread that discusses posfun: #7. I tried this function and it helped alleviate this issue. I'd still like to understand why |
I suspect your cpp file contains parameter dependent branching and that is what causes confusion... Here is an example to demonstrate:
It's important to know that the branching operation is not being taped. So, if you run from R
you will get a 'recording' of the mapping f(x)=exp(x) without branching.
will result in the mapping f(x)=x without branching. If you wish to include the branching in the recording you need to use CppAD's conditional expressions (as in the 'posfun' example). |
@kaskr That makes a lot of sense and is very interesting. My C++ knowledge doesn't go very deep so I was not aware of that. Thanks for clarifying. |
I have a simple logistc model (r and K are fixed effects) where I used the equivalent of ADMB's
posfun
to keep the population from going negative while adding a penalty in a way s.t. differentiability is maintained. I do this to avoid getting NaN values fromfn
andgr
in the MCMC procedure. I'm trying to evaluatefn
across a grid of parameters to visualize contours.It seems to work but only for some starting values. If I build the model with the true parameters it fails:
However if I change the input parameters to what I want to evalulate it works:
Naive question here, but why does
fn
depend on the the values forparameters
inMakeADFun
. It seems to me that would only be used as the starting value for the optimizer.The text was updated successfully, but these errors were encountered: