Creates model latent variables

        Returns
        ----------
        None (changes model attributes)
976714
def _create_latent_variables(self):
        

        for parm in range(self.z_no):
            self.latent_variables.add_z('Scale ' + self.X_names[parm], fam.Flat(transform='exp'), fam.Normal(0, 3))
            self.latent_variables.z_list[parm].start = -5.0
        self.z_no = len(self.latent_variables.z_list)
1122746
def get_cond_latents_at_level(cond_latents, level, hparams):
  """"""
  if cond_latents:
    if hparams.latent_dist_encoder in ["conv_net", "conv3d_net"]:
      return [cond_latent[level] for cond_latent in cond_latents]
    elif hparams.latent_dist_encoder in ["pointwise", "conv_lstm"]:
      return cond_latents[level]
1208002
def create(self, _attributes=None, **attributes):
        
        if _attributes is not None:
            attributes.update(_attributes)

        instance = self._related.new_instance(attributes)

        instance.set_attribute(self.get_plain_foreign_key(), self.get_parent_key())

        instance.save()

        return instance
148365
def _create_variable(orig_v, step, variables):
    
    # get current variable, and convert to be the output of our process step
    try:
        v = _get_variable(orig_v["id"], variables)
    except ValueError:
        v = copy.deepcopy(orig_v)
        if not isinstance(v["id"], six.string_types):
            v["id"] = _get_string_vid(v["id"])
    for key, val in orig_v.items():
        if key not in ["id", "type"]:
            v[key] = val
    if orig_v.get("type") != "null":
        v["type"] = orig_v["type"]
    v["id"] = "%s/%s" % (step.name, get_base_id(v["id"]))
    return v
123930
def make_var(self, op_name, name, shape):
        ''''''
        if op_name in self.weights and name in self.weights[op_name]:
            if self.verbose:
                print("Using: {} {}".format(op_name, name))
            initializer = tf.constant(self.weights[op_name][name], shape=shape)
            return tf.get_variable(name, initializer=initializer, trainable=self.trainable)
        return tf.get_variable(name, shape, trainable=self.trainable)
1325702
def attributes(self, source=None, relation=None, target=None):
        
        attrmatch = lambda a: (
            (source is None or source == a.source) and
            (relation is None or relation == a.relation) and
            (target is None or target == a.target)
        )
        variables = self.variables()
        attrs = [t for t in self.triples() if t.target not in variables]
        return list(filter(attrmatch, attrs))
1095263
def build_model(self, n_features, n_classes):
        
        self._create_placeholders(n_features, n_classes)
        self._create_variables(n_features)

        next_train = self._create_encoding_layers()
        self.mod_y, _, _ = Layers.linear(next_train, n_classes)
        self.layer_nodes.append(self.mod_y)

        self.cost = self.loss.compile(self.mod_y, self.input_labels)
        self.train_step = self.trainer.compile(self.cost)
        self.accuracy = Evaluation.accuracy(self.mod_y, self.input_labels)
343214
def build_variables(self, variable_placeholders):
        
        variables = self.__substitute_names_in_list(variable_placeholders)
        attributes = {}
        for i, variable in enumerate(variables):
            placeholder_name = variable_placeholders[i]
            try:
                vertices = self.g.vs.select(name=variable)
                attributes[placeholder_name] = vertices[0].attributes()
            except:
                pass
        for i, variable in enumerate(variables):
            placeholder_name = variable_placeholders[i]
            try:
                edges = self.g.es.select(name=variable)
                edge_attr = edges[0].attributes()
                attributes[placeholder_name] = edge_attr
            except:
                pass
        for i, variable in enumerate(variables):
            placeholder_name = variable_placeholders[i]
            try:
                attributes[placeholder_name] = self.match_info[placeholder_name]
            except:
                pass
        return attributes
732854
def create(self, **kwargs):
        
        model = self.new(**kwargs)
        return self.save(model)
