/// <summary> /// Calculate the standard deviation value of array data. Supported data type: double/float/int. /// </summary> /// <param name="data">The array data to calculate statistic value.</param> /// <typeparam name="TDataType">Supported data type: double/float/int.</typeparam> /// <returns>The standard deviation value of array data in specific place.</returns> /// <exception cref="NotSupportedException">Supported data type: double/float/int.</exception> public static double StandardDeviation <TDataType>(TDataType[] data) { double standardDeviation = double.NaN; if (ReferenceEquals(typeof(TDataType), typeof(double))) { double[] doubleData = data as double[]; standardDeviation = ArrayStatistics.StandardDeviation(doubleData); } else if (ReferenceEquals(typeof(TDataType), typeof(float))) { float[] floatData = data as float[]; standardDeviation = ArrayStatistics.StandardDeviation(floatData); } else if (ReferenceEquals(typeof(TDataType), typeof(int))) { int[] intData = data as int[]; standardDeviation = ArrayStatistics.StandardDeviation(intData); } else { throw new NotSupportedException("Unsupported data type."); } return(standardDeviation); }
private void GenerarNorm() { var observados = Seccionar(); double acumulador = 0; var frecAbs = new List <double>(); var intervalos = int.Parse(txtInter.Text); var min = Valores.Min(); var max = Valores.Max(); var paso = (max - min) / intervalos; var mean = ArrayStatistics.Mean(Valores.ToArray()); var desEst = ArrayStatistics.StandardDeviation(Valores.ToArray()); for (double i = min; i <= max; i += paso) { var sup = MathNet.Numerics.Distributions.Normal.CDF(mean, desEst, i + paso); var inf = MathNet.Numerics.Distributions.Normal.CDF(mean, desEst, i); double esperado = Valores.Count() * (sup - inf); frecAbs.Add(esperado); } for (int i = 0; i < intervalos - 1; i++) { acumulador = acumulador + Math.Pow(observados[i] - frecAbs[i], 2) / frecAbs[i]; } txtAcum.Text = acumulador.ToString(); var gl = intervalos - 1 - 2; var alpha = 0.95; var chi = MathNet.Numerics.Distributions.ChiSquared.InvCDF(gl, alpha); txtTabulado.Text = chi.ToString(); }
/// <summary> /// Populate 6 month standard deviation /// </summary> public static double GetPriceRangeStdDev(this HistoricalData data) { double[] priceRange = data.High.Select((d, i) => d - data.Low[i]).ToArray(); double stdDev = ArrayStatistics.StandardDeviation(priceRange); return(stdDev); }
public void StandardDeviationConsistentWithNistData(string dataSet, int digits) { var data = _data[dataSet]; AssertHelpers.AlmostEqual(data.StandardDeviation, Statistics.StandardDeviation(data.Data), digits); AssertHelpers.AlmostEqual(data.StandardDeviation, ArrayStatistics.StandardDeviation(data.Data), digits); AssertHelpers.AlmostEqual(data.StandardDeviation, StreamingStatistics.StandardDeviation(data.Data), digits); }
/// <summary> /// Populate 6 month standard deviation /// </summary> public static double GetPriceRangeStdDevFor6Months(this HistoricalData data) { DateTime last6Months = DateTime.UtcNow.AddMonths(-6).Date; int index = ((IReadOnlyList <DateTime>)data.Date).FirstAndIndex(item => item >= last6Months).Item1; List <double> highPrices = data.High.Skip(index).ToList(); List <double> lowPrices = data.Low.Skip(index).ToList(); double rangeStdDev = ArrayStatistics.StandardDeviation(highPrices.Select((item, i) => item - lowPrices[i]).ToArray()); return(rangeStdDev); }
public void ThrowsOnNullData() { double[] data = null; // ReSharper disable InvokeAsExtensionMethod Assert.That(() => Statistics.Minimum(data), Throws.Exception); Assert.That(() => Statistics.Maximum(data), Throws.Exception); Assert.That(() => Statistics.Mean(data), Throws.Exception); Assert.That(() => Statistics.Median(data), Throws.Exception); Assert.That(() => Statistics.Quantile(data, 0.3), Throws.Exception); Assert.That(() => Statistics.Variance(data), Throws.Exception); Assert.That(() => Statistics.StandardDeviation(data), Throws.Exception); Assert.That(() => Statistics.PopulationVariance(data), Throws.Exception); Assert.That(() => Statistics.PopulationStandardDeviation(data), Throws.Exception); Assert.That(() => Statistics.Covariance(data, data), Throws.Exception); Assert.That(() => Statistics.PopulationCovariance(data, data), Throws.Exception); // ReSharper restore InvokeAsExtensionMethod Assert.That(() => SortedArrayStatistics.Minimum(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.Minimum(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.Maximum(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.OrderStatistic(data, 1), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.Median(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.LowerQuartile(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.UpperQuartile(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.Percentile(data, 30), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.Quantile(data, 0.3), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.QuantileCustom(data, 0.3, 0, 0, 1, 0), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.QuantileCustom(data, 0.3, QuantileDefinition.Nearest), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.InterquartileRange(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => SortedArrayStatistics.FiveNumberSummary(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.Minimum(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.Maximum(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.OrderStatisticInplace(data, 1), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.Mean(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.Variance(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.StandardDeviation(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.PopulationVariance(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.PopulationStandardDeviation(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.Covariance(data, data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.PopulationCovariance(data, data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.MedianInplace(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => ArrayStatistics.QuantileInplace(data, 0.3), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => StreamingStatistics.Minimum(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => StreamingStatistics.Maximum(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => StreamingStatistics.Mean(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => StreamingStatistics.Variance(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => StreamingStatistics.StandardDeviation(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => StreamingStatistics.PopulationVariance(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => StreamingStatistics.PopulationStandardDeviation(data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => StreamingStatistics.Covariance(data, data), Throws.Exception.TypeOf <NullReferenceException>()); Assert.That(() => StreamingStatistics.PopulationCovariance(data, data), Throws.Exception.TypeOf <NullReferenceException>()); }
public void StandardDeviationConsistentWithNistData(string dataSet, int digits) { var data = _data[dataSet]; AssertHelpers.AlmostEqualRelative(data.StandardDeviation, Statistics.StandardDeviation(data.Data), digits); AssertHelpers.AlmostEqualRelative(data.StandardDeviation, ArrayStatistics.StandardDeviation(data.Data), digits); AssertHelpers.AlmostEqualRelative(data.StandardDeviation, StreamingStatistics.StandardDeviation(data.Data), digits); AssertHelpers.AlmostEqualRelative(data.StandardDeviation, Math.Sqrt(Statistics.MeanVariance(data.Data).Item2), digits); AssertHelpers.AlmostEqualRelative(data.StandardDeviation, Math.Sqrt(ArrayStatistics.MeanVariance(data.Data).Item2), digits); AssertHelpers.AlmostEqualRelative(data.StandardDeviation, Math.Sqrt(StreamingStatistics.MeanVariance(data.Data).Item2), digits); }
private static List <StatResult> NumericStat(List <string> data) { List <StatResult> results = new List <StatResult>(); try { var numData = data.Select(x => double.Parse(x)).ToList(); double min = ArrayStatistics.Minimum(numData.ToArray()); double max = ArrayStatistics.Maximum(numData.ToArray()); results.Add(new StatResult { Label = "Moyenne", Result = ArrayStatistics.Mean(numData.ToArray()).ToString(CultureInfo.InvariantCulture) }); results.Add(new StatResult { Label = "Médiane", Result = ArrayStatistics.MedianInplace(numData.ToArray()).ToString(CultureInfo.InvariantCulture) }); results.Add(new StatResult { Label = "Maximum", Result = max.ToString(CultureInfo.InvariantCulture) }); results.Add(new StatResult { Label = "Minimum", Result = min.ToString(CultureInfo.InvariantCulture) }); results.Add(new StatResult { Label = "Étendue", Result = (max - min).ToString(CultureInfo.InvariantCulture) }); results.Add(new StatResult { Label = "Écart-type", Result = ArrayStatistics.StandardDeviation(numData.ToArray()).ToString(CultureInfo.InvariantCulture) }); results.Add(new StatResult { Label = "Variance", Result = ArrayStatistics.Variance(numData.ToArray()).ToString(CultureInfo.InvariantCulture) }); } catch (Exception ex) { Logger.LogError(ex.Message); } return(results); }
public void ArrayStatisticsConsistentWithStreamimgStatistics(string dataSet) { var data = _data[dataSet]; AssertHelpers.AlmostEqual(ArrayStatistics.Mean(data.Data), StreamingStatistics.Mean(data.Data), 10); AssertHelpers.AlmostEqual(ArrayStatistics.Variance(data.Data), StreamingStatistics.Variance(data.Data), 10); AssertHelpers.AlmostEqual(ArrayStatistics.StandardDeviation(data.Data), StreamingStatistics.StandardDeviation(data.Data), 10); AssertHelpers.AlmostEqual(ArrayStatistics.PopulationVariance(data.Data), StreamingStatistics.PopulationVariance(data.Data), 10); AssertHelpers.AlmostEqual(ArrayStatistics.PopulationStandardDeviation(data.Data), StreamingStatistics.PopulationStandardDeviation(data.Data), 10); AssertHelpers.AlmostEqual(ArrayStatistics.Covariance(data.Data, data.Data), StreamingStatistics.Covariance(data.Data, data.Data), 10); AssertHelpers.AlmostEqual(ArrayStatistics.PopulationCovariance(data.Data, data.Data), StreamingStatistics.PopulationCovariance(data.Data, data.Data), 10); }
public void ThrowsOnNullData() { double[] data = null; Assert.Throws <ArgumentNullException>(() => Statistics.Minimum(data)); Assert.Throws <ArgumentNullException>(() => Statistics.Maximum(data)); Assert.Throws <ArgumentNullException>(() => Statistics.Mean(data)); Assert.Throws <ArgumentNullException>(() => Statistics.Median(data)); Assert.Throws <ArgumentNullException>(() => Statistics.Quantile(data, 0.3)); Assert.Throws <ArgumentNullException>(() => Statistics.Variance(data)); Assert.Throws <ArgumentNullException>(() => Statistics.StandardDeviation(data)); Assert.Throws <ArgumentNullException>(() => Statistics.PopulationVariance(data)); Assert.Throws <ArgumentNullException>(() => Statistics.PopulationStandardDeviation(data)); Assert.Throws <ArgumentNullException>(() => Statistics.Covariance(data, data)); Assert.Throws <ArgumentNullException>(() => Statistics.PopulationCovariance(data, data)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Minimum(data)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Maximum(data)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.OrderStatistic(data, 1)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Median(data)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.LowerQuartile(data)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.UpperQuartile(data)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Percentile(data, 30)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.Quantile(data, 0.3)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.QuantileCustom(data, 0.3, 0, 0, 1, 0)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.QuantileCustom(data, 0.3, QuantileDefinition.Nearest)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.InterquartileRange(data)); Assert.Throws <ArgumentNullException>(() => SortedArrayStatistics.FiveNumberSummary(data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Minimum(data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Maximum(data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.OrderStatisticInplace(data, 1)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Mean(data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Variance(data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.StandardDeviation(data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.PopulationVariance(data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.PopulationStandardDeviation(data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.Covariance(data, data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.PopulationCovariance(data, data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.MedianInplace(data)); Assert.Throws <ArgumentNullException>(() => ArrayStatistics.QuantileInplace(data, 0.3)); Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Minimum(data)); Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Maximum(data)); Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Mean(data)); Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Variance(data)); Assert.Throws <ArgumentNullException>(() => StreamingStatistics.StandardDeviation(data)); Assert.Throws <ArgumentNullException>(() => StreamingStatistics.PopulationVariance(data)); Assert.Throws <ArgumentNullException>(() => StreamingStatistics.PopulationStandardDeviation(data)); Assert.Throws <ArgumentNullException>(() => StreamingStatistics.Covariance(data, data)); Assert.Throws <ArgumentNullException>(() => StreamingStatistics.PopulationCovariance(data, data)); }
public void StabilityMeanVariance() { // Test around 10^9, potential stability issues var gaussian = new Normal(1e+9, 2, new MersenneTwister(100)); AssertHelpers.AlmostEqual(1e+9, Statistics.Mean(gaussian.Samples().Take(10000)), 11); AssertHelpers.AlmostEqual(4d, Statistics.Variance(gaussian.Samples().Take(10000)), 1); AssertHelpers.AlmostEqual(2d, Statistics.StandardDeviation(gaussian.Samples().Take(10000)), 2); AssertHelpers.AlmostEqual(1e+9, ArrayStatistics.Mean(gaussian.Samples().Take(10000).ToArray()), 11); AssertHelpers.AlmostEqual(4d, ArrayStatistics.Variance(gaussian.Samples().Take(10000).ToArray()), 1); AssertHelpers.AlmostEqual(2d, ArrayStatistics.StandardDeviation(gaussian.Samples().Take(10000).ToArray()), 2); AssertHelpers.AlmostEqual(1e+9, StreamingStatistics.Mean(gaussian.Samples().Take(10000)), 11); AssertHelpers.AlmostEqual(4d, StreamingStatistics.Variance(gaussian.Samples().Take(10000)), 1); AssertHelpers.AlmostEqual(2d, StreamingStatistics.StandardDeviation(gaussian.Samples().Take(10000)), 2); }
public void DoesNotThrowOnEmptyData() { double[] data = new double[0]; Assert.DoesNotThrow(() => Statistics.Minimum(data)); Assert.DoesNotThrow(() => Statistics.Maximum(data)); Assert.DoesNotThrow(() => Statistics.Mean(data)); Assert.DoesNotThrow(() => Statistics.Median(data)); Assert.DoesNotThrow(() => Statistics.Quantile(data, 0.3)); Assert.DoesNotThrow(() => Statistics.Variance(data)); Assert.DoesNotThrow(() => Statistics.StandardDeviation(data)); Assert.DoesNotThrow(() => Statistics.PopulationVariance(data)); Assert.DoesNotThrow(() => Statistics.PopulationStandardDeviation(data)); Assert.DoesNotThrow(() => SortedArrayStatistics.Minimum(data)); Assert.DoesNotThrow(() => SortedArrayStatistics.Maximum(data)); Assert.DoesNotThrow(() => SortedArrayStatistics.OrderStatistic(data, 1)); Assert.DoesNotThrow(() => SortedArrayStatistics.Median(data)); Assert.DoesNotThrow(() => SortedArrayStatistics.LowerQuartile(data)); Assert.DoesNotThrow(() => SortedArrayStatistics.UpperQuartile(data)); Assert.DoesNotThrow(() => SortedArrayStatistics.Percentile(data, 30)); Assert.DoesNotThrow(() => SortedArrayStatistics.Quantile(data, 0.3)); Assert.DoesNotThrow(() => SortedArrayStatistics.QuantileCustom(data, 0.3, 0, 0, 1, 0)); Assert.DoesNotThrow(() => SortedArrayStatistics.QuantileCustom(data, 0.3, QuantileDefinition.Nearest)); Assert.DoesNotThrow(() => SortedArrayStatistics.InterquartileRange(data)); Assert.DoesNotThrow(() => SortedArrayStatistics.FiveNumberSummary(data)); Assert.DoesNotThrow(() => ArrayStatistics.Minimum(data)); Assert.DoesNotThrow(() => ArrayStatistics.Maximum(data)); Assert.DoesNotThrow(() => ArrayStatistics.OrderStatisticInplace(data, 1)); Assert.DoesNotThrow(() => ArrayStatistics.Mean(data)); Assert.DoesNotThrow(() => ArrayStatistics.Variance(data)); Assert.DoesNotThrow(() => ArrayStatistics.StandardDeviation(data)); Assert.DoesNotThrow(() => ArrayStatistics.PopulationVariance(data)); Assert.DoesNotThrow(() => ArrayStatistics.PopulationStandardDeviation(data)); Assert.DoesNotThrow(() => ArrayStatistics.MedianInplace(data)); Assert.DoesNotThrow(() => ArrayStatistics.QuantileInplace(data, 0.3)); Assert.DoesNotThrow(() => StreamingStatistics.Minimum(data)); Assert.DoesNotThrow(() => StreamingStatistics.Maximum(data)); Assert.DoesNotThrow(() => StreamingStatistics.Mean(data)); Assert.DoesNotThrow(() => StreamingStatistics.Variance(data)); Assert.DoesNotThrow(() => StreamingStatistics.StandardDeviation(data)); Assert.DoesNotThrow(() => StreamingStatistics.PopulationVariance(data)); Assert.DoesNotThrow(() => StreamingStatistics.PopulationStandardDeviation(data)); }
/// <summary> /// FInd the standard deviation from the double array (supported platforms: MathNet, Intel IPP) /// </summary> /// <param name="data">input data</param> /// <returns>standard deviation value</returns> public static double StandardDeviation(double[] data) { try { switch (Engine.Provider) { case ProviderEngine.MathNet: return(ArrayStatistics.StandardDeviation(data)); case ProviderEngine.IntelIPP: return(IPP.Statistics.StdDev(data)); default: return(ArrayStatistics.StandardDeviation(data)); } } catch (Exception ex) { throw new Exception(ex.Message); } }
private double[] ApplyAggregationFunction(AggregationMethod method, string argument, int kernelSize, double[] data, double nanLimit, ILogger logger) { var targetDatasetLength = data.Length / kernelSize; var result = new double[targetDatasetLength]; switch (method) { case AggregationMethod.Mean: Parallel.For(0, targetDatasetLength, x => { var chunkData = this.GetNaNFreeData(data, x, kernelSize); var isHighQuality = (chunkData.Length / (double)kernelSize) >= nanLimit; if (isHighQuality) { result[x] = ArrayStatistics.Mean(chunkData); } else { result[x] = double.NaN; } }); break; case AggregationMethod.MeanPolar: double[] sin = new double[targetDatasetLength]; double[] cos = new double[targetDatasetLength]; double limit; if (argument.Contains("*PI")) { limit = Double.Parse(argument.Replace("*PI", "")) * Math.PI; } else { limit = Double.Parse(argument); } var factor = 2 * Math.PI / limit; Parallel.For(0, targetDatasetLength, x => { var chunkData = this.GetNaNFreeData(data, x, kernelSize); var length = chunkData.Length; var isHighQuality = (length / (double)kernelSize) >= nanLimit; if (isHighQuality) { for (int i = 0; i < chunkData.Length; i++) { sin[x] += Math.Sin(chunkData[i] * factor); cos[x] += Math.Cos(chunkData[i] * factor); } result[x] = Math.Atan2(sin[x], cos[x]) / factor; if (result[x] < 0) { result[x] += limit; } } else { result[x] = double.NaN; } }); break; case AggregationMethod.Min: Parallel.For(0, targetDatasetLength, x => { var chunkData = this.GetNaNFreeData(data, x, kernelSize); var isHighQuality = (chunkData.Length / (double)kernelSize) >= nanLimit; if (isHighQuality) { result[x] = ArrayStatistics.Minimum(chunkData); } else { result[x] = double.NaN; } }); break; case AggregationMethod.Max: Parallel.For(0, targetDatasetLength, x => { var chunkData = this.GetNaNFreeData(data, x, kernelSize); var isHighQuality = (chunkData.Length / (double)kernelSize) >= nanLimit; if (isHighQuality) { result[x] = ArrayStatistics.Maximum(chunkData); } else { result[x] = double.NaN; } }); break; case AggregationMethod.Std: Parallel.For(0, targetDatasetLength, x => { var chunkData = this.GetNaNFreeData(data, x, kernelSize); var isHighQuality = (chunkData.Length / (double)kernelSize) >= nanLimit; if (isHighQuality) { result[x] = ArrayStatistics.StandardDeviation(chunkData); } else { result[x] = double.NaN; } }); break; case AggregationMethod.Rms: Parallel.For(0, targetDatasetLength, x => { var chunkData = this.GetNaNFreeData(data, x, kernelSize); var isHighQuality = (chunkData.Length / (double)kernelSize) >= nanLimit; if (isHighQuality) { result[x] = ArrayStatistics.RootMeanSquare(chunkData); } else { result[x] = double.NaN; } }); break; case AggregationMethod.SampleAndHold: Parallel.For(0, targetDatasetLength, x => { var chunkData = this.GetNaNFreeData(data, x, kernelSize); var isHighQuality = (chunkData.Length / (double)kernelSize) >= nanLimit; if (isHighQuality) { result[x] = chunkData.First(); } else { result[x] = double.NaN; } }); break; case AggregationMethod.Sum: Parallel.For(0, targetDatasetLength, x => { var chunkData = this.GetNaNFreeData(data, x, kernelSize); var isHighQuality = (chunkData.Length / (double)kernelSize) >= nanLimit; if (isHighQuality) { result[x] = Vector <double> .Build.Dense(chunkData).Sum(); } else { result[x] = double.NaN; } }); break; default: logger.LogWarning($"The aggregation method '{method}' is not known. Skipping period."); break; } return(result); }