# probability going outside 1 (due to optimization violation of constraint)

I am working on an optimization, which involves the following density:

K = 5
probs = Table[
Binomial[K, j]*(w*p^j*(1 - p)^(K - j) + (1 - w)*
Beta[alpha + j, K - j + beta]/Beta[alpha, beta]), {j, 0, K}]


With

(* alpha>0,beta>0,0<p<1,0<w<1 *)


as constraints for optimization.

The values in 'probs' should all be between 0 and 1, and most importantly they sum to 1!

test1 = {alpha -> 2.3, beta -> 3.2, p -> 0.9999, w -> 0.4};
test2 = {alpha -> 0.9, beta -> 0.1, p -> 0.8, w -> 0.4};
test3 = {alpha -> 120, beta -> 250, p -> 0.7, w -> 0.4};
test4 = {alpha -> 0.003, beta -> 0.0001, p -> 0.001, w -> 0.4};
test5 = {alpha -> 0.0001, beta -> 0.0001, p -> 0.1, w -> 0.4};
probs /. test1
Sum[%[[i]], {i, 1, 6}]
probs /. test2
Sum[%[[i]], {i, 1, 6}]
probs /. test3
Sum[%[[i]], {i, 1, 6}]
probs /. test4
Sum[%[[i]], {i, 1, 6}]
probs /. test5
Sum[%[[i]], {i, 1, 6}]


ALL GOOD!

Test for some extreme values near the boundary,

test6 = {alpha -> 10^(-10), beta -> 30, p -> 0.9999, w -> 0.0001};
test7 = {alpha -> 10^(-11), beta -> 300, p -> 0.8, w -> 0.0001};
test8 = {alpha -> 10^(-12), beta -> 3000, p -> 0.7, w -> 0.0001};
test9 = {alpha -> 10^(-13), beta -> 30000, p -> 0.001, w -> 0.0001};
test10 = {alpha -> 10^(-14), beta -> 300000, p -> 0.1, w -> 0.0001};

probs /. test6
Sum[%[[i]], {i, 1, 6}]
probs /. test7
Sum[%[[i]], {i, 1, 6}]
probs /. test8
Sum[%[[i]], {i, 1, 6}]
probs /. test9
Sum[%[[i]], {i, 1, 6}]
(* Take a lot of time to run!!! Dont know why *)
probs /. test10
Sum[%[[i]], {i, 1, 6}]


Apart from the last one, taking a long time to run, all summation return to 1.

Now, the problematic one!

badset = {alpha -> 10^(-14), beta -> 1.14*10^(26), p -> 0, w -> 0}


The probabilities are MORE than 1.

These certainly sum to more than 1.

We know that the parameters are at the boundary, but I would expect something like Indeterminate, like this

This had cost me three days trying to locate the problem from a large piece of code, where the log-likelihood value is more than 0 (usually a negative number).

Is there a way to work around with it?

Thanks!!

You need higher precision to finish these calculations

badset = N[{alpha -> 10^(-14), beta -> (114/100)*10^(26), p -> 0,
w -> 0}, 30];


Sum[%[[i]], {i, 1, 6}]