def __mean_mol_rank( self, distributions: Dict[Tuple[int, int], Dict[Player, float]]) -> float: """ Compute the mean Mol rank. Arguments: distributions (Dict[Tuple[int, int], Dict[Player, float]]): All the predictions. Returns: The mean Mol rank. """ seasons = {s for s, e in distributions.keys()} all_mol = {s: get_mol_in_season(s) for s in seasons} rank_sum = 0.0 num_pred = 0 for id, distribution in distributions.items(): likelihoods = [-prob for prob in distribution.values()] ranks = rankdata(likelihoods, method="average") rank_map = dict(zip(likelihoods, ranks)) mol = all_mol[id[0]] mol_likelihood = -distribution[mol] rank_sum += rank_map[mol_likelihood] num_pred += 1 return rank_sum / num_pred
def __mean_mol_likelihood( self, distributions: Dict[Tuple[int, int], Dict[Player, float]]) -> float: """ Compute the mean Mol likelihood. Arguments: distributions (Dict[Tuple[int, int], Dict[Player, float]]): All the predictions. Returns: The mean Mol likelihood. """ seasons = {s for s, e in distributions.keys()} all_mol = {s: get_mol_in_season(s) for s in seasons} likelihood_sum = 0.0 num_pred = 0 for id, distribution in distributions.items(): mol = all_mol[id[0]] likelihood_sum += distribution[mol] num_pred += 1 return likelihood_sum / num_pred
def __mol_log_loss( self, distributions: Dict[Tuple[int, int], Dict[Player, float]]) -> float: """ Compute the Mol log loss over the predictions (which is the log loss over only the Mol players). Arguments: distributions (Dict[Tuple[int, int], Dict[Player, float]]): All the predictions. Returns: The Mol log loss over the predictions. """ seasons = {s for s, e in distributions.keys()} all_mol = {s: get_mol_in_season(s) for s in seasons} mol_log_loss = 0.0 num_pred = 0 for id, distribution in distributions.items(): mol = all_mol[id[0]] mol_log_loss -= math.log(distribution[mol]) num_pred += 1 return mol_log_loss / num_pred
# Obtain the predictions from the second model, which is supposed to be the worser performing model. progress_bar = Bar("Distributions Computed of Second Model: ", max = total_tasks) for season in VALIDATE_SEASONS: train_seasons = TRAIN_SEASONS.difference({season}) for episode in range(get_last_episode(season) + 1): distributions2[(season, episode)] = model2.compute_distribution(season, episode, train_seasons) progress_bar.next() progress_bar.finish() print() # Compare the predictions based on episode number for episode in range(EPISODE_GROUPS + 1): dis1 = ValidationMetrics.filter_prediction_episode_num(distributions1, episode, EPISODE_GROUPS) dis2 = ValidationMetrics.filter_prediction_episode_num(distributions2, episode, EPISODE_GROUPS) likelihoods1 = np.array([dis[get_mol_in_season(id[0])] for id, dis in dis1.items()]) likelihoods2 = np.array([dis[get_mol_in_season(id[0])] for id, dis in dis2.items()]) print("Episode Number: " + str(episode)) evaluate(likelihoods1, likelihoods2) print() # Compare the predictions based on number potential mol players for num_potential_mol in POTENTIAL_MOL_GROUPS: dis1 = ValidationMetrics.filter_prediction_potential_mols(distributions1, num_potential_mol) dis2 = ValidationMetrics.filter_prediction_potential_mols(distributions2, num_potential_mol) if dis1 and dis2: likelihoods1 = np.array([dis[get_mol_in_season(id[0])] for id, dis in dis1.items()]) likelihoods2 = np.array([dis[get_mol_in_season(id[0])] for id, dis in dis2.items()]) print("Number potential mol players: " + str(num_potential_mol))
joker_usage = episode.total_joker_usage(exemption_value=sys.maxsize) for player in episode.players: if episode.input[player].immunity: drop_probabilities[player] = 0.0 else: own_usage = joker_usage[player] less_1_joker = sum(joker_usage[p] <= own_usage - 1 for p in joker_usage if p != player) same_jokers = sum(joker_usage[p] == own_usage for p in joker_usage if p != player) more_1_joker = sum(joker_usage[p] >= own_usage + 1 for p in joker_usage if p != player) train_input = [less_1_joker, same_jokers, more_1_joker] train_output = 1.0 if player in episode.result.players else 0.0 drop_probability = estimator.predict_proba( np.array([train_input]))[0][1] drop_probabilities[player] = drop_probability probability_sum = sum(prob for prob in drop_probabilities.values()) drop_probabilities = { player: prob / probability_sum for player, prob in drop_probabilities.items() } print(drop_probabilities) for player in episode.result.players: print(player) print(drop_probabilities[player]) print("Mol Probability: ") print(drop_probabilities[get_mol_in_season(season_id)]) print("Uniform Probability: ") print(1 / len(drop_probabilities))