nextupprevious
Next:TRIA random value from Up:FUNCTIONSPrevious:POISSON random value from

RAND random value from a multivariate distribution

Syntax:
    RAND(<array>) / <,stream> /);
This is in reality a procedure. It is used to generate random variates taken from multivariate random functions. The n-dimensional random functions are given by an n-dimensional <array> whose values are an n-dimensional frequency table. It must be declared of FREQ type and initialized in the INIT section.
The values of the variables must be declared in a two dimensional arrays (one array for each variable). In the first row are the successive values of the first variable, in the second row the successive values of the second variable, etc. The number of rows is then equal to the number of variables. The number of columns must be equal to the number of values of the variable that has the maximum number of values. The name of this array must be VAL_<array>. When the procedure is evaluated, a random value is computed for each variable according to the frequency table given in <array> and these values are stored in an array of name RAND_<array> to be used in the program. The values are computed with random numbers taken from the stream indicated by <stream>. This is an integer from 1 to 10. If omitted, 1 is assumed.

Example 1:

  Test RAND procedure for multivariate random values.
  This example generates random numbers from a distribution
  given by a three variable frequency table given by an array Mul of
  three indexes. The multivariant frequency table is:

                  15 18                   15 18
                 ------                  ------
          2.0   |  1  3           2.0   |  3  2
     0.1  5.0   |  4  3      0.4  5.0   |  2  1
         10.0   |  3  1          10.0   |  3  6

   So, Mul[0.1,5.0,15]=4 is the number of cases in which the values
   of the variables were (0.1, 5.0, 15);
      Mul[0.4,10.0,18]=6
   The sum of all values is 32. The first matrix sum up 15, the
   second one, 17.

   The RAND algorithm selects one vector, for example (0.1, 5.0, 15)
   with a probability according to the frequency table.
   Each value is selected according to its marginal probability
   distribution conditional to the previous values. 
   It is decided between 0.1 and 0.4 according its
   marginal probabilities: 15/32 for 0.1 and 17/32 for 0.4.
   If the selected is, for instance 0.1, the second value is selected
   according to the marginal probabilities: (3+1)/17 for the
   value 2.0,(4+3)/17 for the value 5.0, (3+1)/17 for the value 10.0.
   If the selected is, for instance 5.0, the third value is selected
   according to the probabilities 4/7 for 15.0 and 3/7 for 18.0.
   See that the probability of the value (0.1, 5.0, 15) is
   then 17/32*7/17*4/7=4/32, as may be see directly.
   The following program computes 32000 random numbers with the
   frequencies in the array Mul, counts the different results
   and put them in a table Zzz similar to Mul. The values in Zzz
   must be approximately those in Mul.
  NETWORK
   A:: IT := 1;    RAND(Mul,2);
   IF RANDV_Mul[1] = 0.1   THEN I := 1 ELSE I := 2;
   IF RANDV_Mul[2] = 2.0   THEN J := 1 ELSE
   IF RANDV_Mul[2] = 5.0   THEN J := 2 ELSE J := 3;
   IF RANDV_Mul¤[3] = 15.0  THEN K := 1 ELSE K := 2;
   Zzz[I, J, K] := Zzz[I, J, K] + 1;

   Result (A):: WRITELN;
    FOR I := 1 TO 2 DO
     BEGIN  WRITELN;
      FOR J := 1 TO 3 DO
       BEGIN WRITELN;
        FOR K := 1 TO 2 DO WRITE(Zzz[I, J, K] / 1000: 7: 4);
       END
     END;

    PAUSE; ENDSIMUL;

  INIT
   ACT(A, 0);
   ASSI Mul[1..2, 1..3, 1..2] :=
         (  ( ( 1, 3 ),( 4, 3 ),( 3, 1 ) ) ,
            ( ( 3, 2 ),( 2, 1 ),( 3, 6 ) )  ) ;
   ASSI VAL_Mul[1..3, 1..3]:=( (0.1, 0.4, 0.0), (2, 5, 10), (15, 18, 0) ) ;
   ASSI Zzz[1..2, 1..3, 1..2] :=
        (  ( ( 0, 0 ), ( 0, 0 ), ( 0, 0 ) ) ,
           ( ( 0, 0 ), ( 0, 0 ), ( 0, 0 ) )  ) ;

   ACT(Result, 32000);

  DECL  VAR Mul: ARRAY[1..2, 1..3, 1..2] OF FREQ;
            Zzz: ARRAY[1..2, 1..3, 1..2] OF REAL;
            VAL_Mul: ARRAY[1..3, 1..3] OF REAL;
            I, J, K: INTEGER;
 END.
Example 2:
  Logs are processed by a set of machines. The processing time
  was adjusted by regression to a linear function of the Length L
  and the Diameter D of the logs. Logs arrive each 10 m. with random
  sizes. A frequency table aggregated in 3 diameters (32, 36, 40
  inches) and 4 lengths (15, 25, 35, 45 feet), obtained by sampling,
  gives the quantity in each class.

  NETWORK
  Arrivals (I)  :: IT := 10; RAND(Fld);
                   L := RANDV_Fld[1]; D := RANDV_Fld[2];
  Machines (R)  :: STAY := 8.5 + 0.32 * L + 0.21 * D;
  Dep (E)       ::

  INIT
   ACT(Arrivals, 0); TSIM := 2000; Machines := 3;
   (*Multivariate frequency array  D: rows L: columns:    *)
   ASSI Fld[1..3, 1..4] :=
                                {  Length feet   }
                                { 15  25  35  45 }
                       {32}  ( ( 123, 108, 47, 12 ),
    {Diameter inches}  {36}    (  89, 104, 99, 43 ),
                       {40}    (  22, 87, 106, 172) ) ;

   (*values of the variables (columns) :                *)
   ASSI VAL_Fld[1..2, 1..4]:=
              ( (32, 36, 40, 0), (15, 25, 35, 45)) ;

  DECL  VAR_Fld: ARRAY[1..3, 1..4] OF FREQ;
        VAL_Fld: ARRAY[1..2, 1..4] OF REAL;
        MESSAGES Arrivals(L, D: REAL);
        STATISTICS ALLNODES;
 END.

domingo c

Mon Mar 20 17:39:21 PST 2000