Of course in the previous definition we have that and
are subsets of
and
. 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 :
![]() |
(1.5) |
and a process of symbolic and numeric simplifications. Note that a
joint distribution on is a very powerful object, it
can construct any kernel or conditional kernel of
. In other words once the joint distribution is defined on
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
. In the following lines we depict the use of a
joint distribution and the method
.
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 and
has a bell-shape like distribution (see Figure 1.1)
with two different variances
and
1.4. The
goal is to find the more probable real distance
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
and
are 10 and 15 respectively.
We have then that and
are known (remember that
and
are conditional bell-shape
distributions). However
is unknown and must be obtained
in order to find the more probable
distance
. Program 4 consist in the following steps :
(i) construct a joint distribution model for the set of variables
; (ii) ask the model for
; (iii) instantiate
with the sensor readings
and
getting
and (iv) get the more probable value of
.
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 and variance
the values between
and
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 at line 38. In fact the operator ``
'' is in
ProBT the equivalent of the set union operator ``
''. Three
distributions are constructed at lines 48 to 50. The conditional
bell-shape distributions are constructed with
and
for the first and
and
for the
second. The joint distribution of
and
is given in line
58. The first argument is the variable set
model_vars
,
(i.e. ) the second one is the decomposition
P_dist*P_distA*P_distB
representing
.
Again, the operator ``*'' in ProBT is the conjunction operator for computable objects. Our joint distribution
my_model
represents then
where
is an
uniform distribution and
and
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
and
. At this stage (after
line 61)
P_Cnd_dist
is the conditional kernel
. 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
``'' operator has not yet been implemented for ProBT classes. Line
83 constructs an initially empty kernel, by making instantiate
with the read values
and
we get the final kernel
. Note that the second argument for instantiate
is
model_values
= still
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
in
model_values
does not belongs to its value is
ignored when executing instantiate at line 84. In contrast if one or
more values of
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
.