import numpy as np

class BanditChoiceExploit(object):
    def __init__(self):
        pass
        
    def evaluate(self, posteriorMatrix, legalItemVector, ratingMatrixForUser=None):

        user_indices = np.array(range(len(legalItemVector)))
        user_indices = user_indices[legalItemVector == 1]
        user_ratings = posteriorMatrix[:,user_indices]

        itemIndex = self.get_sample(user_ratings, user_indices)

        return itemIndex

    def get_sample(self, user_ratings, user_indices):
        '''
        Select item with the largest mean
        '''

        mean_ratings = np.mean(user_ratings,axis=0)
        idx = np.argmax(mean_ratings)
        selected_item = user_indices[idx]

        return selected_item


import numpy as np

class BanditChoiceExploit(object):
    def __init__(self):
        pass
        
    def evaluate(self, posteriorMatrix, legalItemVector, ratingMatrixForUser=None):

        user_indices = np.array(range(len(legalItemVector)))
        user_indices = user_indices[legalItemVector == 1]
        user_ratings = posteriorMatrix[:,user_indices]

        itemIndex = self.get_sample(user_ratings, user_indices)

        return itemIndex

    def get_sample(self, user_ratings, user_indices):
        '''
        Select item with the largest mean
        '''

        mean_ratings = np.mean(user_ratings,axis=0)
        idx = np.argmax(mean_ratings)
        selected_item = user_indices[idx]

        return selected_item


Select item with the largest mean