Keep track of the first derivation and second derivation. That is, keep the mean and variance x [i] -x [i-1]. And save the sum and variance (x [i + 1] -x [i]) - (x [i] -x [i-1]).
For a linear trend, the average value of the first derivative should be constant, and if you notice a deviation from the average (which you can calculate using the variance), then you can say that something is wrong. The average value of the second derivative should be 0.
For a quadratic trend, the average value of the first derivative increases. Thus, you will find many samples with a large deviation from the average. The second derivative behavior is similar to the behavior of the first derivative in the linear case.
Algorithm (using only the second derivative):
- For each input, calculate the sign (+ ve or -ve) of the second derivative
- Keep track of how many recently appeared homogeneous characters (i.e. if the sequence is + - ++++ answer 4)
- If the length of the homogeneous signs is greater than the threshold (say, 40?), Then mark it as the beginning of a quadratic sequence
source share