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:
where
- is the parameter of the used parametric model,
- is an instance of ,
- is the evidence,
- is the observed evidence,
- is the distribution of the prior,
- is the evidence model,
- is the distribution of the posterior given the observed evidence .
Parameters
evidenceModel
— The function pointer to the evidence model function in the Bayes-Laplace rule. TheevidenceModel
function can accept an arbitrary number of arguments using its first (void *
) argument. TheevidenceModel
function should return a distribution for the evidence that is expected to be observed given an instance of the model parameter as its second (double
) argument.evidenceModelArgs
— A void pointer pointing to any possible arguments passed to theevidenceModel
function pointer. This argument is directly passed to theevidenceModel
and not modified in any way by theUxHwDoubleBayesLaplace()
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 theevidence
distribution (e.g, viaUxHwDoubleDistFromSamples()
).
Return Values
The UxHwDoubleBayesLaplace()
function returns the distributional value associated with the posterior value of the Bayes-Laplace rule.
Notes
The term 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 by evaluating
the evidence model at permissible model parameter values (effectively calculating for
permissible model parameter values ) and evaluating the resulting distributions at the observed evidence .
✏️ 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 *) ¶ms, prior, evidence, evidenceSampleCount);
printf("posterior = %lf\n", posterior);
return 0;
}