def setup_networks(self): z_dim = self.z_dim hidden_sizes = self.hidden_layers # define the neural networks used later in the model and the guide. # these networks are MLPs (multi-layered perceptrons or simple feed-forward networks) # where the provided activation parameter is used on every linear layer except # for the output layer where we use the provided output_activation parameter self.encoder_y = MLP( [self.input_size] + hidden_sizes + [self.output_size], activation=nn.Softplus, output_activation=nn.Softmax, allow_broadcast=self.allow_broadcast, use_cuda=self.use_cuda, ) # a split in the final layer's size is used for multiple outputs # and potentially applying separate activation functions on them # e.g. in this network the final output is of size [z_dim,z_dim] # to produce loc and scale, and apply different activations [None,Exp] on them self.encoder_z = MLP( [self.input_size + self.output_size] + hidden_sizes + [[z_dim, z_dim]], activation=nn.Softplus, output_activation=[None, Exp], allow_broadcast=self.allow_broadcast, use_cuda=self.use_cuda, ) self.decoder = MLP( [z_dim + self.output_size] + hidden_sizes + [self.input_size], activation=nn.Softplus, output_activation=nn.Sigmoid, allow_broadcast=self.allow_broadcast, use_cuda=self.use_cuda, ) # using GPUs for faster training of the networks if self.use_cuda: self.cuda()
def setup_networks(self): z_dim = self.z_dim hidden_sizes = self.hidden_layers # define the neural networks used later in the model and the guide. # these networks are MLPs (multi-layered perceptrons or simple feed-forward networks) # where the provided activation parameter is used on every linear layer except # for the output layer where we use the provided output_activation parameter # NOTE: we use a customized epsilon-scaled versions of Softmax and # Sigmoid operations for numerical stability self.encoder_y = MLP([self.input_size] + hidden_sizes + [self.output_size], activation=nn.Softplus, output_activation=ClippedSoftmax, epsilon_scale=self.epsilon_scale, use_cuda=self.use_cuda) # a split in the final layer's size is used for multiple outputs # and potentially applying separate activation functions on them # e.g. in this network the final output is of size [z_dim,z_dim] # to produce mu and sigma, and apply different activations [None,Exp] on them self.encoder_z = MLP([self.input_size + self.output_size] + hidden_sizes + [[z_dim, z_dim]], activation=nn.Softplus, output_activation=[None, Exp], use_cuda=self.use_cuda) self.decoder = MLP([z_dim + self.output_size] + hidden_sizes + [self.input_size], activation=nn.Softplus, output_activation=ClippedSigmoid, epsilon_scale=self.epsilon_scale, use_cuda=self.use_cuda) # using GPUs for faster training of the networks if self.use_cuda: self.cuda()