I work on DQN with 12 agents in my environment. At the same time, each agent has a different state and is supposed to take a different action. But when I try to send all 12 states at the same time to the DQN algorithm, I always get 12 identical actions.
import torch as T
import torch.nn as nn
class DeepQNetwork(nn.Module):
def __init__(self,lr):
super(DeepQNetwork, self).__init__()
self.device = T.device('cuda:0' if T.cuda.is_available() else 'cpu')
self.to(self.device)
self.fc1 = nn.Linear(1,64)
self.fc2 = nn.Linear(64,32)
self.fc3 = nn.Linear(32,3)
def forward(self,state):
x = F.relu(self.fc1(state))
x = F.relu(self.fc2(x))
actions = self.fc3(x)
return actions
the state_ looks like [1,2,3,2,2,3,1,2,3,1,1,3] #It indicates the cluster's number in witch the agent is currently located. an example of expected actions [0,2,1,2,1,0,2,1,1,0,0,2]. #It indicates the cluster's number the agent will be joining.
class agent():
def __init__(self):
self.Q_eval = DeepQNetwork(lr)
def choose_action(self,state_ ):
if np.random.random() < self.epsilon:
action = randomchoice() #a manual function that chooses 12 actions randomly
else:
action = []
state_ = ListToTensor(state_ ) #a manual function to transform the list of states to a tensor
state = T.tensor([state_ ]).to(agent.Q_eval.device)
for i in range(12):
actions = agent.Q_eval.forward(state[i])
action.append(T.argmax(actions).item())
I have little knowledge of machine learning so any help or guidance would be helpful to me. Thanks in advance.