1305626
def _initialize(self, no_components, no_item_features, no_user_features):
        

        # Initialise item features.
        self.item_embeddings = (
            (self.random_state.rand(no_item_features, no_components) - 0.5)
            / no_components
        ).astype(np.float32)
        self.item_embedding_gradients = np.zeros_like(self.item_embeddings)
        self.item_embedding_momentum = np.zeros_like(self.item_embeddings)
        self.item_biases = np.zeros(no_item_features, dtype=np.float32)
        self.item_bias_gradients = np.zeros_like(self.item_biases)
        self.item_bias_momentum = np.zeros_like(self.item_biases)

        # Initialise user features.
        self.user_embeddings = (
            (self.random_state.rand(no_user_features, no_components) - 0.5)
            / no_components
        ).astype(np.float32)
        self.user_embedding_gradients = np.zeros_like(self.user_embeddings)
        self.user_embedding_momentum = np.zeros_like(self.user_embeddings)
        self.user_biases = np.zeros(no_user_features, dtype=np.float32)
        self.user_bias_gradients = np.zeros_like(self.user_biases)
        self.user_bias_momentum = np.zeros_like(self.user_biases)

        if self.learning_schedule == "adagrad":
            self.item_embedding_gradients += 1
            self.item_bias_gradients += 1
            self.user_embedding_gradients += 1
            self.user_bias_gradients += 1
862104
def create_attributes(klass, attributes, previous_object=None):
        

        if 'fields' not in attributes:
            if previous_object is None:
                attributes['fields'] = {}
            else:
                attributes['fields'] = previous_object.to_json()['fields']
        return {'fields': attributes['fields']}
1056049
def create_model_instance(self, data):
        
        return self.model(
            session_key=self._get_or_create_session_key(),
            session_data=self.encode(data),
            expire_date=self.get_expiry_date(),
        )
189547
def _create_peephole_variables(self, dtype):
    """"""
    self._w_f_diag = tf.get_variable(
        self.W_F_DIAG,
        shape=[self._hidden_size],
        dtype=dtype,
        initializer=self._initializers.get(self.W_F_DIAG),
        partitioner=self._partitioners.get(self.W_F_DIAG),
        regularizer=self._regularizers.get(self.W_F_DIAG))
    self._w_i_diag = tf.get_variable(
        self.W_I_DIAG,
        shape=[self._hidden_size],
        dtype=dtype,
        initializer=self._initializers.get(self.W_I_DIAG),
        partitioner=self._partitioners.get(self.W_I_DIAG),
        regularizer=self._regularizers.get(self.W_I_DIAG))
    self._w_o_diag = tf.get_variable(
        self.W_O_DIAG,
        shape=[self._hidden_size],
        dtype=dtype,
        initializer=self._initializers.get(self.W_O_DIAG),
        partitioner=self._partitioners.get(self.W_O_DIAG),
        regularizer=self._regularizers.get(self.W_O_DIAG))
533688
def _create_variables_pretrain(self):
        
        for l, layer in enumerate(self.layers):
            self.encoding_w_[l] = tf.Variable(
                self.encoding_w_[l], name='enc-w-{}'.format(l))
            self.encoding_b_[l] = tf.Variable(
                self.encoding_b_[l], name='enc-b-{}'.format(l))
526360
def updateModel(self, X_all, Y_all, X_new, Y_new):
        
        if self.model is None:
            self._create_model(X_all, Y_all)
        else:
            self.model.set_XY(X_all, Y_all)

        # WARNING: Even if self.max_iters=0, the hyperparameters are bit modified...
        if self.max_iters > 0:
            # --- update the model maximizing the marginal likelihood.
            if self.optimize_restarts==1:
                self.model.optimize(optimizer=self.optimizer, max_iters = self.max_iters, messages=False, ipython_notebook=False)
            else:
                self.model.optimize_restarts(num_restarts=self.optimize_restarts, optimizer=self.optimizer, max_iters = self.max_iters, verbose=self.verbose)
823299
def _build_model(self):
        

        if "input_dim" not in self.settings:
            raise ValueError("Model parameter input_dim cannot be None.")

        self.sparse_linear = SparseLinear(
            self.settings["input_dim"], self.cardinality, self.settings["bias"]
        )
354733
def create(model_config, model, source, storage, phases, callbacks=None, restart=True):
    
    return PhaseTrainCommand(
        model_config=model_config,
        model_factory=model,
        source=source,
        storage=storage,
        phases=phases,
        callbacks=callbacks,
        restart=restart
    )