@@ -46,7 +46,7 @@ def store_q_table(self, strpath, filename):
4646 # path.join(path.dirname(path.abspath(__file__)), "logs")
4747 if not path .exists (strpath ):
4848 makedirs (strpath )
49- with open (filename , "wb" ) as f :
49+ with open (strpath + filename , "wb" ) as f :
5050 data = {"q_table" :self .q_values , "state_mapping" : self ._str_to_id }
5151 pickle .dump (data , f )
5252
@@ -236,6 +236,7 @@ def play_game(self, concept_observation, episode_num, testing=False):
236236 parser .add_argument ("--gamma" , help = "Sets gamma discount for Q-learing during training." , default = 0.9 , type = float )
237237 parser .add_argument ("--alpha" , help = "Sets alpha for learning rate during training." , default = 0.1 , type = float )
238238 parser .add_argument ("--logdir" , help = "Folder to store logs" , default = path .join (path .dirname (path .abspath (__file__ )), "logs" ))
239+ parser .add_argument ("--models_dir" , help = "Folder to store models" , default = path .join (path .dirname (path .abspath (__file__ )), "models" ))
239240 parser .add_argument ("--previous_model" , help = "Load the previous model. If training, it will start from here. If testing, will use to test." , type = str )
240241 parser .add_argument ("--testing" , help = "Test the agent. No train." , default = False , type = bool )
241242 parser .add_argument ("--experiment_id" , help = "Id of the experiment to record into Mlflow." , default = '' , type = str )
@@ -492,7 +493,7 @@ def play_game(self, concept_observation, episode_num, testing=False):
492493 # Store the model every --eval_each episodes.
493494 # Use episode (training counter) and not test_episode (test counter)
494495 if episode % args .store_models_every == 0 and episode != 0 :
495- agent .store_q_table (path . join ( path . dirname ( path . abspath ( __file__ )), "models/" ) , f'conceptual_q_agent.experiment{ args .experiment_id } -episodes-{ episode } .pickle' )
496+ agent .store_q_table (args . models_dir , f'conceptual_q_agent.experiment{ args .experiment_id } -episodes-{ episode } .pickle' )
496497
497498 text = f'''Tested for { test_episode } episodes after { episode } training episode.
498499 Wins={ test_wins } ,
@@ -552,8 +553,8 @@ def play_game(self, concept_observation, episode_num, testing=False):
552553 except KeyboardInterrupt :
553554 # Store the q-table
554555 if not args .testing :
555- agent .store_q_table (path . join ( path . dirname ( path . abspath ( __file__ )), "models/" ) , f'conceptual_q_agent.experiment{ args .experiment_id } -episodes-{ episode } .pickle' )
556+ agent .store_q_table (args . models_dir , f'conceptual_q_agent.experiment{ args .experiment_id } -episodes-{ episode } .pickle' )
556557 finally :
557558 # Store the q-table
558559 if not args .testing :
559- agent .store_q_table (path . join ( path . dirname ( path . abspath ( __file__ )), "models/" ) , f'conceptual_q_agent.experiment{ args .experiment_id } -episodes-{ episode } .pickle' )
560+ agent .store_q_table (args . models_dir , f'conceptual_q_agent.experiment{ args .experiment_id } -episodes-{ episode } .pickle' )
0 commit comments