/** * Constructor. */ public GrammarvizRuleChartPanel() { super(); tp = new TSProcessor(); }
/** * Normalizes data in interval 0-1. * * @param data the dataset. * @return normalized dataset. */ public double[] normOne(double[] data) { double[] res = new double[data.length]; double max = max(data); for (int i = 0; i < data.length; i++) { res[i] = data[i] / max; } return res; }
/** * Convert the timeseries into the index using SAX cuts. * * @param series The timeseries to convert. * @param cuts The alphabet cuts. * @return SAX cuts indices. * @throws Exception if error occurs. */ public int[] ts2Index(double[] series, double[] cuts) throws Exception { int[] res = new int[series.length]; for (int i = 0; i < series.length; i++) { res[i] = num2index(series[i], cuts); } return res; }
/** * 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); } }
/** * Constructor. */ public SAXProcessor() { super(); this.tsProcessor = new TSProcessor(); this.na = new NormalAlphabet(); this.ed = new EuclideanDistance(); }
/** * Read at least N elements from the one-column file. * * @param dataFileName the file name. * @param loadLimit the load limit. * @return the read data or empty array if nothing to load. * @throws SAXException if error occurs. * @throws IOException if error occurs. */ public double[] readTS(String dataFileName, int loadLimit) throws SAXException, IOException { Path path = Paths.get(dataFileName); if (!(Files.exists(path))) { throw new SAXException("unable to load data - data source not found."); } BufferedReader reader = Files.newBufferedReader(path, DEFAULT_CHARSET); return readTS(reader, 0, loadLimit); }
/** * Z-Normalize routine. * * @param series the input timeseries. * @param normalizationThreshold the zNormalization threshold value. * @return Z-normalized time-series. */ public double[] znorm(double[] series, double normalizationThreshold) { double[] res = new double[series.length]; double sd = stDev(series); if (sd < normalizationThreshold) { // return series.clone(); // return array of zeros return res; } double mean = mean(series); for (int i = 0; i < res.length; i++) { res[i] = (series[i] - mean) / sd; } return res; }
private static double[] readTimeSeries() throws SAXException, IOException { consoleLogger.info("Reading data ..."); double[] series = tp.readTS(TS2GrammarParameters.IN_FILE, 0); consoleLogger.info("read " + series.length + " points from " + TS2GrammarParameters.IN_FILE); return series; } }
/** * Converts the timeseries into string using given cuts intervals. Useful for not-normal * distribution cuts. * * @param vals The timeseries. * @param cuts The cut intervals. * @return The timeseries SAX representation. */ public char[] ts2String(double[] vals, double[] cuts) { char[] res = new char[vals.length]; for (int i = 0; i < vals.length; i++) { res[i] = num2char(vals[i], cuts); } return res; }
/** * Check for trivial mindist case. * * @param a first string. * @param b second string. * @return true if mindist between strings is zero. */ public boolean checkMinDistIsZero(char[] a, char[] b) { for (int i = 0; i < a.length; i++) { if (charDistance(a[i], b[i]) > 1) { return false; } } return true; }
/** * Compute the variance of timeseries. * * @param series The timeseries. * @return The variance. */ public double var(double[] series) { double res = 0D; double mean = mean(series); int count = 0; for (double tp : series) { res += (tp - mean) * (tp - mean); count += 1; } if (count > 0) { return res / ((Integer) (count - 1)).doubleValue(); } return Double.NaN; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + alphabetSize; long temp; temp = Double.doubleToLongBits(cvError); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(nThreshold); result = prime * result + (int) (temp ^ (temp >>> 32)); result = prime * result + ((nrStartegy == null) ? 0 : nrStartegy.hashCode()); result = prime * result + paaSize; result = prime * result + windowSize; return result; }
/** * 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); } }
/** * Constructor. */ public SAXProcessor() { super(); this.tsProcessor = new TSProcessor(); this.na = new NormalAlphabet(); this.ed = new EuclideanDistance(); }
/** * Read at least N elements from the one-column file. * * @param dataFileName the file name. * @param loadLimit the load limit. * @return the read data or empty array if nothing to load. * @throws SAXException if error occurs. * @throws IOException if error occurs. */ public double[] readTS(String dataFileName, int loadLimit) throws SAXException, IOException { Path path = Paths.get(dataFileName); if (!(Files.exists(path))) { throw new SAXException("unable to load data - data source not found."); } BufferedReader reader = Files.newBufferedReader(path, DEFAULT_CHARSET); return readTS(reader, 0, loadLimit); }
/** * Z-Normalize routine. * * @param series the input timeseries. * @param normalizationThreshold the zNormalization threshold value. * @return Z-normalized time-series. */ public double[] znorm(double[] series, double normalizationThreshold) { double[] res = new double[series.length]; double sd = stDev(series); if (sd < normalizationThreshold) { // return series.clone(); // return array of zeros return res; } double mean = mean(series); for (int i = 0; i < res.length; i++) { res[i] = (series[i] - mean) / sd; } return res; }
/** * Normalizes data in interval 0-1. * * @param data the dataset. * @return normalized dataset. */ public double[] normOne(double[] data) { double[] res = new double[data.length]; double max = max(data); for (int i = 0; i < data.length; i++) { res[i] = data[i] / max; } return res; }
/** * Convert the timeseries into the index using SAX cuts. * * @param series The timeseries to convert. * @param cuts The alphabet cuts. * @return SAX cuts indices. * @throws Exception if error occurs. */ public int[] ts2Index(double[] series, double[] cuts) throws Exception { int[] res = new int[series.length]; for (int i = 0; i < series.length; i++) { res[i] = num2index(series[i], cuts); } return res; }
/** * Converts the timeseries into string using given cuts intervals. Useful for not-normal * distribution cuts. * * @param vals The timeseries. * @param cuts The cut intervals. * @return The timeseries SAX representation. */ public char[] ts2String(double[] vals, double[] cuts) { char[] res = new char[vals.length]; for (int i = 0; i < vals.length; i++) { res[i] = num2char(vals[i], cuts); } return res; }
/** * Check for trivial mindist case. * * @param a first string. * @param b second string. * @return true if mindist between strings is zero. */ public boolean checkMinDistIsZero(char[] a, char[] b) { for (int i = 0; i < a.length; i++) { if (charDistance(a[i], b[i]) > 1) { return false; } } return true; }