# How to include constraints in NMaximize

I am trying to find maximum likelihood estimates of parameters for a fairly complicated multivariate distribution. The support of the distribution depends on its parameters so I need to include some constraints in NMaximize. The following is a simplified version of the problem.

Consider the following code which generates 1000 observations from a Max Stable distribution and estimates the parameters:

SeedRandom@100;
data = RandomReal[MaxStableDistribution[0, 1, 1], 10^3];
pars = FindDistributionParameters[data, MaxStableDistribution[μ, σ, ξ]]
(* {μ -> -0.0296428, σ -> 0.946788, ξ -> 0.945316} *)


Suppose now we want to find these estimates using NMaximize. Let's assume that $\gamma\ne 0$ so I just need to include the constraint $\frac{\gamma (x-\mu )}{\sigma }+1>0$ in the log likelihood function where the PDF is given by the following:

ClearAll[G]

G[x_] = PDF[MaxStableDistribution[μ, σ, γ], x] //
FullSimplify[#, γ != 0 && 1 + (γ (x - μ))/σ > 0] &


I have tried to include the constraint $\frac{\gamma (x-\mu )}{\sigma }+1>0$ in the definition of G by using Boole to no avail. I should add that even without that constraint Nmaximize does not return a result:

NMaximize[{Total[Log[G[data]]], σ > 0, γ != 0}, {μ, σ, γ}]


Any suggestions on how to do this would be gratefully appreciated.

## 1 Answer

Here is a way that could give the same answer as FindDistributionParameters, however I further assume that γ>0. Please see the code below:

LG[x_] = Log[
G[x]] /. {σ -> Exp[s], γ -> Exp[t]} //. {Log[
Times[x__, y_]] :> Log[x] + Log[y], Log[x_^y_] :> y Log[x]}

NMaximize[{Total[LG[data]], μ < Min[data] + Exp[s - t]}, {μ, s, t},
Method -> "RandomSearch"]

• Many thanks @Hsien-Ching Kao. That is a nice solution. I guess one could use the same idea and estimate $|\gamma|$ for the case $\gamma<0$ but I have not tried it yet.
– user371
Jun 22, 2014 at 23:39