Neural network 多输出层神经网络的监督学习训练
我有一个神经网络,它有多个输出层,根据我的代理所处的状态来确定softmax概率。以下是我的网络示例:Neural network 多输出层神经网络的监督学习训练,neural-network,pytorch,supervised-learning,Neural Network,Pytorch,Supervised Learning,我有一个神经网络,它有多个输出层,根据我的代理所处的状态来确定softmax概率。以下是我的网络示例: class policy(nn.Module): def __init__(self): hidden_layer = 32 super(policy, self).__init__() self.affine1 = nn.Linear(3, hidden_layer) self.affine2 = nn.Linear(hidden_lay
class policy(nn.Module):
def __init__(self):
hidden_layer = 32
super(policy, self).__init__()
self.affine1 = nn.Linear(3, hidden_layer)
self.affine2 = nn.Linear(hidden_layer, hidden_layer)
self.output1 = nn.Linear(hidden_layer, 10)
self.output2 = nn.Linear(hidden_layer, 5)
self.output3 = nn.Linear(hidden_layer, 3)
def forward(self, x):
x = torch.nn.functional.relu(self.affine1(x))
x = torch.nn.functional.relu(self.affine2(x))
outputprobs1 = torch.nn.functional.softmax(self.output1(x), dim=-1)
outputprobs2 = torch.nn.functional.softmax(self.output2(x), dim=-1)
outputprobs3 = torch.nn.functional.softmax(self.output3(x), dim=-1)
return outputprobs1, outputprobs2, outputprobs3
softmax概率表示我的代理将执行的某个操作,但该代理基于不同的状态有不同的操作。因为我知道我的代理应该执行哪些操作,所以我希望通过监督学习来培训策略。我计划使用torch.nn.CrossEntropyLoss(),因为这是一个多分类问题。此外,在每个事件中,模型多次从输出概率中进行选择
例如,假设我的代理可以处于3种状态:A、B和C。在状态A中,代理使用output1,在状态B中,代理使用output2,在状态C中,代理使用output3。因此,一个插曲中的一个例子可能是:
- 代理在状态A下启动:选择操作9
- 现在代理处于状态C:选择操作2
- 现在代理处于状态B:选择操作4
- 现在代理处于状态A:选择操作5
torch.logit(outputprobs1)?
非常感谢您的帮助,谢谢