@Test public void testMainScenarios() { PeriodicStochasticFrequencyFunction fun = new PeriodicStochasticFrequencyFunction(UNIT, PERIOD_LENGTH, NULL_POINT, CompositeValuedSet.createCompositeValuedSet(TestUtil.SEED_ARRAY, "[0,20] m=10 std=1", "(20,40]m=15.1 std=1.6", "(40,60] m=16 std=0.1", "(60,80] m=300 std=1", "(80,100] m=10 std=0")); Random r = new Random(TestUtil.SEED); DescriptiveStatistics stat = new DescriptiveStatistics(); for (int i = 0; i < TEST_SIZE; i++) { double x = NULL_POINT + r.nextDouble() * 20; stat.addValue(fun.getFrequency(x)); } assertEquals(10, stat.getMean(), DELTA); assertEquals(1, stat.getStandardDeviation(), DELTA); stat.clear(); for (int i = 0; i < TEST_SIZE; i++) { double x = NULL_POINT + 20 + r.nextDouble() * 20; stat.addValue(fun.getFrequency(x)); } assertEquals(15.1, stat.getMean(), DELTA); assertEquals(1.5, stat.getStandardDeviation(), DELTA); stat.clear(); for (int i = 0; i < TEST_SIZE; i++) { double x = NULL_POINT + 40 + r.nextDouble() * 20; stat.addValue(fun.getFrequency(x)); } assertEquals(16, stat.getMean(), DELTA); assertEquals(0.1, stat.getStandardDeviation(), DELTA); stat.clear(); for (int i = 0; i < TEST_SIZE; i++) { double x = NULL_POINT + 60 + r.nextDouble() * 20; stat.addValue(fun.getFrequency(x)); } assertEquals(300, stat.getMean(), DELTA); assertEquals(1, stat.getStandardDeviation(), DELTA); for (int i = 0; i < TEST_SIZE; i++) { double x = NULL_POINT + 80 + r.nextDouble() * 20; assertEquals(10, fun.getFrequency(x), DELTA); } for (int i = 0; i < TEST_SIZE; i++) { double x = r.nextDouble() * NULL_POINT; assertEquals(10, fun.getFrequency(x), DELTA); } stat.clear(); for (int i = 0; i < TEST_SIZE; i++) { double x = NULL_POINT + 60 + r.nextDouble() * 20 - PERIOD_LENGTH; stat.addValue(fun.getFrequency(x)); } assertEquals(300, stat.getMean(), DELTA); assertEquals(1, stat.getStandardDeviation(), DELTA); stat.clear(); for (int i = 0; i < TEST_SIZE; i++) { double x = NULL_POINT + 60 + r.nextDouble() * 20 + 2 * PERIOD_LENGTH; stat.addValue(fun.getFrequency(x)); } assertEquals(300, stat.getMean(), DELTA); assertEquals(1, stat.getStandardDeviation(), DELTA); }
@Override public int getFrequency(double time) { double periodOffset = 0; if (time >= nullPoint) { periodOffset = time - nullPoint; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; } else { periodOffset = nullPoint - time; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; periodOffset = periodLength - periodOffset; } return Math.max(0, (int) valuedSet.getValue(periodOffset)); }
PeriodicStochasticFrequencyFunction extends FrequencyFunction { @Override public int getFrequency(double time) { double periodOffset = 0; if (time >= nullPoint) { periodOffset = time - nullPoint; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; } else { periodOffset = nullPoint - time; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; periodOffset = periodLength - periodOffset; } return Math.max(0, (int) valuedSet.getValue(periodOffset)); } }
PeriodicStochasticFrequencyFunction extends FrequencyFunction { @Override public int getFrequency(double time) { double periodOffset = 0; if (time >= nullPoint) { periodOffset = time - nullPoint; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; } else { periodOffset = nullPoint - time; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; periodOffset = periodLength - periodOffset; } return Math.max(0, (int) valuedSet.getValue(periodOffset)); } PeriodicStochasticFrequencyFunction(double unit, double periodLength, double nullPoint,
            CompositeValuedSet valuedSet); }
PeriodicStochasticFrequencyFunction extends FrequencyFunction { @Override public int getFrequency(double time) { double periodOffset = 0; if (time >= nullPoint) { periodOffset = time - nullPoint; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; } else { periodOffset = nullPoint - time; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; periodOffset = periodLength - periodOffset; } return Math.max(0, (int) valuedSet.getValue(periodOffset)); } PeriodicStochasticFrequencyFunction(double unit, double periodLength, double nullPoint,
            CompositeValuedSet valuedSet); @Override int getFrequency(double time); }
PeriodicStochasticFrequencyFunction extends FrequencyFunction { @Override public int getFrequency(double time) { double periodOffset = 0; if (time >= nullPoint) { periodOffset = time - nullPoint; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; } else { periodOffset = nullPoint - time; int timesPeriod = (int) (periodOffset / periodLength); periodOffset -= timesPeriod * periodLength; periodOffset = periodLength - periodOffset; } return Math.max(0, (int) valuedSet.getValue(periodOffset)); } PeriodicStochasticFrequencyFunction(double unit, double periodLength, double nullPoint,
            CompositeValuedSet valuedSet); @Override int getFrequency(double time);  }