Message Boards Message Boards

Issue with Arg Max for large binomial equations?

Posted 8 years ago

Hi, I've just joined this site, so apologies if I'm posting in the wrong section or group. I've been finding some strange inconsistencies in my latest mathematica computations. (I'm very much a beginner, so it's likely that the problem lies with me not understanding something about mathematica)

Anyway, I've attached a mathematic file which lays it out (i hope) precisely. It's an issue with Argmax returning values which seem to me to be incorrect.

any help would be greatly appreciated.

Attachments:
POSTED BY: Niall Hughes
6 Replies
Posted 8 years ago

That's very helpful. Thanks a lot for taking the time.

POSTED BY: Niall Hughes
Posted 8 years ago

Why? Just lucky I guess. Nothing beats good starting values.

But more seriously...I chose that value from your figure. And it turns out that if one wants the correct answer (without having to adjust the working precision or other fine-tuning options) the starting value needs to be between around 0.27 and 0.30 to converge to the right answer. From a plot of the derivative we see why:

Plot[df, {x, 0, 1}, PlotRange -> All]

Derivative

If one starts too low, say 0.2, then the result will be somewhere between 0 and 0.2 as the derivative is very close to zero in that range. Same thing for starting values bigger than 0.3 with the end result being somewhere between 0.4 and 1.

So...good starting values, using rational numbers, and plotting curves are all very useful.

POSTED BY: Jim Baldwin
Posted 8 years ago

Jim, one last questions. In the final line, why did you look for the root starting from x=0.3 rather than from 0 (or some other point)? thanks

FindRoot[df == 0, {x, 0.3}]

POSTED BY: Niall Hughes
Posted 8 years ago

Amazing - thank you both. this is very helpful and solves the problem. cheers

POSTED BY: Niall Hughes
Posted 8 years ago

The main thing to do is follow Bill Simpson's advice about changing decimal fractions such as 0.7 to 7/10. But you can also simplify and speed up your calculations by noting that the double sums can be split into parts:

parms = {p1 -> 6/10 - x 55/100,
   p2 -> 7/10 - x 5/10,
   p3 -> 9/10 - x 8/10,
   n1 -> 1000,
   n2 -> 1001,
   n3 -> 1001,
   z -> 500};
s1 = Binomial[n1, z] p1^z (1 - p1)^(n1 - z) //. parms;
s21 = Sum[Binomial[n2, n] (1 - p2)^n  p2^(n2 - n), {n, 0, z}] //. parms;
s22 = Sum[Binomial[n2, n] (1 - p2)^(n2 - n)  p2^n, {n, 0, z}] //. parms;
s31 = Sum[Binomial[n3, m] (1 - p3)^(n3 - m)  p3^m, {m, 0, z}] //. parms;
s32 = Sum[Binomial[n3, m] (1 - p3)^m  p3^(n3 - m), {m, 0, z}] //. parms;
f = s1 (s21*s31 + s22*s32);

Now you can take the derivative of f essentially free of any round-off error and solve for the value of x that makes the derivative equal to zero:

df = D[f, x]
FindRoot[df == 0, {x, 0.3}]
(* {x -> 0.2841121284262152`} *)
POSTED BY: Jim Baldwin
Posted 8 years ago

Mathematica treats numbers with decimal points as approximate with a precision partly derived from the number of digits you enter. You are adding and subtracting several thousand polynomials, of degree up to one thousand, all with coefficients that have only a digit or two of precision.

Try replacing all your approximate numbers with exact rational numbers. That may take longer to calculate, but the rational numbers should not bite you the way it appears the approximate numbers have in your notebook. It might also be necessary to add a WorkingPrecision->nnn option to your Plots, where nnn is some appropriate number of digits of precision for Plot to use in calculating points.

Please report back whether these ideas make the problems go away.

POSTED BY: Bill Simpson
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