/* modify the addEdge function to attach random weights
484406
function (from, to, edgeData) {
    edgeData = edgeData || {}
    edgeData.weight = Math.floor(Math.random() * 10) + 1;
    edgeData.label = edgeData.weight;
    edgeData.style = { 'pointer-events': 'none' }
    g.addEdge(from, to, edgeData);
  }
1324927
public int randomIndexChoice(List<Integer> weights) {
        int result = 0, index;
        double maxKey = 0.0;
        double u, key;
        int weight;

        for (ListIterator<Integer> it = weights.listIterator(); it.hasNext(); ) {
            index = it.nextIndex();
            weight = it.next();
            u = random.nextDouble();
            key = Math.pow(u, (1.0/weight)); // Protect from zero division?

            if (key > maxKey) {
                maxKey = key;
                result = index;
            }
        }

        return result;
    }
1037889
def weighted_random_choice(items):
    
    l = list(items)
    r = random.random() * sum([i[1] for i in l])
    for x, p in l:
        if p > r:
            return x
        r -= p
    return None
1128427
protected void computeWeights(int numSamples, double numSigmas) {
		weights = new float[ numSamples*numSamples ];

		float w[] = new float[ numSamples ];
		for( int i = 0; i < numSamples; i++ ) {
			float x = i/(float)(numSamples-1);
			w[i] = (float) UtilGaussian.computePDF(0, 1, 2f*numSigmas * (x - 0.5f));
		}

		for( int y = 0; y < numSamples; y++ ) {
			for( int x = 0; x < numSamples; x++ ) {
				weights[y*numSamples + x] = w[y]*w[x];
			}
		}
	}
450390
@Override
	public RandomVariable mult(double value) {
		return apply(OperatorType.MULT, new RandomVariable[]{this, constructNewAADRandomVariable(value)});
	}
162519
@Override
	public RandomVariable mult(double value) {
		return apply(new DoubleUnaryOperator() {
			@Override
			public double applyAsDouble(double x) {
				return x * value;
			}
		});
	}
612686
function createRandom(n, min, max) {
    let scale = max - min;
    let array = [];
    for (var i = 0; i < n; i++) {
        array[i] = (Math.random() * scale) + min;
    }
    return new Vector(array);
}
13236
public void addEdge(DiEdge e, double w) {
        if (!getEdges().contains(e)) { 
            super.addEdge(e);
            weights.put(e, w);
        }
    }
1076664
function randomNode (g) {
  var keys = Object.keys(g)
  return keys[~~(keys.length*Math.random())]
}
1107720
private void setUp(Random rand)
    {
        Ws = new ArrayList<>(npl.length);
        bs = new ArrayList<>(npl.length);
        
        //First Hiden layer takes input raw
        DenseMatrix W = new DenseMatrix(npl[0], inputSize);
        Vec b = new DenseVector(W.rows());
        initializeWeights(W, rand);
        initializeWeights(b, W.cols(), rand);
        Ws.add(W);
        bs.add(b);
        
        //Other Hiden Layers Layers 
        for(int i = 1; i < npl.length; i++)
        {
            W = new DenseMatrix(npl[i], npl[i-1]);
            b = new DenseVector(W.rows());
            initializeWeights(W, rand);
            initializeWeights(b, W.cols(), rand);
            Ws.add(W);
            bs.add(b);
        }
        
        //Output layer
        W = new DenseMatrix(outputSize, npl[npl.length-1]);
        b = new DenseVector(W.rows());
        initializeWeights(W, rand);
        initializeWeights(b, W.cols(), rand);
        Ws.add(W);
        bs.add(b);
        
    }
110811
public void addEdge(V from, V to) {
        addVertex(from);
        addVertex(to);
        neighbors.get(from).add(to);
    }
55836
public void add(double x, double weight)
   {
       //See http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
       
       if(weight < 0)
           throw new ArithmeticException("Can not add a negative weight");
       else if(weight == 0)
           return;
       
       double n1 = n;
       n+=weight;
       double delta = x - mean;
       double delta_n = delta*weight/n;
       double delta_n2 = delta_n*delta_n;
       double term1 = delta*delta_n*n1;
       
       
       mean += delta_n;
       m4 += term1 * delta_n2 * (n*n - 3*n + 3) + 6 * delta_n2 * m2 - 4 * delta_n * m3;
       m3 += term1 * delta_n * (n - 2) - 3 * delta_n * m2;
       m2 += weight*delta*(x-mean);
       
       if(min == null)
           min = max = x;
       else
       {
           min = Math.min(min, x);
           max = Math.max(max, x);
       }
   }
1249285
def Kdiag(self, X, target):
        """"""
        np.add(target, self.variance, target)
395550
protected void addToStored(ClassifierWithMemory newClassifier, double newClassifiersWeight) {
		ClassifierWithMemory[] newStored = new ClassifierWithMemory[this.ensemble.length + 1];
		double[][] newStoredWeights = new double[newStored.length][2];

		for (int i = 0; i < newStored.length; i++) {
			if (i < this.ensemble.length) {
				newStored[i] = this.ensemble[i];
				newStoredWeights[i][0] = this.weights[i][0];
				newStoredWeights[i][1] = this.weights[i][1];
			} else {
				newStored[i] = newClassifier;
				newStoredWeights[i][0] = newClassifiersWeight;
				newStoredWeights[i][1] = i;
			}
		}
		this.ensemble = newStored;
		this.weights = newStoredWeights;
	}
832672
public static void randomizeGaussian(MutableDoubleTuple t, Random random)
    {
        for (int i=0; i<t.getSize(); i++)
        {
            double value = random.nextGaussian();
            t.set(i, value);
        }
    }
356521
def _random_fill(self):
        """"""
        a = self._array
        for p, tile in self.positions_with_tile():
            if tile.is_blank():
                a[p] = Tile.random_tile()
912767
public void addEx(double weight, Object xObj, Object yObj, FeatureVector[] fvs) {
        int x = xAlphabet.lookupIndex(xObj);
        int y = yAlphabet.lookupIndex(yObj);
        addEx(weight, x, y, fvs);
    }