### Question:
BernoulliVertex extends VertexImpl<BooleanTensor, BooleanVertex> implements BooleanVertex, ProbabilisticBoolean, SamplableWithManyScalars<BooleanTensor>, LogProbGraphSupplier { @Override public LogProbGraph logProbGraph() { BooleanPlaceholderVertex valuePlaceholder = new BooleanPlaceholderVertex(this.getShape()); DoublePlaceholderVertex probTruePlaceholder = new DoublePlaceholderVertex(probTrue.getShape()); return LogProbGraph.builder() .input(this, valuePlaceholder) .input(probTrue, probTruePlaceholder) .logProbOutput(Bernoulli.logProbGraph(valuePlaceholder, probTruePlaceholder)) .build(); } BernoulliVertex(@LoadShape long[] shape,
                           @LoadVertexParam(PROBTRUE_NAME) Vertex<DoubleTensor, ?> probTrue); @ExportVertexToPythonBindings  BernoulliVertex(Vertex<DoubleTensor, ?> probTrue);  BernoulliVertex(double probTrue);  BernoulliVertex(long[] shape, double probTrue); @SaveVertexParam(PROBTRUE_NAME) DoubleVertex getProbTrue(); @Override double logProb(BooleanTensor value); @Override LogProbGraph logProbGraph(); @Override Map<Vertex, DoubleTensor> dLogProb(BooleanTensor value, Set<? extends Vertex> withRespectTo); @Override BooleanTensor sampleWithShape(long[] shape, KeanuRandom random);  }### Answer:
@Test public void doesExpectedLogProbGraphOnTensor() { DoubleVertex probTrue = ConstantVertex.of(0.25, 0.25); BernoulliVertex bernoulliVertex = new BernoulliVertex(probTrue); LogProbGraph logProbGraph = bernoulliVertex.logProbGraph(); LogProbGraphValueFeeder.feedValue(logProbGraph, probTrue, probTrue.getValue()); LogProbGraphValueFeeder.feedValue(logProbGraph, bernoulliVertex, BooleanTensor.create(true, false)); double expectedDensity = Math.log(0.25) + Math.log(0.75); LogProbGraphContract.matchesKnownLogDensity(logProbGraph, expectedDensity); }
@Test public void logProbGraphClampsProbTrueTo1() { DoubleVertex probTrue = ConstantVertex.of(2.); BernoulliVertex bernoulliVertex = new BernoulliVertex(probTrue); LogProbGraph logProbGraph = bernoulliVertex.logProbGraph(); LogProbGraphValueFeeder.feedValue(logProbGraph, probTrue, probTrue.getValue()); LogProbGraphValueFeeder.feedValue(logProbGraph, bernoulliVertex, BooleanTensor.scalar(true)); LogProbGraphContract.matchesKnownLogDensity(logProbGraph, 0.); }
@Test public void logProbGraphClampsProbTrueTo0() { DoubleVertex probTrue = ConstantVertex.of(-1.); BernoulliVertex bernoulliVertex = new BernoulliVertex(probTrue); LogProbGraph logProbGraph = bernoulliVertex.logProbGraph(); LogProbGraphValueFeeder.feedValue(logProbGraph, probTrue, probTrue.getValue()); LogProbGraphValueFeeder.feedValue(logProbGraph, bernoulliVertex, BooleanTensor.scalar(false)); LogProbGraphContract.matchesKnownLogDensity(logProbGraph, 0.); }