def __init__(self, inputs): self.control_force_spacing = F_max/self.num_of_control_resolution_oneside super(DQN_measurement, self).__init__() self.inputs=inputs self.Batch_Normalize = False k1 = 13; s1 = 5 k2 = 11; s2 = 4 k3 = 9; s3 = 4 filters = (32, 64, 64) self.conv1=nn.Conv1d(2, filters[0], kernel_size = k1, stride = s1, padding = 0, bias = not self.Batch_Normalize) if self.Batch_Normalize: self.bn1=layers.BatchRenorm1d(filters[0]) self.conv2=nn.Conv1d(filters[0], filters[1], kernel_size = k2, stride = s2, padding = 0, bias = not self.Batch_Normalize) if self.Batch_Normalize: self.bn2=layers.BatchRenorm1d(filters[1]) self.conv3=nn.Conv1d(filters[1], filters[2], kernel_size = k3, stride = s3, padding = 0, bias = not self.Batch_Normalize) if self.Batch_Normalize: self.bn3=layers.BatchRenorm1d(filters[2]) if not self.Batch_Normalize: for conv in [self.conv1, self.conv2, self.conv3]: conv.bias.data.zero_() def calculate_next_layer_dim(number, k, s): return (number-(k-1)+(s-1)) // s number = calculate_next_layer_dim(inputs, k1, s1) number = calculate_next_layer_dim(number, k2, s2) number = calculate_next_layer_dim(number, k3, s3) self.fc1=nn.Linear(number * filters[2], 256) self.fc21=layers.FactorizedNoisy(256, 256) self.fc31=layers.FactorizedNoisy(256, self.num_of_control_resolution_oneside*2 + 1) # left and right means doubling, 1 extra for no control self.fc22=layers.Linear_weight_normalize(256, 128) self.fc32=layers.Linear_weight_normalize(128, 1) # and 1 for mean prediction print(' + Number of params: {}'.format(sum([p.data.nelement() for p in self.parameters()])))
def __init__(self, data_length, noisy_layers = 2): self.control_force_spacing = F_max/self.num_of_control_resolution_oneside super(direct_DQN, self).__init__() self.inputs={'data_length':data_length, 'noisy_layers':noisy_layers} self.fc1=layers.Linear_weight_normalize(data_length, 512) self.fc2=layers.Linear_weight_normalize(512, 512) if noisy_layers >= 2: self.fc31=layers.FactorizedNoisy(512, 256) else: self.fc31=layers.Linear_weight_normalize(512, 256) self.fc32=layers.Linear_weight_normalize(512, 128) if noisy_layers >= 1: self.fc41=layers.FactorizedNoisy(256, self.num_of_control_resolution_oneside*2 + 1) # left and right, and 1 extra for no control else: self.fc41=layers.Linear_weight_normalize(256, self.num_of_control_resolution_oneside*2 + 1) self.fc42=layers.Linear_weight_normalize(128, 1) # mean prediction print(' + Number of params: {}'.format(sum([p.data.nelement() for p in self.parameters()])))