Corrupts a binary vector by inverting noiseLevel percent of its bits.

  @param vector     (array) binary vector to be corrupted
  @param noiseLevel (float) amount of noise to be applied on the vector.
553068
def corruptDenseVector(vector, noiseLevel):
  
  size = len(vector)
  for i in range(size):
    rnd = random.random()
    if rnd < noiseLevel:
      if vector[i] == 1:
        vector[i] = 0
      else:
        vector[i] = 1
872797
public INDArray getCorruptedInput(INDArray x, double corruptionLevel) {
        INDArray corrupted = Nd4j.getDistributions().createBinomial(1, 1 - corruptionLevel).sample(x.ulike());
        corrupted.muli(x.castTo(corrupted.dataType()));
        return corrupted;
    }
330531
private static int compareLexical(BitVector a, BitVector b) {
		final int aSize = a.size();
		final int bSize = b.size();
		if (aSize == bSize) return compareNumeric(a, b); // more efficient
		final int size = Math.min(aSize, bSize);
		final int aStart = a.finish - size;
		final int bStart = b.finish - size;
		for (int i = size - 1; i >= 0; i--) {
			boolean aBit = a.getBitAdj(aStart + i);
			boolean bBit = b.getBitAdj(bStart + i);
			if (aBit != bBit) return bBit ? -1 : 1;
		}
		return aSize < bSize ? -1 : 1;
	}
214975
public void computeErrorVector( DMatrixRMaj A , DMatrixRMaj errors ) {
		errors.reshape(A.numRows,1);
		CommonOps_DDRM.mult(A,vectorT,errors);
	}
147876
def _addNoise(self, pattern, noiseLevel, inputSize):
    
    if pattern is None:
      return None

    # Bits that could be noise. These can't be from the original set.
    candidateBits = list(set(range(inputSize)) - set(pattern))
    random.shuffle(candidateBits)

    newBits = set()
    for bit in pattern:
      if random.random() < noiseLevel:
        newBits.add(candidateBits.pop())
      else:
        newBits.add(bit)

    return newBits
711909
private void filter(Vector3f acc) {
        float threshold = 15f;
        if (acc.x > threshold) {
            acc.x = threshold;
        } else if(acc.x < -threshold) {
            acc.x = -threshold;
        }
        if (acc.y > threshold) {
            acc.y = threshold;
        } else if(acc.y < -threshold) {
            acc.y = -threshold;
        }
        if (acc.z > threshold) {
            acc.z = threshold;
        } else if(acc.z < -threshold) {
            acc.z = -threshold;
        }
    }
899971
protected void checkSizes(Matrix A, Vector b, Vector x) {
        if (!A.isSquare())
            throw new IllegalArgumentException("!A.isSquare()");
        if (b.size() != A.numRows())
            throw new IllegalArgumentException("b.size() != A.numRows()");
        if (b.size() != x.size())
            throw new IllegalArgumentException("b.size() != x.size()");
    }
749392
public static void ensureNotSingular( DMatrixSparseCSC A , Random rand ) {
//        if( A.numRows < A.numCols ) {
//            throw new IllegalArgumentException("Fewer equations than variables");
//        }

        int []s = UtilEjml.shuffled(A.numRows,rand);
        Arrays.sort(s);

        int N = Math.min(A.numCols,A.numRows);
        for (int col = 0; col < N; col++) {
            A.set(s[col],col,rand.nextDouble()+0.5);
        }
    }
54088
public void fill_1(byte[] v, int byteoff, int nbits, int bitoff) {
      if (nbits < 0) throw new NegativeArraySizeException("nbits < 0: " + nbits);
      if (byteoff < 0) throw new IndexOutOfBoundsException("byteoff < 0: "+ byteoff);
      if (bitoff < 0) throw new IndexOutOfBoundsException("bitoff < 0: " + bitoff);
      assert v == null || byteoff + ((nbits-1) >> 3) + 1 <= v.length;
      _val = v;
      _nbits = nbits;
      _bitoff = bitoff;
      _byteoff = byteoff;
    }
