/** * This method approximates the input by a stepwise linear function. * It returns an iterator of segments, each segment being defined by a timestamp (start of segment) * and pair (intercept, slope) which determines the time series from the start up to and * excluding the start of the next segment. The algorithm proceeds as follows: * Let n timeValuePairs be processed and alpha be the slope of their least square approximation. * By construction, the mean square error is smaller than epsilon. * We now add the (n+1)th timeValuePair and compute the resulting least square approximation. * This step is repeated until the mean square error remains exceeds epsilon. * If it does, the segment is stored as Pair(start of segment, Pair(intercept, alpha)) * and the process starts over. * * @param input the time series to be linearized * @return a stepwise linear function approximating input by epsilon give by an iterator of * (start of segment, (intercept, slope)) */ public static Iterator<Pair<Double, Pair<Double, Double>>> linearize(Iterator<Pair<Double, Double>> input, double epsilon) { return new TimeSeriesRegression(input, epsilon); } }
/** * This method approximates the input by a stepwise linear function. * It returns an iterator of segments, each segment being defined by a timestamp (start of segment) * and pair (intercept, slope) which determines the time series from the start up to and * excluding the start of the next segment. The algorithm proceeds as follows: * Let n timeValuePairs be processed and alpha be the slope of their least square approximation. * By construction, the mean square error is smaller than epsilon. * We now add the (n+1)th timeValuePair and compute the resulting least square approximation. * This step is repeated until the mean square error remains exceeds epsilon. * If it does, the segment is stored as Pair(start of segment, Pair(intercept, alpha)) * and the process starts over. * * @param input the time series to be linearized * @return a stepwise linear function approximating input by epsilon give by an iterator of * (start of segment, (intercept, slope)) */ public static Iterator<Pair<Double, Pair<Double, Double>>> linearize(Iterator<Pair<Double, Double>> input, double epsilon) { return new TimeSeriesRegression(input, epsilon); } }