Implementation of Inside-Outside algorithm