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:
where
- the evidence is
- the prior is
- the likelihood is
- and the posterior is
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;
}