forward backward algorithm