### Question:
GaussianVertex extends VertexImpl<DoubleTensor, DoubleVertex> implements DoubleVertex, Differentiable, ProbabilisticDouble, SamplableWithManyScalars<DoubleTensor>, LogProbGraphSupplier { @Override public double logProb(DoubleTensor value) { DoubleTensor muValues = mu.getValue(); DoubleTensor sigmaValues = sigma.getValue(); DoubleTensor logPdfs = Gaussian.withParameters(muValues, sigmaValues).logProb(value); return logPdfs.sumNumber(); } GaussianVertex(@LoadShape long[] shape,
                          @LoadVertexParam(MU_NAME) Vertex<DoubleTensor, ?> mu,
                          @LoadVertexParam(SIGMA_NAME) Vertex<DoubleTensor, ?> sigma); @ExportVertexToPythonBindings  GaussianVertex(Vertex<DoubleTensor, ?> mu, Vertex<DoubleTensor, ?> sigma);  GaussianVertex(Vertex<DoubleTensor, ?> mu, double sigma);  GaussianVertex(double mu, Vertex<DoubleTensor, ?> sigma);  GaussianVertex(double mu, double sigma);  GaussianVertex(long[] tensorShape, Vertex<DoubleTensor, ?> mu, double sigma);  GaussianVertex(long[] tensorShape, double mu, Vertex<DoubleTensor, ?> sigma);  GaussianVertex(long[] tensorShape, double mu, double sigma);  GaussianVertex(long[] tensorShape, DoubleTensor mu, DoubleTensor sigma);  GaussianVertex(DoubleTensor mu, DoubleTensor sigma); @SaveVertexParam(MU_NAME) DoubleVertex getMu(); @SaveVertexParam(SIGMA_NAME) DoubleVertex getSigma(); @Override double logProb(DoubleTensor value); @Override LogProbGraph logProbGraph(); @Override Map<Vertex, DoubleTensor> dLogProb(DoubleTensor value, Set<? extends Vertex> withRespectTo); @Override DoubleTensor sampleWithShape(long[] shape, KeanuRandom random);  }### Answer:
@Test public void canLogProbWithBatchSigma() { DoubleTensor mu = DoubleTensor.create(-1, 2); DoubleTensor sigma = DoubleTensor.create(0.5, 1.0, 0.25, 2).reshape(2, 2); GaussianVertex g = new GaussianVertex(mu, sigma); DoubleTensor sample = g.sample(); assertArrayEquals(new long[]{2, 2}, sample.getShape()); double expected = new NormalDistribution(-1, 0.5).logDensity(sample.getValue(0, 0)) + new NormalDistribution(2, 1).logDensity(sample.getValue(0, 1)) + new NormalDistribution(-1, 0.25).logDensity(sample.getValue(1, 0)) + new NormalDistribution(2, 2).logDensity(sample.getValue(1, 1)); double actual = g.logProb(sample); assertEquals(expected, actual, 1e-6); }
@Test public void canLogProbWithBatchMu() { DoubleTensor mu = DoubleTensor.create(-1, 2, 0.5, 1.5).reshape(2, 2); DoubleTensor sigma = DoubleTensor.create(0.5, 1.0); GaussianVertex g = new GaussianVertex(mu, sigma); DoubleTensor sample = g.sample(); assertArrayEquals(new long[]{2, 2}, sample.getShape()); double expectedLogDensity = new NormalDistribution(-1, 0.5).logDensity(sample.getValue(0, 0)) + new NormalDistribution(2, 1).logDensity(sample.getValue(0, 1)) + new NormalDistribution(0.5, 0.5).logDensity(sample.getValue(1, 0)) + new NormalDistribution(1.5, 1).logDensity(sample.getValue(1, 1)); assertEquals(g.logProb(sample), expectedLogDensity, 1e-6); }