@Override public ArithmeticDouble nextGaussian(double mu, double sigma) { double randomDouble = random.nextGaussian(mu, sigma); return new ArithmeticDouble(randomDouble); } }
private static void initializeMomentumForEachVariable(List<? extends Variable<DoubleTensor, ?>> variables, Map<VariableReference, DoubleTensor> momentums, KeanuRandom random) { for (Variable<DoubleTensor, ?> variable : variables) { momentums.put(variable.getReference(), random.nextGaussian(variable.getShape())); } }
@Override public ArithmeticDouble nextGaussian(ArithmeticDouble mu, double sigma) { double randomDouble = random.nextGaussian(mu.getValue(), sigma); return new ArithmeticDouble(randomDouble); }
@Override public ArithmeticDouble nextGaussian(double mu, ArithmeticDouble sigma) { double randomDouble = random.nextGaussian(mu, sigma.getValue()); return new ArithmeticDouble(randomDouble); }
@Override public DoubleTensor sample(long[] shape, KeanuRandom random) { DoubleTensor unityGaussian = random.nextGaussian(shape); return unityGaussian.timesInPlace(sigma).plusInPlace(mu); }
public DoubleTensor nextGaussian(long[] shape, DoubleTensor mu, DoubleTensor sigma) { return nextGaussian(shape).timesInPlace(sigma).plusInPlace(mu); }
public DoubleTensor nextGaussian(long[] shape) { if (Arrays.equals(shape, Tensor.SCALAR_SHAPE)) { return new ScalarDoubleTensor(nextGaussian()); } else { return new Nd4jDoubleTensor(doubleNextGaussian(shape)); } }
@Override public ArithmeticDouble nextGaussian(ArithmeticDouble mu, ArithmeticDouble sigma) { double randomDouble = random.nextGaussian(mu.getValue(), sigma.getValue()); return new ArithmeticDouble(randomDouble); }
@Before public void setup() { alwaysAccept = mock(KeanuRandom.class); when(alwaysAccept.nextDouble()).thenReturn(0.0); when(alwaysAccept.nextGaussian(any())).thenReturn(DoubleTensor.ZERO_SCALAR); alwaysReject = mock(KeanuRandom.class); when(alwaysReject.nextDouble()).thenReturn(1.0); when(alwaysReject.nextGaussian(any())).thenReturn(DoubleTensor.ZERO_SCALAR); }
@Test public void canSampleGaussianScalar() { assertEquals(0, random.nextGaussian(new long[0]).getRank()); assertEquals(1, random.nextGaussian(new long[]{1}).getRank()); assertEquals(2, random.nextGaussian(new long[]{1, 1}).getRank()); assertEquals(2, random.nextGaussian(new long[]{2, 3}).getRank()); }
@Override public Proposal getProposal(Set<Variable> variables, KeanuRandom random) { Proposal proposal = new Proposal(); for (Variable variable : variables) { if (!(variable.getValue() instanceof DoubleTensor)) { throw new IllegalStateException("Gaussian proposal function cannot be used for discrete variable " + variable); } DoubleTensor sample = random.nextGaussian(variable.getShape(), (DoubleTensor) variable.getValue(), sigma); proposal.setProposal(variable, sample); } proposalNotifier.notifyProposalCreated(proposal); return proposal; }
.collect(Collectors.toMap( Variable::getReference, v -> random.nextGaussian(v.getShape()) ));
@Override public DoubleTensor sample(long[] shape, KeanuRandom random) { DoubleTensor chi2Samples = ChiSquared.withParameters(v).sample(shape, random); return random.nextGaussian(shape).divInPlace(chi2Samples.divInPlace(v.toDouble()).sqrtInPlace()); }
@Override public DoubleTensor sample(long[] shape, KeanuRandom random) { TensorShapeValidation.checkTensorsMatchNonLengthOneShapeOrAreLengthOne(shape, mu.getShape()); final DoubleTensor choleskyCov = covariance.choleskyDecomposition(); final DoubleTensor variateSamples = random.nextGaussian(mu.getShape()); final DoubleTensor covTimesVariates = isUnivariate() ? choleskyCov.times(variateSamples) : choleskyCov.matrixMultiply(variateSamples); return covTimesVariates.plus(mu); }
public DoubleTensor sample(int nSamples, KeanuRandom random) { // get a random sample as the mean of a gaussian // then draw a sample from the gaussian around that mean with the bandwidth as the standard deviation DoubleTensor value = Uniform.withParameters( DoubleTensor.scalar(0), DoubleTensor.scalar(samples.getLength()) ).sample(new long[]{nSamples}, random); DoubleTensor index = value.floorInPlace(); double[] shuffledSamples = new double[nSamples]; int j = 0; for (Double i : index.asFlatList()) { shuffledSamples[j] = samples.getValue(i.intValue()); j++; } DoubleTensor sampleMus = DoubleTensor.create(shuffledSamples); return random.nextGaussian(new long[]{nSamples}).timesInPlace(bandwidth).plusInPlace(sampleMus); }