> next up previous contents index
: plKernelTable : Kernels dictionaries : Kernels dictionaries   目次   索引

plKernelMap

Definition 21   A kernel map is a kernel dictionary with a map like structure and it retrieves an element by a sequential access. In a kernel map $\Omega_k$ can contain both, discrete and/or real type variables.

Example 14   Lets consider an example of a kernel map on $\Omega_s=\{X\}$ and $\Omega_s=\{Y\}$ with $X\in[1,100]$, $Y=[0,200]$, $\rho_0=plUniform(Y)$ and a set $S=\{(1,78,\rho_1),(60.81,\rho_2),$ $(56.91,\rho_3),(30.01,\rho_4), (40.01,\rho_5) \}$ with


$\displaystyle \rho_1$ $\textstyle =$ $\displaystyle plNormal(Y,100,10)$  
$\displaystyle \rho_2$ $\textstyle =$ $\displaystyle plNormal(Y,50,12)$  
$\displaystyle \rho_3$ $\textstyle =$ $\displaystyle plNormal(Y,41,5)$  
$\displaystyle \rho_4$ $\textstyle =$ $\displaystyle plGamma(Y,5.0,1.0)$  
$\displaystyle \rho_5$ $\textstyle =$ $\displaystyle plGamma(Y,8.0,1.0)$ (3.19)

Program 10 shows the construction of the kernel map and Figure 3.12 depicts is representation.



Program 10: A kernel map.

     1  /*=============================================================================
     2   * File           : kernelMap.cpp
     3   *=============================================================================
     4   *
     5   *------------------------- Description ---------------------------------------
     6   * This program shows the main functionalities of the kernel dictionary:
     7   * kernelMap.
     8   *-----------------------------------------------------------------------------
     9  */
    10
    11
    12  #include <pl.h>
    13
    14  main()
    15  {
    16    /**********************************************************************
    17       Defining the variable type, set and values
    18    ***********************************************************************/
    19    plRealType Tx(1,100);
    20    plRealType Ty(0,200);
    21
    22    plSymbol x("x",Tx);
    23    plSymbol y("y",Ty);
    24
    25    plValues values(x^y);
    26
    27    /**********************************************************************
    28       Constructing kernel dictionary P( y | x)
    29    ***********************************************************************/
    30    plCUniform Py0(y);
    31    plNormal Py1(y,100,10);
    32    plNormal Py2(y,50,12);
    33    plNormal Py3(y,41,5);
    34    plGamma  Py4(y,5.0,1.0);
    35    plGamma  Py5(y,8.0,1.0);
    36
    37    plKernelMap Py(y,x);
    38
    39    // Pushing the default kernel
    40    Py.push_default(Py0);
    41
    42    // Pushing the pairs (key, kernel)
    43    values [x] = 1.78l;
    44    Py.push(values,Py1);
    45    cout<<"inserting kernel for x= "<<values[x]<<endl;
    46
    47    values [x] = 60.8l;
    48    Py.push(values,Py2);
    49    cout<<"inserting kernel for x= "<<values[x]<<endl;
    50
    51    values [x] = 56.9l;
    52    Py.push(values,Py3);
    53    cout<<"inserting kernel for x= "<<values[x]<<endl;
    54
    55    values [x] = 30.0l;
    56    Py.push(values,Py4);
    57    cout<<"inserting kernel for x= "<<values[x]<<endl;
    58
    59    values [x] = 40.0l;
    60    Py.push(values,Py5);
    61    cout<<"inserting kernel for x= "<<values[x]<<"\n\n";
    62
    63    cout<<Py<<"\n\n";
    64
    65    /**********************************************************************
    66       Reading some key values and instantiating the corresponding kernel
    67    ***********************************************************************/
    68
    69    plFloat vx,vy;
    70    plKernel new_kernel;
    71
    72    for(int i=0;i<3;i++) {
    73      cout<<"Value for x: ";
    74      cin>>vx;
    75      cout<<"Value for y: ";
    76      cin>>vy;
    77      values[x] = vx;
    78      values[y] = vy;
    79      if (Py.find(values))
    80        cout<<"Kernel FOUND for x="<<vx<<"\nthe kernel is: ";
    81      else
    82        cout<<"Kernel NOT FOUND for x="<<vx<<"\nussing default kernel: ";
    83      Py.instantiate(new_kernel,values);
    84      cout<<new_kernel<<endl;
    85      cout<<"compute = "<<new_kernel.compute(values)<<"\n\n";
    86    }
    87  }

図 3.12: Representation of the kerneMap at Example 14
\begin{figure}\begin{center}
\psfig{figure=kernelMap.eps, width= 10cm}
\end{center}
\end{figure}

At its creation the kernel map is empty, line 37, then the default kernel is specified by means of the push_default method, line 40. A plValues is used to indicate values of $x$ then, by using the push method, we associate to each of the values a specific kernel, lines 42 to 61. Finally, we print and test out kernel map, lines 63 to 86. By giving the $x$ and $y$ values a sequence of computes are executed. For those values of $x$ inserted into the kernel map the associated kernel is used, for the others values, the default kernel is employed. An example of the program output is given below.

inserting kernel for x= 1.78
inserting kernel for x= 60.8
inserting kernel for x= 56.9
inserting kernel for x= 30
inserting kernel for x= 40

P(y | x) = plKernelMap = {
(1.78 )= P(y | x) = plNormal(y,100,10)
(30 )= P(y | x) = plGamma(y, 5, 1, 0)
(40 )= P(y | x) = plGamma(y, 8, 1, 0)
(56.9 )= P(y | x) = plNormal(y,41,5)
(60.8 )= P(y | x) = plNormal(y,50,12)
Default =  0.005
}

Value for x: 20.7
Value for y: 75.4
Kernel NOT FOUND for x=20.7
ussing default kernel: P(y) =  0.005
compute = 0.005

Value for x: 1.78
Value for y: 45
Kernel FOUND for x=1.78
the kernel is: P(y) = plNormal(y,100,10)
compute = 1.07698e-08

Value for x: 56.9
Value for y: 45.7
Kernel FOUND for x=56.9
the kernel is: P(y) = plNormal(y,41,5)
compute = 0.0512943


next up previous contents index
: plKernelTable : Kernels dictionaries : Kernels dictionaries   目次   索引
Juan-Manuel Ahuactzin 平成17年3月31日