CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: [RESOLVED] Help with math algorithm

1. Senior Member
Join Date
Oct 2008
Posts
1,456

## Re: [RESOLVED] Help with math algorithm

Originally Posted by nuzzle
Come on, don't be dramatic. There's no dangerous philosophical minefield here. The problem is stated and can be solved under full uncertainity.
I tried explaining why the idea of "full uncertainity" is a very delicate and possibly bad posed one, and why your specific idea of "full uncertainty" is just meaningless. That said, it's clear that you are inert to any form of argumentation so you're free to ignore the complexity of the subject and insist thinking whatever you like ...

Originally Posted by nuzzle
Still I'm a little curious as to whether you can to come up with something that changes the optimal escape direction.
well, I consider my last post a precondition to agree on such a possible example. So, if you still think that your idea of an "100% uncertainty" optimal strategy is meaningful then I'm 100 % sure that I won't succeed in convincing you. So, I won't post what I would consider a complete example.

Anyway, let's pretend you're right, that I'm guilty of having modified the problem, that this won't impress anybody and that "going to arcos(1/8)" is the universal, most elegant and beautiful solution to the OP problem. So, let me try to solve the much less ambitious task of finding a probabilistic modeling that gives a different optimal angle:

suppose the runner, standing in the middle of a river of width W, with a water front approaching him at a distance D, is going to move to an angle P relative to the river bank direction; suppose that he's using a compass to fix his direction and that there are many reference points ( trees, rocks, buildings, etc ... ) on the river bank enabling him to fix, let's pretend exactly, the direction of the river bank. Therefore, his direction of motion will take the form p = P + E where E is the error of the compass; let's pretend it is unbiased, that is that E follows a fixed symmetric unimodal distribution g(E) statistically indipendent on the other model parameters, like a reasonable true compass would be.

Now, we could probably obtain the wanted result by quite general assumptions, but, to keep things simple, let's suppose that W and D follows a joint probability density f(W,D) with support equal to some fixed cube [0,Wmax]x[Dmin,+inf). Again just to simplify the calculations take Dmin >= sqrt(63/4)*Wmax and suppose f() and g() almost everywhere differentiable.

then, the escape probability Q(P) equals ( where a(W,D) := 2*D/W, for brevity )

Q(P) = integral_from_0_to_Wmax integral_from_Dmin_to_inf { integral_from{ arccos( ( 8 + a*sqrt(a^2-63) )/( 1 + a^2 ) ) - P }_to{ arccos( ( 8 - a*sqrt(a^2-63) )/( 1 + a^2 ) ) - P }_of{ g(E) dE } f(W,D) dW dD }

then, let

S(D/W) := ( arccos( ( 8 - a*sqrt(a^2-63) )/( 1 + a^2 ) ) + arccos( ( 8 + a*sqrt(a^2-63) )/( 1 + a^2 ) ) ) / 2
L(D/W) := ( arccos( ( 8 - a*sqrt(a^2-63) )/( 1 + a^2 ) ) - arccos( ( 8 + a*sqrt(a^2-63) )/( 1 + a^2 ) ) ) / 2

S() and L() are monotonically increasing almost everywhere differentiable functions ( = almost everywhere invertible ) of d/w going from P0 := arccos(1/8) to pi/2 and from 0 to pi, resp. Let S be the corresponding random variable and h(S) its probability density; clearly E is still indipendent of S, and the support of h() is the interval [P0,pi/2].

hence, we have

Q(P) = integral_from_P0_to_{pi/2} { integral_from{ S - L - P }_to{ S + L - P }_of{ g(E) dE } h(S) dS

and differentiating under the integral sign

Q'(P) = integral_from_P0_to_{pi/2} { integral_from{ S - L - P }_to{ S + L - P }_of{ - g'(E) dE } h(S) dS

more specifically,

