input: an array of weights <<txname1> <weight1>> <<txname2> <weight2>>...
       if this does not get set then even weighting will be used

    :param weights: [[tx1,wght1],[tx2,wght2],...[txN,wightN]]
    :type weights: list
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
1217325
public int getNumWeights() {
    if (weights == null) return 0;
    int numWeights = 0;
    for (double[] wts : weights) {
      numWeights += wts.length;
    }
    return numWeights;
  }
987323
@Override
    public void setWeights(Map<String, INDArray> weights) throws InvalidKerasConfigurationException {
        this.weights = new HashMap<>();
        if (weights.containsKey(conf.getKERAS_PARAM_NAME_W())) {
            INDArray kerasParamValue = weights.get(conf.getKERAS_PARAM_NAME_W());
            INDArray paramValue;
            switch (this.getDimOrder()) {
                case TENSORFLOW:
                    paramValue = kerasParamValue.permute(2, 1, 0);
                    paramValue = paramValue.reshape(
                            paramValue.size(0), paramValue.size(1),
                            paramValue.size(2), 1);
                    break;

                case THEANO:
                    paramValue = kerasParamValue.permute(2, 1, 0);
                    paramValue = paramValue.reshape(
                            paramValue.size(0), paramValue.size(1),
                            paramValue.size(2), 1).dup();
                    for (int i = 0; i < paramValue.tensorsAlongDimension(2, 3); i++) {
                        INDArray copyFilter = paramValue.tensorAlongDimension(i, 2, 3).dup();
                        double[] flattenedFilter = copyFilter.ravel().data().asDouble();
                        ArrayUtils.reverse(flattenedFilter);
                        INDArray newFilter = Nd4j.create(flattenedFilter, copyFilter.shape());
                        INDArray inPlaceFilter = paramValue.tensorAlongDimension(i, 2, 3);
                        inPlaceFilter.muli(0).addi(newFilter);
                    }
                    break;
                default:
                    throw new InvalidKerasConfigurationException("Unknown keras backend " + this.getDimOrder());
            }

            this.weights.put(ConvolutionParamInitializer.WEIGHT_KEY, paramValue);
        } else
            throw new InvalidKerasConfigurationException(
                    "Parameter " + conf.getKERAS_PARAM_NAME_W() + " does not exist in weights");

        if (hasBias) {
            if (weights.containsKey(conf.getKERAS_PARAM_NAME_B()))
                this.weights.put(ConvolutionParamInitializer.BIAS_KEY, weights.get(conf.getKERAS_PARAM_NAME_B()));
            else
                throw new InvalidKerasConfigurationException(
                        "Parameter " + conf.getKERAS_PARAM_NAME_B() + " does not exist in weights");
        }
        removeDefaultWeights(weights, conf);
    }
981516
def reweight(self, weight, edges=None, copy=False):
    ''''''
    if not self.is_weighted():
      warnings.warn('Cannot supply weights for unweighted graph; '
                    'ignoring call to reweight')
      return self
    if edges is None:
      return self._update_edges(weight, copy=copy)
    ii, jj = self.pairs()[edges].T
    return self.add_edges(ii, jj, weight=weight, symmetric=False, copy=copy)
933951
def _check_list_weights(parameter, name):
    '''
    
    '''
    if not isinstance(parameter, list):
        raise ValueError('%s must be formatted with a list of tuples' % name)
    weight = np.sum([val[1] for val in parameter])
    if fabs(weight - 1.) > 1E-8:
        raise ValueError('%s weights do not sum to 1.0!' % name)
    return parameter
627523
public static double[][] initializeUniformlyInTwoDimensions(double epsilon, int numberOfWeights) {
		double[][] weights = new double[numberOfWeights][2];
		
		int indexOfWeight;
		double w, jump;
		
		jump = (1 - (2 * epsilon)) / (numberOfWeights - 1);
		indexOfWeight = 0;
		
		w = epsilon;
		
		//while(w <= (1-epsilon))
		while (indexOfWeight < numberOfWeights) {
			weights[indexOfWeight][0] = w;
			weights[indexOfWeight][1] = 1 - w;
			
			w = w + jump;
			
			indexOfWeight = indexOfWeight + 1;
		}
		
		return weights;
	}
124991
def weighted_choice(choices):
    
    values, weights = zip(*choices)
    total = 0
    cum_weights = []
    for w in weights:
        total += w
        cum_weights.append(total)
    x = random.uniform(0, total)
    i = bisect.bisect(cum_weights, x)
    return values[i]
678321
def _compute_weights(self):
        

        n = self.n
        c = 1. / (n + 1)
        self.Wm = np.full(n + 1, c)
        self.Wc = self.Wm
1014421
public void setWeight(int i, double w)
    {
        if(i >= size() || i < 0)
            throw new IndexOutOfBoundsException("Dataset has only " + size() + " members, can't access index " + i );
        else if(Double.isNaN(w) || Double.isInfinite(w) || w < 0)
            throw new ArithmeticException("Invalid weight assignment of  " + w);
        
        if(w == 1 && weights == null)
            return;//nothing to do, already handled implicitly
        
        if(weights == null)//need to init?
        {
            weights = new double[size()];
            Arrays.fill(weights, 1.0);
        }
        
        //make sure we have enouh space
        if (weights.length <= i)
            weights = Arrays.copyOfRange(weights, 0, Math.max(weights.length*2, i+1));
        
        weights[i] = w;
    }
149755
def convert_weights_to_numpy(weights_dict):
        """"""
        return dict([(k.replace("arg:", "").replace("aux:", ""), v.asnumpy())
                     for k, v in weights_dict.items()])
