Adapt weights according one desired value and its input.

        Args:

        * `d` : desired value (float)

        * `x` : input array (1-dimensional array)
326826
def adapt(self, d, x):
        
        self.update_memory_x(x)
        m_d, m_x = self.read_memory()
        # estimate
        y = np.dot(self.w, x-m_x) + m_d
        e = d - y
        nu = self.mu / (self.eps + np.dot(x-m_x, x-m_x))
        dw = nu * e * (x-m_x)
        self.w += dw
        self.update_memory_d(d)
499366
def _apply_to_array(self, yd, y, weights, off_slices, ref_slice, dim):
        """"""

        ndims = len(y.shape)

        all = slice(None, None, 1)

        ref_multi_slice = [all] * ndims
        ref_multi_slice[dim] = ref_slice

        for w, s in zip(weights, off_slices):
            off_multi_slice = [all] * ndims
            off_multi_slice[dim] = s
            if abs(1 - w) < 1.E-14:
                yd[ref_multi_slice] += y[off_multi_slice]
            else:
                yd[ref_multi_slice] += w * y[off_multi_slice]
977495
def d(self,value):
        
        assert value.shape[0]==self.P*self.N, 'd dimension mismatch'
        self._d = value
        self.clear_cache()
1278879
def mds(means, weights, d):
    
    X = dim_reduce(means, weights, d)
    if X.shape[0]==2:
        return X.dot(weights)
    else:
        return X.T.dot(weights)
972399
def rescale(x, min=0., max=1., axis=0):
    
    def innerfn(x, min, max):
        return np.interp(x, [np.min(x), np.max(x)], [min, max])

    if isinstance(x, pd.DataFrame):
        return x.apply(innerfn, axis=axis, args=(min, max,))
    else:
        return pd.Series(innerfn(x, min, max), index=x.index)
178525
def amean(x, weights=None):
    
    w_arr, x_arr = _preprocess_inputs(x, weights)
    return (w_arr*x_arr).sum(axis=0) / w_arr.sum(axis=0)
193844
def _preprocess_inputs(x, weights):
    
    if weights is None:
        w_arr = np.ones(len(x))
    else:
        w_arr = np.array(weights)
    x_arr = np.array(x)
    if x_arr.ndim == 2:
        if w_arr.ndim == 1:
            w_arr = w_arr[:, np.newaxis]
    return x_arr, w_arr
727677
def add(self, delta):
        
        if self.lw is None:
            return Weights(lw=delta)
        else:
            return Weights(lw=self.lw + delta)
578969
def _call(self, x):
        """"""
        out = x.asarray().ravel()[self._indices_flat]

        if self.variant == 'point_eval':
            weights = 1.0
        elif self.variant == 'integrate':
            weights = getattr(self.domain, 'cell_volume', 1.0)
        else:
            raise RuntimeError('bad variant {!r}'.format(self.variant))

        if weights != 1.0:
            out *= weights

        return out
