/** * Convert the timeseries into SAX string representation. * * @param ts the timeseries. * @param paaSize the PAA size. * @param cuts the alphabet cuts. * @param nThreshold the normalization thresholds. * * @return The SAX representation for timeseries. * @throws SAXException if error occurs. */ public char[] ts2string(double[] ts, int paaSize, double[] cuts, double nThreshold) throws SAXException { if (paaSize == ts.length) { return tsProcessor.ts2String(tsProcessor.znorm(ts, nThreshold), cuts); } else { // perform PAA conversion double[] paa = tsProcessor.paa(tsProcessor.znorm(ts, nThreshold), paaSize); return tsProcessor.ts2String(paa, cuts); } }
/** * Convert the timeseries into SAX string representation. * * @param ts the timeseries. * @param paaSize the PAA size. * @param cuts the alphabet cuts. * @param nThreshold the normalization thresholds. * * @return The SAX representation for timeseries. * @throws SAXException if error occurs. */ public char[] ts2string(double[] ts, int paaSize, double[] cuts, double nThreshold) throws SAXException { if (paaSize == ts.length) { return tsProcessor.ts2String(tsProcessor.znorm(ts, nThreshold), cuts); } else { // perform PAA conversion double[] paa = tsProcessor.paa(tsProcessor.znorm(ts, nThreshold), paaSize); return tsProcessor.ts2String(paa, cuts); } }
char[] currentString = tsProcessor.ts2String(paa, cuts); sb.append("\"").append(currentString).append("\"").append(TAB);
char[] currentString = tsProcessor.ts2String(paa, cuts); sb.append("\"").append(currentString).append("\"").append(TAB);
char[] currentString = tsp.ts2String(paa, na.getCuts(this.saxAlphabetSize));
char[] currentString = tsp.ts2String(paa, na.getCuts(this.saxAlphabetSize));
/** * Converts the input time series into a SAX data structure via chunking and Z normalization. * * @param ts the input data. * @param paaSize the PAA size. * @param cuts the Alphabet cuts. * @param nThreshold the normalization threshold value. * * @return SAX representation of the time series. * @throws SAXException if error occurs. */ public SAXRecords ts2saxByChunking(double[] ts, int paaSize, double[] cuts, double nThreshold) throws SAXException { SAXRecords saxFrequencyData = new SAXRecords(); // Z normalize it double[] normalizedTS = tsProcessor.znorm(ts, nThreshold); // perform PAA conversion if needed double[] paa = tsProcessor.paa(normalizedTS, paaSize); // Convert the PAA to a string. char[] currentString = tsProcessor.ts2String(paa, cuts); // create the datastructure for (int i = 0; i < currentString.length; i++) { char c = currentString[i]; int pos = (int) Math.floor(i * ts.length / currentString.length); saxFrequencyData.add(String.valueOf(c).toCharArray(), pos); } return saxFrequencyData; }
/** * Converts the input time series into a SAX data structure via chunking and Z normalization. * * @param ts the input data. * @param paaSize the PAA size. * @param cuts the Alphabet cuts. * @param nThreshold the normalization threshold value. * * @return SAX representation of the time series. * @throws SAXException if error occurs. */ public SAXRecords ts2saxByChunking(double[] ts, int paaSize, double[] cuts, double nThreshold) throws SAXException { SAXRecords saxFrequencyData = new SAXRecords(); // Z normalize it double[] normalizedTS = tsProcessor.znorm(ts, nThreshold); // perform PAA conversion if needed double[] paa = tsProcessor.paa(normalizedTS, paaSize); // Convert the PAA to a string. char[] currentString = tsProcessor.ts2String(paa, cuts); // create the datastructure for (int i = 0; i < currentString.length; i++) { char c = currentString[i]; int pos = (int) Math.floor(i * ts.length / currentString.length); saxFrequencyData.add(String.valueOf(c).toCharArray(), pos); } return saxFrequencyData; }
private static double[] seriesValuesAsHeat(double[] series, String className, HashMap<String, HashMap<String, Double>> tfidf, Params params) throws Exception { Alphabet a = new NormalAlphabet(); double[] weights = new double[series.length]; HashMap<String, Integer> words = new HashMap<String, Integer>(); for (int i = 0; i <= series.length - params.getWindowSize(); i++) { double[] subseries = tsp.subseriesByCopy(series, i, i + params.getWindowSize()); double[] paa = tsp.paa(tsp.znorm(subseries, params.getnThreshold()), params.getPaaSize()); char[] sax = tsp.ts2String(paa, a.getCuts(params.getAlphabetSize())); words.put(String.valueOf(sax), i); } for (Entry<String, HashMap<String, Double>> e : tfidf.entrySet()) { for (Entry<String, Double> e1 : e.getValue().entrySet()) { if (words.containsKey(e1.getKey())) { int idx = words.get(e1.getKey()); double increment = 0.0; if (className.equalsIgnoreCase(e.getKey())) { increment = e1.getValue(); } else { // increment = -e1.getValue(); } for (int i = 0; i < params.getWindowSize(); i++) { weights[idx + i] = weights[idx + i] + increment; } } } } return weights; }
private static Map<Integer, Integer[]> getPatternLocationsForTheClass(String className, Map<String, List<double[]>> trainData, String pattern, Params params) throws IndexOutOfBoundsException, Exception { Alphabet a = new NormalAlphabet(); Map<Integer, Integer[]> res = new HashMap<Integer, Integer[]>(); int seriesCounter = 0; for (double[] series : trainData.get(className)) { List<Integer> arr = new ArrayList<Integer>(); for (int i = 0; i <= series.length - params.getWindowSize(); i++) { double[] paa = tsp.paa(tsp.znorm(tsp.subseriesByCopy(series, i, i + params.getWindowSize()), params.getnThreshold()), params.getPaaSize()); char[] sax = tsp.ts2String(paa, a.getCuts(params.getAlphabetSize())); if (pattern.equalsIgnoreCase(String.valueOf(sax))) { arr.add(i); } } res.put(seriesCounter, arr.toArray(new Integer[0])); seriesCounter++; } return res; } }
char[] currentString = tsProcessor.ts2String(paa, cuts);
char[] currentString = tsProcessor.ts2String(paa, cuts);
char[] currentString = tp.ts2String(paa, na.getCuts(params.alphabetSize));
String sax = String.valueOf(tp.ts2String( tp.paa(tp.znorm(tp.subseriesByCopy(series, i, i + motifSize), znormThreshold), paaSize), normalA.getCuts(alphabetSize)));
String sax = String.valueOf(tp.ts2String( tp.paa(tp.znorm(tp.subseriesByCopy(series, i, i + motifSize), znormThreshold), paaSize), normalA.getCuts(alphabetSize)));
char[] currentString = tsProcessor.ts2String(paa, cuts);
char[] currentString = tsProcessor.ts2String(paa, cuts);
char[] currentString = tsProcessor.ts2String(paa, cuts);
char[] currentString = tsProcessor.ts2String(paa, cuts);
char[] currentString = tp.ts2String(paa, normalA.getCuts(A_SIZE));