public int CommonCount(FixedTimeStepSeries Other) { double[] val1; double[] val2; AlignRemoveDeletevalues(Other, out val1, out val2); return(val1.Count()); }
/// <summary> /// Returns a timestampseries at the required timestep /// Returns a new empty timestampseries if no data exists. /// </summary> /// <param name="TimeStep"></param> /// <returns></returns> public FixedTimeStepSeries GetTs(TimeStepUnit TimeStep) { FixedTimeStepSeries toreturn; if (!data.TryGetValue(TimeStep, out toreturn)) { if (data.Count == 0) { toreturn = new FixedTimeStepSeries() { TimeStepSize = TimeStep, Name = Name + "_" + TimeStep.ToString() }; } if (data.ContainsKey(TimeStepUnit.Day)) { toreturn = TSTools.ChangeZoomLevel(data[TimeStepUnit.Day], TimeStep, Accumulate); } else if (data.ContainsKey(TimeStepUnit.Month)) { toreturn = TSTools.ChangeZoomLevel(data[TimeStepUnit.Month], TimeStep, Accumulate); } data.Add(TimeStep, toreturn); } return(toreturn); }
public static FixedTimeStepSeries Substract(FixedTimeStepSeries ts1, FixedTimeStepSeries ts2) { FixedTimeStepSeries ToReturn = new FixedTimeStepSeries(); ToReturn.TimeStepSize = ts1.TimeStepSize; ToReturn.DeleteValue = ts1.DeleteValue; ToReturn.StartTime = ts1.StartTime; DateTime End = ts1.EndTime; if (ts1.StartTime > ts2.StartTime) { ToReturn.StartTime = ts2.StartTime; } if (ts1.EndTime > ts2.EndTime) { End = ts2.EndTime; } var val1 = ts1.GetValues(ToReturn.StartTime, End); var val2 = ts2.GetValues(ToReturn.StartTime, End); for (int i = 0; i < val1.Count(); i++) { if (val1[i] == ts1.DeleteValue || val2[i] == ts2.DeleteValue) { ToReturn.Add(ToReturn.DeleteValue); } else { ToReturn.Add(val1[i] - val2[i]); } } return(ToReturn); }
/// <summary> /// Returns the FBAL-value /// </summary> /// <param name="Other"></param> /// <returns></returns> public double?FBAL(FixedTimeStepSeries Other) { double[] val1; double[] val2; AlignRemoveDeletevalues(Other, out val1, out val2); int c = val1.Count(); if (c > 0) { return((val1.Average() - val2.Average()) / val1.Average()); } return(null); }
/// <summary> /// Returns the R-squared value /// </summary> /// <param name="Other"></param> /// <returns></returns> public double?R2(FixedTimeStepSeries Other) { double[] val1; double[] val2; AlignRemoveDeletevalues(Other, out val1, out val2); int c = val1.Count(); if (c > 0) { return(TSTools.R2(val1, val2)); } return(null); }
/// <summary> /// Returns the RMSE value /// </summary> /// <param name="Other"></param> /// <returns></returns> public double?RMSE(FixedTimeStepSeries Other) { double[] val1; double[] val2; AlignRemoveDeletevalues(Other, out val1, out val2); int c = val1.Count(); if (c > 0) { double me = 0; for (int i = 0; i < c; i++) { me += Math.Pow(val1[i] - val2[i], 2); } return(Math.Pow(me / c, 0.5)); } return(null); }
public double?MAE(FixedTimeStepSeries Other) { double[] val1; double[] val2; AlignRemoveDeletevalues(Other, out val1, out val2); int c = val1.Count(); if (c > 0) { double mae = 0; for (int i = 0; i < c; i++) { mae += Math.Abs(val1[i] - val2[i]); } return(mae / c); } return(null); }
public void AlignRemoveDeletevalues(FixedTimeStepSeries Other, out double[] val1, out double[] val2) { List <double> var1 = new List <double>(); List <double> var2 = new List <double>(); if (Other.TimeStepSize == TimeStepSize & Other.TimeStepMultiplier == TimeStepMultiplier) { if (Other.StartTime == StartTime) { for (int i = 0; i < Math.Min(this.Count, Other.Count); i++) { if (Items[i].Value != DeleteValue & Other.Items[i].Value != Other.DeleteValue) { var1.Add(Items[i].Value); var2.Add(Other.Items[i].Value); } } } } val1 = var1.ToArray(); val2 = var2.ToArray(); }
public void SetTs(FixedTimeStepSeries ts) { data.Clear(); data.Add(ts.TimeStepSize, ts); }
/// <summary> /// Gets a fixedtimestepseries at another zoom level. /// </summary> /// <param name="Data"></param> /// <param name="NewZoomLevel"></param> /// <param name="Accumulate"></param> /// <returns></returns> public static FixedTimeStepSeries ChangeZoomLevel(FixedTimeStepSeries Data, TimeStepUnit NewZoomLevel, bool Accumulate) { if (Data.TimeStepSize <= NewZoomLevel) { return(null); } FixedTimeStepSeries ToReturn = new FixedTimeStepSeries(); ToReturn.DeleteValue = Data.DeleteValue; ToReturn.TimeStepSize = NewZoomLevel; ToReturn.StartTime = GetTimeOfFirstTimeStep(Data.StartTime, NewZoomLevel); ToReturn.OffSetStartTime = Data.OffSetStartTime; ToReturn.OffSetEndTime = Data.OffSetEndTime; List <double> newvalues = new List <double>(); int localcount = 0; int counter = 0; switch (NewZoomLevel) { case TimeStepUnit.Year: { int currentyear = -1; foreach (var v in Data.Items) { if (Data.GetTime(counter).Year == currentyear) { if (v.Value != Data.DeleteValue) { newvalues[newvalues.Count - 1] += v.Value; } } else { currentyear = Data.GetTime(counter).Year; if (!Accumulate & newvalues.Count > 0) { newvalues[newvalues.Count - 1] /= localcount; } localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (localcount != 12) //only use complete years { newvalues.RemoveAt(newvalues.Count - 1); } else { if (!Accumulate) { newvalues[newvalues.Count - 1] /= localcount; } } } break; case TimeStepUnit.Month: int currentmonth = Data.StartTime.Month; newvalues.Add(0); foreach (var v in Data.Items) { if (Data.GetTime(counter).Month == currentmonth) { if (v.Value != Data.DeleteValue) { newvalues[newvalues.Count - 1] += v.Value; } } else { currentmonth = Data.GetTime(counter).Month; if (!Accumulate) { newvalues[newvalues.Count - 1] /= localcount; } localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (!Accumulate) { newvalues[newvalues.Count - 1] /= localcount; } break; case TimeStepUnit.Day: int currentday = Data.StartTime.Day; newvalues.Add(0); foreach (var v in Data.Items) { if (Data.GetTime(counter).Day == currentday) { if (v.Value != Data.DeleteValue) { newvalues[newvalues.Count - 1] += v.Value; } } else { currentday = Data.GetTime(counter).Day; if (!Accumulate) { newvalues[newvalues.Count - 1] /= localcount; } localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (!Accumulate) { newvalues[newvalues.Count - 1] /= localcount; } break; case TimeStepUnit.Hour: int currenthour = Data.StartTime.Hour; newvalues.Add(0); foreach (var v in Data.Items) { if (Data.GetTime(counter).Hour == currenthour) { if (v.Value != Data.DeleteValue) { newvalues[newvalues.Count - 1] += v.Value; } } else { currenthour = Data.GetTime(counter).Hour; if (!Accumulate) { newvalues[newvalues.Count - 1] /= localcount; } localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (!Accumulate) { newvalues[newvalues.Count - 1] /= localcount; } break; case TimeStepUnit.Minute: int currentminute = Data.StartTime.Minute; newvalues.Add(0); foreach (var v in Data.Items.Where(vv => vv.Value != Data.DeleteValue)) { if (Data.GetTime(counter).Minute == currentminute) { newvalues[newvalues.Count - 1] += v.Value; } else { currentminute = Data.GetTime(counter).Minute; if (!Accumulate) { newvalues[newvalues.Count - 1] /= localcount; } localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (!Accumulate) { newvalues[newvalues.Count - 1] /= localcount; } break; case TimeStepUnit.Second: break; case TimeStepUnit.None: break; default: break; } ToReturn.AddRange(newvalues.Select(n => new ValueDouble(n))); return(ToReturn); }