> next up previous contents index
: Anonymous conditional kernels : Anonymous computable objects : Anonymous computable objects   目次   索引

Anonymous kernels

Definition 29   An anonymous kernel is a kernel where the compute function $f(\Omega_s)$ has been provided by the programmer.

For instance, suppose you want to construct a kernel corresponding to a Laplace distribution (see Figure 4.3):


$\displaystyle Laplace(x,\mu,b)$ $\textstyle =$ $\displaystyle \frac{1}{2b}\exp\left(-\frac{\vert x-\mu\vert}{b}\right)$ (4.7)

図 4.3: Two examples of Laplace distributions for $\mu =3.0$ and $b=0.6$ (continuous line) and $\mu =2.0$ and $b=0.3$ (dashed line).

where $\mu$ is the mean and $2b^2$ is the variance. A kernel representing this distribution can be constructed by means of an anonymous kernel. The basic idea is very simple and is depicted by the following example.

Example 18   Here we implement an anonymous kernel with a Laplace distribution function with $\mu =3.0$ and $b=0.6$. The goal is to generate a gnuplot file showing the resulting 100,000 random values histogram generated with this distribution, the best value is also found.



Program 15: A Laplace distribution.

     1  /*=============================================================================
     2   * File           : laplace.cpp
     3   *=============================================================================
     4   *
     5   *------------------------- Description ---------------------------------------
     6   * This program implements an anonymous kernel corresponding to a Laplace    
     7   * distribution with  mu = 3.0 an b = 0.6. It generates a gnuplot file
     8   * that depicts the histogram resulting from drawing 100000 values from 
     9   * the Laplace distribution. To see the histogram make "gnuplot test_laplace".
    10   *-----------------------------------------------------------------------------
    11  */
    12
    13  #include <pl.h>
    14
    15  #define B 0.6
    16  #define MU 3.0
    17
    18
    19  plProbValue laplace(const plValues &x)
    20  {
    21    double xx = x[0];
    22
    23    return (1.0/(2.0*B)*exp(-fabs(xx-MU)/B));
    24  }
    25
    26
    27  main()
    28  {
    29    /**********************************************************************
    30       Defining the variable type, set and values 
    31    ***********************************************************************/
    32
    33    plRealType distance(0,10,1000);
    34    plSymbol x("x",distance);
    35    plValues v(x);
    36
    37    /**********************************************************************
    38       Creating the external function and the anonymous kernel
    39    ***********************************************************************/
    40
    41    plExternalProbFunction laplace_dist(x,laplace);
    42    plAnonymousKernel Px(x,laplace_dist);
    43
    44    /**********************************************************************
    45       Drawing 10 000 values an writing the resulting histogram in the 
    46       gnuplot file "test_laplace"
    47     ***********************************************************************/
    48    
    49    Px.test_draw(100000,"test_laplace");
    50
    51    /**********************************************************************
    52       Getting and showing the best value of the distribution
    53     ***********************************************************************/
    54
    55    Px.best(v);
    56    cout<<"The best is "<<v<<endl;
    57  }

Program 15 shows the solution. We begin by defining an external probability function, line 41; an intermediary object that allows to construct the anonymous kernels at line 42. The $compute$ function of Px is then the Laplace distribution function coded by lines 19 to 24. At line 49 a test of 100 000 random values is generated with Px, the result is a gnuplot file that plots the resulting histogram4.2, see Figure 4.4. Finally, lines 55 and 56 compute and show the following result:

The best is { x=3.00004 }

To get the previous value, ProBT runs an optimization algorithm with the external probability function, for more details see section [*].

図 4.4: The resulting histogram for an anonymous kernel corresponding to a Laplace distribution function with $\mu =2.0$ and $b=0.3$.

A new version of Program 15 (using an object class) is obtainin by substituting lines 19 to 24 by

class laplace_pdf {

  double mu; // mean
  double b;  // variance is 2*b^2

public:
  // Constructor from the mean end b parameters
  laplace_pdf(const double &mean, const double &the_b);

  // This method returns the evaluation of f(x) where f(x) is a
  // Laplace pdf with mean mu and variance 2*b^2
  plProbValue laplace(const plValues &x);
  

};

// Constructor
laplace_pdf::laplace_pdf(const double &mean, const double &the_b) {
  mu = mean;
  b = the_b;
}

// Returns Laplace(x,mean,b)
plProbValue laplace_pdf::laplace(const plValues &x)
{
  double xx = x[0];

  return (1.0/(2.0*b)*exp(-fabs(xx-mu)/b));
}

and lines 41 and 42 by

  laplace_pdf my_pdf_obj(MU,B);
  plExternalProbFunction laplace_dist(x,&my_pdf_obj,&laplace_pdf::laplace);
  plAnonymousKernel Px(x,laplace_dist);


next up previous contents index
: Anonymous conditional kernels : Anonymous computable objects : Anonymous computable objects   目次   索引
Juan-Manuel Ahuactzin 平成17年3月31日