def _init_params_nets(self): self.arguments_networks = {} self.arguments_dict = {} for a in self.action_dict: action = self.all_actions[self.action_dict[a]] args = action.args for arg in args: self.arguments_dict[ arg.name] = arg.id # store 'name':id pairs for future use if debug: print('\narg.name: ', arg.name) size = self.all_arguments[arg.id].sizes if debug: print('size: ', size) if len(size) == 1: if debug: print("Init CategoricalNet for " + arg.name + ' argument') self.arguments_networks[arg.name] = net.CategoricalNet( self.net.n_features, size[0]) else: if debug: print("Init SpatialNet for " + arg.name + ' argument') self.arguments_networks[arg.name] = net.SpatialNet( self.net.n_features, size) return
def __init__(self, action_space, env, n_layers, linear_size, in_channels, n_channels, **non_spatial_HPs): """ Parameters ---------- action_space: int Number of (discrete) possible actions to take map_size: int If input is (batch_dim, n_channels, linear_size, linear_size), then map_size = linear_size - 2 env: int Instance of the environment **net_args: dict (optional) Dictionary of {'key':value} pairs valid for OheNet """ super(SpatialActor, self).__init__() # Environment-related attributes self.action_dict = {0: _NO_OP, 1: _SELECT_ARMY, 2: _MOVE_SCREEN} self.screen_res = env.observation_spec()[0]['feature_screen'][1:] self.all_actions = env.action_spec()[0][1] self.all_arguments = env.action_spec()[0][0] # Useful HyperParameters as attributes self.n_channels = n_channels # Networks self.spatial_features_net = net.SpatialFeatures( n_layers, linear_size, in_channels, n_channels) self.nonspatial_features_net = net.NonSpatialFeatures( linear_size, n_channels, **non_spatial_HPs) self.linear = nn.Linear(n_channels, action_space) self._init_params_nets()
def __init__(self, n_layers, linear_size, in_channels, n_channels, **non_spatial_HPs): """ Parameters ---------- map_size: int If input is (batch_dim, n_channels, linear_size, linear_size), then map_size = linear_size - 2 **net_args: dict (optional) Dictionary of {'key':value} pairs valid for OheNet """ super(SpatialBasicCritic, self).__init__() self.net = nn.Sequential( net.SpatialFeatures(n_layers, linear_size, in_channels, n_channels), net.NonSpatialFeatures(linear_size, n_channels, **non_spatial_HPs), nn.Linear(n_channels, 1))
def __init__(self, map_size, **net_args): """ Parameters ---------- map_size: int If input is (batch_dim, n_channels, linear_size, linear_size), then map_size = linear_size - 2 **net_args: dict (optional) Dictionary of {'key':value} pairs valid for OheNet """ super(OheBasicCritic, self).__init__() self.net = net.OheNet(map_size, **net_args) self.linear = nn.Linear(self.net.n_features, 1)
def __init__(self, action_space, map_size, **net_args): """ Parameters ---------- action_space: int Number of (discrete) possible actions to take map_size: int If input is (batch_dim, n_channels, linear_size, linear_size), then map_size = linear_size - 2 **net_args: dict (optional) Dictionary of {'key':value} pairs valid for OheNet """ super(OheActor, self).__init__() self.action_dict = {0: _NO_OP, 1: _SELECT_ARMY, 2: _MOVE_SCREEN} self.net = net.OheNet(map_size, **net_args) self.linear = nn.Linear(self.net.n_features, action_space)