An offline algorithm for change detection