Samples the sequence repeatedly, making numSamples passes over the entire sequence.
Destructively modifies the sequence in place.
424350
public void sampleSequenceRepeatedly(SequenceModel model, int numSamples) {
    int[] sequence = getRandomSequence(model);
    sampleSequenceRepeatedly(model, sequence, numSamples);
  }
1230488
public synchronized void update(double sample) {
        long now = System.currentTimeMillis();

        if (lastMillis == 0) {    // first sample
            average = sample;
            lastMillis = now;
            return;
        }
        long deltaTime = now - lastMillis;
        double coeff = Math.exp(-1.0 * ((double)deltaTime / windowMillis));
        average = (1.0 - coeff) * sample + coeff * average;

        lastMillis = now;
    }
1220426
public static void sampleWithoutReplacement(int[] array, int numArgClasses, Random rand) {
    int[] temp = new int[numArgClasses];
    for (int i = 0; i < temp.length; i++) {
      temp[i] = i;
    }
    shuffle(temp, rand);
    System.arraycopy(temp, 0, array, 0, array.length);
  }
1000026
public double[] sample(int numSamples, Random rand)
    {
        double[] samples = new double[numSamples];
        for(int i = 0; i < samples.length; i++)
            samples[i] = invCdf(rand.nextDouble());
        
        return samples;
    }
1018310
def downsample(self, sample_factor=2):
        
        if sample_factor < 0:
            raise Exception('Factor for subsampling must be postive, got %g' % sample_factor)
        newlength = floor(len(self.index) / sample_factor)
        func = lambda v: v[0:int(newlength * sample_factor)].reshape(-1, sample_factor).mean(axis=1)
        newindex = arange(newlength)
        return self.map(func, index=newindex)
294024
@Override
	public Iterator<T> sample(final Iterator<T> input) {
		if (fraction == 0) {
			return emptyIterable;
		}

		return new SampledIterator<T>() {
			T currentElement;
			int currentCount = 0;

			@Override
			public boolean hasNext() {
				if (currentCount > 0) {
					return true;
				} else {
					samplingProcess();
					if (currentCount > 0) {
						return true;
					} else {
						return false;
					}
				}
			}

			@Override
			public T next() {
				if (currentCount <= 0) {
					samplingProcess();
				}
				currentCount--;
				return currentElement;
			}

			public int poisson_ge1(double p) {
				// sample 'k' from Poisson(p), conditioned to k >= 1.
				double q = Math.pow(Math.E, -p);
				// simulate a poisson trial such that k >= 1.
				double t = q + (1 - q) * random.nextDouble();
				int k = 1;
				// continue standard poisson generation trials.
				t = t * random.nextDouble();
				while (t > q) {
					k++;
					t = t * random.nextDouble();
				}
				return k;
			}

			private void skipGapElements(int num) {
				// skip the elements that occurrence number is zero.
				int elementCount = 0;
				while (input.hasNext() && elementCount < num) {
					currentElement = input.next();
					elementCount++;
				}
			}

			private void samplingProcess() {
				if (fraction <= THRESHOLD) {
					double u = Math.max(random.nextDouble(), EPSILON);
					int gap = (int) (Math.log(u) / -fraction);
					skipGapElements(gap);
					if (input.hasNext()) {
						currentElement = input.next();
						currentCount = poisson_ge1(fraction);
					}
				} else {
					while (input.hasNext()) {
						currentElement = input.next();
						currentCount = poissonDistribution.sample();
						if (currentCount > 0) {
							break;
						}
					}
				}
			}
		};
	}
1209381
function arraySample(array) {
      var length = array.length;
      return length ? array[baseRandom(0, length - 1)] : undefined$1;
    }
930867
function decode$1(samples) {
  /** @type {!Int16Array} */
  let pcmSamples = new Int16Array(samples.length);
  for (let i=0; i<samples.length; i++) {
    pcmSamples[i] = decodeSample(samples[i]);
  }
  return pcmSamples;
}
1037538
public double resample(final double samples, final Timebase oldRate)
	{
		if (samples == 0)
		{
			return 0;
		}
		else if (!this.equals(oldRate))
		{
			final double resampled = resample(samples, oldRate, this);

			return resampled;
		}
		else
		{
			return samples;
		}
	}
265546
public long resample(final long samples, final Timebase oldRate)
	{
		try
		{
			return resample(samples, oldRate, false);
		}
		catch (ResamplingException e)
		{
			// should never happen
			throw new RuntimeException(e);
		}
	}
83158
public void sampleSequenceBackward(SequenceModel model, int[] sequence, double temperature) {
    for (int pos=sequence.length-1; pos>=0; pos--) {
      samplePosition(model, sequence, pos, temperature);
    }
  }
880618
public final static Sample append(List<Sample> samples) {
        if (samples.size() == 0) {
            return buildSample(0, new double[0]);
        }

        int sampleCount = 0;

        // append voices to each other
        double[] first = samples.get(0).getInterleavedSamples();
        sampleCount += samples.get(0).getSampleCount();

        double[][] samples_ary = new double[samples.size() - 1][];
        for (int i = 0; i < samples_ary.length; i++) {
            samples_ary[i] = samples.get(i + 1).getInterleavedSamples();
            sampleCount += samples.get(i + 1).getSampleCount();
        }

        double[] appended = concatAll(first, samples_ary);

        return buildSample(sampleCount, appended);
    }
64342
def update(self, value):
    """"""
    super(UniformSample, self).update(value)

    self.count += 1
    c = self.count
    if c < len(self.sample):
      self.sample[c-1] = value
    else:
      r = random.randint(0, c)
      if r < len(self.sample):
        self.sample[r] = value
810853
def clear_samples(self):
        
        # store the iteration that the clear is occuring on
        self._lastclear = self.niterations
        self._itercounter = 0
        # now clear the chain
        self._sampler.reset()
1315300
private void setNextSamplePosition(long position)
    {
        tryAgain: while (true)
        {
            position += minIndexInterval;
            long test = indexIntervalMatches++;
            for (int start : startPoints)
                if ((test - start) % BASE_SAMPLING_LEVEL == 0)
                    continue tryAgain;

            nextSamplePosition = position;
            return;
        }
    }
157967
def sample(records, k, random_seed=None):
    

    if random_seed is not None:
        random.seed(random_seed)

    result = []
    for i, record in enumerate(records):
        if len(result) < k:
            result.append(record)
        else:
            r = random.randint(0, i)
            if r < k:
                result[r] = record
    return result
49502
public static int[] sampleWithoutReplacement(int sampleSize, int n) {
        // This implements a modified form of the genshuf() function from
        // Programming Pearls pg. 129.
        
        // TODO: Design a faster method that only generates min(m, n-m) integers.
        
        int[] array = IntSort.getIndexArray(n);
        for (int i=0; i<sampleSize; i++) {
            int j = Prng.nextInt(n - i) + i;
            // Swap array[i] and array[j]
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
        return Arrays.copyOf(array, sampleSize);
    }