double[] paa = tsProcessor.paa(subSection, SAX_PAA_SIZE); sb.append(Arrays.toString(paa).replaceAll("\\s+", "")).append(TAB);
double[] paa = tsProcessor.paa(subSection, SAX_PAA_SIZE); sb.append(Arrays.toString(paa).replaceAll("\\s+", "")).append(TAB);
double[] paa = tsp.paa(subSection, this.saxPAASize);
double[] paa = tsp.paa(subSection, this.saxPAASize);
/** * 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; }
/** * Computes the normalized distance. The whole idea is that rules map to subsequences of different * length. * * @param series * @param reference * @param candidate * @param zNormThreshold * @return * @throws Exception */ private static double normalizedDistance(double[] series, RuleInterval reference, RuleInterval candidate, double zNormThreshold) throws Exception { double[] ref = Arrays.copyOfRange(series, reference.getStart(), reference.getEnd()); double[] cand = Arrays.copyOfRange(series, candidate.getStart(), candidate.getEnd()); double divisor = Integer.valueOf(ref.length).doubleValue(); // if the reference is the longest, we shrink it down with PAA // if (ref.length > cand.length) { ref = tp.paa(ref, cand.length); divisor = Integer.valueOf(cand.length).doubleValue(); // update the normalization value } // if the candidate is longest, we shrink it with PAA too // else { cand = tp.paa(cand, ref.length); } return ed.distance(tp.znorm(ref, zNormThreshold), tp.znorm(cand, zNormThreshold)) / divisor; }
/** * 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; }
double[] paa = tsProcessor.paa(subseries, paaSize);
double[] paa = tsProcessor.paa(subseries, paaSize);
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; } }
double[] paa = tsProcessor.paa(subSection, paaSize);
/** * 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); } }
double[] paa = tp.paa(subSection, params.paaSize);
double[] paa = tsProcessor.paa(subseries, paaSize); int[] leterIndexes = tsProcessor.ts2Index(paa, cuts);
double[] paa = tsProcessor.paa(subSection, paaSize);
double[] paa = tsProcessor.paa(subSection, paaSize);
double[] paa = tsProcessor.paa(subseries, paaSize); int[] leterIndexes = tsProcessor.ts2Index(paa, cuts);
double[] paa = tsProcessor.paa(subSection, paaSize);