Created
July 16, 2024 01:27
-
-
Save philipshen/1bd8c37016ad401db44ac282ecd6ea82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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