Q'(P0) = integral_from_P0_to_{pi/2} { integral_from{ S - L - P0 }_to{ S + L - P0 }_of{ - g'(E) dE } } h(S) dS =
= integral_from_P0_to_{pi/2} { {
integral_from{ S - L - P0 }_to{ 0 }_of{ - g'(E) dE } +
integral_from{ 0 }_to{ S + L - P0 }_of{ - g'(E) dE }
} } h(S) dS =

but |S - L - P0| is always less then S + L - P0, so

Q'(P0) = integral_from_P0_to_{pi/2} { {
integral_from{ S - L - P0 }_to{ 0 }_of{ - g'(E) dE } +
integral_from{ 0 }_to{ -( S + L - P0 ) }_of{ - g'(E) dE } +
integral_from{ -( S + L - P0 ) }_to{ S + L - P0 }_of{ - g'(E) dE }
} } h(S) dS

now, g' is an odd function <=0 for E >=0 and >=0 for E<=0, hence

Q'(P0) = integral_from_P0_to_{pi/2} { {
integral_from{ -( S + L - P0 ) }_to{ S + L - P0 }_of{ - g'(E) dE }
} } h(S) dS

the inner integral is always >= 0, but again being g unimodal there exist an epsilon > 0 such as g'(E) is strictly negative for 0<E<epsilon, so it suffices that h(S) is non zero whenever -( S + L - P0 ) < epsilon which is always true because the support of h() is [P0,pi/2].

this proves that Q'(P0) > 0, that is P0 is not a local extremum and hence is not a maximum of the escape probability.

In other words, we have proven that a runner applying the arccos(1/8) strategy with a perfectly unbiased compass will have less chances of escape of a runner going to arccos(1/8) + C, where C is a function of the compass precision given a possibly wide class of prior probability distributions of the river geometry.

as I said above, this is not meant as an argument for the "full uncertainty" thing, so spare me your comment about the obviously <<irrefutable>> fact that "under full uncerainty" C would "go" to 0, or the like ...

Originally Posted by nuzzle
Do we have THE optimal solution to the problem or don't we?
do you know the difference between "to any practical use, [this or that] solution is correct" and "[this or that] solution is correct" ?

Originally Posted by nuzzle
What are you trying to prove? All your attempts so far have stumbled on this.
do you know the difference between "I do not understand [this or that]" and "[this or that] is false" ? because it looks like your ego forbids you to accept anything that doesn't come directly from your own mouth ...

2. Elite Member
Join Date
May 2009
Posts
2,413

## Re: [RESOLVED] Help with math algorithm

Originally Posted by superbonzo
suppose that he's using a compass to fix his direction
This is where you change the problem. The original problem assumes nothing about the runner but you're putting a compass in his hands. So with all due respect for your math proficiency and effort, you've solved the wrong problem.

because it looks like your ego forbids you to accept anything that doesn't come directly from your own mouth ...
I promise that as soon as you show the original problem has more than one optimal escape direction I'll utter the magic words: I was wrong. But I won't accept cheating; No unphysical solutions, no model induced anomalities and no problem changes.

Finally, who has the biggest ego here? You've tried every trick in the book to obscure the fact that you're wrong. Everything from linguistic acrobatics to scientific mumbo jumbo. You were wrong plain and simple. Accept that and move on.
Last edited by nuzzle; October 26th, 2012 at 01:41 AM.

3. Senior Member
Join Date
Oct 2008
Posts
1,456

## Re: [RESOLVED] Help with math algorithm

Originally Posted by nuzzle
Accept that and move on.
don't worry, I'll do. The good thing about on line forums is that everybody can come here and, if interested in, read all replies and draw their own conclusions on what the original problem was and in which ways and to which aims has been solved.

I do like arguing with people, but when dialectics resolves in a mere exercise of rhetorics and scientific or philosophical reasoning becomes a matter of mumbo jumbo and acrobatics, I admit I'm lost

4. Elite Member
Join Date
May 2009
Posts
2,413

## Re: [RESOLVED] Help with math algorithm

Originally Posted by superbonzo
Well, my motivation in this thread has been to draw a clear line between the original problem and possible modifications.

--- clear line ---
Last edited by nuzzle; November 9th, 2012 at 03:26 AM.

5. Elite Member
Join Date
May 2009
Posts
2,413

## Re: [RESOLVED] Help with math algorithm

Originally Posted by superbonzo
In other words, we have proven that a runner applying the arccos(1/8) strategy with a perfectly unbiased compass will have less chances of escape of a runner going to arccos(1/8) + C, where C is a function of the compass precision given a possibly wide class of prior probability distributions of the river geometry.

as I said above, this is not meant as an argument for the "full uncertainty" thing, so spare me your comment about the obviously <<irrefutable>> fact that "under full uncerainty" C would "go" to 0, or the like ...
I hate to revive this thread again but since your conclusions are wrong I don't want to leave it unchallenged.

The fact is that there's an optimal escape direction and it's dependent only on the water-to-runner speed ratio (fixed to 8 in the problem formulation). A simple high-school level analysis shows that. It follows that if you want to introduce probablities for different aspects of the problem only those affecting this ratio can influence the optimal escape direction. Period.

You've introduced a compass which doesn't accurately show the direction so the runner cannot know for sure whether he's taking the optimal escape direction. But this doesn't change the optimal escape direction. It can't since it's unrelated to both the speeds of water and runner.

So what have you? After some sophisticated math you claim to have found a new optimal escape direction. It would be the old optimal escape direction modified by an additive constant. Now if your analysis is correct this just shows that if the compass has a known systematic error, that is if it's always off with a certain number of degrees, you must compensate for that to make sure you aim in the optimal escape direction indeed.

Otherwise the best you can do is trusting the compass. You set the optimal escape direction and start running knowing that the only things that can ever make this direction obsolete are new assumptions on how fast you can run or how fast water is approaching.
Last edited by nuzzle; November 9th, 2012 at 04:00 AM.

6. Senior Member
Join Date
Oct 2008
Posts
1,456

## Re: [RESOLVED] Help with math algorithm

Originally Posted by nuzzle
So what have you? After some sophisticated math you claim to have found a new optimal escape direction. It would be the old optimal escape direction modified by an additive constant. Now if your analysis is correct this just shows that if the compass has a known systematic error, that is if it's always off with a certain number of degrees, you must compensate for that to make sure you aim in the optimal escape direction indeed.
no, the compass is unbiased: if you decide to run at an angle A the compass will give you A on avarage, and any random deviation from A will be symmetrically distributed with respect to A. ( BTW, this has already been clearly stated above ... BTW again, "sophisticated math" ? really ? it's just a bunch of basic integral calculus theorems )

Originally Posted by nuzzle
Otherwise the best you can do is trusting the compass.
again no, as proven above, the "best" you (=the runner) can do is to analize the problem statistically and conclude that a different angle is better, provided some possibly very wide class of prior probability distributions of the river geometry is assumed.

that said, quoting myself, as I said above, this is not meant as an argument for the "full uncertainty" thing nor as an argument against your naive and tautological meaning of what an "optimal" strategy means in general terms. I gave up on that seemingly impossible task (sarcasm intended) many posts ago ...

7. Elite Member
Join Date
May 2009
Posts
2,413

## Re: [RESOLVED] Help with math algorithm

Originally Posted by superbonzo
no, the compass is unbiased: if you decide to run at an angle A the compass will give you A on avarage, and any random deviation from A will be symmetrically distributed with respect to A. ( BTW, this has already been clearly stated above ... BTW again, "sophisticated math" ? really ? it's just a bunch of basic integral calculus theorems )
Well, I meant sophisticated looking actually. Suitable to hide behind.

I was merely interpreting your results. If the compass is unbiased there shouldn't be an additive constant. Either it must be zero or your calculations are wrong.

again no, as proven above, the "best" you (=the runner) can do is to analize the problem statistically and conclude that a different angle is better, provided some possibly very wide class of prior probability distributions of the river geometry is assumed.
Sure but such a statistic analysis must pertain to the water-to-runner speed ratio because that's the only thing that influences the optimal escape angle.

that said, quoting myself, as I said above, this is not meant as an argument for the "full uncertainty" thing nor as an argument against your naive and tautological meaning of what an "optimal" strategy means in general terms. I gave up on that seemingly impossible task (sarcasm intended) many posts ago ...
Well I can easily back up my reasoning more formally.

Full uncertainity means that nothing at all is assumed about water or runner (except for a fixed water-to-runner speed ratio). Not where the waterfront is when the runner starts running, nor where he stands on the waterbed, nor what prompts him to start running in the first place. It could be his feet got wet, or he sees whitewater or hears a distant rumble, or he just acts on a hunch.

The waterfront will be at an unknown distance from the runner when he starts to run. One distance of special interest is the distance of no return. It is the shortest distance at which the runner can still make it dry to shore. If the waterfront is closer downstream to him when he starts to run he will drown regardless of how he runs. If it is farther upstream he can make it with a margin. This is very much like the time horizon of black holes. Once a certain border is crossed you are doomed.

I have stated without proof that the optimal escape strategy is to run at the angle that makes the distance of no return as short as possible. With other words, you run at the angle that lets the waterfront come the closest to you and you still will make it. To me intuitively this is the best strategy because it gives you the largest margin of safety regardless of where the water actually is when you start to run.

A proof is surprisingly simple:

(1) Let call the one angle associated with the distance of no return for the O angle.

(2) If the waterfront is somewhere upstream of the distance of no return the O angle will be replaced by two angles. The runner will make it if he picks any angle between those two angles. Lets call such a section of angles a window of opportunity.

(3) If a certain angle lies within every possible window of opportunity it will always take the runner dry to shore. And the only angle that does that (in this problem) is the O angle (it is even exact in the middle of any window of opportunity). So using the O angle is the optimal escape strategy and this completes the proof.

It has been shown that under full uncertainity, one and only one specific escape angle always takes the runner dry to shore. Therefore the optimal escape strategy is to always use this angle.
Last edited by nuzzle; November 11th, 2012 at 01:14 AM.

8. Senior Member
Join Date
Oct 2008
Posts
1,456

## Re: [RESOLVED] Help with math algorithm

Originally Posted by nuzzle
I was merely interpreting your results.
ah so, here is how it works: you read something that you don't understand, you "interpret" it randomly and you conclude that is wrong ... really fascinating ...

Originally Posted by nuzzle
Either it must be zero or your calculations are wrong.
if you're so sure, you should have no difficulty in finding a probability distribution of the compass error satisfying the condition in post #31 ( symmetric, unimodal and with avarage 0 ) and compute the angle where the escape probability is maximal to conclude that it's always equal to arccos(1/8). Good luck

Originally Posted by nuzzle
the optimal escape strategy is to run at the angle that makes the distance of no return as short as possible[...]A proof is surprisingly simple:[...]Let call the one angle associated with the distance of no return for the optimal escape angle.[...]This completes the proof.
so, you prove that something is optimal by "calling" it optimal ... I'm again fascinated ...

9. Elite Member
Join Date
May 2009
Posts
2,413

## Re: [RESOLVED] Help with math algorithm

Originally Posted by superbonzo
so, you prove that something is optimal by "calling" it optimal ... I'm again fascinated ...
I called the angle optimal and then I showed it was optimal indeed. It's pretty kosher but okay I'll change it.

Is that all you have to say? I proved formally that you are wrong and I'm right and all you manage to come up with is nitpicking. Well, I've suspected for some time now that there isn't much of real insight behind your pompous and seemingly scientific facade and here it's in full view. Chewing formalia isn't enought if you want to discuss with me.

Face it, you're wrong on all accounts. The problem at hand has a straighforward high-school level solution. It's valid under full uncertainity. There is an optimal strategy for escape. Everybody know this, even you, but you can't back off now, can you.
Last edited by nuzzle; November 10th, 2012 at 02:21 AM.

10. Senior Member
Join Date
Oct 2008
Posts
1,456

## Re: [RESOLVED] Help with math algorithm

Originally Posted by nuzzle
I called the angle optimal and then I showed it was optimal indeed. But okay I'll change it.
you haven't changed anything, you're still "proving" that something is "optimal" by arbitrarily defining what "optimal" is for you. Nowhere in your "proof" you explain why and in which sense that angle is "optimal" in universal terms and how this relates to the idea of its being a solution of the problem under "full uncertainty". As far as the example in post#31 is concerned, I repeat again, you could just compute the maximal escape probability angle given the conditions in post #31 to prove you're right; contrary to you, I always admit the possibility of being wrong ( and I usually learn something when it happens; so it's neither offending nor something to be unpleased of ), the reason being that any non trivial argumentation can have pitfalls and sources of error. That said, I see no error in post #31 ( again, just find a counterexample ! ) and anybody reading ( and understanding ) that proof should come to the same conclusion ...

Originally Posted by nuzzle
Is that all you have to say?
there's nothing much to say indeed. My opinion is that you're inert to any form of argumentation, both phylosohical and mathematical, probably for both psychological reasons and cultural deficiencies on your part ( is a basic integral calculus proof "Suitable to hide behind" ? I must conclude that all the 20th century math, including modern probability theory, is an obscure-suitable-to-hide-behind object for you ... ). Arguing in these conditions is just a waste of time for both. Don't worry, I promise I'll leave you your precious last word, so that everybody can appreciate your egotistic dialectics ...

11. Elite Member
Join Date
May 2009
Posts
2,413

## Re: [RESOLVED] Help with math algorithm

Originally Posted by superbonzo
you're still "proving" that something is "optimal" by arbitrarily defining what "optimal" is for you.
Every proof is constructed by someone, in this case me. And there is no universal definition of optimum. It must be defined in each case as I did. The optimal escape angle is the one that most likely takes you dry to shore regardless of where the waterfront is when you start running. Any runner will agree to that unless he has a deathwish.

Regarding #31. If you conclude that the compass influences the optimal escape angle you're wrong. No equation shuffling is necessary to know that. It can be established on pure principal grounds. It's because waterfront and compass are independent entities. To me that's pretty obvious and it should be to you too if you think about it.

Finally I think you should drop your pompous attitude. You're not the only one who knows some math around here. Your pretencious facade doesn't impress me at all. And your ad-hominem attacks aren't appropriate. The reason your argumentation falls short is because you are wrong and not because I would be stupid.
Last edited by nuzzle; November 10th, 2012 at 06:44 AM.

12. Elite Member
Join Date
May 2009
Posts
2,413

## Re: [RESOLVED] Help with math algorithm

Originally Posted by superbonzo
you haven't changed anything, you're still "proving" that something is "optimal" by arbitrarily defining what "optimal" is for you. Nowhere in your "proof" you explain why and in which sense that angle is "optimal" in universal terms and how this relates to the idea of its being a solution of the problem under "full uncertainty". As far as the example in post#31 is concerned, I repeat again, you could just compute the maximal escape probability angle given the conditions in post #31 to prove you're right; contrary to you, I always admit the possibility of being wrong ( and I usually learn something when it happens; so it's neither offending nor something to be unpleased of ), the reason being that any non trivial argumentation can have pitfalls and sources of error. That said, I see no error in post #31 ( again, just find a counterexample ! ) and anybody reading ( and understanding ) that proof should come to the same conclusion ...
Well, you can lead a horse to water but you can't make him drink. I'll explain one final time why you're dead wrong.

A simple high-school level analysis gives a solution in the form of a window of opportunity. Any angle within this window will take the runner dry to shore. The middle angle has the biggest safety margin. The end angles are daredevil angles and if you go for one of them you just about make it.

Most importantly, the middle angle is always the same. It's fixed regardless of the positions of runner and waterfront, and regardless of whether you assign probabilities to them or not. What varies is the width. There are three situations:

1. The waterfront is upstream of the point of no return. The window of opportunity is open. The farther upstream the wider the window of opportunity.

2. At the point of no return the width of the window of opportunity has shrunk to zero. There's no leeway. Only one escape angle is still available and that's the middle of the window of opportunity.

3. The waterfront has passed the point of no return. The window of opportunity is closed and escape is no longer possible. The runner drowns regardless of how he runs.

This is the insight you get from solving the original problem. There is an optimal escape angle and it's the middle of the window of opportunity. It's optimal because it's the only angle that always lets the runner slip into the window of opportunity if it's open. Tough luck if it isn't but since you don't know beforehand it's best to run as if it were. This is the most sensible definition of optimality. Ask any runner with a wish to live.

Now a compass is introduced to model the runner's ability to pick a certain escape angle. How does this influence the original problem? Not at all! If you want to hit a still standing target with unknown width you aim for the middle if you know where it is. That's optimal and no aiming device will change that. In case it's systematically off you compensate as to still be aiming for the middle.

So you're completely wrong in all your assumptions and your calculations in #31 is overkill at best. There does exist one optimal escape angle and a compass doesn't change that. The only time it would not make sense to set the optimal escape angle would be if the compass were off in a known way. Then you would set an off target angle to get the optimal escape angle.
Last edited by nuzzle; November 17th, 2012 at 08:15 AM.

13. Senior Member
Join Date
Oct 2008
Posts
1,456

## Re: [RESOLVED] Help with math algorithm

dear nuzzle, if you're so sure that an unbiased compass cannot change the escape probability maximizing angle as read by the runner, just prove it: write down a probability distribution as of post #31 and compute the maximizing angle analitically or simply find an error in post #31 or whatever ... nobody is asking you to prove the Poincaré conjecture or solve some complex PDE; if you're still dedicating time to this thread, why can't you go a step further and prove your claims quantitatively according to modern probability theory ?

Originally Posted by nuzzle
the middle angle is always the same
BTW, yes, the argcos(1/8) angle is always in the "window of opportunity" but it's not the middle point of the "window of opportunity". This is also the reason why an unbiased symmetric compass response can slightly shift the optimal angle as read by the runner and it's the core of the simple proof in post #31.

14. Elite Member
Join Date
May 2009
Posts
2,413

## Re: [RESOLVED] Help with math algorithm

Originally Posted by superbonzo
why can't you go a step further and prove your claims quantitatively according to modern probability theory ?
Because my interest in this is to use plain reasoning only.

BTW, yes, the argcos(1/8) angle is always in the "window of opportunity" but it's not the middle point of the "window of opportunity".
Our models define the window of opportunity slightly different. In my model it's a section on shore and the optimal escape angle is the direction to its exact middle.

This is also the reason why an unbiased symmetric compass response can slightly shift the optimal angle as read by the runner and it's the core of the simple proof in post #31.
Well, okay but it doesn't change the optimal escape angle as you claimed it would. And the compass definately is a modification of the original problem.

Still it's clear to me now where the constant in #31 comes from. I have no immediate reason to believe #31 wouldn't hold so assuming it does then: When the compass is set to the optimal escape angle it will deviate according to some probability distribution due to errors. This distribution of deviation will be symmetric in compass angles but when angles are translated to positions on shore the distribution is skewed and becomes asymmetrical. To still get as much as possible of the skewed probability mass inside any window of opportunity (making escape maximally probable) the whole distribution needs to be shifted. To do that the compass is set to the optimal escape angle adjusted by a constant.

With that I feel ready to drop this thread. Hopefully I get asked this question at a job interview sometime.
Last edited by nuzzle; November 19th, 2012 at 03:16 AM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•