public static LocalPatternMatch CreateFrom(LocalPattern p0, LocalPattern p1) { var match = new LocalPatternMatch(); match.Dist = p0.DistanceTo(p1); match.X = p0.Position; match.Y = p1.Position; match.PositionDelta = p1.Position - p0.Position; match.AmplitudeDelta = p1.Amplitude - p0.Amplitude; match.TempScaleDelta = p1.TemporalScale - p0.TemporalScale; match.AmpScaleDelta = p1.AmplitudeScale - p0.AmplitudeScale; return match; }
public double DistanceTo(LocalPattern lp1) { double shapeDiffSum = 0; for (int i = 0; i < Shape.Count; ++i) { shapeDiffSum += Math.Abs(lp1.Shape[i] - Shape[i]); } //return shapeDiffSum; //return Math.Abs(lp1.Amplitude - Amplitude); return Math.Abs(lp1.Shape[0] - Shape[0]); }
private static IList<LocalPattern> GetLocalPatterns(IList<double> data, int windowSize) { var lps = new List<LocalPattern>(); int halfWs = windowSize/2; for (int i = halfWs; i < data.Count - halfWs; i += halfWs) { var lp = new LocalPattern(); lp.Position = (double)i / (data.Count - 1); double ampSum = 0; var nums = new double[windowSize]; for (int k = -halfWs; k <= halfWs; k++) { nums[k + halfWs] = data[i + k]; ampSum += data[i + k]; } lp.Amplitude = ampSum/windowSize; lp.Shape = MathUtil.Dwt(nums); lps.Add(lp); } return lps; }