Returns a default initializer for the weights of a convolutional module.
320117
def create_weight_initializer(fan_in_shape, dtype=tf.float32):
  """"""
  stddev = 1 / math.sqrt(np.prod(fan_in_shape))
  return tf.truncated_normal_initializer(stddev=stddev, dtype=dtype)
1259648
def _build(self):
    
    if "w" not in self._initializers:
      stddev = 1 / math.sqrt(np.prod(self._shape))
      self._initializers["w"] = tf.truncated_normal_initializer(stddev=stddev)

    self._w = tf.get_variable("w",
                              shape=self._shape,
                              dtype=self._dtype,
                              initializer=self._initializers["w"],
                              partitioner=self._partitioners.get("w", None),
                              regularizer=self._regularizers.get("w", None))
    return self._w
351342
def getSparseWeights(weightSparsity, inputSize, outputSize):
  
  # Initialize weights in the typical fashion.
  w = torch.Tensor(outputSize, inputSize)
  stdv = 1. / math.sqrt(w.size(1))
  w.data.uniform_(-stdv, stdv)

  numZeros = int(round((1.0 - weightSparsity) * inputSize))

  outputIndices = np.arange(outputSize)
  inputIndices = np.array([np.random.permutation(inputSize)[:numZeros]
                           for _ in outputIndices], dtype=np.long)

  # Create tensor indices for all non-zero weights
  zeroIndices = np.empty((outputSize, numZeros, 2), dtype=np.long)
  zeroIndices[:, :, 0] = outputIndices[:, None]
  zeroIndices[:, :, 1] = inputIndices
  zeroIndices = torch.LongTensor(zeroIndices.reshape(-1, 2))

  zeroWts = (zeroIndices[:, 0], zeroIndices[:, 1])
  w.data[zeroWts] = 0.0

  return w
205712
def _setweights(self):
        ""
        for layer in self.layer_names:
            raw_w = getattr(self, f'{layer}_raw')
            self.module._parameters[layer] = F.dropout(raw_w, p=self.weight_p, training=self.training)
519417
def set_default(eng, algorithms=0xFFFF):
    
    if not isinstance(eng,Engine):
        eng=Engine(eng)
    global default
    libcrypto.ENGINE_set_default(eng.ptr, c_int(algorithms))
    default = eng
629393
def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
                    trainable_initializers=None, trainable_regularizers=None,
                    name=None):
    """"""
    return self._core.initial_state(
        batch_size, dtype=dtype, trainable=trainable,
        trainable_initializers=trainable_initializers,
        trainable_regularizers=trainable_regularizers, name=name)
118882
def _setweights(self):
        
        for name_w in self.weights:
            raw_w = getattr(self.module, name_w + '_raw')
            w = torch.nn.functional.dropout(raw_w, p=self.dropout, training=self.training)
            if hasattr(self.module, name_w):
                delattr(self.module, name_w)
            setattr(self.module, name_w, w)
531654
def initialize_training(self, training_info: TrainingInfo, model_state=None, hidden_state=None):
        
        if model_state is None:
            self.model.reset_weights()
        else:
            self.model.load_state_dict(model_state)
1069678
def ConvCnstrMODMaskOptionsDefaults(method='fista'):
    

    dflt = copy.deepcopy(ccmodmsk_class_label_lookup(method).Options.defaults)
    if method == 'fista':
        dflt.update({'MaxMainIter': 1, 'BackTrack':
                     {'gamma_u': 1.2, 'MaxIter': 50}})
    else:
        dflt.update({'MaxMainIter': 1, 'AutoRho':
                     {'Period': 10, 'AutoScaling': False,
                      'RsdlRatio': 10.0, 'Scaling': 2.0,
                      'RsdlTarget': 1.0}})
    return dflt
1201212
private ClassicCounter<Pair<F, L>> convertSVMStructWeights(ClassicCounter<Integer> weights, Index<F> featureIndex, Index<L> labelIndex) {
    // int numLabels = labelIndex.size();
    int numFeatures = featureIndex.size();
    ClassicCounter<Pair<F, L>> newWeights = new ClassicCounter<Pair<F, L>>();
    for (int i : weights.keySet()) {
      L l = labelIndex.get((i-1) / numFeatures); // integer division on purpose
      F f = featureIndex.get((i-1) % numFeatures);
      double w = weights.getCount(i);
      newWeights.incrementCount(new Pair<F, L>(f, l),w);
    }

    return newWeights;
  }
967078
def _weight_init(self, m, n, name):
        
        x = np.sqrt(6.0/(m+n))
        with tf.name_scope(name) as scope:
            return tf.Variable(
                tf.random_uniform(
                    [m, n], minval=-x, maxval=x), name=name)
1118711
def initial_state(self, batch_size, dtype=tf.float32, trainable=False,
                    trainable_initializers=None, trainable_regularizers=None,
                    name=None):
    """"""
    core_initial_state = self._core.initial_state(
        batch_size, dtype=dtype, trainable=trainable,
        trainable_initializers=trainable_initializers,
        trainable_regularizers=trainable_regularizers, name=name)

    dropout_masks = [None] * len(self._dropout_state_size)
    def set_dropout_mask(index, state, keep_prob):
      if index is not None:
        ones = tf.ones_like(state, dtype=dtype)
        dropout_masks[index] = tf.nn.dropout(ones, keep_prob=keep_prob)
    tf.contrib.framework.nest.map_structure(
        set_dropout_mask,
        self._dropout_indexes, core_initial_state, self._keep_probs)

    return core_initial_state, dropout_masks
450638
def reset_weights(self):
        
        init.uniform_(self.linear.weight, -3e-3, 3e-3)
        init.zeros_(self.linear.bias)
596858
def _init_model(self):
        
        model = Sequential()
        model.add(Conv2D(input_shape=list(self.image_size) + [self.channels], filters=self.filters,
                         kernel_size=self.kernel_size, activation='relu', data_format='channels_last'))
        model.add(
            Conv2D(filters=self.filters, kernel_size=self.kernel_size, activation='relu', data_format='channels_last'))
        model.add(MaxPooling2D())
        model.add(
            Conv2D(filters=self.filters, kernel_size=self.kernel_size, activation='relu', data_format='channels_last'))
        model.add(
            Conv2D(filters=self.filters, kernel_size=self.kernel_size, activation='relu', data_format='channels_last'))
        model.add(MaxPooling2D())

        model.add(Flatten())
        model.add(Dense(units=len(self.emotion_map.keys()), activation="relu"))
        if self.verbose:
            model.summary()
        self.model = model
1271123
def init_net_params(scale, layer_sizes, rs=npr.RandomState(0)):
    """"""
    return [(scale * rs.randn(m, n),   # weight matrix
             scale * rs.randn(n))      # bias vector
            for m, n in zip(layer_sizes[:-1], layer_sizes[1:])]
8975
def RandomNormalInitializer(stddev=1e-2):
  """"""
  def init(shape, rng):
    return (stddev * backend.random.normal(rng, shape)).astype('float32')
  return init
481934
def initialize_weights(self):
        """"""
        n = self._outputSize
        m = self._inputSize
        self._Q = self._random.sample((n,m))

        # Normalize the weights of each units
        for i in range(n):
            self._Q[i] /=  np.sqrt( np.dot(self._Q[i], self._Q[i]) )