def create(self, architecture: Architecture, metadata: Metadata, arguments: Configuration) -> Any: # create the input layer input_layer = self.create_input_layer(architecture, metadata, arguments) # wrap the input layer with the special gain input layer (to receive the mask) input_layer = GAINInputLayer(input_layer, metadata.get_num_features()) # create the hidden layers factory hidden_layers_factory = self.create_other( "HiddenLayers", architecture, metadata, arguments.get("hidden_layers", {})) # create the output layer factory # this is different from a normal discriminator # because the output has the size of the input # it predicts if each feature is real or fake output_layer_factory = SingleOutputLayerFactory( metadata.get_num_features(), activation=Sigmoid()) # create the encoder return FeedForward(input_layer, hidden_layers_factory, output_layer_factory, default_hidden_activation=Tanh())
def create_input_layer(self, architecture: Architecture, metadata: Metadata, arguments: Configuration) -> InputLayer: # override the input layer size return self.create_other( "SingleInputLayer", architecture, metadata, Configuration({"input_size": metadata.get_num_features()}))
def create_output_layer_factory( self, architecture: Architecture, metadata: Metadata, arguments: Configuration) -> OutputLayerFactory: # override the output layer size output_layer_configuration = { "output_size": metadata.get_num_features() } # copy activation arguments only if defined if "output_layer" in arguments and "activation" in arguments.output_layer: output_layer_configuration[ "activation"] = arguments.output_layer.activation # create the output layer factory return self.create_other("SingleOutputLayer", architecture, metadata, Configuration(output_layer_configuration))
def create(self, architecture: Architecture, metadata: Metadata, arguments: Configuration) -> Any: # create input layer input_layer_configuration = {} if self.code: input_layer_configuration[ "input_size"] = architecture.arguments.code_size else: input_layer_configuration[ "input_size"] = metadata.get_num_features() input_layer = self.create_other( "SingleInputLayer", architecture, metadata, Configuration(input_layer_configuration)) # conditional if "conditional" in architecture.arguments: # wrap the input layer with a conditional layer input_layer = ConditionalLayer( input_layer, metadata, **architecture.arguments.conditional) # mini-batch averaging if arguments.get("mini_batch_averaging", False): input_layer = MiniBatchAveraging(input_layer) # create the hidden layers factory hidden_layers_factory = self.create_other( "HiddenLayers", architecture, metadata, arguments.get("hidden_layers", {})) # create the output activation if self.critic: output_activation = View(-1) else: output_activation = Sequential(Sigmoid(), View(-1)) # create the output layer factory output_layer_factory = SingleOutputLayerFactory( 1, activation=output_activation) # create the discriminator return FeedForward(input_layer, hidden_layers_factory, output_layer_factory, default_hidden_activation=LeakyReLU(0.2))
def create(self, architecture: Architecture, metadata: Metadata, arguments: Configuration) -> Any: # create the input layer input_layer = self.create_input_layer(architecture, metadata, arguments) # wrap the input layer with the special gain input layer (to receive the mask) input_layer = GAINInputLayer(input_layer, metadata.get_num_features()) # create the hidden layers factory hidden_layers_factory = self.create_other( "HiddenLayers", architecture, metadata, arguments.get("hidden_layers", {})) # create the output layer factory output_layer_factory = self.create_output_layer_factory( architecture, metadata, arguments) # create the encoder return FeedForward(input_layer, hidden_layers_factory, output_layer_factory, default_hidden_activation=Tanh())