1197692
def change_weights(self):
        
        dw_count, dw_sum = 0, 0.0
        if len(self.cacheLayers) != 0:
            changeLayers = self.cacheLayers
        else:
            changeLayers = self.layers
        for layer in changeLayers:
            if layer.active and layer.type != 'Input':
                if not layer.frozen:
                    if self._quickprop or self.splitEpsilon:
                        layer.dweight = self.deltaWeight(self.epsilon,
                                                         layer.wed,
                                                         self.momentum,
                                                         layer.dweight,
                                                         layer.wedLast,
                                                         layer.weight,
                                                         self.numConnects(layer.name))
                    else:
                        layer.dweight = self.epsilon * layer.wed + self.momentum * layer.dweight
                    layer.weight += layer.dweight
                    #print "layer.wed = ",layer.wed
                    #print "layer.weight = ",layer.weight," layer.dweight = ",layer.dweight
                    layer.wedLast = Numeric.array(layer.wed) # make copy
                    if self._quickprop:
                        layer.wed = layer.weight * self.decay # reset to last weight, with decay
                    else:
                        layer.wed = layer.wed * 0.0 # keep same numeric type, just zero it
                    dw_count += len(layer.dweight)
                    dw_sum += Numeric.add.reduce(abs(layer.dweight))
        if len(self.cacheConnections) != 0:
            changeConnections = self.cacheConnections
        else:
            changeConnections = self.connections
        for connection in changeConnections:
            if (connection.active
                and connection.fromLayer.active
                and connection.toLayer.active
                and not connection.frozen):
                toLayer = connection.toLayer
                if self._quickprop or self.splitEpsilon:
                    # doing it one vector at a time, to match layer bias training (a quickprop abstraction)
                    for i in range(len(connection.dweight)):
                        Numeric.put(connection.dweight[i],
                                    Numeric.arange(len(connection.dweight[i])),
                                    self.deltaWeight(self.epsilon,
                                                     connection.wed[i],
                                                     self.momentum,
                                                     connection.dweight[i],
                                                     connection.wedLast[i],
                                                     connection.weight[i],
                                                     self.numConnects(connection.toLayer.name)))
                else:
                    connection.dweight = self.epsilon * connection.wed + self.momentum * connection.dweight
                connection.weight += connection.dweight
                #print "connection.wed = ",connection.wed
                #print "connection.weight = ",connection.weight," connection.dweight = ",connection.dweight
                # reset values:
                connection.wedLast = Numeric.array(connection.wed) # make copy
                if self._quickprop:
                    connection.wed = connection.weight * self.decay 
                else:
                    connection.wed = connection.wed * 0.0 # keeps the same Numeric type, but makes it zero
                # get some stats
                dw_count += Numeric.multiply.reduce(connection.dweight.shape)
                dw_sum += Numeric.add.reduce(Numeric.add.reduce(abs(connection.dweight)))
        if self.verbosity >= 1:
            print("WEIGHTS CHANGED")
            if self.verbosity > 2:
                self.display()
        return (dw_count, dw_sum)
787430
def setdict(self, D=None):
        """"""

        if D is not None:
            self.D = np.asarray(D, dtype=self.dtype)
        self.Df = sl.rfftn(self.D, self.cri.Nv, self.cri.axisN)
        # Compute D^H S
        self.DSf = np.conj(self.Df) * self.Sf
        if self.cri.Cd > 1:
            self.DSf = np.sum(self.DSf, axis=self.cri.axisC, keepdims=True)
        if self.opt['HighMemSolve'] and self.cri.Cd == 1:
            self.c = sl.solvedbd_sm_c(
                self.Df, np.conj(self.Df), self.mu*self.GHGf + self.rho,
                self.cri.axisM)
        else:
            self.c = None
1084635
def adapt(self, d, x):
        
        y = np.dot(self.w, x)
        e = d - y
        R1 = np.dot(np.dot(np.dot(self.R,x),x.T),self.R)
        R2 = self.mu + np.dot(np.dot(x,self.R),x.T)
        self.R = 1/self.mu * (self.R - R1/R2)
        dw = np.dot(self.R, x.T) * e
        self.w += dw
347887
def set_weights_by_dict(self,weights):
    
    self._weights = []
    txnames = [x.name for x in self._transcriptome.transcripts]
    for txname in txnames:
      if txname in weights:
        self._weights.append(float(weights[txname]))
      else:
        self._weights.append(float(0))
    return
8822
def _adjust(a, a_offset, b):
    
    x = (b[-1] & 0xFF) + (a[a_offset + len(b) - 1] & 0xFF) + 1
    a[a_offset + len(b) - 1] = ctypes.c_ubyte(x).value
    x >>= 8

    for i in range(len(b)-2, -1, -1):
        x += (b[i] & 0xFF) + (a[a_offset + i] & 0xFF)
        a[a_offset + i] = ctypes.c_ubyte(x).value
        x >>= 8
24452
def t(self, value):
        """"""
        assert (isinstance(value, scipy.ndarray) and (value.dtype ==
                'float') and (value.shape == self.t.shape))
        if (self._t != value).any():
            self._t = value.copy()
            self._updateInternals()
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
529926
void setWeight(Token tok, double d) {
		Double oldWeight = (Double)weightMap.get(tok);
		totalWeight += oldWeight==null ? d : (d - oldWeight.doubleValue());
		weightMap.put(tok,new Double(d));
	}