Example usage for org.apache.commons.math3.distribution ConstantRealDistribution ConstantRealDistribution

List of usage examples for org.apache.commons.math3.distribution ConstantRealDistribution ConstantRealDistribution

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution ConstantRealDistribution ConstantRealDistribution.

Prototype

public ConstantRealDistribution(double value) 

Source Link

Document

Create a constant real distribution with the given value.

Usage

From source file:com.wormsim.LaunchFromCodeMain.java

private static SimulationConditions makeCustomInitialConditions() {
    HashMap<String, IntegerDistribution> map = new HashMap<>();

    map.put("TestStrain L2", new EnumeratedIntegerDistribution(new int[] { 1 }));

    return new SimulationConditions(new ConstantRealDistribution(10000.0),
            // new NormalDistribution(1000.0, 200.0),
            new RealDistribution[] { new ConstantRealDistribution(0.0) }, map);
}

From source file:com.ibm.og.util.Distributions.java

private static Distribution constant(final double average) {
    checkArgument(average >= 0.0, "average must be >= 0.0 [%s]", average);
    final String s = String.format("ConstantDistribution [average=%s]", average);
    return new RealDistributionAdapter(new ConstantRealDistribution(average), s);
}

From source file:com.github.aptd.simulation.CMain.java

private static void execute(final CommandLine p_cli) {
    final double l_changetimemin = Double.parseDouble(p_cli.getOptionValue("changetimemin", "100"));
    final double l_changetimemax = Double.parseDouble(p_cli.getOptionValue("changetimemax", "100"));
    final int l_numberofpassengers = Integer.parseUnsignedInt(p_cli.getOptionValue("numberofpassengers", "20"));
    final double l_lightbarrierminfreetime = Double
            .parseDouble(p_cli.getOptionValue("lightbarrierminfreetime", "3.0"));
    final double l_delayseconds = Double.parseDouble(p_cli.getOptionValue("delayseconds", "0.0"));

    // load configuration
    CConfiguration.INSTANCE.loadfile(p_cli.getOptionValue("config", ""));

    // execute experiments in batch processing and starts http server
    new Thread(() -> datamodel(p_cli).map(i -> i.getLeft().model().get(

            EFactory.from(CConfiguration.INSTANCE.getOrDefault("local", "runtime", "type")).factory(),

            i.getRight(),//  w  ww . jav  a 2  s.  c om

            p_cli.hasOption("iteration") ? Long.parseLong(p_cli.getOptionValue("iteration"))
                    : (long) CConfiguration.INSTANCE.getOrDefault(0, "default", "iteration"),

            !p_cli.hasOption("sequential")
                    && CConfiguration.INSTANCE.<Boolean>getOrDefault(true, "runtime", "parallel"),

            p_cli.hasOption("timemodel") ? p_cli.getOptionValue("timemodel") : "step",

            () -> {
                if (l_changetimemax <= l_changetimemin)
                    return new ConstantRealDistribution(l_changetimemin);
                final RandomGenerator l_randomgenerator = new JDKRandomGenerator();
                l_randomgenerator.setSeed(Long.parseLong(p_cli.getOptionValue("changetimeseed", "1")));
                return new UniformRealDistribution(l_randomgenerator, l_changetimemin, l_changetimemax);
            },

            l_numberofpassengers, l_lightbarrierminfreetime, l_delayseconds))
            .forEach(i -> ERuntime.LOCAL.get().execute(i))).start();

    // start http server if possible
    if (p_cli.hasOption("interactive"))
        CHTTPServer.execute();
}

From source file:com.wormsim.utils.Utils.java

/**
 * Returns the distribution associated with the specified string. See the
 * handbook for details of what is accepted. Or the code...
 *
 * @param str The string representing a distribution
 *
 * @return The distribution/*from   ww w .  j a  v  a 2s.co  m*/
 */
public static RealDistribution readRealDistribution(String str) {
    if (str.matches("[0-9]+(.[0-9]*)?")) {
        // I.E. a number
        return new ConstantRealDistribution(Double.valueOf(str));
    } else {
        int index = str.indexOf('(');
        String prefix = str.substring(0, index).toLowerCase(Locale.ROOT);
        switch (prefix) {
        case "n":
        case "norm":
        case "normal": {
            int comma_index = str.indexOf(',', index);
            return new NormalDistribution(Double.valueOf(str.substring(index + 1, comma_index).trim()),
                    Double.valueOf(str.substring(comma_index + 1, str.length() - 2).trim()));
        }
        case "u":
        case "uni":
        case "uniform": {
            int comma_index = str.indexOf(',', index);
            return new UniformRealDistribution(Double.valueOf(str.substring(index + 1, comma_index - 1)),
                    Double.valueOf(str.substring(comma_index).trim()));
        }
        default:
            throw new IllegalArgumentException(
                    "Unrecognised distribution form, see handbook for details. " + "Provided \"" + str + "\".");
        }
    }
}

From source file:org.apache.beam.sdk.io.synthetic.BundleSplitterTest.java

@Test
public void bundlesShouldBeEvenForConstDistribution() {
    long expectedBundleSize = 2;
    options.bundleSizeDistribution = fromRealDistribution(new ConstantRealDistribution(2));
    splitter = new BundleSplitter(options);

    List<OffsetRange> bundleSizes = splitter.getBundleSizes(4, 0, options.numRecords);

    bundleSizes.stream().map(range -> range.getTo() - range.getFrom())
            .forEach(size -> assertEquals(expectedBundleSize, size.intValue()));
}

