initilize dense layer weight.
510235
def init_dense_weight(layer):
    '''
    '''
    units = layer.units
    weight = np.eye(units)
    bias = np.zeros(units)
    layer.set_weights(
        (add_noise(weight, np.array([0, 1])), add_noise(bias, np.array([0, 1])))
    )
1144792
def init(h):
    """"""
    # heapify
    n = h.size()
    for i in six.moves.range(int(math.floor(n/2)) - 1, -1, -1):
        down(h, i, n)
647199
def init_nn_params(scale, layer_sizes, rs=npr.RandomState(0)):
    """"""
    return [(rs.randn(insize, outsize) * scale,   # weight matrix
             rs.randn(outsize) * scale)           # bias vector
            for insize, outsize in zip(layer_sizes[:-1], layer_sizes[1:])]
470331
def decrease_weight(self, proxy):
        """"""
        new_weight = proxy.weight * self.dec_ratio
        if new_weight < self.weight_thr:
            self.remove_proxy(proxy)
        else:
            proxy.weight = new_weight
399744
def update_weights(self, x, y):
        """"""
        m     = self._inputSize
        n     = self._outputSize
        W     = self._W
        Q     = self._Q
        t     = self._t
        alpha = self._alpha
        beta  = self._beta
        gamma = self._gamma
        p     = self._p

        for i in range(n):
            for j in range(n):
                Delta_W  = - alpha * ( y[i] * y[j] - p*p )
                W[i,j]  += Delta_W

                if i==j or W[i,j] > 0:
                    W[i,j] = 0.


        for i in range(n):
            for j in range(m):
                Delta_Q  = beta * y[i] * ( x[j] - Q[i,j] )
                Q[i,j]  += Delta_Q



        for i in range(n):
            Delta_t  = gamma * ( y[i] - p )
            t[i]    += Delta_t
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)
751588
def create(lr, weight_decay=0, momentum=0, layer_groups=False):
    
    return SgdFactory(lr=lr, weight_decay=weight_decay, momentum=momentum, layer_groups=layer_groups)
1179319
def init_conv_weight(layer):
    '''
    '''
    n_filters = layer.filters
    filter_shape = (layer.kernel_size,) * get_n_dim(layer)
    weight = np.zeros((n_filters, n_filters) + filter_shape)

    center = tuple(map(lambda x: int((x - 1) / 2), filter_shape))
    for i in range(n_filters):
        filter_weight = np.zeros((n_filters,) + filter_shape)
        index = (i,) + center
        filter_weight[index] = 1
        weight[i, ...] = filter_weight
    bias = np.zeros(n_filters)

    layer.set_weights(
        (add_noise(weight, np.array([0, 1])), add_noise(bias, np.array([0, 1])))
    )
938994
def _init_horizontal(self):
        """"""
        self.scale.grid(row=0, sticky='ew')
        padx1, padx2 = 0, 0
        pady1, pady2 = 0, 0
        # showvalue
        if self._showvalue:
            self.label.configure(text=self._formatter.format(self._start))
            self.update_idletasks()
            if self._labelpos == 'n':
                self.label.place(in_=self.scale, bordermode='outside',
                                 rely=0, x=0, anchor='s')
                pady1 = self.label.winfo_reqheight()
            elif self._labelpos == 's':
                self.label.place(in_=self.scale, bordermode='outside',
                                 rely=1, x=0, anchor='n')
                pady2 = self.label.winfo_reqheight()
            elif self._labelpos in ['w', 'e']:
                padx = self.label.winfo_reqwidth()
                self.label.configure(text=self._formatter.format(self._start + self._extent))
                self.update_idletasks()
                padx = max(padx, self.label.winfo_reqwidth())
                if self._labelpos == 'w':
                    anchor = 'e'
                    relx = 0
                    padx1 = padx
                else:
                    anchor = 'w'
                    relx = 1
                    padx2 = padx
                self.label.place(in_=self.scale, bordermode='outside',
                                 relx=relx, rely=0.5, anchor=anchor)

                h = self.label.winfo_reqheight()
                hs = self.scale.winfo_reqheight()
                if h > hs:
                    pady = (h - hs) // 2
                    if self._tickinterval:
                        if self._tickpos == 'n':
                            pady1 = pady
                        else:   # self._tickpos == 's'
                            pady2 = pady
                    else:
                        pady1, pady2 = pady, pady

        # ticks
        pady1_2, pady2_2 = 0, 0
        if self._tickinterval:
            nb_interv = int(self._extent / self._tickinterval)
            h = self.scale.winfo_reqheight()
            if self._tickpos == 's':
                for i in range(nb_interv + 1):
                    tick = self._start + i * self._tickinterval
                    self.ticks.append(tick)
                    self.ticklabels.append(ttk.Label(self,
                                                     style=self._style_name + ".TLabel",
                                                     text=self._formatter.format(tick)))
                    self.ticklabels[i].place(in_=self.scale, bordermode='outside',
                                             x=0, y=h + pady2 + 1, anchor='n')
                pady2_2 = self.ticklabels[-1].winfo_reqheight()
            else:  # self._tickpos == 'n':
                for i in range(nb_interv + 1):
                    tick = self._start + i * self._tickinterval
                    self.ticks.append(tick)
                    self.ticklabels.append(ttk.Label(self,
                                                     style=self._style_name + ".TLabel",
                                                     text=self._formatter.format(tick)))
                    self.ticklabels[i].place(in_=self.scale, bordermode='outside',
                                             x=0, y=-1 - pady1, anchor='s')
                pady1_2 = self.ticklabels[-1].winfo_reqheight()
            self.update_idletasks()
        self.scale.grid_configure(pady=(pady1 + pady1_2, pady2 + pady2_2),
                                  padx=(padx1, padx2))
