/** * {@inheritDoc} */ @Override public int sample() { return innerDistribution.sample(); } }
/** * {@inheritDoc} */ @Override public double sample() { return innerDistribution.sample(); } }
/** * Generate a random sample from the distribution. * * @param sampleSize the number of random values to generate. * @return an array representing the random sample. * @throws NotStrictlyPositiveException if {@code sampleSize} is not * positive. */ public Object[] sample(int sampleSize) throws NotStrictlyPositiveException { if (sampleSize <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize); } final Object[] out = new Object[sampleSize]; for (int i = 0; i < sampleSize; i++) { out[i] = sample(); } return out; }
out[i] = sample();
private Object generateSingleRowValue() { Object ret = null; ValueType type = schema.getType(); if (distribution instanceof AbstractIntegerDistribution) { ret = ((AbstractIntegerDistribution) distribution).sample(); } else if (distribution instanceof AbstractRealDistribution) { ret = ((AbstractRealDistribution) distribution).sample(); } else if (distribution instanceof EnumeratedDistribution) { ret = ((EnumeratedDistribution) distribution).sample(); } ret = convertType(ret, type); return ret; }
/** * {@inheritDoc} */ @Override public int sample() { return innerDistribution.sample(); } }
/** * {@inheritDoc} */ @Override public int sample() { return innerDistribution.sample(); } }
/** * {@inheritDoc} */ @Override public double sample() { return innerDistribution.sample(); } }
/** * {@inheritDoc} */ @Override public double sample() { return innerDistribution.sample(); } }
public T sample() { return enumeratedDistribution.sample(); }
List<Pair<Boolean,Double>> list = new ArrayList<Pair<Boolean,Double>>(); list.add(new ImmutablePair(true, 0.2)); list.add(new ImmutablePair(false, 0.8)); EnumeratedDistribution e = new EnumeratedDistribution(list); //execute case 1 if (e.sample()) { //execute case 2 } ...
List<Pair<String,Double>> list = new ArrayList<Pair<String,Double>>(); list.add(new ImmutablePair("name_1", 0.2)); list.add(new ImmutablePair("name_2", 0.4)); list.add(new ImmutablePair("name_3", 0.4)); EnumeratedDistribution e = new EnumeratedDistribution(list); switch(e.sample()) { case "name_1" : ... break; case "name_2" : ... break; case "name_3" : ... break; }
@Override protected void eval() { val = enumeratedDistribution.sample().get(); }
@Override protected void eval() { val = enumeratedDistribution.sample().get(); }
/** * Generate a random sample from the distribution. * * @param sampleSize the number of random values to generate. * @return an array representing the random sample. * @throws NotStrictlyPositiveException if {@code sampleSize} is not * positive. */ public Object[] sample(int sampleSize) throws NotStrictlyPositiveException { if (sampleSize <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize); } final Object[] out = new Object[sampleSize]; for (int i = 0; i < sampleSize; i++) { out[i] = sample(); } return out; }
/** * Generate a random sample from the distribution. * * @param sampleSize the number of random values to generate. * @return an array representing the random sample. * @throws NotStrictlyPositiveException if {@code sampleSize} is not * positive. */ public Object[] sample(int sampleSize) throws NotStrictlyPositiveException { if (sampleSize <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize); } final Object[] out = new Object[sampleSize]; for (int i = 0; i < sampleSize; i++) { out[i] = sample(); } return out; }
out[i] = sample();
/** * sample a sequence of integers from the model, using current (hPrev) memory state, seedIx is seed letter for first time step */ public String sample(int seedIx) { INDArray x = Nd4j.zeros(vocabSize, 1); x.putScalar(seedIx, 1); int sampleSize = 144; INDArray ixes = Nd4j.create(sampleSize); INDArray h = hPrev.dup(); for (int t = 0; t < sampleSize; t++) { h = Transforms.tanh(wxh.mmul(x).add(whh.mmul(h)).add(bh)); INDArray y = (why.mmul(h)).add(by); INDArray pm = Nd4j.getExecutioner().execAndReturn(new OldSoftMax(y)).ravel(); List<Pair<Integer, Double>> d = new LinkedList<>(); for (int pi = 0; pi < vocabSize; pi++) { d.add(new Pair<>(pi, pm.getDouble(0, pi))); } try { EnumeratedDistribution<Integer> distribution = new EnumeratedDistribution<>(d); int ix = distribution.sample(); x = Nd4j.zeros(vocabSize, 1); x.putScalar(ix, 1); ixes.putScalar(t, ix); } catch (Exception e) { } } return getSampleString(ixes); }
EnumeratedDistribution<Integer> distribution = new EnumeratedDistribution<>(d); int ix = distribution.sample();