Skip to content

Commit

Permalink
Bug-fix: "convolutions": len(network["channels"]) - 1 instead of `-…
Browse files Browse the repository at this point in the history
… len(network["nodes"])`.
  • Loading branch information
hallvardnmbu committed Mar 13, 2024
1 parent df6ebee commit 8b8f9af
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
10 changes: 2 additions & 8 deletions breakout/DQN.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __init__(self,
"discount": other.get("discount", 0.99),
"gamma": other.get("gamma", 0.95),

"convolutions": len(network["channels"]) - len(network.get("nodes", [])),
"convolutions": len(network["channels"]) - 1,

"optimizer": optimizer["optimizer"](self.parameters(), lr=optimizer["lr"],
**optimizer.get("hyperparameters", {}))
Expand Down Expand Up @@ -250,12 +250,6 @@ def preprocess(self, state):
-------
output : torch.Tensor
"""
# state = (torch.tensor(state,
# dtype=torch.float32).view(self.shape["original"]) /
# torch.tensor(255,
# dtype=torch.float32))[:, :, self.shape["height"], self.shape["width"]]
# state = torch.nn.functional.max_pool2d(state, self.shape["max_pooling"])

state = torch.tensor(state, dtype=torch.float32).view(self.shape["original"])
state = state[:, :, self.shape["height"], self.shape["width"]] / 255.0

Expand Down Expand Up @@ -396,7 +390,7 @@ def learn(self, network, clamp=None):
# BACKPROPAGATION
# --------------------------------------------------------------------------------------

loss = torch.nn.functional.huber_loss(actual, optimal, reduction="mean")
loss = torch.nn.functional.mse_loss(actual, optimal)

self.parameter["optimizer"].zero_grad()
loss.backward()
Expand Down
4 changes: 3 additions & 1 deletion enduro/DQN.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self,
Kernel size for each layer.
channels : list, optional
Number of channels for each hidden layer.
nodes : list of int, optional
Number of nodes in fully-connected layer(s).
optimizer : dict
Contains the optimizer for the model and its hyperparameters. The dictionary must
contain the following keys:
Expand Down Expand Up @@ -174,7 +176,7 @@ def __init__(self,
"discount": other.get("discount", 0.99),
"gamma": other.get("gamma", 0.95),

"convolutions": len(network["channels"]) - len(network.get("nodes", [])),
"convolutions": len(network["channels"]) - 1,

"optimizer": optimizer["optimizer"](self.parameters(), lr=optimizer["lr"],
**optimizer.get("hyperparameters", {}))
Expand Down
2 changes: 1 addition & 1 deletion tetris/DQN.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __init__(self,
"discount": other.get("discount", 0.99),
"gamma": other.get("gamma", 0.95),

"convolutions": len(network["channels"]) - len(network.get("nodes", [])),
"convolutions": len(network["channels"]) - 1,

"optimizer": optimizer["optimizer"](self.parameters(), lr=optimizer["lr"],
**optimizer.get("hyperparameters", {}))
Expand Down

0 comments on commit 8b8f9af

Please sign in to comment.