public static IEnumerable <TemporalGapTuple> DoCorrelationAnalysis( List <TimeSeries> tss, CorrelationAnalysisParameters parameters) { return(tss .SelectMany(ts1 => tss, (ts1, ts2) => DoCorrelationAnalysis(ts1, ts2, parameters)) .Select(analysis => analysis.MaxBy(tg => tg.Correlation)) .DistinctBy(tg => tg.GetId())); }
public static IEnumerable <TemporalGapTuple> DoCorrelationAnalysis( TimeSeries ts1, TimeSeries ts2, CorrelationAnalysisParameters parameters) { return(parameters.GetTimeSpans() .Select(span => new TemporalGapTuple { Indicator = ts1, Target = ts2, TemporalGap = -span, Correlation = GetCorrelationBetween(ts1, ts2.OffsetBy(span)) })); }
/// <summary> /// Plots the autocorrelation function in a plot view. /// </summary> /// <param name="plotInfo"></param> /// <param name="span"></param> /// <param name="steps"></param> /// <returns></returns> public static PlotView GetAutocorrelationFunctionPlotView( TimeSeriesPlotInfo plotInfo, TimeSpan span, int steps) { TimeSeries ts = plotInfo.Series; CorrelationAnalysisParameters parameters = new CorrelationAnalysisParameters() { Span = span, NumberOfSpansInthePast = 0, NumberOfSpansIntheFuture = steps }; FunctionSeries series = new FunctionSeries { MarkerType = plotInfo.Marker, Color = OxyColor.FromArgb(plotInfo.Color.A, plotInfo.Color.R, plotInfo.Color.G, plotInfo.Color.B), Title = plotInfo.Title, }; DoCorrelationAnalysis(ts, ts, parameters) .Where(pair => pair.TemporalGap.Ticks > 0) .OrderBy(pair => pair.TemporalGap.Ticks) .ForEach(pair => { double x = (int)pair.TemporalGap.DivideBy(span); DataPoint point = new DataPoint(x, pair.Correlation); series.Points.Add(point); }); PlotModel model = new PlotModel(); model.Series.Add(series); return(new PlotView { Model = model, Dock = DockStyle.Fill, Visible = true, }); }