> next up previous contents index
: Variables: types, sets and : Programming with ProBT : Conditional kernels   目次   索引

Joint distributions

\begin{figure}\begin{center}
\psfig{figure=robot.ps, width=2.5cm}
\end{center}\end{figure}

Definition 6   A joint distribution is a kernel on $\Omega$ provided of the method $ask(\Omega_s,\Omega_k)$ returning:

Of course in the previous definition we have that $\Omega_s$ and $\Omega_k$ are subsets of $\Omega$ and $\Omega_s \cap \Omega_k = \emptyset$. A joint distribution is constructed by means of a set of computable objects and it represents the main source to infer other computable objects. Inferences from a joint distribution are obtained by applying the Bayes's Law :


$\displaystyle P(x\vert y) = \frac{P(x)P(y\vert x)}{P(y)} = \frac{P(x)P(y\vert x)}{\sum_{x_i\in X}{}P(x_i)P(y\vert x_i)}$     (1.5)

and a process of symbolic and numeric simplifications. Note that a joint distribution on $\Omega$ is a very powerful object, it can construct any kernel or conditional kernel of $\Omega_s\subset
\Omega$. In other words once the joint distribution is defined on $\Omega$ it is possible to get the distribution function of any subset of variables on your model conditioned or not to knowing some of the values on $\Omega$. In the following lines we depict the use of a joint distribution and the method $ask(\cdot)$.

Program 4 deals with a typical problem in robotics: sensor fusion. Most of the robots combine the reading of its sensors to obtain a more accurate information. Our example simulates this situation. We simulates reading the distance of and object from two sensors placed at the same location. The two measures $dA$ and $dB$ has a bell-shape like distribution (see Figure 1.1) with two different variances $\sigma_A$ and $\sigma_B$ 1.4. The goal is to find the more probable real distance $d$ of the object. In our example we assume that the object can be uniformly placed between a distance of 0 and 100 meters and that the variances $\sigma_A$ and $\sigma_B$ are 10 and 15 respectively.

図 1.1: A bell-shape distribution with mean 25 and variance 7

We have then that $P(dA\vert d)$ and $P(dB\vert d)$ are known (remember that $P(dA\vert d)$ and $P(dB\vert d)$ are conditional bell-shape distributions). However $P(d\vert dA~dB)$ is unknown and must be obtained in order to find the more probable distance $d$. Program 4 consist in the following steps : (i) construct a joint distribution model for the set of variables $\{
d, dA, dB\}$; (ii) ask the model for $P(d\vert dA~dB)$; (iii) instantiate $P(d\vert dA~dB)$ with the sensor readings $va$ and $vb$ getting $P(d\vert dA=va~dB=vb)$ and (iv) get the more probable value of $d$.



Program 4: Finding the most probable distance.

     1  /*=============================================================================
     2   * File           : sensors.cpp
     3   *=============================================================================
     4   *
     5   *------------------------- Description ---------------------------------------
     6   * This program simulates reading the distance of and object with two
     7   * sensors. The two measures has a bellshape like distribution with two
     8   * different variances. The goal is to find the more probable real distance 
     9   *-----------------------------------------------------------------------------
    10  */
    11
    12  #define MIN_DIST 0
    13  #define MAX_DIST 100
    14  #define STD_DEV_A 10
    15  #define STD_DEV_B 15
    16
    17
    18  #include <pl.h>
    19
    20  main ()
    21  {
    22    /**********************************************************************
    23       Defining the variable type, set and values 
    24    ***********************************************************************/
    25
    26    plIntegerType distance(MIN_DIST,MAX_DIST);    // Distance type
    27    plIntegerType measureA(0,                     // Measure type for sensor A
    28                           MAX_DIST+2*STD_DEV_A);
    29    plIntegerType measureB(0,                     // Measure type for sensor B
    30                           MAX_DIST+2*STD_DEV_B);
    31
    32    plSymbol d("d",distance);                     // Real distance variable
    33    plSymbol dA("dA",measureA);                   // sensor A measure
    34    plSymbol dB("dB",measureB);                   // sensor B measure
    35
    36                                   
    37    plVariable model_vars;  // The variables of the model are the distance {d}
    38    model_vars = d^dA^dB;   // union measures A and B  {dA, dB}             
    39
    40
    41    plValues model_values(model_vars);  // A variable values for storing
    42                                        // our data
    43
    44    /**********************************************************************
    45       Defining the elementary variables distributions 
    46    ***********************************************************************/
    47
    48    plUniform P_dist(d);                     // d has an uniform distribution
    49    plCndBellShape P_distA(dA,d,STD_DEV_A); // da and db are bellshape like 
    50    plCndBellShape P_distB(dB,d,STD_DEV_B); // distribution with a 
    51                                             // predefined variance
    52
    53    /**********************************************************************
    54     Defining the joint distribution P(d dA dB) = P(d) P(da|d) P(db|d)
    55     then ask the model  P( d | dA dB)
    56    ***********************************************************************/
    57
    58    plJointDistribution my_model(model_vars,P_dist*P_distA*P_distB); 
    59    
    60    plCndKernel P_Cnd_dist;
    61    my_model.ask(P_Cnd_dist,d,dA^dB);        // Get P( d | dA dB)
    62
    63
    64    /**********************************************************************
    65     Read measures from sensor A and B, then get P( d | dA=va dA=va)  
    66    ***********************************************************************/
    67   
    68    int va, vb;
    69
    70    do {
    71      cout<<"Please enter the measure of sensor A : ";
    72      cin>>va;
    73    }while (va <0 || va >MAX_DIST+2*STD_DEV_A);
    74      
    75    do {
    76      cout<<"Please enter the measure of sensor B : ";
    77      cin>>vb;
    78    }while (vb <0 || vb >MAX_DIST+2*STD_DEV_B);
    79
    80    model_values[dA]=va;
    81    model_values[dB]=vb;
    82
    83    plKernel P_dist_after_measure;
    84    P_Cnd_dist.instantiate(P_dist_after_measure,
    85                           model_values);        //Get P( d | dA=va dA=va)
    86
    87    P_dist_after_measure.best(model_values);     //Get the most probable distance
    88
    89
    90    cout<<"\nThe more probable distance is : ";   
    91    cout<<model_values[d]<<"\n\n";        
    92  }

