Exemple #1
0
    def __init__(self, wps_prob_table):
        self.game_list = [x for x in wps_prob_table.columns.values.tolist() if 'sch' in x]

        d = {}

            

        avg_dollar_returns_dict = fh.read_dict(fh.dollar_returns_file_path)
        # set up index and columns for the dataframe
        ind_l = [] ; bet_type_l = [] ; bet_l = [] ; pred_prob_l = [] ; avg_dollar_return_l = [] ; predicted_return_l = [] ; selected_l = [] ; act_ret_l = [] 
        for bet_type, bets in avg_dollar_returns_dict.items():
            for bet, avg_dollar_return in bets.items():
                ind_l.append(bet_type + '_' + str(bet))
                bet_type_l.append(bet_type)
                bet_l.append(bet)
                pred_prob_l.append(0)
                avg_dollar_return_l.append(avg_dollar_return)
                predicted_return_l.append(0)
                selected_l.append(0)
                act_ret_l.append(0)
        top_df = pd.DataFrame()

        for game_name in self.game_list:
            ll = []
            for ind in ind_l:
                ll.append(game_name + "_" + ind)
                #ll.append(game_name)
            d[game_name]= ll            
            df =pd.DataFrame(data = {'bet_type':bet_type_l, 'bet':bet_l,'predicted_prob':pred_prob_l,'avg_dollar_return':avg_dollar_return_l,'predicted_return':predicted_return_l,'selected':selected_l,'actual_return':act_ret_l,'my_return':act_ret_l, 'game_name': ll}, index = ind_l)
            top_df = top_df.append(df, ignore_index = True)
        #top_df.T
        top_df = top_df.set_index('game_name')
        #print top_df.head()
        #print top_df.shape
        self.top_df = top_df
def calculate_quadratic_loss_function():
    """
    1 -2pi + sum((pj)^2)
    """
    tot_qlf = 0
    tot_ilf = 0
    
    def calc_qlf(p_vector, WPSL_vector):
        qlf = None
        inverse_WPSL_vector = [0 if a== 1 else 1 for a in WPSL_vector]
        pi = sum([a*b for a,b in zip(p_vector,WPSL_vector)])
        pj = sum([x**2 for x in [a*b for a,b in zip(p_vector,inverse_WPSL_vector)]])
        qlf = 1 - 2*pi + pj
        return qlf
        
    def calc_ilf(p_vector, WPSL_vector):
        ilf = 0
        pri = sum([a*b for a,b in zip(p_vector,WPSL_vector)])
        #!!!!!!pri # if pri = 0 then make it a small probability such as 0.01 ???
        if pri  <= 0.05:
            pri = 0.05
            #print pri
            ilf = -math.log(pri,2)
        return ilf


    p_dict = fh.read_dict(fh.prediction_dict_file_path)
    ar_dict = fh.read_dict(fh.prediction_actual_results_dict_file_path)
    for game_name, game_data in p_dict.items():
#        print
#        print game_name
#        print game_data
#        print ar_dict[game_name]
#        print game_name, ar_dict[game_name]
        for ind, player_dict in enumerate(game_data):
            #print player_dict.values()[0]
            p_vect = player_dict.values()[0]
            #print ar_dict[game_name][ind].values()[0]
            WPSL_vec = ar_dict[game_name][ind].values()[0]
            #print calc_qlf(p_vect, WPSL_vec)
            tot_qlf += calc_qlf(p_vect, WPSL_vec)
            tot_ilf += calc_ilf(p_vect, WPSL_vec)
    #print tot_qlf
    return tot_qlf, tot_ilf
def calculate_ilf(n):
    tot_ilf = 0
    count = 0
   
    p_dict = fh.read_dict(fh.prediction_dict_file_path)
    ar_dict = fh.read_dict(fh.prediction_actual_results_dict_file_path)
    for game_name, game_data in p_dict.items():
        count += 1
        pri = 0
        #print game_name
        for k in game_data.keys():
#            print game_name
            #print k, game_data[k], ar_dict[game_name][k]
            pri += (game_data[k] * ar_dict[game_name][k])/float(n)
            pri = 0.001
            #print pri
            ilf = -math.log(pri,2)
            #print game_name, ilf
            tot_ilf += ilf

    return tot_ilf
def get_player_season_records():
    """
    If the player season record does not exist for the top level data directory
    it is created, otherwise it is just returned from a file location
    Returns a dictionary of dictionaries for the player season record in the form:
    {eggy:richard [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 3]]} called all_player_season_records
    """
    fh.set_up_paths(DATA_DIR)
    all_player_season_records = {}
    if fh.file_exists(fh.player_season_records_file_path):
        all_player_season_records = fh.read_dict(fh.player_season_records_file_path)
    else:
        all_player_season_records = create_player_season_records()
        fh.write_dict(fh.player_season_records_file_path,all_player_season_records)
#    print fin_list
    return all_player_season_records