Skip to main content

Bayes-Laplace Rule

Name

UxHwDoubleBayesLaplace, UxHwFloatBayesLaplace Apply Bayes-Laplace rule to distributions.

Synopsis

#include <uxhw.h>

double UxHwDoubleBayesLaplace(double (*likelihood)(double), double prior, double evidence);
float UxHwFloatBayesLaplace(float (*likelihood)(float), float prior, float evidence);

Description

The UxHwDoubleBayesLaplace function returns the result of the Bayes-Laplace rule applied to the distribution associated with the evidence value, given the prior distribution associated with prior value and the likelihood conditional distribution associated with function pointer likelihood.

Bayes-Laplace rule is computed using:

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

where

  • the evidence is ee
  • the prior is fHf_H
  • the likelihood is fEHf_{E|H}
  • and the posterior is fHE=ef_{H|E=e}

Parameters

  • likelihood The function pointer to the likelihood function in the Bayes-Laplace rule.
  • prior The prior distribution in the Bayes-Laplace rule.
  • evidence The evidence distribution in the Bayes-Laplace rule.

Return Values

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

  Examples

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

/*
* This function models a sensor which readings are subject to a Gaussian noise.
*/
double
noisySensor(double measurand)
{
return UxHwDoubleGaussDist(measurand, 0.2);
}

int
main(int argc, char * argv[])
{
double prior = UxHwDoubleUniformDist(0.0, 2.0);
printf("prior = %lf\n", prior);

double evidence = 0.5;

double posterior = UxHwDoubleBayesLaplace(&noisySensor, prior, evidence);
printf("posterior = %lf\n", posterior);

return 0;
}