Message Boards Message Boards

0
|
5824 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Why does NMaximize does not follow the constraints that were given to it?

Posted 10 years ago

skinks = {56, 19, 28, 18, 24, 14, 9}; kskinks = 7;

myBBBlik[data_, kdata_, f0_?NumericQ, p_?NumericQ, w_?NumericQ, alpha_?NumericQ, beta_?NumericQ] :=

    Block[
    {K, fj, pj, loglik},
    K = kdata;
    fj = Prepend[PadRight[data, K], f0];
    pj = Table[
        PDF[MixtureDistribution[{w, 1 - w}, {BinomialDistribution[K, p], 
        BetaBinomialDistribution[alpha, beta, K]}], j],
        {j, 0, K}
    ];
    loglik = LogGamma[Tr[fj] + 1] - Tr[LogGamma[fj + 1]] + Tr[fj*Log[pj]];
    Print[loglik];
    loglik
];

pars = {f0,p,w,allpha,beta};
cons = {f0 > 0 && 0 < p < 1 && 0 < w < 1 && alpha > 0 && beta > 0};
cons2 = {f0 > 0 , 0 < p < 1 , 0 < w < 1 , alpha > 0 , beta > 0};

NMaximize[{myBBBlik[skinks, kskinks, Sequence @@ pars], cons}, pars, Method -> {"RandomSearch", "SearchPoints" -> Automatic}]

Note that it may crash your kernel!

If you take out the line Print[loglik];, it will give your the correct answer. Works perfect. However, if you leave it in and it may crash your kernel, but you will see something (unbelievable && unexpected) like this: enter image description here

Why does it even call the function myBBBlik? Values like -717.752 and -360.232 are long way from 0. These would not considered when you have alpha>0,beta>0. This is just really something I don't understand the way MMA works.

I am using MMA 10.0.2 X64 (win)

POSTED BY: Casper YC

If it's crashing the kernel, then you're running out of memory, which would explain why the answer is wrong. Also, I suggest you not use the RandomSearch method. I get better results with DifferentialEvolution or SimulatedAnnealing.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract