Implementation of the forward-backward algorithm for inspection.