52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
import torch
|
|
import torch.nn as nn
|
|
|
|
N_VEL = 2
|
|
N_SUB = 2
|
|
state_dim = N_VEL * N_SUB
|
|
num_actions = 2 ** (N_SUB * N_VEL)
|
|
M = 16
|
|
|
|
|
|
class Net(nn.Module):
|
|
def __init__(self, n_input_channels, n_actions):
|
|
## input channels 是数据的输入的维度
|
|
## 每个状态是一个
|
|
## N * N * (M_c + 1)的tensor
|
|
## 其中 N * N 代表的是用户的数量 如果有1000个用户 大概为32
|
|
## 第M_c个matrix代表的是当前用户的申请或是离开
|
|
super(Net, self).__init__()
|
|
self.conv1 = nn.Conv2d(in_channels=n_input_channels, out_channels=16, kernel_size=5, stride=1, padding=0)
|
|
self.conv2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, stride=1, padding=0)
|
|
self.fc1 = nn.Linear(in_features=4 * 4 * 32, out_features=512)
|
|
self.fc2 = nn.Linear(in_features=512, out_features=512)
|
|
self.fc3 = nn.Linear(in_features=512, out_features=n_actions)
|
|
# nn.init.normal_(self.fc1.weight, 0., 0.1)
|
|
# nn.init.constant_(self.fc1.bias, 0.1)
|
|
# self.fc2 = nn.Linear(500, 300)
|
|
# nn.init.normal_(self.fc2.weight, 0., 0.1)
|
|
# nn.init.constant_(self.fc2.bias, 0.1)
|
|
# self.fc3 = nn.Linear(300, 250)
|
|
# nn.init.normal_(self.fc3.weight, 0., 0.1)
|
|
# nn.init.constant_(self.fc3.bias, 0.1)
|
|
# self.fc4 = nn.Linear(250, n_actions)
|
|
# nn.init.normal_(self.fc4.weight, 0., 0.1)
|
|
# nn.init.constant_(self.fc4.bias, 0.1)
|
|
|
|
def forward(self, x):
|
|
x = torch.sigmoid(self.conv1(x))
|
|
x = torch.sigmoid(self.conv2(x))
|
|
x = x.view(x.size(0), -1)
|
|
x = torch.sigmoid(self.fc1(x))
|
|
x = torch.sigmoid(self.fc2(x))
|
|
output = self.fc3(x)
|
|
return output
|
|
|
|
|
|
if __name__ == "__main__":
|
|
input_channels = 10 * 10 * 16
|
|
num_actions = 16
|
|
q_network = Net(input_channels, num_actions)
|
|
|
|
print(q_network)
|