populate the weight-sums for each chain
 (an optimization)
496805
def populate_markov_sum
    @markov_weighted_sum = {}
    @markov_chains.each do |word,followers|
      @markov_weighted_sum[word] = followers.inject(0) {|sum,kv| sum + kv[1]}
    end
  end
991305
private void recomputeLoadSums() {
        loadsHaveChanged.set(false);
        for (int d = 0; d < nbDims; d++) {
            int sli = 0;
            int sls = 0;
            for (int b = 0; b < nbBins; b++) {
                sli += loads[d][b].getLB();
                sls += loads[d][b].getUB();
            }
            this.sumLoadInf[d].set(sli);
            this.sumLoadSup[d].set(sls);
        }
    }
145217
def cardinal(self, to):
        
        return sum(m.cardinal(to) for m in self.submodules)
238696
def adapt_sum(line, cfg, filter_obj):
    """"""
    lines = filter_obj.filter_all(line)
    res_s = [sum(it) for it in lines]
    r = res_s.index(min(res_s))
    return lines[r]
1285746
def sum(x, weights=None):
    '''
    
    '''
    x = to_potential(x)
    if is_const_potential(x): return PotentialConstant(np.sum(x.c))
    else:                     return PotentialSum(x, weights=weights)
1165530
def build_chain(self, **kwargs):
        
        set_defaults(self._chain_defaults, kwargs)
        set_defaults(self._defaults, kwargs)
        return Chain(self, **kwargs)
123141
def constant_cost_withGradients(x):
    
    return np.ones(x.shape[0])[:,None], np.zeros(x.shape)
615958
private void computeWeights(Node node) {
    int wsum = 0;
    for(Node child : node.children) {
      computeWeights(child);
      wsum += child.weight;
    }
    node.weight = Math.max(1, wsum);
  }
681440
def precompute_optimzation_Y(laplacian_matrix, n_samples, relaxation_kwds):
    """"""
    relaxation_kwds.setdefault('presave',False)
    relaxation_kwds.setdefault('presave_name','pre_comp_current.npy')
    relaxation_kwds.setdefault('verbose',False)
    if relaxation_kwds['verbose']:
        print ('Making Lk and nbhds')
    Lk_tensor, nbk, si_map = \
        compute_Lk(laplacian_matrix, n_samples, relaxation_kwds['subset'])
    if relaxation_kwds['presave']:
        raise NotImplementedError('Not yet implemented presave')
    return { 'Lk': Lk_tensor, 'nbk': nbk, 'si_map': si_map }
99017
def trace2array(self, sl):
        """"""
        chain = []
        for stochastic in self.stochastics:
            tr = stochastic.trace.gettrace(slicing=sl)
            if tr is None:
                raise AttributeError
            chain.append(tr)
        return np.hstack(chain)
459939
def tally(self, chain):
        """"""

        arr = np.asarray(self._getfunc())
        arr = arr.reshape((1,) + arr.shape)
        self.db._arrays[chain, self.name].append(arr)
1301571
def calcuate_bboxes(im_shape, patch_size):
    """"""
    h, w = im_shape
    ph, pw = patch_size

    steps_h = chain(range(0, h - ph, ph), [h - ph])
    steps_w = chain(range(0, w - pw, pw), [w - pw])

    return product(steps_h, steps_w)
447503
def precompute_optimzation_S(laplacian_matrix,n_samples,relaxation_kwds):
    """"""
    relaxation_kwds.setdefault('presave',False)
    relaxation_kwds.setdefault('presave_name','pre_comp_current.npy')
    relaxation_kwds.setdefault('verbose',False)
    if relaxation_kwds['verbose']:
        print ('Pre-computing quantities Y to S conversions')
        print ('Making A and Pairs')
    A, pairs = makeA(laplacian_matrix)
    if relaxation_kwds['verbose']:
        print ('Making Rk and nbhds')
    Rk_tensor, nbk = compute_Rk(laplacian_matrix,A,n_samples)
    # TODO: not quite sure what is ATAinv? why we need this?
    ATAinv = np.linalg.pinv(A.T.dot(A).todense())
    if relaxation_kwds['verbose']:
        print ('Finish calculating pseudo inverse')
    if relaxation_kwds['presave']:
        raise NotImplementedError('Not yet implemented presave')
    return { 'RK': Rk_tensor, 'nbk': nbk,
             'ATAinv': ATAinv, 'pairs': pairs, 'A': A }
1218958
private void diffClique(float[] weights, int p) {
		for (int t = 0; t < orders.length; t++) {
			if (data[p][t] == -1)
				continue;

			if (orders[t] == 0) {
				if (golds[p] != preds[p]) {
					int ts = data[p][t] + golds[p];
					int ps = data[p][t] + preds[p];
					adjust(weights, ts, ps);
				}
			}
			if (p > 0 && orders[t] == 1) {
				int ts = data[p][t] + (golds[p - 1] * ysize + golds[p]);
				int ps = data[p][t] + (preds[p - 1] * ysize + preds[p]);
				adjust(weights, ts, ps);
			}
		}
	}
961481
def _compute_weights(self):
        

        n = self.n
        lambda_ = self.alpha**2 * (n +self.kappa) - n

        c = .5 / (n + lambda_)
        self.Wc = np.full(2*n + 1, c)
        self.Wm = np.full(2*n + 1, c)
        self.Wc[0] = lambda_ / (n + lambda_) + (1 - self.alpha**2 + self.beta)
        self.Wm[0] = lambda_ / (n + lambda_)
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
40221
void computeWeights(Cache cache, float v_x, float v_y) {
		float[] weights = cache.weights.data;
		// first compute the weights
		float totalWeight = 0.0f;
		for (int i = 0; i < controls.size(); i++) {
			Control c = controls.get(i);

			float d2 = c.p.distance2(v_x, v_y);
			// check for the special case
			if( d2 == 0 ) {
				for (int j = 0; j < controls.size(); j++) {
					weights[j] = i==j ? 1.0f : 0.0f;
				}
				totalWeight = 1.0f;
				break;
			} else {
				totalWeight += weights[i] = 1.0f/(float)Math.pow(d2,alpha);
			}
		}
		cache.totalWeight = totalWeight;
	}