--- title: RecSys RL Env keywords: fastai sidebar: home_sidebar summary: "OpenAI Gym's Box environment that simulates a recommendation system by picking item and giving feedback signals." description: "OpenAI Gym's Box environment that simulates a recommendation system by picking item and giving feedback signals." nb_path: "nbs/rl/envs/rl.envs.recsys.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

class Env[source]

Env(config, rating_matrix, dataset_name:str) :: Env

Environment for the recommender system https://github.com/openai/gym/blob/master/gym/core.py

{% endraw %} {% raw %}
{% endraw %} {% raw %}
class Config(object):
    action_size = 1
    state_size = 6
    env_n_components = 32
    saves_folder_path = './'
    env_tol = 1e-4
    env_max_iter = 1000
    env_alpha = 0.001
    total_group_num = 3
    history_length = 2
    rewards = [0, 1]
{% endraw %} {% raw %}
config = Config()
{% endraw %} {% raw %}
from scipy.sparse import coo_matrix

group_ids = np.array([1,1,1,2,2,3])
item_ids = np.array([1,2,3,2,3,1])
ratings = np.array([1,0,0,1,1,0])

rating_matrix = coo_matrix((ratings, (group_ids, item_ids)), shape=(4, 4)).tocsr()

env = Env(config=config, rating_matrix=rating_matrix, dataset_name='val')
Load environment: ./env_val_32.npy
{% endraw %} {% raw %}
state = env.reset()
state
[2, 2, 3]
{% endraw %} {% raw %}
new_state, reward, _, _ = env.step(0)
new_state, reward
([2, 2, 3], 0)
{% endraw %}