%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import binom
import ipywidgets as W
@W.interact(duration=(0.0, 4.0), interval=(12, 36), nodes=(1, 8))
def plotit(duration, interval, nodes=4):
# probability that any given node is cordoned
p = 1.0 * duration / interval
p_inverse = 1 - p
# n = for number of nodes available
n = np.arange(0, nodes + 1)
prob = binom.pmf(n, nodes, p)
plt.semilogy(n, prob, '-o')
plt.title("Probability that N nodes are cordoned at any given time")
plt.xticks(n)
plt.xlabel("cordoned nodes")
plt.ylabel("P")
print(f"Probability of N/{nodes} nodes cordoned:")
for i, p_i in zip(n, prob):
print(f"{i}: 1/{1/p_i:.2g}")
Failed to display Jupyter Widget of type interactive
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
plotit(duration=2, interval=24)
Probability of N/4 nodes cordoned: 0: 1/1.4 1: 1/3.9 2: 1/29 3: 1/4.7e+02 4: 1/2.1e+04