SeasonalOutlier extends AbstractOutlierVariable { @Override public void data(TsPeriod start, DataBlock data) { TsPeriod pstart=new TsPeriod(start.getFrequency(), position); int pos = pstart.minus(start); data.set(0); int freq = start.getFrequency().intValue(); double z = -1.0 / (freq - 1); int xpos; int len = data.getLength(); if (zeroEnded) { int j = 1; if (pos < 0) { return; } else if (pos > len) { int n = pos - len; j = 1 + n % freq; xpos = len; } else { xpos = pos; } do { for (; j < freq && xpos > 0; ++j) { data.set(--xpos, z); } if (xpos > 0) { data.set(--xpos, 1); } else { break; } j = 1; } while (true); } else { if (pos < 0) { xpos = pos % freq; } else { xpos = pos; } if (xpos < 0) { int max=Math.min(len, freq + xpos); for (int j = 0; j < max; ++j) { data.set(j, z); } xpos += freq; } for (int i = xpos; i < len;) { data.set(i++, 1); for (int j = 1; j < freq && i < len; ++i, ++j) { data.set(i, z); } } } } SeasonalOutlier(Day pos); @Override void data(TsPeriod start, DataBlock data); @Override OutlierType getOutlierType(); String getCode(); @Override boolean isSignificant(TsDomain domain); boolean isZeroEnded(); void setZeroEnded(boolean value); @Override FilterRepresentation getFilterRepresentation(int freq); static final String CODE; }
@Test public void testAround() { TsPeriod pos = new TsPeriod(TsFrequency.Monthly, 2000, 3); SeasonalOutlier so1 = new SeasonalOutlier(pos.firstday()); for (int i = -6; i < 6; ++i) { DataBlock data = new DataBlock(12); so1.data(pos.minus(i), data); } }