Forward-backward algorithm (smoothing)