355687
protected void indexVectorInternal(double[] vector) throws Exception {
		if (vector.length != vectorLength) {
			throw new Exception("The dimensionality of the vector is wrong!");
		}
		// apply a random transformation if needed
		if (transformation == TransformationType.RandomRotation) {
			vector = rr.rotate(vector);
		} else if (transformation == TransformationType.RandomPermutation) {
			vector = rp.permute(vector);
		}
		// transform the vector into a PQ code
		int[] pqCode = new int[numSubVectors];

		for (int i = 0; i < numSubVectors; i++) {
			// take the appropriate sub-vector
			int fromIdex = i * subVectorLength;
			int toIndex = fromIdex + subVectorLength;
			double[] subvector = Arrays.copyOfRange(vector, fromIdex, toIndex);
			// assign the sub-vector to the nearest centroid of the respective sub-quantizer
			pqCode[i] = computeNearestProductIndex(subvector, i);
		}

		if (numProductCentroids <= 256) {
			byte[] pqByteCode = transformToByte(pqCode);
			if (loadIndexInMemory) { // append the ram-based index
				pqByteCodes.add(pqByteCode);
			}
			appendPersistentIndex(pqByteCode); // append the disk-based index
		} else {
			short[] pqShortCode = transformToShort(pqCode);
			if (loadIndexInMemory) { // append the ram-based index
				pqShortCodes.add(pqShortCode);
			}
			appendPersistentIndex(pqShortCode); // append the disk-based index
		}

	}
1181308
@Override
    @SuppressWarnings("unchecked")
    protected void fixup(int k) {
        if (onMinLevel(k)) {
            int p = k / 2;
            K kValue = array[k];
            if (p > 0 && ((Comparable<? super K>) array[p]).compareTo(kValue) < 0) {
                array[k] = array[p];
                array[p] = kValue;
                fixupMax(p);
            } else {
                fixupMin(k);
            }
        } else {
            int p = k / 2;
            K kValue = array[k];
            if (p > 0 && ((Comparable<? super K>) kValue).compareTo(array[p]) < 0) {
                array[k] = array[p];
                array[p] = kValue;
                fixupMin(p);
            } else {
                fixupMax(k);
            }
        }
    }
421731
public static double[] xVals(double[] vector) {


        if (vector == null)
            return null;
        double[] x = new double[vector.length / 2];
        int count = 0;
        for (int i = 0; i < vector.length; i++) {
            if (i % 2 != 0)
                x[count++] = vector[i];
        }
        return x;
    }
853693
public static double sumOfAbsolutes (double[] vector) {
        // Declare and initialize the accumulator:
        double total = 0.0;

        // Iterate over the vector:
        for (int i = 0; i < vector.length; i++) {
            total += Math.abs(vector[i]);
        }

        // Done, return:
        return total;
    }
264779
def addNoise(vecs, percent=0.1, n=2048):
  
  noisyVecs = []
  for vec in vecs:
    nv = vec.copy()
    for idx in vec:
      if numpy.random.random() <= percent:
        nv.discard(idx)
        nv.add(numpy.random.randint(n))
    noisyVecs.append(nv)

  return noisyVecs
1270363
function(vector) {
            	var dot = this.dot(vector);
            	return (dot === null) ? null : (Math.abs(dot) <= sylvester.precision);
                }
89567
public static double sumOfMeanDifferencesOnePoint(double[] vector) {
        double mean = sum(vector) / vector.length;
        double ret = 0;
        for (int i = 0; i < vector.length; i++) {
            double vec1Diff = Math.pow(vector[i] - mean, 2);
            ret += vec1Diff;
        }
        return ret;
    }
1038909
public static /*@pure@*/ double mean(double[] vector) {
  
    double sum = 0;

    if (vector.length == 0) {
      return 0;
    }
    for (int i = 0; i < vector.length; i++) {
      sum += vector[i];
    }
    return sum / (double) vector.length;
  }