Advertisement
Guest User

Untitled

a guest
Jan 13th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. def chances_to_meet(person_a_wait_minutes, person_b_wait_minutes, time_window_minutes):
  4. a = person_a_wait_minutes / time_window_minutes
  5. b = person_b_wait_minutes / time_window_minutes
  6. return a - 1/2 * a ** 2 + b - 1/2 * b ** 2
  7.  
  8. #%% Show probability of meeting given same times
  9.  
  10. person_a = [t*60/8 for t in range(9)]
  11. person_b = [t*60/8 for t in range(9)]
  12.  
  13. meeting_times_1 = list(zip(person_a,person_b))
  14. probabilites_1 = []
  15.  
  16. for pa, pb in meeting_times_1:
  17. probabilites_1.append(chances_to_meet(pa,pb,60))
  18.  
  19. df1 = pd.DataFrame(probabilites_1, index = meeting_times_1)
  20. ax1 = df1.plot(title="Probability that Romeo and Juliet will meet within an hour window given equal wait times",
  21. legend=None)
  22.  
  23. ax1.set_xlabel("Minutes that (Romeo, Juliet) will wait before leaving")
  24. ax1.set_ylabel("Probability of meeting each other")
  25.  
  26.  
  27. #%% Show probability of meeting given one will wait indefinitely
  28.  
  29. person_a = [60 for t in range(9)]
  30. person_b = [t*60/8 for t in range(9)]
  31.  
  32. meeting_times_1 = list(zip(person_a,person_b))
  33. probabilites_1 = []
  34.  
  35. for pa, pb in meeting_times_1:
  36. probabilites_1.append(chances_to_meet(pa,pb,60))
  37.  
  38. df2 = pd.DataFrame(probabilites_1, index = meeting_times_1)
  39. ax2 = df2.plot(title="Probability that Romeo and Juliet will meet within an hour window if Romeo waits the whole hour",
  40. legend=None)
  41.  
  42. ax2.set_xlabel("Minutes that (Romeo, Juliet) will wait before leaving")
  43. ax2.set_ylabel("Probability of meeting each other")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement