Skip to main content

Bayes-Laplace Rule

Name

UxHwDoubleBayesLaplace, UxHwFloatBayesLaplace Apply Bayes-Laplace rule to distributions.

Synopsis

#include <uxhw.h>

double UxHwDoubleBayesLaplace(double (*evidenceModel)(void *, double), void * evidenceModelArgs, double prior, double evidence, size_t evidenceSampleCount);
float UxHwFloatBayesLaplace(float (*evidenceModel)(void *, float), void * evidenceModelArgs, float prior, float evidence, size_t evidenceSampleCount);

Description

The UxHwDoubleBayesLaplace() function implements the the Bayes-Laplace rule which, given a parametric model (known as the evidence model) with a single parameter for an observable phenomenon, allows the application to update the belief on the permissible values of the model parameter expressed as a distribution (known as the prior) based on observations of the modelled phenomenon (known as the evidence) to obtain a new belief on the permissible values of the model parameter expressed as a distribution (known as the posterior).

Bayes-Laplace rule is computed using:

fHE=e(h)=fEH=h(e)fH(h)fEH=x(e)fH(x)dx,f_{H \mid E=e}(h) = \frac{f_{E \mid H=h}(e) f_H(h)}{\int f_{E \mid H = x}(e) f_H(x)\,dx},

where

  • HH is the parameter of the used parametric model,
  • hh is an instance of HH,
  • EE is the evidence,
  • ee is the observed evidence,
  • fHf_H is the distribution of the prior,
  • fEHf_{E \mid H} is the evidence model,
  • fHE=ef_{H \mid E=e} is the distribution of the posterior given the observed evidence ee.

Parameters

  • evidenceModel The function pointer to the evidence model function in the Bayes-Laplace rule. The evidenceModel function can accept an arbitrary number of arguments using its first (void *) argument. The evidenceModel function should return a distribution for the evidence that is expected to be observed given an instance hh of the model parameter as its second (double) argument.
  • evidenceModelArgs A void pointer pointing to any possible arguments passed to the evidenceModel function pointer. This argument is directly passed to the evidenceModel and not modified in any way by the UxHwDoubleBayesLaplace() function.
  • prior The prior distribution in the Bayes-Laplace rule.
  • evidence The evidence distribution in the Bayes-Laplace rule.
  • evidenceSampleCount The number of evidence samples that the application used to create the evidence distribution (e.g, via UxHwDoubleDistFromSamples()).

Return Values

The UxHwDoubleBayesLaplace() function returns the distributional value associated with the posterior value of the Bayes-Laplace rule.

Notes

The term fEH=h(e)f_{E \mid H=h}(e) in the Bayes-Laplace rule is known as the likelihood that one will observe the evidence e given the model parameter H takes the value h. The UxHwDoubleBayesLaplace() function calculates this likelihood internally for the provided evidence model fEHf_{E \mid H} by evaluating the evidence model at permissible model parameter values hh (effectively calculating fEH=hf_{E \mid H=h} for permissible model parameter values hh) and evaluating the resulting distributions at the observed evidence ee.

  Examples

#include <stdio.h>
#include <uxhw.h>

/*
* Other sensor parameters.
*/
typedef struct
{
double noisySensorParameter1;
double noisySensorParameter2;
} NoisySensorParameters;

/*
* The evidence model function that accepts the measurand as well as any number
* of other possible function arguments using the `otherArgs` argument.
* This function models a sensor which readings are subject to a Gaussian noise.
* The sensor uses two different sensor parameters to calculate the standard deviation
* of the noise.
*/
double
noisySensor(void * otherArgs, double measurand)
{
double sensorParam1 = ((NoisySensorParameters *)otherArgs)->noisySensorParameter1;
double sensorParam2 = ((NoisySensorParameters *)otherArgs)->noisySensorParameter2;

return UxHwDoubleGaussDist(measurand, sensorParam1 * sensorParam2);
}

int
main(int argc, char * argv[])
{
double prior = UxHwDoubleUniformDist(0.0, 2.0);
NoisySensorParameters params;
size_t evidenceSampleCount = 100;

/*
* Set the noisy sensor parameters;
*/
params.noisySensorParameter1 = 2.0;
params.noisySensorParameter2 = 3.0;

printf("prior = %lf\n", prior);

double evidence = 0.5;

/*
* Call the Bayes-Laplace function, passing the `noisySensor` function pointer,
* the sensor parameters `params`, the `prior` and `evidence` distributions
* (in this example `evidence` is just a particle value), and the `evidenceSampleCount`.
*/
double posterior = UxHwDoubleBayesLaplace(&noisySensor, (void *) &params, prior, evidence, evidenceSampleCount);

printf("posterior = %lf\n", posterior);

return 0;
}