Skip to content

Instantly share code, notes, and snippets.

@mstimberg
Last active March 12, 2020 15:26
Show Gist options
  • Save mstimberg/0f11f1e15c949e1c254afd2b57d35cdf to your computer and use it in GitHub Desktop.
Save mstimberg/0f11f1e15c949e1c254afd2b57d35cdf to your computer and use it in GitHub Desktop.
Visualize the remaining time estimated with a simple algorithm that estimates only based on the total time elapsed so far.
import numpy as np
import matplotlib.pyplot as plt
scenarios = [('constant', [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.], # elapsed time
[.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.]), # fraction of simulation completed
('varying', [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.],
[.1, .175, .3, .375, .5, .575, .7, .775, .9, 1.]),
('slow start', [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.],
[.05, 0.1, 0.15, 0.2, 0.25, 0.4, 0.55, 0.7, 0.85, 1.0]),
('slow end', [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.],
[.15, .3, .45, .6, .75, .8, .85, .9, .95, .1])
]
def estimate(elapsed, completed):
# Normally this is rounded to the next second for display
return (1 - completed) / completed * elapsed
vectorized_estimate = np.vectorize(estimate)
fig, axes = plt.subplots(len(scenarios), 1, sharex=True)
for ax, (name, elapsed, completed) in zip(axes, scenarios):
estimated_remaining_time = vectorized_estimate(elapsed[:-1], completed[:-1])
real_remaining_time = elapsed[-1] - np.array(elapsed[:-1])
ax.plot(100*np.array(elapsed[:-1])/elapsed[-1], real_remaining_time, color='gray', lw=2)
ax.plot(100*np.array(elapsed[:-1])/elapsed[-1], estimated_remaining_time, 'o')
ax.set_title(name)
axes[-1].set_xlabel('elapsed time (%)')
axes[-1].set_ylabel('remaining time')
fig.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment