### Question:
LogNormalDegreeDistribution implements DegreeDistribution { @Override public Sample createSample(final int size, final Random random) { LogNormalDistribution distro = new LogNormalDistribution(meanLog, sdLog); distro.reseedRandomGenerator(random.nextLong()); return new Sample() { @Override public int getNextDegree() { return (int) (0.5 + distro.sample()); } @Override public int getNextIndex() { return (int) distro.inverseCumulativeProbability(random.nextDouble()); } }; } LogNormalDegreeDistribution(double meanLog, double sdLog); @Override Sample createSample(final int size, final Random random);  }### Answer:
@Test public void logNormalSampleIsWithinBounds() throws Exception { double meanLog = 0.5715735; double sdLog = 0.5886170; Random random = new Random(); LogNormalDegreeDistribution distro = new LogNormalDegreeDistribution(meanLog, sdLog); int n = 10000; DegreeDistribution.Sample sample = distro.createSample(n, random); DescriptiveStatistics stats = new DescriptiveStatistics(); for (int i = 0; i < n; i++) { double value = sample.getNextDegree(); stats.addValue(value); } assertEquals(2.11, stats.getMean(), 0.5); assertEquals(1.35, stats.getStandardDeviation(), 0.5); }
@Test public void indexesFollowLogNormalDistribution() throws Exception { double meanLog = 0.5715735; double sdLog = 0.5886170; Random random = new Random(); LogNormalDegreeDistribution distro = new LogNormalDegreeDistribution(meanLog, sdLog); int n = 1000; DegreeDistribution.Sample sample = distro.createSample(n, random); DescriptiveStatistics stats = new DescriptiveStatistics(); for (int i = 0; i < n; i++) { int index = sample.getNextIndex(); stats.addValue(index); } assertEquals(1.6, stats.getMean(), 0.5); }
@Ignore @Test public void verifyDistributionsManuallyInR() throws IOException { double meanLog = 0.5715735; double sdLog = 0.5886170; Random random = new Random(); LogNormalDegreeDistribution distro = new LogNormalDegreeDistribution(meanLog, sdLog); int n = 10000; DegreeDistribution.Sample sample = distro.createSample(n, random); writeTo(new File("/tmp/distro.csv"), ps -> { ps.println("degree"); for (int i = 0; i < n; i++) { ps.println(sample.getNextDegree()); } }); writeTo(new File("/tmp/distro-inv-cuml.csv"), ps -> { ps.println("index"); for (int i = 0; i < n; i++) { ps.println(sample.getNextIndex()); } }); }