本文整理汇总了Java中net.seninp.jmotif.sax.TSProcessor类的典型用法代码示例。如果您正苦于以下问题:Java TSProcessor类的具体用法?Java TSProcessor怎么用?Java TSProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TSProcessor类属于net.seninp.jmotif.sax包,在下文中一共展示了TSProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Shingles
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
/**
* Constructor. Creates all the data structures.
*
* @param alphabetSize the expected alphabet size.
* @param shingleSize the expected shingle size.
*/
public Shingles(int alphabetSize, int shingleSize) {
// init data structures
shingles = new HashMap<String, int[]>();
indexTable = new HashMap<String, Integer>();
// build all shingles index
String[] alphabet = new String[alphabetSize];
for (int i = 0; i < alphabetSize; i++) {
alphabet[i] = String.valueOf(TSProcessor.ALPHABET[i]);
}
// and make an index table
String[] allStrings = SAXProcessor.getAllPermutations(alphabet, shingleSize);
for (int i = 0; i < allStrings.length; i++) {
indexTable.put(allStrings[i], i);
}
}
示例2: testProperIndexing
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
/**
* Test the simple SAX conversion.
*
* @throws Exception if error occurs.
*/
@Test
public void testProperIndexing() throws Exception {
double[] ts1 = TSProcessor.readFileColumn(filenameTEK14, 0, 0);
NormalAlphabet na = new NormalAlphabet();
SAXProcessor sp = new SAXProcessor();
SAXRecords res = sp.ts2saxViaWindow(ts1, 400, 6, na.getCuts(3),
NumerosityReductionStrategy.EXACT, 0.01);
String str = res.getSAXString(" ");
res.buildIndex();
String str1 = "";
for (int i = 11; i < 47; i++) {
SAXRecord r = res.getByIndex(res.mapStringIndexToTSPosition(i));
str1 = str1.concat(String.valueOf(r.getPayload()) + " ");
}
assertTrue("Asserting substring existence", str.indexOf(str1) > 0);
assertEquals("Asserting substring the index", 11 * 6 + 11 * 1, str.indexOf(str1));
}
示例3: main
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
public static void main(String[] args) throws IOException, SAXException {
SAXProcessor sp = new SAXProcessor();
for (String fname : filenames) {
String inFname = pathPrefix + fname;
String outFname = inFname + ".shingled.txt";
double[] series = TSProcessor.readFileColumn(inFname, 0, 0);
System.err.println("read " + inFname + ", " + series.length + " points ...");
Map<String, Integer> shingledData = sp.ts2Shingles(series, WIN_SIZE, PAA_SIZE, A_SIZE,
NumerosityReductionStrategy.NONE, 0.001, LEVEL);
StringBuilder shingles = new StringBuilder(
BitmapParameters.SHINGLE_SIZE * (shingledData.size() + 2));
StringBuilder freqs = new StringBuilder(
BitmapParameters.SHINGLE_SIZE * (shingledData.size() + 2));
TreeSet<String> keys = new TreeSet<String>(shingledData.keySet());
for (String shingle : keys) {
shingles.append(QUOTE).append(shingle).append(QUOTE).append(COMMA);
freqs.append(shingledData.get(shingle)).append(COMMA);
}
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(outFname)));
bw.write(shingles.delete(shingles.length() - 1, shingles.length()).toString());
bw.write(CR);
bw.write(freqs.delete(freqs.length() - 1, freqs.length()).toString());
bw.write(CR);
bw.close();
}
}
示例4: setUpBeforeClass
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
InputStream fileStream = new FileInputStream("src/resources/dataset/300_signal1.txt.gz");
InputStream gzipStream = new GZIPInputStream(fileStream);
Reader decoder = new InputStreamReader(gzipStream, "US-ASCII");
BufferedReader buffered = new BufferedReader(decoder);
ts = TSProcessor.readTS(buffered, 0, 10000);
}
示例5: testParallelSAXNONE
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
/**
* Test parallel SAX conversion.
*
* @throws Exception if error occurs.
*/
@Test
public void testParallelSAXNONE() throws Exception {
SAXProcessor sp = new SAXProcessor();
NormalAlphabet na = new NormalAlphabet();
double[] ts = TSProcessor.readFileColumn(TEST_DATA, 0, 0);
// test EXACT
//
SAXRecords sequentialRes = sp.ts2saxViaWindow(ts, WINDOW_SIZE, PAA_SIZE,
na.getCuts(ALPHABET_SIZE), NumerosityReductionStrategy.NONE, NORM_THRESHOLD);
String sequentialString = sequentialRes.getSAXString(" ");
ParallelSAXImplementation ps1 = new ParallelSAXImplementation();
for (int threadsNum : THREADS_NUM) {
SAXRecords parallelRes = ps1.process(ts, threadsNum, WINDOW_SIZE, PAA_SIZE, ALPHABET_SIZE,
NumerosityReductionStrategy.NONE, NORM_THRESHOLD);
String parallelStr = parallelRes.getSAXString(" ");
if (sequentialString.equalsIgnoreCase(parallelStr)) {
assertTrue("assert correctness", sequentialString.equalsIgnoreCase(parallelStr));
}
else {
String[] arr1 = sequentialString.split(" ");
String[] arr2 = parallelStr.split(" ");
for (int i = 0; i < Math.min(arr1.length, arr2.length); i++) {
if (!arr1[i].equalsIgnoreCase(arr2[i])) {
System.out.println("Error in index " + i + ", string " + arr1[i] + " versus " + arr2[i]
+ ", threads: " + threadsNum);
assertTrue("assert correctness", arr1[i].equalsIgnoreCase(arr2[i]));
}
}
}
}
}
示例6: testParallelSAXExact
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
/**
* Test parallel SAX conversion.
*
* @throws Exception if error occurs.
*/
@Test
public void testParallelSAXExact() throws Exception {
SAXProcessor sp = new SAXProcessor();
NormalAlphabet na = new NormalAlphabet();
double[] ts = TSProcessor.readFileColumn(TEST_DATA, 0, 0);
// test EXACT
//
SAXRecords sequentialRes = sp.ts2saxViaWindow(ts, WINDOW_SIZE, PAA_SIZE,
na.getCuts(ALPHABET_SIZE), NumerosityReductionStrategy.EXACT, NORM_THRESHOLD);
String sequentialString = sequentialRes.getSAXString(" ");
ParallelSAXImplementation ps1 = new ParallelSAXImplementation();
for (int threadsNum : THREADS_NUM) {
SAXRecords parallelRes = ps1.process(ts, threadsNum, WINDOW_SIZE, PAA_SIZE, ALPHABET_SIZE,
NumerosityReductionStrategy.EXACT, NORM_THRESHOLD);
String parallelStr = parallelRes.getSAXString(" ");
if (sequentialString.equalsIgnoreCase(parallelStr)) {
assertTrue("assert correctness", sequentialString.equalsIgnoreCase(parallelStr));
}
else {
String[] arr1 = sequentialString.split(" ");
String[] arr2 = parallelStr.split(" ");
for (int i = 0; i < Math.min(arr1.length, arr2.length); i++) {
if (!arr1[i].equalsIgnoreCase(arr2[i])) {
System.out.println("Error in index " + i + ", string " + arr1[i] + " versus " + arr2[i]
+ ", threads: " + threadsNum);
assertTrue("assert correctness", arr1[i].equalsIgnoreCase(arr2[i]));
}
}
}
}
}
示例7: testParallelSAXMINDIST
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
/**
* Test parallel SAX conversion.
*
* @throws Exception if error occurs.
*/
@Test
public void testParallelSAXMINDIST() throws Exception {
SAXProcessor sp = new SAXProcessor();
NormalAlphabet na = new NormalAlphabet();
double[] ts = TSProcessor.readFileColumn(TEST_DATA, 0, 0);
// test EXACT
//
SAXRecords sequentialRes = sp.ts2saxViaWindow(ts, WINDOW_SIZE, PAA_SIZE,
na.getCuts(ALPHABET_SIZE), NumerosityReductionStrategy.MINDIST, NORM_THRESHOLD);
String sequentialString = sequentialRes.getSAXString(" ");
ParallelSAXImplementation ps1 = new ParallelSAXImplementation();
for (int threadsNum : THREADS_NUM) {
SAXRecords parallelRes = ps1.process(ts, threadsNum, WINDOW_SIZE, PAA_SIZE, ALPHABET_SIZE,
NumerosityReductionStrategy.MINDIST, NORM_THRESHOLD);
String parallelStr = parallelRes.getSAXString(" ");
if (sequentialString.equalsIgnoreCase(parallelStr)) {
assertTrue("assert correctness", sequentialString.equalsIgnoreCase(parallelStr));
}
else {
String[] arr1 = sequentialString.split(" ");
String[] arr2 = parallelStr.split(" ");
for (int i = 0; i < Math.min(arr1.length, arr2.length); i++) {
if (!arr1[i].equalsIgnoreCase(arr2[i])) {
System.out.println("Error in index " + i + ", string " + arr1[i] + " versus " + arr2[i]
+ ", threads: " + threadsNum);
assertTrue("assert correctness", arr1[i].equalsIgnoreCase(arr2[i]));
}
}
}
}
}
示例8: testParallelSAXrollbac
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
/**
* Test parallel SAX conversion.
*
* @throws Exception if error occurs.
*/
@Test
public void testParallelSAXrollbac() throws Exception {
SAXProcessor sp = new SAXProcessor();
NormalAlphabet na = new NormalAlphabet();
int threadsNum = 10;
int slidingWindowSize = 300; // so itll be eneven...
double[] ts = TSProcessor.readFileColumn(TEST_DATA, 0, 0);
// test MINDIST
//
SAXRecords sequentialResMINDIST = sp.ts2saxViaWindow(ts, slidingWindowSize, PAA_SIZE,
na.getCuts(ALPHABET_SIZE), NumerosityReductionStrategy.EXACT, NORM_THRESHOLD);
String sequentialStringMINDIST = sequentialResMINDIST.getSAXString(" ");
ParallelSAXImplementation ps1 = new ParallelSAXImplementation();
SAXRecords parallelRes = ps1.process(ts, threadsNum, slidingWindowSize, PAA_SIZE, ALPHABET_SIZE,
NumerosityReductionStrategy.EXACT, NORM_THRESHOLD);
String parallelStr = parallelRes.getSAXString(" ");
if (sequentialStringMINDIST.equalsIgnoreCase(parallelStr)) {
assertTrue("assert correctness", sequentialStringMINDIST.equalsIgnoreCase(parallelStr));
}
else {
String[] arr1 = sequentialStringMINDIST.split(" ");
String[] arr2 = parallelStr.split(" ");
for (int i = 0; i < Math.min(arr1.length, arr2.length); i++) {
if (!arr1[i].equalsIgnoreCase(arr2[i])) {
System.out.println("Error in index " + i + ", string " + arr1[i] + " versus " + arr2[i]
+ ", threads: " + threadsNum);
assertTrue("assert correctness", arr1[i].equalsIgnoreCase(arr2[i]));
}
}
}
}
示例9: setUp
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
double[] series = TSProcessor.readFileColumn(TEST_DATA_FNAME, 0, 0);
SAXProcessor sp = new SAXProcessor();
saxData = sp.ts2saxViaWindow(series, WIN_SIZE, PAA_SIZE, na.getCuts(ALPHABET_SIZE), NR_STRATEGY,
NORM_THRESHOLD);
}
示例10: main
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
public static void main(String[] args) throws IOException, SAXException {
double[] ts = TSProcessor.readFileColumn(INPUT_FNAME, 0, 0);
double[] cuts = na.getCuts(SAX_A_SIZE);
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("test_sax.txt")));
// scan across the time series extract sub sequences, and convert them to strings
char[] previousString = null;
for (int i = 0; i <= ts.length - SAX_WIN_SIZE; i++) {
StringBuffer sb = new StringBuffer();
sb.append(i).append(TAB);
// fix the current subsection
double[] subSection = Arrays.copyOfRange(ts, i, i + SAX_WIN_SIZE);
sb.append(Arrays.toString(subSection).replaceAll("\\s+", "")).append(TAB);
// Z normalize it
subSection = tsProcessor.znorm(subSection, SAX_NORM_THRESHOLD);
// perform PAA conversion if needed
double[] paa = tsProcessor.paa(subSection, SAX_PAA_SIZE);
sb.append(Arrays.toString(paa).replaceAll("\\s+", "")).append(TAB);
// Convert the PAA to a string.
char[] currentString = tsProcessor.ts2String(paa, cuts);
sb.append("\"").append(currentString).append("\"").append(TAB);
if (null != previousString) {
if (NumerosityReductionStrategy.EXACT.equals(NR_STRATEGY)
&& Arrays.equals(previousString, currentString)) {
// NumerosityReduction
sb.append("skipped").append(CR);
bw.write(sb.toString());
continue;
}
else if (NumerosityReductionStrategy.MINDIST.equals(NR_STRATEGY)
&& sp.checkMinDistIsZero(previousString, currentString)) {
continue;
}
}
previousString = currentString;
sb.append("kept").append(CR);
bw.write(sb.toString());
}
bw.close();
}
示例11: main
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
SAXProcessor sp = new SAXProcessor();
// data
//
double[] dat = TSProcessor.readFileColumn(DAT_FNAME, 1, 0);
// TSProcessor tp = new TSProcessor();
// double[] dat = tp.readTS("src/resources/dataset/asys40.txt", 0);
// double[] dat = TSProcessor.readFileColumn(filename, columnIdx,
// sizeLimit)FileColumn(DAT_FNAME, 1, 0);
LOGGER.info("read {} points from {}", dat.length, DAT_FNAME);
String str = "win_width: " + cPoint + "; SAX: W " + SAX_WINDOW_SIZE + ", P " + SAX_PAA_SIZE
+ ", A " + SAX_ALPHABET_SIZE + ", STR " + SAX_NR_STRATEGY.toString();
int frameCounter = 0;
int startOffset = cPoint;
while (cPoint < dat.length - startOffset - 1) {
if (0 == cPoint % 2) {
BufferedImage tsChart = getChart(dat, cPoint);
// bitmap 1
//
double[] win1 = Arrays.copyOfRange(dat, cPoint - startOffset, cPoint);
Map<String, Integer> shingledData1 = sp.ts2Shingles(win1, SAX_WINDOW_SIZE, SAX_PAA_SIZE,
SAX_ALPHABET_SIZE, SAX_NR_STRATEGY, SAX_NORM_THRESHOLD, SHINGLE_SIZE);
BufferedImage pam1 = getHeatMap(shingledData1, "pre-window");
double[] win2 = Arrays.copyOfRange(dat, cPoint, cPoint + startOffset);
Map<String, Integer> shingledData2 = sp.ts2Shingles(win2, SAX_WINDOW_SIZE, SAX_PAA_SIZE,
SAX_ALPHABET_SIZE, SAX_NR_STRATEGY, SAX_NORM_THRESHOLD, SHINGLE_SIZE);
BufferedImage pam2 = getHeatMap(shingledData2, "post-window");
// the assemble
//
BufferedImage target = new BufferedImage(800, 530, BufferedImage.TYPE_INT_ARGB);
Graphics targetGraphics = target.getGraphics();
targetGraphics.setColor(Color.WHITE);
targetGraphics.fillRect(0, 0, 799, 529);
targetGraphics.drawImage(tsChart, 0, 0, null);
targetGraphics.drawImage(pam1, 10, 410, null);// draws the first image onto it
targetGraphics.drawImage(pam2, 120, 410, null);// draws the first image onto it
targetGraphics.setColor(Color.RED);
targetGraphics.setFont(new Font("monospaced", Font.PLAIN, 16));
targetGraphics.drawString(str, 300, 420);
targetGraphics.setColor(Color.BLUE);
targetGraphics.setFont(new Font("monospaced", Font.PLAIN, 24));
double dist = ed.distance(toVector(shingledData1), toVector(shingledData2));
targetGraphics.drawString("ED=" + df.format(dist), 300, 480);
// String fileName = new SimpleDateFormat("yyyyMMddhhmmssSS'.png'").format(new Date());
File outputfile = new File("dframe" + String.format("%04d", frameCounter) + ".png");
ImageIO.write(target, "png", outputfile);
frameCounter++;
}
cPoint++;
}
}
示例12: call
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
@Override
public HashMap<Integer, char[]> call() throws Exception {
NormalAlphabet na = new NormalAlphabet();
TSProcessor tsp = new TSProcessor();
// SAXProcessor sp = new SAXProcessor();
HashMap<Integer, char[]> res = new HashMap<Integer, char[]>();
res.put(-1, String.valueOf(this.id).toCharArray());
// scan across the time series extract sub sequences, and convert
// them to strings
char[] previousString = null;
for (int i = this.intervalStart; i < this.intervalEnd - (this.saxWindowSize - 1); i++) {
// fix the current subsection
double[] subSection = Arrays.copyOfRange(this.ts, i, i + this.saxWindowSize);
// Z normalize it
subSection = tsp.znorm(subSection, normalizationThreshold);
// perform PAA conversion if needed
double[] paa = tsp.paa(subSection, this.saxPAASize);
// Convert the PAA to a string.
char[] currentString = tsp.ts2String(paa, na.getCuts(this.saxAlphabetSize));
if (null != previousString) {
if (NumerosityReductionStrategy.EXACT.equals(this.numerosityReductionStrategy)
&& Arrays.equals(previousString, currentString)) {
// NumerosityReduction
continue;
}
// there is no MINDIST at the moment
// else if (NumerosityReductionStrategy.MINDIST.equals(this.numerosityReductionStrategy)
// && sp.checkMinDistIsZero(previousString, currentString)) {
// continue;
// }
}
previousString = currentString;
res.put(i, currentString);
LOGGER.trace(this.id + ", " + String.valueOf(currentString) + ", " + i);
if (Thread.currentThread().isInterrupted()) {
LOGGER.info("SAXWorker was interrupted... returning NULL");
return null;
}
}
// System.out.println(this.id + "@" + res.getSAXString(" "));
return res;
}
示例13: setUp
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
series = TSProcessor.readFileColumn(TEST_DATA_FNAME, 0, 0);
series = Arrays.copyOf(series, 800);
}
示例14: setUp
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
series = TSProcessor.readFileColumn(TEST_DATA_FNAME, 0, 0);
}
示例15: main
import net.seninp.jmotif.sax.TSProcessor; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Date startTime = new Date();
double[] ts = TSProcessor.readFileColumn(INPUT_FNAME, 0, 0);
Date readTime = new Date();
System.out.println(SAXProcessor.timeToString(startTime.getTime(), readTime.getTime())
+ ":\t read " + ts.length + " points from " + INPUT_FNAME);
SAXRecords sax = sp.ts2saxViaWindow(ts, SAX_WIN_SIZE, SAX_PAA_SIZE, na.getCuts(SAX_A_SIZE),
NumerosityReductionStrategy.NONE, SAX_NORM_THRESHOLD);
Date saxTime = new Date();
System.out.println(SAXProcessor.timeToString(readTime.getTime(), saxTime.getTime())
+ ":\t discretized " + ts.length + " points into " + sax.getIndexes().size() + " words.");
String str = sax.getSAXString(" ");
for (int i = 0; i < 20; i++) {
System.out.println("Iteration " + i);
// Sequitur
// prepareCycle();
// Date t0 = new Date();
// SAXRule grammar = SequiturFactory.runSequitur(str);
// GrammarRules rulesData = grammar.toGrammarRulesData();
// System.out.println(SAXProcessor.timeToString(t0.getTime(), (new Date()).getTime())
// + "\t inferred " + rulesData.size() + " Sequitur rules");
// grammar = null;
// rulesData = null;
// New repair
prepareCycle();
Date t1 = new Date();
RePairGrammar grammar1 = RePairFactory.buildGrammar(str);
GrammarRules rulesData1 = grammar1.toGrammarRulesData();
System.out.println(SAXProcessor.timeToString(t1.getTime(), (new Date()).getTime())
+ "\t inferred " + rulesData1.size() + " RePair rules..");
// System.out.println(rulesData1.toString());
grammar1 = null;
}
}