From 250cfa4f16364673de5e4b8c8948779a1fe97e93 Mon Sep 17 00:00:00 2001 From: philomenec Date: Tue, 23 Jun 2020 18:23:19 +0200 Subject: [PATCH] fix landing page after a click --- recogym/envs/abstract.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/recogym/envs/abstract.py b/recogym/envs/abstract.py index 4d8a4de..420863a 100644 --- a/recogym/envs/abstract.py +++ b/recogym/envs/abstract.py @@ -102,11 +102,21 @@ def reset(self, user_id=0): # Record number of times each product seen for static policy calculation. self.organic_views = np.zeros(self.config.num_products) - def generate_organic_sessions(self): + def generate_organic_sessions(self, initial_product = None): # Initialize session. session = OrganicSessions() + if initial_product is not None : + # If a product is specified, use it as initial page for the organic session + session.next( + DefaultContext(self.current_time, self.current_user_id), + initial_product + ) + + # Update markov state. + self.update_state() + while self.state == organic: # Add next product view. self.update_product_view() @@ -179,10 +189,13 @@ def step(self, action_id): if reward == 1: self.state = organic # After a click, Organic Events always follow. - + initial_product = action_id + else : + initial_product = None + # Markov state dependent logic. if self.state == organic: - sessions = self.generate_organic_sessions() + sessions = self.generate_organic_sessions(initial_product) else: sessions = self.empty_sessions