class CheatingStudents {

    public static double runUsingBinomial(int numberOfStudents, int numberOfYesAnswers) {
        int numberOfSamples = 100;

        UniformVertex probabilityOfCheating = new UniformVertex(0.0, 1.0);
        DoubleVertex pYesAnswer = probabilityOfCheating.times(0.5).plus(0.25);
        BinomialVertex answerTotal = new BinomialVertex(pYesAnswer, numberOfStudents);
        answerTotal.observe(numberOfYesAnswers);

        KeanuProbabilisticModel model = new KeanuProbabilisticModel(answerTotal.getConnectedGraph());

        NetworkSamplesGenerator samplesGenerator = Keanu.Sampling.MetropolisHastings.withDefaultConfig()
            .generatePosteriorSamples(model, singletonList(probabilityOfCheating));

        NetworkSamples networkSamples = samplesGenerator.dropCount(numberOfSamples / 10)
            .downSampleInterval(model.getLatentVariables().size())
            .generate(numberOfSamples);

        double approximateProbabilityOfCheating = networkSamples
            .getDoubleTensorSamples(probabilityOfCheating)
            .getAverages()
            .scalar();

        return approximateProbabilityOfCheating;
    }

}