1370211
def _raw_weights(self):
        
        if self._debug:
            return np.array([[],[],[],[]])

        if not self._running:
            raise ValueError('Weight sensor is not running!')
        if len(self._weight_buffers) == 0:
            time.sleep(0.3)
            if len(self._weight_buffers) == 0:
                raise ValueError('Weight sensor is not retrieving data!')
        weights = np.array(self._weight_buffers)
        return weights
272591
@Override
    public void setWeights(Map<String, INDArray> weights) throws InvalidKerasConfigurationException {
        this.weights = new HashMap<>();
        if (center) {
            if (weights.containsKey(PARAM_NAME_BETA))
                this.weights.put(BatchNormalizationParamInitializer.BETA, weights.get(PARAM_NAME_BETA));
            else
                throw new InvalidKerasConfigurationException("Parameter " + PARAM_NAME_BETA + " does not exist in weights");
        } else {
            INDArray dummyBeta = Nd4j.zerosLike(weights.get(PARAM_NAME_BETA));
            this.weights.put(BatchNormalizationParamInitializer.BETA, dummyBeta);
        }
        if (scale) {
            if (weights.containsKey(PARAM_NAME_GAMMA))
                this.weights.put(BatchNormalizationParamInitializer.GAMMA, weights.get(PARAM_NAME_GAMMA));
            else
                throw new InvalidKerasConfigurationException(
                        "Parameter " + PARAM_NAME_GAMMA + " does not exist in weights");
        } else {
            INDArray dummyGamma = weights.containsKey(PARAM_NAME_GAMMA)
                    ? Nd4j.onesLike(weights.get(PARAM_NAME_GAMMA))
                    : Nd4j.onesLike(weights.get(PARAM_NAME_BETA));
            this.weights.put(BatchNormalizationParamInitializer.GAMMA, dummyGamma);
        }
        if (weights.containsKey(conf.getLAYER_FIELD_BATCHNORMALIZATION_MOVING_MEAN()))
            this.weights.put(BatchNormalizationParamInitializer.GLOBAL_MEAN, weights.get(conf.getLAYER_FIELD_BATCHNORMALIZATION_MOVING_MEAN()));
        else
            throw new InvalidKerasConfigurationException(
                    "Parameter " + conf.getLAYER_FIELD_BATCHNORMALIZATION_MOVING_MEAN() + " does not exist in weights");
        if (weights.containsKey(conf.getLAYER_FIELD_BATCHNORMALIZATION_MOVING_VARIANCE()))
            this.weights.put(BatchNormalizationParamInitializer.GLOBAL_VAR, weights.get(conf.getLAYER_FIELD_BATCHNORMALIZATION_MOVING_VARIANCE()));
        else
            throw new InvalidKerasConfigurationException(
                    "Parameter " + conf.getLAYER_FIELD_BATCHNORMALIZATION_MOVING_VARIANCE() + " does not exist in weights");
        if (weights.size() > 4) {
            Set<String> paramNames = weights.keySet();
            paramNames.remove(PARAM_NAME_BETA);
            paramNames.remove(PARAM_NAME_GAMMA);
            paramNames.remove(conf.getLAYER_FIELD_BATCHNORMALIZATION_MOVING_MEAN());
            paramNames.remove(conf.getLAYER_FIELD_BATCHNORMALIZATION_MOVING_VARIANCE());
            String unknownParamNames = paramNames.toString();
            log.warn("Attempting to set weights for unknown parameters: "
                    + unknownParamNames.substring(1, unknownParamNames.length() - 1));
        }
    }
244474
def _wva(values, weights):
        
        assert len(values) == len(weights) and len(weights) > 0
        return sum([mul(*x) for x in zip(values, weights)]) / sum(weights)
380036
def _parse_weights(weight_args, default_weight=0.6):
    """"""
    weights_dict = {}
    r_group_weight = default_weight
    for weight_arg in weight_args:
        for weight_assignment in weight_arg.split(','):
            if '=' not in weight_assignment:
                raise ValueError(
                    'Invalid weight assignment: {}'.format(weight_assignment))

            key, value = weight_assignment.split('=', 1)
            value = float(value)
            if key == 'R':
                r_group_weight = value
            elif key == '*':
                default_weight = value
            elif hasattr(Atom, key):
                weights_dict[Atom(key)] = value
            else:
                raise ValueError('Invalid element: {}'.format(key))

    return weights_dict, r_group_weight, default_weight
1302149
def weight_matrices(nn):
    

    if isinstance(nn, ndarray):
        return nn

    try:
        return weight_matrices(nn.connections)
    except:
        pass

    try:
        return weight_matrices(nn.module)
    except:
        pass

    # Network objects are ParameterContainer's too, but won't reshape into a single matrix,
    # so this must come after try nn.connections
    if isinstance(nn, (ParameterContainer, Connection)):
        return reshape(nn.params, (nn.outdim, nn.indim))

    if isinstance(nn, basestring):
        try:
            fn = nn
            nn = NetworkReader(fn, newfile=False)
            return weight_matrices(nn.readFrom(fn))
        except:
            pass
    # FIXME: what does NetworkReader output? (Module? Layer?) need to handle it's type here

    try:
        return [weight_matrices(v) for (k, v) in nn.iteritems()]
    except:
        try:
            connections = nn.module.connections.values()
            nn = []
            for conlist in connections:
                nn += conlist
            return weight_matrices(nn)
        except:
            return [weight_matrices(v) for v in nn]
1049287
def _weighted_selection(l, n):
    
    cuml = []
    items = []
    total_weight = 0.0
    for weight, item in l:
        total_weight += weight
        cuml.append(total_weight)
        items.append(item)

    return [items[bisect.bisect(cuml, random.random()*total_weight)] for _ in range(n)]
739754
def set_weights(params, new_params):
        
        for param, new_param in zip(params, new_params):
            param.data.copy_(new_param.data)