I have been working with probability and machine learning lately, particularly with fitting distributions to datasets. Fitting data is something covered in conventional pre-college curriculum, but I have only ever done it when all of my data has been complete. More recently I ran into a problem.

One fundamental feature in autonomous driving is the distance to the car in front of you. This tends to be a real number, something hopefully a bit bigger than a few meters when travelling at high speeds and potentially quite large when traffic is low. If you have a set of sensors on your car, like radars or lidar, you can only pick up cars up to a certain distance away from yourself. What do you do if there is no car in front of you? Set the distance to infinity?

This is a good example of censored data, a feature where data must fall within a given range but you know when it does so. The other types are truncated and missing data. Data is truncated when the only data you have is within a certain range, and you do not know of the occurrences when it falls outside of that range. Missing Data occurs when you missed or corrupted a reading, or for some reason it is not available. A good example is the velocity of the car in front of you.

So how does one handle fitting distributions to such features?

The answer is a surprisingly straightforward application of Bayes' theorem.

Consider first a toy problem, obtained from "Information Theory, Inference, and Learning Algorithms" by David MacKay:

Unstable particles are emitted from a source a decay at a distance , a real number that has an exponential probability distribution which characteristic length . decays are observed at locations . What is ?

Solving this for the case with perfect data provides us some insight.

The probability distribution for a single sample point, given , is:

from the definition for the exponential probability distribution.

Applying *Bayes' theorem*:

We can see that simply by conditioning on the data available and setting a prior we can determine the likelihood distribution for the value of . From here we can do what we wish, such as picking the most likely value for .

Suppose, however, that the data is truncated. Suppose that we only get readings for particle decays between and . Fitting in the same way is going to cause inconsistencies. Let us start again, following the same steps.

The probability distribution for a single sample point, potentially truncated, given , is:

where

We then apply *Bayes' theorem*:

This is *very* similar, and was quite easy to determine.

Without going into detail, we can derive the model for censored data. Suppose is censored to be less than .

where is the probability of being uncensored and being the dirac distribution.

The final case is missing data. Here, you know when the data is missing but you have no information about where it was. This sort of data must be fitted using the original method and only the observed values.