From source file:org.apache.beam.sdk.io.synthetic.BundleSplitterTest.java

@Test
public void bundleSizesShouldBeProportionalToTheOneSuggestedInBundleSizeDistribution() {
    long expectedBundleSize = 4;
    options.bundleSizeDistribution = fromRealDistribution(new ConstantRealDistribution(2));
    options.numRecords = 16;/*from w w w. j av  a 2  s  .  c o m*/
    splitter = new BundleSplitter(options);

    List<OffsetRange> bundleSizes = splitter.getBundleSizes(4, 0, options.numRecords);

    bundleSizes.stream().map(range -> range.getTo() - range.getFrom())
            .forEach(size -> assertEquals(expectedBundleSize, size.intValue()));
}

From source file:org.apache.beam.sdk.io.synthetic.BundleSplitterTest.java

@Test
public void consequentBundlesShouldHaveTheSameRangeEndAndStart() {
    int desiredNumberOfBundles = 2;
    options.bundleSizeDistribution = fromRealDistribution(new ConstantRealDistribution(2));
    splitter = new BundleSplitter(options);

    List<OffsetRange> bundleSizes = splitter.getBundleSizes(desiredNumberOfBundles, 0, options.numRecords);

    assertEquals(bundleSizes.get(0).getTo(), bundleSizes.get(1).getFrom());
    assertEquals(bundleSizes.get(0).getTo(), bundleSizes.get(1).getFrom());
    assertEquals(desiredNumberOfBundles, bundleSizes.size());
}

From source file:org.apache.beam.sdk.io.synthetic.SyntheticBoundedIOTest.java

@Test
public void testSplitIntoSingleRecordBundles() throws Exception {
    PipelineOptions options = PipelineOptionsFactory.create();
    SyntheticSourceOptions sourceOptions = new SyntheticSourceOptions();
    sourceOptions.numRecords = 10;//w w  w  .j a  va  2s.c o  m
    sourceOptions.setSeed(123456);
    sourceOptions.bundleSizeDistribution = fromRealDistribution(new ConstantRealDistribution(1.0));
    sourceOptions.forceNumInitialBundles = 10;
    SyntheticBoundedSource source = new SyntheticBoundedSource(sourceOptions);
    List<SyntheticBoundedSource> sources = source.split(42L, options);
    for (SyntheticBoundedSource recordSource : sources) {
        recordSource.validate();
        assertEquals(1, recordSource.getEndOffset() - recordSource.getStartOffset());
    }
    SourceTestUtils.assertSourcesEqualReferenceSource(source, sources, options);
}

From source file:org.apache.beam.sdk.io.synthetic.SyntheticStepTest.java

@Test
public void testSyntheticStepWithPreservingInputKeyDistribution() throws Exception {
    SyntheticStep.Options options = SyntheticTestUtils.optionsFromString("{\"outputRecordsPerInputRecord\": 2,"
            + " \"preservesInputKeyDistribution\": true," + "\"keySizeBytes\": 10," + "\"valueSizeBytes\": 20,"
            + "\"numHotKeys\": 3," + "\"hotKeyFraction\": 0.3," + "\"seed\": 123456}",
            SyntheticStep.Options.class);
    options.delayDistribution = SyntheticOptions.fromRealDistribution(new ConstantRealDistribution(10));

    PCollection<byte[]> result = p
            .apply(Create.of(ImmutableList.of(KV.of(intToByteArray(1), intToByteArray(11)),
                    KV.of(intToByteArray(2), intToByteArray(22)),
                    KV.of(intToByteArray(3), intToByteArray(33)))))
            .apply(ParDo.of(new SyntheticStep(options))).apply(Keys.create());

    List<byte[]> expected = ImmutableList.of(intToByteArray(1), intToByteArray(1), intToByteArray(2),
            intToByteArray(2), intToByteArray(3), intToByteArray(3));
    PAssert.that(result).containsInAnyOrder(expected);
    p.run().waitUntilFinish();//  w  w  w.  j  a v  a  2 s.c  om
}

From source file:org.apache.beam.sdk.io.synthetic.SyntheticStepTest.java

@Test
public void testSyntheticStepWithoutPreservingInputKeyDistribution() throws Exception {
    SyntheticStep.Options options = SyntheticTestUtils.optionsFromString("{\"outputRecordsPerInputRecord\": 2,"
            + " \"preservesInputKeyDistribution\": false," + "\"keySizeBytes\": 10," + "\"valueSizeBytes\": 20,"
            + "\"numHotKeys\": 3," + "\"hotKeyFraction\": 0.3," + "\"seed\": 123456}",
            SyntheticStep.Options.class);
    options.delayDistribution = SyntheticOptions.fromRealDistribution(new ConstantRealDistribution(10));

    PCollection<KV<byte[], byte[]>> result = p
            .apply(Create.of(ImmutableList.of(KV.of(intToByteArray(1), intToByteArray(11)))))
            .apply(ParDo.of(new SyntheticStep(options)));

    PAssert.that(result).satisfies((Iterable<KV<byte[], byte[]>> input) -> {
        int count = 0;
        for (KV<byte[], byte[]> elm : input) {
            count += 1;/*from  www  .j  av a 2  s  . co m*/
            assertEquals(10, elm.getKey().length);
            assertEquals(20, elm.getValue().length);
        }
        assertEquals(2, count);
        return null;
    });
    p.run().waitUntilFinish();
}