public Missing(int seed, double p, Sampler<T> delegate, T missingMarker) { this.p = p; this.delegate = delegate; this.missingMarker = missingMarker; gen = RandomUtils.getRandom(seed); }
@Override public int hashCode() { return 31 * RandomUtils.hashDouble(weight) + value.hashCode(); } }
@Test public void testHashFloat() { assertEquals(new Float(0.0f).hashCode(), RandomUtils.hashFloat(0.0f)); assertEquals(new Float(1.0f).hashCode(), RandomUtils.hashFloat(1.0f)); assertEquals(new Float(Float.POSITIVE_INFINITY).hashCode(), RandomUtils.hashFloat(Float.POSITIVE_INFINITY)); assertEquals(new Float(Float.NaN).hashCode(), RandomUtils.hashFloat(Float.NaN)); }
static void train(Matrix input, Vector target, OnlineLearner lr) { RandomUtils.useTestSeed(); Random gen = RandomUtils.getRandom(); // train on samples in random order (but only one pass) for (int row : permute(gen, 60)) { lr.train((int) target.get(row), input.viewRow(row)); } lr.close(); }
@Test public void testNextTwinPrime() { assertEquals(5, RandomUtils.nextTwinPrime(-1)); assertEquals(5, RandomUtils.nextTwinPrime(1)); assertEquals(5, RandomUtils.nextTwinPrime(2)); assertEquals(5, RandomUtils.nextTwinPrime(3)); assertEquals(7, RandomUtils.nextTwinPrime(4)); assertEquals(7, RandomUtils.nextTwinPrime(5)); assertEquals(13, RandomUtils.nextTwinPrime(6)); assertEquals(RandomUtils.MAX_INT_SMALLER_TWIN_PRIME + 2, RandomUtils.nextTwinPrime(RandomUtils.MAX_INT_SMALLER_TWIN_PRIME)); try { RandomUtils.nextTwinPrime(RandomUtils.MAX_INT_SMALLER_TWIN_PRIME + 1); fail(); } catch (IllegalArgumentException iae) { // good } }
@Override @Before public void setUp() { RandomUtils.useTestSeed(); }
public FastIDSet(int size, float loadFactor) { Preconditions.checkArgument(size >= 0, "size must be at least 0"); Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0"); this.loadFactor = loadFactor; int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor); Preconditions.checkArgument(size < max, "size must be less than %d", max); int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size)); keys = new long[hashSize]; Arrays.fill(keys, NULL); }
@Override @Before public void setUp() { RandomUtils.useTestSeed(); }
private MultiNormal(Matrix scale, Vector mean, int dimension) { gen = RandomUtils.getRandom(); this.dimension = dimension; this.scale = scale; this.mean = mean; }
@Override public int hashCode() { int result = size; Iterator<Element> iter = iterateNonZero(); while (iter.hasNext()) { Element ele = iter.next(); result += ele.index() * RandomUtils.hashDouble(ele.get()); } return result; }
public FastIDSet(int size, float loadFactor) { Preconditions.checkArgument(size >= 0, "size must be at least 0"); Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0"); this.loadFactor = loadFactor; int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor); Preconditions.checkArgument(size < max, "size must be less than %d", max); int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size)); keys = new long[hashSize]; Arrays.fill(keys, NULL); }
@Override @Before public void setUp() { RandomUtils.useTestSeed(); }
@Override public int hashCode() { return (int) itemID ^ RandomUtils.hashFloat(value); }
/** * Constructs a uniform distribution with the given minimum and maximum, using a {@link * org.apache.mahout.math.jet.random.engine.MersenneTwister} seeded with the given seed. */ public Uniform(double min, double max, int seed) { this(min, max, RandomUtils.getRandom(seed)); }
@Test public void testHashDouble() { assertEquals(new Double(0.0).hashCode(), RandomUtils.hashDouble(0.0)); assertEquals(new Double(1.0).hashCode(), RandomUtils.hashDouble(1.0)); assertEquals(new Double(Double.POSITIVE_INFINITY).hashCode(), RandomUtils.hashDouble(Double.POSITIVE_INFINITY)); assertEquals(new Double(Double.NaN).hashCode(), RandomUtils.hashDouble(Double.NaN)); }
public FastIDSet(int size, float loadFactor) { Preconditions.checkArgument(size >= 0, "size must be at least 0"); Preconditions.checkArgument(loadFactor >= 1.0f, "loadFactor must be at least 1.0"); this.loadFactor = loadFactor; int max = (int) (RandomUtils.MAX_INT_SMALLER_TWIN_PRIME / loadFactor); Preconditions.checkArgument(size < max, "size must be less than %d", max); int hashSize = RandomUtils.nextTwinPrime((int) (loadFactor * size)); keys = new long[hashSize]; Arrays.fill(keys, NULL); }
@Before public void setUp() throws Exception { testTempDir = null; RandomUtils.useTestSeed(); }
@Override public int hashCode() { return (int) itemID ^ RandomUtils.hashFloat(value); }
public IndianBuffet(double alpha, WordFunction<T> converter) { this.alpha = alpha; this.converter = converter; gen = RandomUtils.getRandom(); }
@Override public int hashCode() { return (int) itemID1 ^ (int) itemID2 ^ RandomUtils.hashDouble(value); }