# Path: striatum/storage/history.py
# class History(object):
# class HistoryStorage(object):
# class MemoryHistoryStorage(HistoryStorage):
#     def __init__(self, history_id, context, recommendations, created_at,
#                  rewarded_at=None):
#     def update_reward(self, rewards, rewarded_at):
#     def rewards(self):
#     def get_history(self, history_id):
#     def get_unrewarded_history(self, history_id):
#     def add_history(self, context, recommendations, rewards=None):
#     def add_reward(self, history_id, rewards):
#     def __init__(self):
#     def get_history(self, history_id):
#     def get_unrewarded_history(self, history_id):
#     def add_history(self, context, recommendations, rewards=None):
#     def add_reward(self, history_id, rewards):
# 
# Path: striatum/storage/model.py
# class ModelStorage(object):
# class MemoryModelStorage(ModelStorage):
#     def get_model(self):
#     def save_model(self):
#     def __init__(self):
#     def get_model(self):
#     def save_model(self, model):
# 
# Path: striatum/bandit/ucb1.py
# class UCB1(BaseBandit):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None):
#     def _ucb1_score(self):
#     def get_action(self, context=None, n_actions=None):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def remove_action(self, action_id):
# 
# Path: striatum/bandit/linucb.py
# LOGGER = logging.getLogger(__name__)
#         A = model['A']  # pylint: disable=invalid-name
# class LinUCB(BaseBandit):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None, context_dimension=128, alpha=0.5):
#     def _init_action_model(self, model, action_id):
#     def _linucb_score(self, context):
#     def get_action(self, context, n_actions=None):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def remove_action(self, action_id):
# 
# Path: striatum/bandit/linthompsamp.py
# LOGGER = logging.getLogger(__name__)
#         B = np.identity(self.context_dimension)  # pylint: disable=invalid-name
#         B = model['B']  # pylint: disable=invalid-name
#         B = model['B']  # pylint: disable=invalid-name
# class LinThompSamp(BaseBandit):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None, context_dimension=128, delta=0.5,
#                  R=0.01, epsilon=0.5, random_state=None):
#     def _linthompsamp_score(self, context):
#     def get_action(self, context, n_actions=None):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def remove_action(self, action_id):
# 
# Path: striatum/bandit/exp4p.py
# LOGGER = logging.getLogger(__name__)
# class Exp4P(BaseBandit):
#     def __init__(self, actions, historystorage, modelstorage, delta=0.1,
#                  p_min=None, max_rounds=10000):
#     def _exp4p_score(self, context):
#     def get_action(self, context=None, n_actions=1):
#     def reward(self, history_id, rewards):
# 
# Path: striatum/bandit/exp3.py
# LOGGER = logging.getLogger(__name__)
# class Exp3(BaseBandit):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None, gamma=0.3, random_state=None):
#     def _exp3_probs(self):
#     def get_action(self, context=None, n_actions=None):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def remove_action(self, action_id):
# 
# Path: striatum/bandit/bandit.py
# class BaseBandit(object):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None):
#     def history_storage(self):
#     def get_action(self, context, n_actions=None):
#     def _get_action_with_empty_action_storage(self, context, n_actions):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def update_action(self, action):
#     def remove_action(self, action_id):
#     def calculate_cum_reward(self):
#     def calculate_avg_reward(self):
#     def plot_avg_reward(self):
#     def plot_avg_regret(self):


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from striatum.storage import history
from striatum.storage import model
from striatum.bandit import ucb1
from striatum.bandit import linucb
from striatum.bandit import linthompsamp
from striatum.bandit import exp4p
from striatum.bandit import exp3
from striatum.bandit.bandit import Action
from sklearn.naive_bayes import MultinomialNB
from sklearn.linear_model import LogisticRegression
from sklearn.multiclass import OneVsRestClassifier
# -*- coding: utf-8 -*-
"""
==============================
Contextual bandit on MovieLens
==============================

The script uses real-world data to conduct contextual bandit experiments. Here we use
MovieLens 10M Dataset, which is released by GroupLens at 1/2009. Please fist pre-process
datasets (use "movielens_preprocess.py"), and then you can run this example.
"""



def get_data():
    streaming_batch = pd.read_csv('streaming_batch.csv', sep='\t', names=['user_id'], engine='c')
    user_feature = pd.read_csv('user_feature.csv', sep='\t', header=0, index_col=0, engine='c')
    actions_id = list(pd.read_csv('actions.csv', sep='\t', header=0, engine='c')['movie_id'])
    reward_list = pd.read_csv('reward_list.csv', sep='\t', header=0, engine='c')
    action_context = pd.read_csv('action_context.csv', sep='\t', header=0, engine='c')

    actions = []
    for key in actions_id:

