def __init__(self, n_observables, n_hidden, activation="tanh", dropout_prob=0.0): super(DenseComponentRatioModel, self).__init__() # Save input self.n_hidden = n_hidden self.activation = get_activation_function(activation) self.dropout_prob = dropout_prob # Build network self.layers = nn.ModuleList() n_last = n_observables # Hidden layers for n_hidden_units in n_hidden: if self.dropout_prob > 1.0e-9: self.layers.append(nn.Dropout(self.dropout_prob)) self.layers.append(nn.Linear(n_last, n_hidden_units)) n_last = n_hidden_units # Log r layer if self.dropout_prob > 1.0e-9: self.layers.append(nn.Dropout(self.dropout_prob)) self.layers.append(nn.Linear(n_last, 1))
def __init__( self, components, morphing_matrix, n_observables, n_parameters, n_hidden, activation="tanh", dropout_prob=0.0, clamp_component_ratios=5.0, ): super().__init__() # Save input self.n_hidden = n_hidden self.activation = get_activation_function(activation) self.dropout_prob = dropout_prob self.n_components, self.n_parameters = components.shape self.clamp_component_ratios = clamp_component_ratios # Morphing setup self.register_buffer("components", torch.tensor(components)) self.register_buffer("morphing_matrix", torch.tensor(morphing_matrix)) logger.debug("Loaded morphing matrix into PyTorch model:\n %s", morphing_matrix) # Build networks for all components self.dsigma_component_estimators = nn.ModuleList() for _ in range(self.n_components): self.dsigma_component_estimators.append( DenseComponentRatioModel(n_observables, n_hidden, activation, dropout_prob) ) self.log_sigma_ratio_components = torch.nn.Parameter(torch.zeros((self.n_components, 1))) # (n_components, 1)
def __init__( self, n_conditionals, n_inputs, n_hiddens, activation="relu", input_order="sequential", mode="sequential", ): super().__init__(n_conditionals, n_inputs) # save input arguments self.activation = activation self.n_conditionals = n_conditionals self.n_inputs = n_inputs self.n_hiddens = n_hiddens self.mode = mode # create network's parameters self.degrees = create_degrees(n_inputs, n_hiddens, input_order, mode) self.Ms, self.Mmp = create_masks(self.degrees) self.Wx, self.Ws, self.bs, self.Wm, self.bm, self.Wp, self.bp = create_weights_conditional( n_conditionals, n_inputs, n_hiddens, None ) self.input_order = self.degrees[0] self.activation_function = get_activation_function(activation) # Output info. TODO: make these not properties of self self.m = None self.logp = None # Dtype and GPU / CPU management self.to_args = None self.to_kwargs = None
def __init__(self, n_inputs, n_hiddens, activation="relu", input_order="sequential", mode="sequential"): super(GaussianMADE, self).__init__(n_inputs) # save input arguments self.activation = activation self.n_inputs = n_inputs self.n_hiddens = n_hiddens self.mode = mode # create network's parameters self.degrees = create_degrees(n_inputs, n_hiddens, input_order, mode) self.Ms, self.Mmp = create_masks(self.degrees) self.Ws, self.bs, self.Wm, self.bm, self.Wp, self.bp = create_weights( n_inputs, n_hiddens, None) self.input_order = self.degrees[0] self.activation_function = get_activation_function(activation) # Output info self.m = None self.logp = None # Dtype and GPU / CPU management self.to_args = None self.to_kwargs = None
def __init__(self, n_observables, n_parameters, n_hidden, activation="tanh", dropout_prob=0.0): super().__init__() assert n_parameters == 1 # Save input self.n_hidden = n_hidden self.activation = get_activation_function(activation) self.dropout_prob = dropout_prob # Build networks for all components self.dsigma_a = DenseComponentRatioModel(n_observables, n_hidden, activation, dropout_prob) self.dsigma_b = DenseComponentRatioModel(n_observables, n_hidden, activation, dropout_prob) self.sigma_a = torch.nn.Parameter(torch.ones((1,))) self.sigma_b = torch.nn.Parameter(torch.ones((1,)))
def __init__( self, n_conditionals, n_inputs, n_hiddens, n_components=10, activation="relu", input_order="sequential", mode="sequential", ): super(ConditionalMixtureMADE, self).__init__(n_conditionals, n_inputs) # save input arguments self.activation = activation self.n_conditionals = n_conditionals self.n_inputs = n_inputs self.n_hiddens = n_hiddens self.mode = mode self.n_components = n_components # create network's parameters self.degrees = create_degrees(n_inputs, n_hiddens, input_order, mode) self.Ms, self.Mmp = create_masks(self.degrees) logger.debug("Mmp shape: %s", self.Mmp.shape) (self.Wx, self.Ws, self.bs, self.Wm, self.bm, self.Wp, self.bp, self.Wa, self.ba) = create_weights_conditional(n_conditionals, n_inputs, n_hiddens, n_components) self.input_order = self.degrees[0] # Shaping things self.Mmp = self.Mmp.unsqueeze(2) self.ba.data = self.ba.data.unsqueeze(0) self.bp.data = self.bp.data.unsqueeze(0) self.bm.data = self.bm.data.unsqueeze(0) self.activation_function = get_activation_function(activation) # Output info. TODO: make these not properties of self self.m = None self.logp = None self.loga = None # Dtype and GPU / CPU management self.to_args = None self.to_kwargs = None
def __init__(self, n_observables, n_parameters, n_hidden, activation="tanh"): super(LocalScoreEstimator, self).__init__() # Save input self.n_hidden = n_hidden self.activation = get_activation_function(activation) # Build network self.layers = nn.ModuleList() n_last = n_observables # Hidden layers for n_hidden_units in n_hidden: self.layers.append(nn.Linear(n_last, n_hidden_units)) n_last = n_hidden_units # Log r layer self.layers.append(nn.Linear(n_last, n_parameters))
def __init__(self, n_observables, n_parameters, n_hidden, activation="tanh"): super(DenseSingleParameterizedRatioModel, self).__init__() # Save input self.n_hidden = n_hidden self.activation = get_activation_function(activation) # Build network self.layers = nn.ModuleList() n_last = n_observables + n_parameters # Hidden layers for n_hidden_units in n_hidden: self.layers.append(nn.Linear(n_last, n_hidden_units)) n_last = n_hidden_units # Log r layer self.layers.append(nn.Linear(n_last, 1))
def __init__( self, components, morphing_matrix, n_observables, n_parameters, n_hidden, activation="tanh", dropout_prob=0.0 ): super(DenseMorphingAwareRatioModel, self).__init__() # Save input self.n_hidden = n_hidden self.activation = get_activation_function(activation) self.dropout_prob = dropout_prob self.n_components, self.n_parameters = components.shape # Morphing setup self.components = torch.tensor(components) self.morphing_matrix = torch.tensor(morphing_matrix) logger.debug("Loaded morphing matrix into PyTorch model:\n %s", morphing_matrix) # Build networks for all components self.component_estimators = nn.ModuleList() for _ in range(self.n_components): self.component_estimators.append( DenseComponentRatioModel(n_observables, n_hidden, activation, dropout_prob) )