415355
private function initWeightEmbeddable(): void
    {
        $this->setWeightEmbeddable(
            new WeightEmbeddable(
                WeightEmbeddableInterface::DEFAULT_UNIT,
                WeightEmbeddableInterface::DEFAULT_VALUE
            ),
            false
        );
    }
1229476
def addStencilBranch(self, disp, weight):
        
        self.stencil[tuple(disp)] = weight
        self.__setPartionLogic(disp)
468204
def initialize(self):
        
        if getattr(self, '_initialized', False):
            return

        out = getattr(self, '_output_layers', None)
        if out is None:
            self.initialize_layers()
        self._check_for_unused_kwargs()

        iter_funcs = self._create_iter_funcs(
            self.layers_, self.objective, self.update,
            self.y_tensor_type,
            )
        self.train_iter_, self.eval_iter_, self.predict_iter_ = iter_funcs
        self._initialized = True
1219146
def _init_lsr(n_items, alpha, initial_params):
    """"""
    if initial_params is None:
        weights = np.ones(n_items)
    else:
        weights = exp_transform(initial_params)
    chain = alpha * np.ones((n_items, n_items), dtype=float)
    return weights, chain
556491
def _set_initial(self, C_in, scale_in):
        """
        self.C_in = C_in
        self.scale_in = scale_in
995462
def layerize(begin_update=None, predict=None, *args, **kwargs):
    """"""
    if begin_update is not None:
        return FunctionLayer(begin_update, predict=predict, *args, **kwargs)

    def wrapper(begin_update):
        return FunctionLayer(begin_update, *args, **kwargs)

    return wrapper
1022130
private static void handleLegacyWeightInitFromJson(String json, Layer layer, ObjectMapper mapper, JsonNode vertices) {
        if (layer instanceof BaseLayer && ((BaseLayer) layer).getWeightInitFn() == null) {
            String layerName = layer.getLayerName();

            try {
                if (vertices == null) {
                    JsonNode jsonNode = mapper.readTree(json);
                    vertices = jsonNode.get("vertices");
                }

                JsonNode vertexNode = vertices.get(layerName);
                JsonNode layerVertexNode = vertexNode.get("LayerVertex");
                if (layerVertexNode == null || !layerVertexNode.has("layerConf")
                        || !layerVertexNode.get("layerConf").has("layer")) {
                    return;
                }
                JsonNode layerWrapperNode = layerVertexNode.get("layerConf").get("layer");

                if (layerWrapperNode == null || layerWrapperNode.size() != 1) {
                    return;
                }

                JsonNode layerNode = layerWrapperNode.elements().next();
                JsonNode weightInit = layerNode.get("weightInit"); //Should only have 1 element: "dense", "output", etc
                JsonNode distribution = layerNode.get("dist");

                Distribution dist = null;
                if(distribution != null) {
                    dist = mapper.treeToValue(distribution, Distribution.class);
                }

                if (weightInit != null) {
                    final IWeightInit wi = WeightInit.valueOf(weightInit.asText()).getWeightInitFunction(dist);
                    ((BaseLayer) layer).setWeightInitFn(wi);
                }

            } catch (IOException e) {
                log.warn("Layer with null ActivationFn field or pre-0.7.2 activation function detected: could not parse JSON",
                        e);
            }
        }
    }
739754
def set_weights(params, new_params):
        
        for param, new_param in zip(params, new_params):
            param.data.copy_(new_param.data)