### Question:
GaussianProposalDistribution implements ProposalDistribution { @Override public <T> double logProb(Probabilistic<T> variable, T ofValue, T givenValue) { if (!(ofValue instanceof DoubleTensor)) { throw new ClassCastException("Only DoubleTensor values are supported - not " + ofValue.getClass().getSimpleName()); } if (!sigmas.containsKey(variable)) { throw new IllegalStateException("A sigma was not specified for variable " + variable); } Gaussian proposalDistribution = (Gaussian) Gaussian.withParameters((DoubleTensor) ofValue, sigmas.get(variable)); return proposalDistribution.logProb((DoubleTensor) givenValue).sumNumber(); } GaussianProposalDistribution(List<? extends Variable> variables, DoubleTensor sigma);  GaussianProposalDistribution(List<? extends Variable> variables, DoubleTensor sigma, List<ProposalListener> listeners);  GaussianProposalDistribution(Map<? extends Variable, DoubleTensor> sigmas);  GaussianProposalDistribution(Map<? extends Variable, DoubleTensor> sigmas, List<ProposalListener> listeners); @Override Proposal getProposal(Set<? extends Variable> variables, KeanuRandom random); @Override double logProb(Probabilistic<T> variable, T ofValue, T givenValue); @Override void onProposalRejected();  }### Answer:
@Test public void theLogProbAtToIsMultivariateGaussian() { double logProb = proposalDistribution.logProbAtToGivenFrom(proposal); DoubleTensor mu = DoubleTensor.concat(currentStateForVertex1, currentStateForVertex2); DoubleTensor cov = DoubleTensor.concat(sigmaForVertex1, sigmaForVertex2).pow(2.).diag(); DoubleTensor x = DoubleTensor.concat(proposedStateForVertex1, proposedStateForVertex2); DoubleTensor expectedLogProb = MultivariateGaussian.withParameters(mu, cov).logProb(x); assertThat(logProb, closeTo(expectedLogProb.sumNumber(), 1e-14)); }
@Test public void theLogProbAtFromIsMultivariateGaussian() { double logProb = proposalDistribution.logProbAtFromGivenTo(proposal); DoubleTensor mu = DoubleTensor.concat(proposedStateForVertex1, proposedStateForVertex2); DoubleTensor cov = DoubleTensor.concat(sigmaForVertex1, sigmaForVertex2).pow(2.).diag(); DoubleTensor x = DoubleTensor.concat(currentStateForVertex1, currentStateForVertex2); DoubleTensor expectedLogProb = MultivariateGaussian.withParameters(mu, cov).logProb(x); assertThat(logProb, closeTo(expectedLogProb.sumNumber(), 1e-14)); }
@Test public void logProbThrowsIfProposalIsMissingASigmaForAVariable() { CauchyVertex notInProposalDistribution = new CauchyVertex(1., 1.); thrown.expect(IllegalStateException.class); thrown.expectMessage("A sigma was not specified for variable " + notInProposalDistribution); proposalDistribution.logProb(notInProposalDistribution, DoubleTensor.scalar(1.), DoubleTensor.scalar(2.)); }