Here we explain Program 4. Lines 26 to 30 corresponds to the types definition. Note that measures A and B goes from zero to MAX_DIST+2*VARIANCE_A and MAX_DIST+2*VARIANCE_B respectively. We suppose that all the read values are in these intervals. In fact, in a bell-shape distribution with mean $\mu$ and variance $\sigma$ the values between $\mu-2\sigma$ and $\mu+2\sigma$ represents more that 95% of the graph surface (i.e. in this case the values that we expect to read from sensors). The value MAX_DIST represents the maximal distance to which our object can be placed. By consequence we assume that MAX_DIST+2*VARIANCE_A and MAX_DIST+2*VARIANCE_B are the maximal distance given by sensors. Any measure out of these ranges is considered and invalid measure. Our example consist then in three different variables and they are constructed in lines 32 to 34. Note that in contrast with our previous example here we can not use a plArray because all our variables are of different types. Lines 37 and 38 construct a variable set containing the three variables. First in line 37 an empty variable is constructed then it is set to $\{
d, dA, dB\}$ at line 38. In fact the operator ``$\land$'' is in ProBT the equivalent of the set union operator ``$\cup$''. Three distributions are constructed at lines 48 to 50. The conditional bell-shape distributions are constructed with $\Omega_s=\{dA\}$ and $\Omega_k=\{d\}$ for the first and $\Omega_s=\{dA\}$ and $\Omega_k=\{d\}$ for the second. The joint distribution of $d,dA$ and $dB$ is given in line 58. The first argument is the variable set model_vars, (i.e. $\Omega$) the second one is the decomposition P_dist*P_distA*P_distB representing $P(d) P(da~\vert~d) P(db~\vert~d)$. Again, the operator ``*'' in ProBT is the conjunction operator for computable objects. Our joint distribution my_model represents then $P(d~dA~dB) = P(d) P(dA~\vert~d) P(dB~\vert~d)$ where $P(d)$ is an uniform distribution and $P(dA~\vert~d)$ and $P(dB~\vert~d)$ are conditional bell-shapes with different variance but same mean. An initially empty kernel is constructed at line 60. This kernel is passed as a reference argument at method ask (line 61), the result of the question will be set there. The second and third arguments correspond to the question sets $\Omega_s=\{dA\}$ and $\Omega_k=\{d\}$. At this stage (after line 61) P_Cnd_dist is the conditional kernel $P(d~\vert~dA~dB)$. Lines 68 to 78 simulates sensors reading. We assign the reading to model_values at lines 80,81. Note we did not make something like ``cin>>model_values[dA]'' because the ``$\gg$'' operator has not yet been implemented for ProBT classes. Line 83 constructs an initially empty kernel, by making instantiate with the read values $dA=va$ and $dB=vb$ we get the final kernel $P( d~\vert~dA=va~dA=va)$. Note that the second argument for instantiate is model_values =$\{
d, dA, dB\}$ still $\Omega_k=\{dA,dB\}$ in P_Cnd_dist. In fact the method instantiate will search for the values that are needed ignoring all other values. That is, given that $d$ in model_values does not belongs to $\Omega_k$ its value is ignored when executing instantiate at line 84. In contrast if one or more values of $\Omega_k$ are not found in the second argument ProBT will generate a run time error. We arrive to the end of the program, line 87 gets the more probable distance and is printed by line 91.

Here is the output of Program 4:

Please enter the measure of captor A : 48
Please enter the measure of captor B : 32

The more probable distance is : 43

Note that if we inverse the sensor reading the output is as follows:

Please enter the measure of captor A : 32
Please enter the measure of captor B : 48

The more probable distance is : 37

The result reflects the accuracy difference between sensors. Sensor A is more trustworthy than sensor B (it has a smaller variance) that's why sensor A measure has more influence in the final estimation of $d$.


next up previous contents index
: Variables: types, sets and : Programming with ProBT : Conditional kernels   目次   索引
Juan-Manuel Ahuactzin 平成17年3月31日