Skip to content

Instantly share code, notes, and snippets.

@philipshen
Created July 16, 2024 01:27
Show Gist options
  • Select an option

  • Save philipshen/1bd8c37016ad401db44ac282ecd6ea82 to your computer and use it in GitHub Desktop.

Select an option

Save philipshen/1bd8c37016ad401db44ac282ecd6ea82 to your computer and use it in GitHub Desktop.
def distilled_most_probable_place(logs, decay):
max_time = logs['timestamp_eastern'].max()
place_probabilities = defaultdict(float)
for _, log in logs.iterrows():
delta_t = (max_time - log['timestamp_eastern']).total_seconds()
# time_weight = max(0, 1 - (decay * delta_t)**3)
time_weight = max(0, 1 - lambda_decay * delta_t)
for place in log.possible_places:
adjusted_prob = place['probability'] * time_weight
place_probabilities[place['name']] += adjusted_prob
return max(place_probabilities, key=place_probabilities.get)
def v2_snap_decision(user_id, decay=0.005, time_window_secs=15*60):
min_timestamp = datetime.now() - timedelta(seconds=time_window_secs)
recent_logs = logs[(logs['timestamp_eastern'] >= min_timestamp) & logs['user_id'] = user_id]
return distilled_most_probable_place(recent_logs, decay=decay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment