Skip to content

Add KRVI_algo_final#2

Open
ayakayal wants to merge 3 commits into
masterfrom
KRVI_algo
Open

Add KRVI_algo_final#2
ayakayal wants to merge 3 commits into
masterfrom
KRVI_algo

Conversation

@ayakayal

Copy link
Copy Markdown
Collaborator

Added KRVI_algo_final.py and Ensured master remains clean by moving changes to this branch.

@ayakayal ayakayal requested a review from alexcmtk February 18, 2025 11:06

@alexcmtk alexcmtk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small changes. I'll review again once done.

Comment thread .gitignore
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
wandb/
*.csv

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not be great to ignore all csv and text files. While, yes, we do not submit data, typically, important information can be in this format sometimes. The preferred pattern is to ignore all txt, csv files in some nominated subfolder (e.g. where you keep your logs).

Comment thread KRVI_algo_final.py
state = np.array([state])
elif isinstance(state, np.ndarray):
# Ensure the state is a numpy array
state = state

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass is preferred

Comment thread KRVI_algo_final.py

if isinstance(state, dict):
# Extract the observation from the dictionary
state = state['observation']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other returns are np.ndarray but this doesn't have to be? return type is inconsistent.

Comment thread KRVI_algo_final.py
self.action_transformation = action_transformation
# File paths
self.csv_file = 'krvi_metrics.csv'
self.config_file = 'config.txt'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the txt file you're ignoring then it shouldn't be ignored.

Comment thread KRVI_algo_final.py
self.verbose = verbose
self.seed = seed
self.optim_botorch = optim_botorch
self.optimal_V = optimal_V

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this is optional but if it's only used for computing regret, it should not be here

Comment thread KRVI_algo_final.py
def train(self, T: int):

action_space = np.arange(self.env.action_space.n) # Assuming discrete action space

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace (final time - please remove throughout)

Comment thread KRVI_algo_final.py

for episode in range(T):
if self.verbose > 0:
print(f'Episode {episode}')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to print things, but it's better to log them. On top of the CSV all std output can be captured to a file (another file).

Comment thread KRVI_algo_final.py



def train(self, T: int):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is very long. It's usually a bad pattern. Can you extract some private methods? A good rule of thumb is that wherever you have a comment header in the body e.g. # Execute episode you should instead have a private method self._execute_episode instead. Aim to have no more than 10 lines per method like this.

Comment thread test_KRVI_algo_final.py
import gymnasium as gym
from gpytorch.kernels import ScaleKernel, RBFKernel
import numpy as np
def action_transformation(action_index):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space

Comment thread test_KRVI_algo_final.py

env=gym.make('FrozenLake-v1', desc=None, map_name="4x4", is_slippery=False)
env = FrozenLake2DStateWrapper(env, rescale=True)
optimal_V= None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I'm now convinced this is not needed, we shouldn't make it part of the algorithm? Which other predictive model or RL algorithm that you have seen takes the ground truth as part of the constructor, optional or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants