### Question:
DirichletVertex extends VertexImpl<DoubleTensor, DoubleVertex> implements DoubleVertex, Differentiable, ProbabilisticDouble, SamplableWithManyScalars<DoubleTensor>, LogProbGraphSupplier { @Override public double logProb(DoubleTensor value) { DoubleTensor concentrationValues = concentration.getValue(); DoubleTensor logPdfs = Dirichlet.withParameters(concentrationValues).logProb(value); return logPdfs.sumNumber(); } DirichletVertex(@LoadShape long[] tensorShape,
                           @LoadVertexParam(CONCENTRATION_NAME) Vertex<DoubleTensor, ?> concentration); @ExportVertexToPythonBindings  DirichletVertex(Vertex<DoubleTensor, ?> concentration);  DirichletVertex(long[] tensorShape, double concentration);  DirichletVertex(double... concentration); @SaveVertexParam(CONCENTRATION_NAME) DoubleVertex getConcentration(); @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 dLogProbMatchesFiniteDifferenceCalculationFordPdconcentration() { UniformVertex concentrationHyperParam = new UniformVertex(1.5, 3.0); DoubleTensor hyperParamValue = DoubleTensor.create(new double[]{7, 7}, 1, 2); concentrationHyperParam.setValue(hyperParamValue); DirichletVertex dirichlet = new DirichletVertex(concentrationHyperParam); DoubleTensor startingValue = DoubleTensor.create(new double[]{0.1, 0.9}, new long[]{1, 2}); double start = 0.1; double end = 0.9; double step = 0.05; double gradientDelta = 0.01; for (double i = start; i < end; i = i + step) { dirichlet.setAndCascade(startingValue); double[] dirchletValue = startingValue.asFlatDoubleArray(); double[] values = hyperParamValue.asFlatDoubleArray(); concentrationHyperParam.setAndCascade(DoubleTensor.create(new double[]{values[0] - gradientDelta, values[1] - gradientDelta})); double lnDensityA1 = dirichlet.logProb(startingValue); concentrationHyperParam.setAndCascade(DoubleTensor.create(new double[]{values[0] + gradientDelta, values[1] + gradientDelta})); double lnDensityA2 = dirichlet.logProb(startingValue); double diffLnDensityApproxExpected = (lnDensityA2 - lnDensityA1) / (2 * gradientDelta); Map<Vertex, DoubleTensor> diffln = dirichlet.dLogProbAtValue(concentrationHyperParam); double actualDiff = diffln.get(concentrationHyperParam).getValue(0, 0) + diffln.get(concentrationHyperParam).getValue(0, 1); assertEquals(diffLnDensityApproxExpected, actualDiff, 0.001); startingValue = DoubleTensor.create(new double[]{dirchletValue[0] + step, dirchletValue[1] - step}, new long[]{1, 2}); } }