/** * Creates a new instance of a sine {@link IntensityFunction}. This method * requires constant values to be set. For using supplied values see * {@link #buildStochasticSupplier()}. * @return A new instance. */ public IntensityFunction build() { checkArgument(isConstant(amplitudeSup), "Amplitude should be a constant (not a supplier)."); checkArgument(isConstant(frequencySup), "Frequency should be a constant (not a supplier)."); checkArgument(isConstant(heightSup), "Height should be a constant (not a supplier)."); checkArgument(isConstant(phaseShiftSup), "PhaseShift should be a constant (not a supplier)."); return build(0L); }
.period(period) .area(ordersPerPeriod) .build();
/** * Tests whether phase shifts are correctly implemented. */ @Test public void testPhaseShift() { SineIntensity si = (SineIntensity) IntensityFunctions.sineIntensity() .phaseShift(0).build(); nonZeroCheck(Range.closed(0d, 1d), si, Range.open(0d, .5)); si = (SineIntensity) IntensityFunctions.sineIntensity().phaseShift(.5) .build(); nonZeroCheck(Range.closed(0d, 1d), si, Range.open(.25, .75)); // check default assertEquals(IntensityFunctions.sineIntensity().build(), si); si = (SineIntensity) IntensityFunctions.sineIntensity().phaseShift(1) .build(); nonZeroCheck(Range.closed(0d, 1d), si, Range.open(.5, 1d)); si = (SineIntensity) IntensityFunctions.sineIntensity().phaseShift(1.5) .build(); nonZeroCheck(Range.closed(0d, 1d), si, Range.closedOpen(0d, .25), Range.openClosed(.75, 1d)); si = (SineIntensity) IntensityFunctions.sineIntensity().phaseShift(2) .build(); nonZeroCheck(Range.closed(0d, 1d), si, Range.open(0d, .5)); }
.build(); assertEquals(.369903, sine.area(), 0.000001); assertEquals( sine = (SineIntensity) IntensityFunctions.sineIntensity().build(); assertEquals(.31831, sine.area(), 0.00001); assertEquals( .build(); assertEquals(.269903, sine.area(), 0.000001); assertEquals( .period(3600d) .height(10) .build(); assertEquals(36000, sine.area(), 0.00001); assertEquals( .frequency(1d / 10d) .height(2) .build(); assertEquals(27.2065, sine.area(), 0.0001); assertEquals(
.period(30 * 60 * 1000L) .area(10) .build())) .locations(Locations.builder() .min(new Point(0, 0))
/** * Check whether the * {@link TimeSeries#nonHomogenousPoisson(double, StochasticSupplier)} * function behaves as expected. */ @Test public void test2() { final IntensityFunction func1 = IntensityFunctions.sineIntensity() .period(60) .height(-.5) .build(); final IntensityFunction func2 = IntensityFunctions.sineIntensity() .period(30) .height(1.5) .build(); final StochasticSupplier<IntensityFunction> funcSup = StochasticSuppliers .fromIterable(Iterables.cycle(func1, func2)); final TimeSeriesGenerator tsg = TimeSeries.nonHomogenousPoisson(120, funcSup); // note that these tests will not work for all results of the // TimeSeriesGenerator, it is possible (but less likely) that the produced // dynamism values are different from the expectations as expressed in the // tests below. for (int i = 0; i < 20; i++) { assertTrue(Metrics.measureDynamism(tsg.generate(i), 120) < .25); assertTrue(Metrics.measureDynamism(tsg.generate(i), 120) > .40); } }
/** * @return Test configs */ @Parameters public static Collection<Object[]> data() { return Arrays.asList(new Object[][] { {TimeSeries.homogenousPoisson(60d, 10)}, {TimeSeries.homogenousPoisson(60d, 100)}, {TimeSeries.homogenousPoisson(180d, 10)}, {TimeSeries.homogenousPoisson(180d, 100)}, {TimeSeries.nonHomogenousPoisson(60d, IntensityFunctions .sineIntensity() .period(60).area(10).build())}, {TimeSeries.nonHomogenousPoisson(60d, IntensityFunctions .sineIntensity() .period(60).area(10).phaseShift(2).build())}, {TimeSeries.nonHomogenousPoisson(60d, IntensityFunctions .sineIntensity() .period(60).area(10).height(1).build())}, {TimeSeries.nonHomogenousPoisson(300d, IntensityFunctions .sineIntensity() .period(60).area(10).height(1).build())}, {TimeSeries.nonHomogenousPoisson(600d, IntensityFunctions .sineIntensity() .period(600).area(200).height(1).build())} }); }
/** * @return The test configs. */ @Parameters public static Collection<Object[]> data() { return Arrays .asList(new Object[][] { {IntensityFunctions.sineIntensity().area(10).period(20).build()}, {IntensityFunctions.sineIntensity().area(10).height(.5).period(20) .build()}, {IntensityFunctions.sineIntensity().area(10).height(-.5).period(20) .build()}, {IntensityFunctions.sineIntensity().area(10).phaseShift(0) .period(20) .build()}, {IntensityFunctions.sineIntensity().area(10).height(1).period(20) .build()} }); }
@Override public IntensityFunction get(long seed) { return builder.build(seed); } }