Failure diagnosis and prognosis in stochastic discrete-event and cyber-physical systems