Forward-backward algorithm