plCndNormal
is a
represents a collection of plNormal
kernels either with
variable means (
compute
and
instantiate
in a plCnNormal
kernel.
1 /*============================================================================= 2 * File : cndNormal.cpp 3 *============================================================================= 4 * 5 *------------------------- Description --------------------------------------- 6 * This program shows the main functionalities of a plCndNormalKernel. 7 * 8 *----------------------------------------------------------------------------- 9 */ 10 11 12 #include <pl.h> 13 14 15 main() 16 { 17 /********************************************************************** 18 Defining the variable type, set and values 19 ***********************************************************************/ 20 plRealType Tx(0.0,2.10); 21 plRealType Ty(0.0,120); 22 plRealType Std_Type(0.0,20); 23 24 plSymbol X("x",Tx); 25 plSymbol Y("y",Ty); 26 27 plSymbol X_mean("mx",Tx); 28 plSymbol Y_mean("my",Ty); 29 plVariable Mean(X_mean^Y_mean); 30 plArray Sigma("sigma",Std_Type,2,2,2); 31 32 plValues values(X^Y^Mean^Sigma); 33 34 /********************************************************************** 35 Constructing the conditional kernel P(X Y | Mean Sigma) 36 ***********************************************************************/ 37 38 plCndNormal my_cnd_kernel(X^Y,Mean,Sigma); 39 cout<<"The conditional kernel is :"<<my_cnd_kernel<<"\n\n"; 40 41 /********************************************************************** 42 Capturing the values of the mean and variance-covariance matrix 43 ***********************************************************************/ 44 45 plFloat v; 46 47 cout<<"Give me the mean on x: "; cin>>v; 48 values[X_mean] = v; 49 cout<<"Give me the mean on y: "; cin>>v; 50 values[Y_mean] = v; 51 cout<<"Give me the (X,X) variance: "; cin>>v; 52 values[Sigma(0,0)] = v; 53 cout<<"Give me the (X,Y) variance: "; cin>>v; 54 values[Sigma(0,1)] = v; 55 // The variance-covariance matrix is simetric so 56 values[Sigma(1,0)] = v; 57 cout<<"Give me the (Y,Y) variance: "; cin>>v; 58 values[Sigma(1,1)] = v; 59 60 /********************************************************************** 61 Illustrating the main functionalities: instantiate and compute 62 ***********************************************************************/ 63 64 plKernel new_kernel; 65 66 // Select a kernel from the family of kernels with the previous values 67 my_cnd_kernel.instantiate(new_kernel,values); 68 69 // Print the resulting kernel 70 cout<<"\nThe new kernel is: "<<new_kernel<<"\n\n"; 71 72 // Capture the values of X and Y 73 cout<<"Give me the value of X: "; cin>>v; 74 values[X] = v; 75 cout<<"Give me the value of Y: "; cin>>v; 76 values[Y] = v; 77 78 // Execute a compute with the new kernel 79 cout<<"\nCompute with the new kernel "; 80 cout<<new_kernel.compute(values)<<endl; 81 82 // Execute a compute with the conditional kernel 83 cout<<"Compute with the conditional kernel: "; 84 cout<<my_cnd_kernel.compute(values)<<endl; 85 }
The plVariable
Mean
at line 29 contains two variables
mx
and my
. They represent the means of
and
respectively. In line 30 the
plArray
Sigma
represents the variance-covariance variable matrix. The values of the
matrix are given by rows, that is sigma(0,0)
corresponds to
,
sigma(0,1)
to ,
sigma(1,0)
to and
sigma(1,1)
to . The conditional
normal distribution is created at line 38. Note that, both the mean
and variance are variables. However, ProBT provides other constructors
allowing the creation of conditional normal distributions with only
one variable parameter. Lines 45 to 58 captures a particular instance
of the mean and variance-covariance variables. This values are then
used at lines 60 to 84 to show the functionalities of the functions
and
. At line 67 a new kernel is obtained from
the conditional kernel by instantiating it with the captured
values. Lines 80 and 84 executes the
function for both the
conditional kernel
my_cnd_kernel
and the kernel
new_kernel
. The difference between the two functions
is that in
my_cnd_kernel
it is defined over
and in
new_kernel
it is defined over .
my_cnd_kernel
represents then a family of normal kernels with variable mean an
variance-covariance matrix. The function permits to
select one of these normal kernels.
One output of the program is the following:
The conditional kernel is :P(x y | mx my sigma(0,0) sigma(0,1) sigma(1,0) sigma(1,1)) = plCndNormal(x y, mx my sigma(0,0) sigma(0,1) sigma(1,0) sigma(1,1)) Give me the mean on x: 1.10 Give me the mean on y: 50 Give me the (X,X) variance: 0.5 Give me the (X,Y) variance: 25.6 Give me the (Y,Y) variance: 10.5 The new kernel is: P(x y) = plNormal(x y,1.1,50) Give me the value of X: 1.98 Give me the value of Y: 60.5 Compute with the new kernel 0.238076 Compute with the conditional kernel: 0.238076