Post Reply 
[VA] SRC #012a - Then and Now: Probability
10-13-2022, 09:44 PM (This post was last modified: 10-13-2022 09:54 PM by C.Ret.)
Post: #33
RE: [VA] SRC #012a - Then and Now: Probability
(10-13-2022 08:14 AM)J-F Garnier Wrote:  I updated my code above accordingly.

I get exactly the same value. But it's not surprising, even if our codes don't look alike, I actually do the calculation in the same direction as Jean-François.

It takes 5708.4 seconds (nearly 2 hours) to display the result using this compact code that is more readable by using line breaks and indents to show all nested loops:
10  DESTROY ALL @ OPTION BASE 1 @ DELAY 0
  @ INPUT "[VA]SRC012a R,S=";R,S @ T0=TIME
20  REAL T,W(R,R),P(R,R),Q(R,R) @ INTEGER A,B,I,J,K,M 
30  DISP "Init"
  @ FOR I=1 TO R
  @   FOR J=1 TO I
  @     W(I,J)=2*(3-(J=1)-(I=J)-(I=R))
  @   NEXT J
  @ NEXT I
40 DISP "Comp"
  @ Q(1,1)=1 @ M=2
  @ FOR K=1 TO S
  @   FOR I=1 TO M
50      FOR J=1 TO CEIL(I/2)
  @       P(I,J)=0 
60        FOR A=MAX(1,I-1) TO MIN(I+1,M)
  @         FOR B=MAX(1,J-(A<=I)) TO MIN(J+(I<=A),A)
70            IF A<>I OR J<>B THEN P(I,J)=P(I,J)+Q(A,B)/W(A,B)
80          NEXT B
  @       NEXT A
  @       P(I,1+I-J)=P(I,J)
  @     NEXT J
  @   NEXT I
  @   IF M<R THEN M=M+1
90    DISP K;TIME-T0
  @   INVERSE 0,131*K*M/S/R
  @   MAT Q=P
  @ NEXT K
100 T=0
  @ FOR J=1 TO R @ T=T+P(R,J) @ NEXT J @ DISP TIME-T0;R;STR$(S);T



To save time, I use the symmetry of the problem by calculating only the right half of each row of the equilateral triangle. In the I-th row, columns J and 1+I-J are symmetrical positions with equal probability P(I,J) = P(I,1+I-J).

Also, after M steps, the man goes further than the M+1 row. This leaves all the probabilities of the following rows at zero, which limits calculations and saves a little time.

My code uses two instructions from specific modules.
* The first is the INVERSE instruction of the JPC ROM module which show the progress of the calculation by inverting the display. Suffice to say that it does not speed things up and that we can easily do without it. It's just a gadget to make the user wait.
* The second is a MAT Q=P instruction which allows you to 'quickly' copy the newly calculated probabilities from table P into the table Q. I was hoping for a smarter use of my new module. but, for the moment, I have not found a way to perform the calculation more directly. By tha way,

Note the power of the HP-71B, while other systems do not have enough registers to memorize all the points of the triangle, the HP-71B allows, for simplicity, to use half of two matrices.
Moreover, I use a third W array to store the weights of each point. So much memory!



But I am not satisfied with this version. I'm like Werner, I think we're on the wrong track and there's a smarter way that avoids calculating all the iterations and probabilities of every point in the triangle.

So maybe my MATH module can be better exploited. Besides, I discover with horror that my 1A version does not have an RSUM command or any other means of obtaining the sum of the probabilities of the last row in one instruction.

Perhaps calculating iteratively, the probabilities of each point of the triangle will help us for the following questions?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #012a - Then and Now: Probability - C.Ret - 10-13-2022 09:44 PM



User(s) browsing this thread: 1 Guest(s)