List of usage examples for org.apache.commons.math3.distribution PascalDistribution PascalDistribution
public PascalDistribution(RandomGenerator rng, int r, double p) throws NotStrictlyPositiveException, OutOfRangeException
From source file:net.myrrix.common.collection.SamplingLongPrimitiveIterator.java
public SamplingLongPrimitiveIterator(RandomGenerator random, LongPrimitiveIterator delegate, double samplingRate) { Preconditions.checkNotNull(random);//from ww w .j av a 2s .co m Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random, 1, samplingRate); this.delegate = delegate; this.hasNext = true; doNext(); }
From source file:com.cloudera.oryx.common.collection.SamplingLongPrimitiveIterator.java
/** * * @param random random number generator to re-use * @param delegate iterator to sample from * @param samplingRate sampling rate in (0,1] *//*from w w w. ja va 2s . c om*/ public SamplingLongPrimitiveIterator(RandomGenerator random, LongPrimitiveIterator delegate, double samplingRate) { Preconditions.checkNotNull(random); Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random, 1, samplingRate); this.delegate = delegate; this.hasNext = true; doNext(); }
From source file:de.fosd.jdime.matcher.cost_model.CMParameters.java
/** * Constructs a new <code>CMParameters</code> configured from the given <code>MergeContext</code>. * * @param context/* w w w . j a va 2s . com*/ * the <code>MergeContext</code> to use */ public CMParameters(MergeContext context) { setNoMatchWeight(context.getWn()); setRenamingWeight(context.getWr()); setAncestryViolationWeight(context.getWa()); setSiblingGroupBreakupWeight(context.getWs()); setOrderingWeight(context.getWo()); rng = new RandomAdaptor(context.getSeed().map(Well19937c::new).orElse(new Well19937c())); assignDist = new PascalDistribution(rng, 1, context.getpAssign()); setPAssign(context.getpAssign()); setFixLower(context.getFixLower()); setFixUpper(context.getFixUpper()); setBeta(30); setParallel(context.isCmMatcherParallel()); setFixRandomPercentage(context.isCmMatcherFixRandomPercentage()); lcaCache = new ConcurrentHashMap<>(); siblingCache = new ConcurrentHashMap<>(); otherSiblingsCache = new ConcurrentHashMap<>(); exactContainsCache = new ConcurrentHashMap<>(); boundContainsCache = new ConcurrentHashMap<>(); }
From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java
@Override public RandomNumberDistribution<Integer> getPascal(final RandomNumberStream rng, final Number r, final Number p) { final IntegerDistribution dist = new PascalDistribution( RandomNumberStream.Util.asCommonsRandomGenerator(rng), r.intValue(), p.doubleValue()); return new RandomNumberDistribution<Integer>() { @Override/*from w ww .ja v a 2 s . c om*/ public Integer draw() { return dist.sample(); } }; }
From source file:net.myrrix.online.som.SelfOrganizingMaps.java
/** * @return map of initialized {@link Node}s, where each node is empty and initialized to a randomly chosen * input vector normalized to unit length *//* ww w. ja v a 2 s . c o m*/ private static Node[][] buildInitialMap(FastByIDMap<float[]> vectors, int mapSize) { double p = ((double) mapSize * mapSize) / vectors.size(); // Choose mapSize^2 out of # vectors IntegerDistribution pascalDistribution; if (p >= 1.0) { // No sampling at all, we can't fill the map with one pass even pascalDistribution = null; } else { // Number of un-selected elements to skip between selections is geometrically distributed with // parameter p; this is the same as a negative binomial / Pascal distribution with r=1: pascalDistribution = new PascalDistribution(RandomManager.getRandom(), 1, p); } LongPrimitiveIterator keyIterator = vectors.keySetIterator(); Node[][] map = new Node[mapSize][mapSize]; for (Node[] mapRow : map) { for (int j = 0; j < mapSize; j++) { if (pascalDistribution != null) { keyIterator.skip(pascalDistribution.sample()); } while (!keyIterator.hasNext()) { keyIterator = vectors.keySetIterator(); // Start over, a little imprecise but affects it not much Preconditions.checkState(keyIterator.hasNext()); if (pascalDistribution != null) { keyIterator.skip(pascalDistribution.sample()); } } float[] sampledVector = vectors.get(keyIterator.nextLong()); mapRow[j] = new Node(sampledVector); } } return map; }
From source file:org.apache.mahout.cf.taste.impl.common.SamplingLongPrimitiveIterator.java
public SamplingLongPrimitiveIterator(RandomWrapper random, LongPrimitiveIterator delegate, double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0"); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; this.hasNext = true; doNext();// ww w .j a v a2s .co m }
From source file:org.apache.mahout.common.iterator.SamplingIterator.java
public SamplingIterator(RandomWrapper random, Iterator<? extends T> delegate, double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0. But samplingRate = " + samplingRate); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; }
From source file:org.codelibs.elasticsearch.taste.common.SamplingLongPrimitiveIterator.java
public SamplingLongPrimitiveIterator(final RandomWrapper random, final LongPrimitiveIterator delegate, final double samplingRate) { Preconditions.checkNotNull(delegate); Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0"); // Geometric distribution is special case of negative binomial (aka Pascal) with r=1: geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate); this.delegate = delegate; hasNext = true;// w w w. j a va 2 s. c o m doNext(); }