| """ |
| Pyro model for online learning of component failure probabilities. |
| """ |
| import pyro |
| import pyro.distributions as dist |
| import torch |
|
|
| def failure_model(observations=None): |
| """ |
| Bayesian model for component failure rates. |
| observations: tensor of observed failures (0/1) for each component. |
| """ |
| |
| switch_failure_rate = pyro.sample("switch_failure", dist.Beta(1, 10)) |
| server_failure_rate = pyro.sample("server_failure", dist.Beta(1, 20)) |
| service_failure_rate = pyro.sample("service_failure", dist.Beta(1, 5)) |
| |
| |
| if observations is not None: |
| with pyro.plate("components", len(observations)): |
| pyro.sample("obs", dist.Bernoulli(probs=...), obs=observations) |
| |
| return { |
| "switch": switch_failure_rate, |
| "server": server_failure_rate, |
| "service": service_failure_rate |
| } |