# Path: striatum/storage/history.py
# class History(object):
# class HistoryStorage(object):
# class MemoryHistoryStorage(HistoryStorage):
#     def __init__(self, history_id, context, recommendations, created_at,
#                  rewarded_at=None):
#     def update_reward(self, rewards, rewarded_at):
#     def rewards(self):
#     def get_history(self, history_id):
#     def get_unrewarded_history(self, history_id):
#     def add_history(self, context, recommendations, rewards=None):
#     def add_reward(self, history_id, rewards):
#     def __init__(self):
#     def get_history(self, history_id):
#     def get_unrewarded_history(self, history_id):
#     def add_history(self, context, recommendations, rewards=None):
#     def add_reward(self, history_id, rewards):
# 
# Path: striatum/storage/model.py
# class ModelStorage(object):
# class MemoryModelStorage(ModelStorage):
#     def get_model(self):
#     def save_model(self):
#     def __init__(self):
#     def get_model(self):
#     def save_model(self, model):
# 
# Path: striatum/bandit/ucb1.py
# class UCB1(BaseBandit):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None):
#     def _ucb1_score(self):
#     def get_action(self, context=None, n_actions=None):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def remove_action(self, action_id):
# 
# Path: striatum/bandit/linucb.py
# LOGGER = logging.getLogger(__name__)
#         A = model['A']  # pylint: disable=invalid-name
# class LinUCB(BaseBandit):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None, context_dimension=128, alpha=0.5):
#     def _init_action_model(self, model, action_id):
#     def _linucb_score(self, context):
#     def get_action(self, context, n_actions=None):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def remove_action(self, action_id):
# 
# Path: striatum/bandit/linthompsamp.py
# LOGGER = logging.getLogger(__name__)
#         B = np.identity(self.context_dimension)  # pylint: disable=invalid-name
#         B = model['B']  # pylint: disable=invalid-name
#         B = model['B']  # pylint: disable=invalid-name
# class LinThompSamp(BaseBandit):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None, context_dimension=128, delta=0.5,
#                  R=0.01, epsilon=0.5, random_state=None):
#     def _linthompsamp_score(self, context):
#     def get_action(self, context, n_actions=None):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def remove_action(self, action_id):
# 
# Path: striatum/bandit/exp4p.py
# LOGGER = logging.getLogger(__name__)
# class Exp4P(BaseBandit):
#     def __init__(self, actions, historystorage, modelstorage, delta=0.1,
#                  p_min=None, max_rounds=10000):
#     def _exp4p_score(self, context):
#     def get_action(self, context=None, n_actions=1):
#     def reward(self, history_id, rewards):
# 
# Path: striatum/bandit/exp3.py
# LOGGER = logging.getLogger(__name__)
# class Exp3(BaseBandit):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None, gamma=0.3, random_state=None):
#     def _exp3_probs(self):
#     def get_action(self, context=None, n_actions=None):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def remove_action(self, action_id):
# 
# Path: striatum/bandit/bandit.py
# class BaseBandit(object):
#     def __init__(self, history_storage, model_storage, action_storage,
#                  recommendation_cls=None):
#     def history_storage(self):
#     def get_action(self, context, n_actions=None):
#     def _get_action_with_empty_action_storage(self, context, n_actions):
#     def reward(self, history_id, rewards):
#     def add_action(self, actions):
#     def update_action(self, action):
#     def remove_action(self, action_id):
#     def calculate_cum_reward(self):
#     def calculate_avg_reward(self):
#     def plot_avg_reward(self):
#     def plot_avg_regret(self):


# Path: examples/movielens_bandit.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from striatum.storage import history
from striatum.storage import model
from striatum.bandit import ucb1
from striatum.bandit import linucb
from striatum.bandit import linthompsamp
from striatum.bandit import exp4p
from striatum.bandit import exp3
from striatum.bandit.bandit import Action
from sklearn.naive_bayes import MultinomialNB
from sklearn.linear_model import LogisticRegression
from sklearn.multiclass import OneVsRestClassifier

# -*- coding: utf-8 -*-
"""
==============================
Contextual bandit on MovieLens
==============================

The script uses real-world data to conduct contextual bandit experiments. Here we use
MovieLens 10M Dataset, which is released by GroupLens at 1/2009. Please fist pre-process
datasets (use "movielens_preprocess.py"), and then you can run this example.
"""



def get_data():
    streaming_batch = pd.read_csv('streaming_batch.csv', sep='\t', names=['user_id'], engine='c')
    user_feature = pd.read_csv('user_feature.csv', sep='\t', header=0, index_col=0, engine='c')
    actions_id = list(pd.read_csv('actions.csv', sep='\t', header=0, engine='c')['movie_id'])
    reward_list = pd.read_csv('reward_list.csv', sep='\t', header=0, engine='c')
    action_context = pd.read_csv('action_context.csv', sep='\t', header=0, engine='c')

    actions = []
    for key in actions_id:

        action = Action(key)