# Is optimizing() function giving global or local maximum

Dear users,

I am trying to learn Stan’s optimizing() function and its output. As an example I am using the following Bernoulli example.

``````data {
int<lower=0> N; // number of trials
int<lower=0, upper=1> y[N]; // success on trial n
}
parameters {
real<lower=0, upper=1> theta; // chance of success
}
model {
// theta ~ uniform(0, 1); // prior (optimised value is 0.4)
theta ~ normal(0.5, 0.5);  //(optimised value is 0.42)
y ~ bernoulli(theta); // likelihood
}
``````

With R code

``````N <- 5;
y <- c(0,1,1,0,0);
model <- stan_model("bernoulli.stan");
mle <- optimizing(model, data=list(N = N, y = y));
print(mle, digits = 2)
``````

My questions are:

1. How do I know that the optimized values produced from the optimizing() function are unique and global maximum. Reading through Stan’s reference 2.17.0 (page 385) , it seems there can more than one posterior mode and the algorithm may return a local maximum.

2. On page 422 of the Reference guide, it says that if parameters are constrained it is best to code them as unconstrained for better efficiency. How would the above Stan code be changed so that this can be achieved?

Thanks

Whether an optimum is global or not depends on the problem, algorithm, and initial conditions. In general L-BFGS doesn’t guarantee convergence to a global optimum so the usual solutions are 1) use multiple initial values and see empirically if you get the same optimum, and 2) analyze the specific problem to see if you can create some guarantees. So any answer will depend on the specific problem

Thanks @sakrejda.

Would you be able to add some details for this: how do i create the guarantees? Is there any example which I can follow?
Thanks