Skip to content

Commit

Permalink
Fixed minor bugs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-il-forte committed Feb 5, 2025
1 parent 2bc7612 commit 24fe268
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions tests/rl_utils/test_value_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import torch
import numpy as np
from mushroom_rl.policy import DeterministicPolicy
from mushroom_rl.environments.segway import Segway
from mushroom_rl.core import Core, Agent
Expand Down Expand Up @@ -49,7 +50,8 @@ def gae(V, s, ss, r, absorbing, last, gamma, lam):

def _value_functions_tester(test_fun, correct_fun, *args):
mdp = Segway()
V = Regressor(TorchApproximator, input_shape=mdp.info.observation_space.shape, output_shape=(1,), network=Net, loss=torch.nn.MSELoss(), optimizer={'class': torch.optim.Adam, 'params': {'lr': 0.001}})
V = Regressor(TorchApproximator, input_shape=mdp.info.observation_space.shape, output_shape=(1,),
network=Net, loss=torch.nn.MSELoss(), optimizer={'class': torch.optim.Adam, 'params': {'lr': 0.001}})

state, action, reward, next_state, absorbing, last = _get_episodes(mdp, 10)

Expand All @@ -68,7 +70,7 @@ def _value_functions_tester(test_fun, correct_fun, *args):
assert torch.allclose(adv, correct_adv)

def _get_episodes(mdp, n_episodes=100):
mu = torch.tensor([6.31154476, 3.32346271, 0.49648221]).unsqueeze(0)
mu = np.array([6.31154476, 3.32346271, 0.49648221])

approximator = Regressor(LinearApproximator,
input_shape=mdp.info.observation_space.shape,
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_numpy_split():
assert np.allclose(last, un_last)

def get_episodes(mdp, n_episodes=100):
mu = torch.tensor([6.31154476, 3.32346271, 0.49648221]).unsqueeze(0)
mu = np.array([6.31154476, 3.32346271, 0.49648221])

approximator = Regressor(LinearApproximator,
input_shape=mdp.info.observation_space.shape,
Expand Down

0 comments on commit 24fe268

Please sign in to comment.