utils.py 1.22 KB
Newer Older
20200318029 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
"""
Colby Wise
LinUCB1 Multi-Arm Bandit Problem
Re-inforcement Learning

Data helper functions that return the correct
column or row from a pandas dataframe
"""

import pandas as pd


"""
Read in CSV data file and remove 'timestamp' column
@param:
    file - file directory
@return:
    data - pandas dataframe of action & context vectors
"""
def getData(file):
        data = pd.read_csv(file, sep=" ", header=None)
        data = data.loc[:,:101]
        return data 

"""
Helps sequentially retrieve a context vector at each time step
in the algorithm
@param:
    data - pandas df
    idx - time step (row) wanted
@return:
    x - context vector for given time step
"""
def getContext(data, idx):
    return data.loc[idx, 2:]

"""
Helps sequentially retrieve an action vector at each time step
in the algorithm
@param:
    data - pandas df
    idx - time step (row) wanted
@return:
    action - action vector for given time step
"""
def getAction(data, idx):
    return data.loc[idx, 0]

"""
Helps sequentially retrieve a reward vector at each time step
in the algorithm
@param:
    data - pandas df
    idx - time step (row) wanted
@return:
    reward - reward vector for given time step
"""
def getReward(data, idx):
    return data.loc[idx, 1]