Functions

/Users/garethloy/Musimathics/Musimat1.2/MusimatChapter9/C091406.cpp File Reference

#include "MusimatChapter9.h"

Go to the source code of this file.

Functions

 MusimatChapter9Section (C091406)
RealList f (12.0, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0)
Static Void para1 ()
Real sum (RealList L)
Static Void para2 ()
RealList normalize (RealList L, Real s)
Static Void para3 ()

Function Documentation

RealList f ( 12.  0,
11.  0,
10.  0,
9.  0,
8.  0,
7.  0,
6.  0,
5.  0,
4.  0,
3.  0,
2.  0,
1.  0 
)
MusimatChapter9Section ( C091406   )

Definition at line 2 of file C091406.cpp.

References para1(), para2(), and para3().

                                {
        Print("*** 9.14.6 Cumulative Distribution Function ***");
        /*****************************************************************************
         
         9.14.6 Cumulative Distribution Function
         
         Let's rotate each of the weights in figure 9.21 and then concatenate them. Their sum is 78, so we divide 
         the length of each weight by 78 so that the weights sum to a length of 1.0 (figure 9.21). We have effec-
         tively divided up the x-axis in the unit interval into 12 areas that are proportional to the weights in the 
         original distribution. Now we pick a random number in the unit interval with the Random() function, 
         see which interval the number would fall in, and then determine the chosen pitch. The probability that 
         a particular interval will be chosen is proportional to the extent of its footprint on the x-axis.
         
         How can we represent this formally so that a computer can do this? First, the definition
         of list f shown below defines the weights for each pitch, lowest to highest, left to right. 
         Note that the type of list f is RealList.
         *****************************************************************************/
        para1(); // Step into this function to continue.
        para2(); // Step into this function to continue.
        para3(); // Step into this function to continue.
}
RealList normalize ( RealList  L,
Real  s 
)

Definition at line 60 of file C091406.cpp.

                                      {
        For (Integer i = 0; i < Length(L); i = i + 1) {
                L[i] = L[i]/s;
        }
        Return(L);
}
Static Void para1 (  )

Definition at line 26 of file C091406.cpp.

References f().

                    {
        Print("*** Cumulative Distribution Function ***");
        Print("f=", f);
        /*****************************************************************************
         
         Next, we normalize the weights so that they sum to 1.0 (see appendix A, A.3).
         Normalizing is done in two steps:
         
         1. Find the sum of all weights with the sum() function:
         *****************************************************************************/
}
Static Void para2 (  )

Definition at line 46 of file C091406.cpp.

References f(), and sum().

                    {
        /*****************************************************************************
         Given the definition of RealList f above, 
         *****************************************************************************/
        
        Print("Sum of f: ", sum(f));
        
        /*****************************************************************************
         prints 78.
         
         2. Divide each weight by sum(f) so that the sum of the weights equals 1.0:
         *****************************************************************************/
}
Static Void para3 (  )

Definition at line 67 of file C091406.cpp.

References f(), retrograde(), and sum().

                    {
        /*****************************************************************************
         The normalize() function can be replaced with operations performed directly on the list.
         This statement:
         
         RealList r = normalize(f, sum(f));
         
         can be replaced with:
         
         RealList r = f / sum(f);
         
         So we don't really need the normalize() function.
         Given the definition of RealList f above, the statements:
         *****************************************************************************/
        
        RealList r = f / sum(f);
        Print("Normalized f=", r);
        RationalList x = RealListToRationalList(r); // RealListToRationalList is a built-in function
        Print(x);
        
        /*****************************************************************************
         print 
         {{2,13}, {11,78}, {5,39}, {3,26}, {4,39}, {7,78}, {1,13}, {5,78}, {2,39}, {1,26}, {1,39}, {1,78}
         which correspond to the reduced form of the following ratios, as we'd expect:
         {12/78, 11/78, 10/78, 9/78, 8/78, 7/78, 6/78, 5/78, 4/78, 3/78, 2/78, 1/78}.
         
         After these two steps, r will look like figure 9.20 except that all values are scaled down by 78. (The 
         built-in RealToRational() function is described in appendix B, B.2.2.) 
         
         Next, we create a function such that each step along the x-axis accumulates all the weights to 
         its left with its own weight (figure 9.22). The first column has a height of 12/78, the second of 
         12/78 + 11/78, the next of 12/78 + 11/78 + 10/78, and so on. This function is called a cumulative 
         distribution function.
         
         *****************************************************************************/
}
Real sum ( RealList  L )

Definition at line 38 of file C091406.cpp.

                     {
        Real s = 0.0;
        For (Integer i = 0; i < Length(L); i = i + 1) {
                s = s + L[i];
        }
        Return(s);
}