public void D2D10DivideByD2MultiplyBy2DistributionShouldBeGood() { var statistics = new DescriptiveStatistics(rolls); Assert.AreEqual(d2d10div2mul2.Minimum, statistics.Minimum, "Expected min differs from actual min"); Assert.AreEqual(d2d10div2mul2.Maximum, statistics.Maximum, "Expected max differs from actual max"); Assert.AreEqual(12.25, statistics.Mean, 1, "Expected mean differs to much from actual mean"); Assert.Greater(statistics.Skewness, 0.8, "Distribution is not skewed enough"); Assert.Less(statistics.Kurtosis, 0, "Distribution is not platykurtic at all"); }
public void D4D6DistributionShouldBeGood() { // We're combining several random dice, so distribution is not uniform at all, // since sums in lower range have higher chance of appearing. var statistics = new DescriptiveStatistics(rolls); Assert.AreEqual(cd4d6mr2t5.Minimum, statistics.Minimum, "Expected min differs from actual min"); Assert.AreEqual(cd4d6mr2t5.Maximum, statistics.Maximum, "Expected max differs from actual max"); Assert.AreEqual(5.25, statistics.Mean, 1, "Expected mean differs to much from actual mean"); Assert.Greater(statistics.Skewness, 0.2, "Distribution is not skewed enough"); Assert.Less(statistics.Kurtosis, 0, "Distribution is not platykurtic at all"); }
/// <summary> Determines whether a specified values are distributed in a 'uniformish' way: /// mean value is as expected, distribution is platykurtic and not skewed. </summary> /// <param name="randomValues">The random values.</param> /// <param name="minValue">The minimum possible value.</param> /// <param name="maxValue">The maximum possible value.</param> public static void IsUniformishDistribution(double[] randomValues, double minValue, double maxValue) { var statistics = new DescriptiveStatistics(randomValues); double meanMargin = (maxValue < 1) ? maxValue / 5 : 1; Assert.AreEqual((minValue + maxValue) / 2, statistics.Mean, meanMargin, "Expected mean differs to much from actual mean"); Assert.AreEqual(minValue, statistics.Minimum, "Expected min differs from actual min"); Assert.AreEqual(maxValue, statistics.Maximum, "Expected max differs from actual max"); Assert.AreEqual(0, statistics.Skewness, 0.1, "Distribution is skewed too much"); Assert.Less(statistics.Kurtosis, 0, "Distribution is not platykurtic at all"); }
public void DescriptiveStatisticsDataContractSerializationTest() { var expected = new DescriptiveStatistics(new[] { 1.0, 2.0, 3.0 }); var serializer = new DataContractSerializer(typeof(DescriptiveStatistics)); var stream = new MemoryStream(); serializer.WriteObject(stream, expected); stream.Position = 0; var actual = (DescriptiveStatistics)serializer.ReadObject(stream); Assert.That(actual.Count, Is.EqualTo(expected.Count)); Assert.That(actual.Maximum, Is.EqualTo(expected.Maximum)); Assert.That(actual.Mean, Is.EqualTo(expected.Mean)); }
private static Aggregates Aggregate(IEnumerable<double> doubles) { var enumerable = doubles as double[] ?? doubles.ToArray(); var stats = new DescriptiveStatistics(enumerable); var min = stats.Minimum; var max = stats.Maximum; var mean = stats.Mean; var median = enumerable.Median(); var variance = stats.Variance; var skewness = stats.Skewness; var kurtosis = stats.Kurtosis; var valueRange = max - min; var result = new Aggregates(min, max, mean, median, variance, valueRange, skewness, kurtosis); return result; }
static void Main(string[] args) { var rnd = new System.Random(); double[] data = new double[10000000]; int i; for (i = 0; i < 10000000; i++) { data[i] = rnd.NextDouble(); } //宣言的に記述する Console.WriteLine("宣言的な記述をするためにDescriptiveStatisticsクラスを使用する。"); var stat = new DescriptiveStatistics(data); //重い! //標準偏差 Console.WriteLine("Standard Deviation = {0}", stat.StandardDeviation); //平均 Console.WriteLine("Mean = {0}", stat.Mean); //メジアン Console.WriteLine("Median = {0}", stat.Median); //分散 Console.WriteLine("Variance = {0}", stat.Variance); //歪度 Console.WriteLine("Skewness = {0}", stat.Skewness); //尖度 Console.WriteLine("Kurtosis = {0}", stat.Kurtosis); //以上のようにDescriptiveStatisticsクラスはStatisticsとは1:1ではないので注意が必要 //拡張メソッドを使用する Console.WriteLine("\r\nStatisticsクラスのメソッドを拡張メソッドとして使用する。"); //標準偏差 Console.WriteLine("Standard Deviation = {0}", data.StandardDeviation()); //母標準偏差 Console.WriteLine("Population Standard Deviation = {0}", data.PopulationStandardDeviation()); //標本分散 Console.WriteLine("Variance = {0}", data.Variance()); //メジアン(中央値) Console.WriteLine("Median = {0}", data.Median()); //順序統計量 //Console.WriteLine("Order Statisitc(i-Order = 123) = {0}", data.OrderStatistic(123)); //OrderStatisticは拡張メソッドに対応していない。 Console.Write("何か入力してください..."); Console.Read(); }
public static double JaqueBeraTest(double[] sampleList) { // Get the Skewness and Kurtosis in a single run using Math.Net DescriptiveStatistics statistics = new DescriptiveStatistics(sampleList); double kurtosis = statistics.Kurtosis; double skewness = statistics.Skewness; int sampleCount = sampleList.Length; double JB = sampleCount / 6 * (Math.Pow(skewness, 2) + Math.Pow(kurtosis - 3, 2) / 4); // Because of really small sample, use a table of distrubution quantitiles generated by Monte Carlo simulation // P-value JB // 0.10 4.61 // 0.05 5.99 // 0.01 9.21 // Lower p value reject the normal distrubution hypothesis. Higher JB means lower p-value. So higher JB rejects // H0, So lower JB means higher score. // return JB; return ScoreUtil.MapToZeroOneTrignometry(JB, true, 50); }
public List<double> DetectOscillation(List<double> data) { var dct = mDct.Forward(data); var stats = new DescriptiveStatistics(dct); double sigma = stats.StandardDeviation; double seaLevel = 3 * sigma; //set all values below sea level to zero dct = dct.Select(x => (Math.Abs(x) > seaLevel) ? x : 0.0).ToList(); var ret = new List<double>(); foreach (var component in ExtractFrequencyComponents(dct)) { //get zero crossings var zeroCrossings = Enumerable.Range(0, component.Count()-1) .Where(i => Math.Sign(component[i]) > 0 && Math.Sign(component[i + 1]) < 0) .ToList(); var increments = new List<double>(); for (int i = 1; i < zeroCrossings.Count(); i++) { increments.Add(2 * (zeroCrossings[i] - zeroCrossings[i - 1])); } var iStats = new DescriptiveStatistics(increments); if ((iStats.StandardDeviation / iStats.Mean) < (1.0 / 3)) { ret.Add(iStats.Mean); } } return ret; }
protected Tuple<VariableInfo, Exception> getVariableInfo(statdataEntities ctx, VariableDesc oVar) { Exception err = null; VariableInfo info = null; if (oVar == null) { return new Tuple<VariableInfo, Exception>(info, new ArgumentNullException()); } DbVariable pVar = findVariable(ctx, oVar); if (pVar == null) { return new Tuple<VariableInfo, Exception>(info, err); } info = new VariableInfo(); String stype = pVar.VarType.Trim().ToLower(); info.VariableId = pVar.Id; info.VariableName = pVar.Name; info.DataSetId = pVar.DataSetId; info.DataSetName = pVar.DataSet.Name; info.DataType = stype; info.IsCategVar = pVar.IsCateg; if ((stype == "bool") || (stype == "string")) { info.IsCategVar = true; } { var q1 = pVar.Values; int nMissing = 0; int nCount = 0; foreach (var p in q1) { String sval = p.Value; if (!String.IsNullOrEmpty(sval)) { sval = StatHelpers.ConvertValue(sval); } if (String.IsNullOrEmpty(sval)) { ++nMissing; } ++nCount; }// p info.MissingValuesCount = nMissing; info.TotalValuesCount = nCount; } if (info.IsCategVar) { Dictionary<String, int> dict = new Dictionary<string, int>(); var q2 = from x in pVar.Values select x.Value; foreach (var p in q2) { String sval = StatHelpers.ConvertValue(p); if (!String.IsNullOrEmpty(sval)) { if (!dict.ContainsKey(sval)) { dict[sval] = 1; } else { dict[sval] = dict[sval] + 1; } } }// p CategValueDescs vv = new CategValueDescs(); var keys = dict.Keys; foreach (var s in keys) { CategValueDesc c = new CategValueDesc(); c.StringValue = s; c.Count = dict[s]; c.VariableId = info.VariableId; vv.Add(c); } info.CategValues = vv; info.DistinctValues = keys.ToList(); } else { var q3 = pVar.Values; int nCount = 0; List<double> dList = new List<double>(); foreach (var p in q3) { String sval = StatHelpers.ConvertValue(p.Value); if (!String.IsNullOrEmpty(sval)) { double xcur = 0; if (double.TryParse(sval, out xcur)) { dList.Add(xcur); }// ok } }// p nCount = dList.Count(); if (nCount > 0) { DescriptiveStatistics st = new DescriptiveStatistics(dList); info.MinValue = st.Minimum; info.MaxValue = st.Maximum; info.MeanValue = myconvert(st.Mean); info.Deviation = myconvert(st.StandardDeviation); info.Skewness = myconvert(st.Skewness); info.Flatness = myconvert(st.Kurtosis); dList.Sort(); var oAr = dList.ToArray(); info.Quantile05 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.05)); info.Quantile10 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.10)); info.Quantile25 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.25)); info.Median = myconvert(SortedArrayStatistics.Quantile(oAr, 0.5)); info.Quantile75 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.75)); info.Quantile90 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.90)); info.Quantile95 = myconvert(SortedArrayStatistics.Quantile(oAr, 0.10)); } } info.IsModified = false; // return new Tuple<VariableInfo, Exception>(info, err); }
private void LineReceived(string line) { double dTemperature, dTemperatureRound, dTemperatureStd; try { DateTime dtStart = DateTime.Now; //label1.Text = line; //receives line with point 21.45 to make it to double one needs to use //CultureInfo.InvariantCulture dTemperature = double.Parse(line, CultureInfo.InvariantCulture); dTemperatureRound = Math.Round(dTemperature, 4); label1.Text = Convert.ToString(dTemperatureRound); chart1.Series[0].BorderWidth = 2; chart1.Series[0].ChartType = SeriesChartType.Line; tsTimespent = DateTime.Now - dtStarttime; listdTimespent.Add(i); listdTemperature.Add(dTemperatureRound); DescriptiveStatistics descrStat = new DescriptiveStatistics(listdTemperature); double dKurtosis = descrStat.Kurtosis; double dSkewness = descrStat.Skewness; dTemperatureStd = Math.Round(listdTemperature.StandardDeviation(),4); label4Std.Text = Convert.ToString(dTemperatureStd); label5Mittel.Text = Convert.ToString(Math.Round(listdTemperature.Mean(),4)); label6Zentral.Text = Convert.ToString(Math.Round(listdTemperature.Median(),4)); label73xStd.Text = Convert.ToString(3*dTemperatureStd); label9Min.Text = Convert.ToString(Math.Round(listdTemperature.Min(),4)); label9Max.Text = Convert.ToString(Math.Round(listdTemperature.Max(),4)); label11Schiefe.Text = Convert.ToString(Math.Round(dSkewness, 4)); label11Wolbung.Text = Convert.ToString(Math.Round(dKurtosis, 4)); chart1.Series[0].Points.AddXY(tsTimespent.TotalSeconds, dTemperatureRound); //chart1.Series[0].Points.AddXY(i, dTemperatureRound); chart1.ChartAreas["ChartArea1"].AxisX.Minimum = listdTimespent[0]; chart1.ChartAreas["ChartArea1"].AxisY.Minimum = (listdTemperature.Min() - 0.5); chart1.ChartAreas["ChartArea1"].AxisY.Maximum = (listdTemperature.Max() + 0.5); //chart1.ChartAreas["ChartArea1"].AxisX = new Axis { LabelStyle = new LabelStyle() { Font = new Font("Verdana", 7.5f) } }; //chart1.ChartAreas["ChartArea1"].AxisX.TitleFont = "Verdana"; //chart1.ChartAreas["ChartArea1"].AxisX.Title = "Zeit [s]"; //chart1.ChartAreas["ChartArea1"].AxisY.Title = "Temparature [C]"; DateTime time = DateTime.Now; //string format = "MMM ddd d HH:mm yyyy"; string format = "yyyyMMddHHmmssffff"; //label2.Text = time.ToString(format); i++; //comment } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void SampleTest(double mean, double sdv, int seed) { var dis = new Normal(mean, sdv); var hybrid = new UnivariateHybridMC(0, dis.DensityLn, 10, 0.1, 1000, 1, new System.Random(seed)) { BurnInterval = 0 }; double[] sample = hybrid.Sample(10000); double effective = MCMCDiagnostics.EffectiveSize(sample, x => x); var stats = new DescriptiveStatistics(sample); //Testing the mean using the normal distribution. double meanConvergence = 3*sdv/Math.Sqrt(effective); Assert.AreEqual(stats.Mean, mean, meanConvergence, "Mean"); double deviationRation = Math.Pow(stats.StandardDeviation/sdv, 2); //Approximating chi-square with normal distribution. (Degree of freedom is large) double deviationConvergence = 3*Constants.Sqrt2/Math.Sqrt(effective); Assert.AreEqual(deviationRation, 1, deviationConvergence, "Standard Deviation"); }
public void Consumer() { string TemperatureString; double TemperatureDouble; DescriptiveStatistics descrStat = new DescriptiveStatistics(TemperatureList); double dKurtosis = descrStat.Kurtosis; double dSkewness = descrStat.Skewness; while (true) { ConsumerWatch.Start(); TemperatureString = blockingCollection.Take(); TemperatureDouble = double.Parse(TemperatureString, NumberStyles.Float, CultureInfo.InvariantCulture); Data.Add(new CollectionDataValue { xData = x, yData = TemperatureDouble }); TemperatureList.Add(TemperatureDouble); ServerStatus = "Receiving temperature data and sending response to the Client."; #region TemperatureStatistics Temperature = "Current temperature: " + String.Format("{0:0.0000}", TemperatureDouble) + " [°C]" + Environment.NewLine + "Mean: " + String.Format("{0:0.0000}", TemperatureList.Mean()) + " [°C]" + Environment.NewLine + "Median: " + String.Format("{0:0.0000}", TemperatureList.Median()) + " [°C]" + Environment.NewLine + "Standard deviation: " + String.Format("{0:0.0000}", TemperatureList.StandardDeviation()) + " [°C]" + Environment.NewLine + "3x Standard deviation: " + String.Format("{0:0.0000}", 3 * TemperatureList.StandardDeviation()) + " [°C]" + Environment.NewLine + "Max: " + String.Format("{0:0.0000}", TemperatureList.Max()) + " [°C]" + Environment.NewLine + "Min: " + String.Format("{0:0.0000}", TemperatureList.Min()) + " [°C]" + Environment.NewLine + "Kurtosis: " + String.Format("{0:0.0000}", descrStat.Kurtosis) + "\r\n" + "Skewness: " + String.Format("{0:0.0000}", descrStat.Skewness) + "\r\n" + "Sample number: " + Convert.ToString(x); #endregion x++; ConsumerWatch.Stop(); ConsumerExecutionTime = string.Format("Consumer execution: {0} [ms]", ConsumerWatch.Elapsed.TotalMilliseconds); ConsumerWatch.Reset(); } }
public void SampleTest(double[] sdv, double[] mean, double rho, int seed) { var pdfLn = new DensityLn<double[]>(x => LogDen(x, sdv, mean, rho)); var hybrid = new HybridMC(new double[] { 0, 0 }, pdfLn, 10, 0.1, 1000, new double[] { 1, 1 }, new System.Random(seed)) { BurnInterval = 0 }; const int sampleSize = 10000; double[][] sample = hybrid.Sample(sampleSize); double[][] newSamples = ArrangeSamples(sampleSize, sample); var convergence = new double[2]; var sampleMean = new double[2]; var sampleSdv = new double[2]; for (int i = 0; i < 2; i++) { // ReSharper disable once AccessToModifiedClosure convergence[i] = 1/Math.Sqrt(MCMCDiagnostics.EffectiveSize(sample, x => x[i])); var stats = new DescriptiveStatistics(newSamples[i]); sampleMean[i] = stats.Mean; sampleSdv[i] = stats.StandardDeviation; } double sampleRho = Correlation.Pearson(newSamples[0], newSamples[1]); for (int i = 0; i < 2; i++) { string index = i.ToString(CultureInfo.InvariantCulture); Assert.AreEqual(mean[i], sampleMean[i], 10*convergence[i], index + "Mean"); Assert.AreEqual(sampleSdv[i]*sampleSdv[i], sdv[i]*sdv[i], 10*convergence[i], index + "Standard Deviation"); } double convergenceRho = 1/Math.Sqrt(MCMCDiagnostics.EffectiveSize(sample, x => (x[0] - sampleMean[0])*(x[1] - sampleMean[1]))); Assert.AreEqual(sampleRho*sampleSdv[0]*sampleSdv[1], rho*sdv[0]*sdv[1], 10*convergenceRho, "Rho"); }
/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient">Pearson product-moment correlation coefficient</seealso> public void Run() { // 1. Initialize the new instance of the ChiSquare distribution class with parameter dof = 5. var chiSquare = new ChiSquare(5); Console.WriteLine(@"1. Initialize the new instance of the ChiSquare distribution class with parameter DegreesOfFreedom = {0}", chiSquare.DegreesOfFreedom); Console.WriteLine(@"{0} distributuion properties:", chiSquare); Console.WriteLine(@"{0} - Largest element", chiSquare.Maximum.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Smallest element", chiSquare.Minimum.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Mean", chiSquare.Mean.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Median", chiSquare.Median.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Mode", chiSquare.Mode.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Variance", chiSquare.Variance.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Standard deviation", chiSquare.StdDev.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Skewness", chiSquare.Skewness.ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // 2. Generate 1000 samples of the ChiSquare(5) distribution Console.WriteLine(@"2. Generate 1000 samples of the ChiSquare(5) distribution"); var data = new double[1000]; for (var i = 0; i < data.Length; i++) { data[i] = chiSquare.Sample(); } // 3. Get basic statistics on set of generated data using extention methods Console.WriteLine(@"3. Get basic statistics on set of generated data using extention methods"); Console.WriteLine(@"{0} - Largest element", data.Maximum().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Smallest element", data.Minimum().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Mean", data.Mean().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Median", data.Median().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Biased population variance", data.PopulationVariance().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Variance", data.Variance().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Standard deviation", data.StandardDeviation().ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Biased sample standard deviation", data.PopulationStandardDeviation().ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // 4. Compute the basic statistics of data set using DescriptiveStatistics class Console.WriteLine(@"4. Compute the basic statistics of data set using DescriptiveStatistics class"); var descriptiveStatistics = new DescriptiveStatistics(data); Console.WriteLine(@"{0} - Kurtosis", descriptiveStatistics.Kurtosis.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Largest element", descriptiveStatistics.Maximum.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Smallest element", descriptiveStatistics.Minimum.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Mean", descriptiveStatistics.Mean.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Variance", descriptiveStatistics.Variance.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Standard deviation", descriptiveStatistics.StandardDeviation.ToString(" #0.00000;-#0.00000")); Console.WriteLine(@"{0} - Skewness", descriptiveStatistics.Skewness.ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // Generate 1000 samples of the ChiSquare(2.5) distribution var chiSquareB = new ChiSquare(2); var dataB = new double[1000]; for (var i = 0; i < data.Length; i++) { dataB[i] = chiSquareB.Sample(); } // 5. Correlation coefficient between 1000 samples of ChiSquare(5) and ChiSquare(2.5) Console.WriteLine(@"5. Correlation coefficient between 1000 samples of ChiSquare(5) and ChiSquare(2.5) is {0}", Correlation.Pearson(data, dataB).ToString("N04")); Console.WriteLine(); // 6. Correlation coefficient between 1000 samples of f(x) = x * 2 and f(x) = x * x data = SignalGenerator.EquidistantInterval(x => x * 2, 0, 100, 1000); dataB = SignalGenerator.EquidistantInterval(x => x * x, 0, 100, 1000); Console.WriteLine(@"6. Correlation coefficient between 1000 samples of f(x) = x * 2 and f(x) = x * x is {0}", Correlation.Pearson(data, dataB).ToString("N04")); Console.WriteLine(); }
private void loadButton_Click(object sender, EventArgs e) { treeView1.Nodes.Clear(); var ofd = new OpenFileDialog(); ofd.InitialDirectory = @"H: \Users\Jack\Source\Repos\BraitenbergSimulator\BraitenbergSimulator\BraitenbergSimulator"; ofd.Filter = "yaml files (*.yaml)|*.yaml|All files (.*)|*.*"; ofd.FilterIndex = 0; ofd.Multiselect = true; ofd.RestoreDirectory = true; if(ofd.ShowDialog() == DialogResult.OK) { var myModel = new PlotModel { Title = "Full graph" }; myModel.PlotType = PlotType.Cartesian; myModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -50, Maximum = 50 }); myModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -50, Maximum = 50 }); var myModel2 = new PlotModel { Title = "Up to first boundary collision" }; myModel2.PlotType = PlotType.Cartesian; var myModel3 = new PlotModel { Title = "Angle" }; myModel3.PlotType = PlotType.Cartesian; List<OxyColor> colors = new List<OxyColor>(myModel.DefaultColors); while(ofd.FileNames.Length > colors.Count) { colors.AddRange(colors); } int i = 0; List<double> distances = new List<double>(); List<double> closestApproaches = new List<double>(); foreach (var filename in ofd.FileNames) { TestResult t = new TestResult(filename, @"H: \Users\Jack\Source\Repos\BraitenbergSimulator\BraitenbergSimulator\BraitenbergSimulator\yaml"); foreach (var v in t.VehiclesData) { DrawGraph(ref myModel, v.Value, t.Scene, colors[i]); } DrawGraph2(ref myModel2, t.VehiclesData.First().Value, t.Scene, t.InnerTestResult.VehicleData[0].BoundaryCollisions != null ? t.InnerTestResult.VehicleData[0].BoundaryCollisions[0].Time : -1, colors[i]); DrawGraph3(ref myModel3, t.VehiclesData.First().Value, t.Scene, t.InnerTestResult.VehicleData[0].BoundaryCollisions != null ? t.InnerTestResult.VehicleData[0].BoundaryCollisions[0].Time : -1, colors[i]); //System.Diagnostics.Debug.WriteLine(colors[i].ToString()); TreeNode tn = new TreeNode(t.Scene.Name); tn.ForeColor = colors[i].ToColor(); tn.Nodes.Add("Distance travelled: " + t.InnerTestResult.VehicleData[0].Distance); distances.Add(t.InnerTestResult.VehicleData[0].Distance); treeView1.Nodes.Add(tn); i++; } stats = new YStats {TestCount = ofd.FileNames.Length, Test = treeView1.Nodes[0].Text}; TreeNode distStats = new TreeNode("distance stats"); DescriptiveStatistics ds = new DescriptiveStatistics(distances); distStats.Nodes.Add("Mean: " + ds.Mean); distStats.Nodes.Add("Standard deviation: " + ds.StandardDeviation); stats.Distance.Max = ds.Maximum; stats.Distance.Min = ds.Maximum; stats.Distance.StandardDeviation = ds.StandardDeviation; stats.Distance.Mean = ds.Mean; treeView1.Nodes.Add(distStats); TreeNode approachNode = new TreeNode("closest approach stats"); DescriptiveStatistics cs = new DescriptiveStatistics(closestApproaches); approachNode.Nodes.Add("Mean: " + cs.Mean); approachNode.Nodes.Add("Standard deviation: " + cs.StandardDeviation); treeView1.Nodes.Add(approachNode); stats.ClosestApproach.Max = cs.Maximum; stats.ClosestApproach.Min = cs.Maximum; stats.ClosestApproach.StandardDeviation = cs.StandardDeviation; stats.ClosestApproach.Mean = cs.Mean; this.plotView1.Model = myModel; this.plotView2.Model = myModel2; this.plotView3.Model = myModel3; } }
public static Dictionary<VariableDesc, Dictionary<int, int>> GetIntData(Dictionary<VariableDesc, ValueDescs> oData, MatriceComputeMode mode, int nClasses) { Dictionary<VariableDesc, Dictionary<int, int>> oRet = new Dictionary<VariableDesc, Dictionary<int, int>>(); var keys = oData.Keys; foreach (var key in keys) { oRet[key] = new Dictionary<int, int>(); var rdict = oRet[key]; var vals = (oData[key]).ToArray(); int n = vals.Length; int[] ddata = new int[n]; if (key.IsNumVar) { double[] data = new double[n]; for (int i = 0; i < n; ++i) { var v = vals[i]; double vv = v.DoubleValue; data[i] = vv; }// i if (mode == MatriceComputeMode.modeNormalize) { DescriptiveStatistics st = new DescriptiveStatistics(data); double ec = st.StandardDeviation; if (ec <= 0.0) { return null; } double mean = st.Mean; for (int i = 0; i < n; ++i) { data[i] = (data[i] - mean) / ec; }// i } else if (mode == MatriceComputeMode.modeProfil) { DescriptiveStatistics st = new DescriptiveStatistics(data); double vmin = st.Minimum; double vmax = st.Maximum; if (vmax <= vmin) { return null; } double rg = vmax - vmin; for (int i = 0; i < n; ++i) { data[i] = (data[i] - vmin) / rg; } } else if (mode == MatriceComputeMode.modeRank) { double[] dz = BertinPartition.GetRanks(data); if (dz == null) { return null; } for (int i = 0; i < n; ++i) { data[i] = dz[i]; } } var pc = BertinPartition.GetPartition(data, nClasses); if (pc == null) { return null; } var cc = pc.Classes; for (int i = 0; i < n; ++i) { var v = vals[i]; int ind = v.Index; rdict[ind] = cc[i]; }// i } else { String[] data = new String[n]; for (int i = 0; i < n; ++i) { var v = vals[i]; data[i] = v.StringValue; }// i var p = BertinPartition.GetPartition(data); if (p == null) { return null; } var cc = p.Classes; for (int i = 0; i < n; ++i) { var v = vals[i]; int ind = v.Index; rdict[ind] = cc[i]; }// i } }// key return oRet; }
public void smallestElement(int column) { var sheet = reoGridControl2.CurrentWorksheet; int N = sheet.RowCount; float[] dataF = new float[N]; int jumlahData = 0; for (int i = 0; i < N; i++) { if (sheet[i, column] != null && sheet[i, column].ToString() != "") { float.TryParse(sheet[i, column].ToString(), out dataF[i]); jumlahData++; } } double[] dataD = new double[jumlahData]; for (int i = 0; i < jumlahData; i++) { dataD[i] = System.Convert.ToDouble(dataF[i]); } var statistics = new DescriptiveStatistics(dataD); var smallestElementD = (float)statistics.Minimum; results.Add(smallestElementD); }
public GeometricalDistributionFitting(Histogram histogram) { this.histogram = histogram; statistics = new DescriptiveStatistics(histogram.Numbers); }
private Dictionary<string, object> sampleDesignOperations(List<Double> dataDesign,double n,double N) { DescriptiveStatistics statistics = new DescriptiveStatistics(dataDesign); results = new Dictionary<string, object>(); results.Add("Mean", statistics.Mean); results.Add("StandardDeviation", statistics.StandardDeviation); results.Add("VariationCoefficient", (statistics.StandardDeviation / statistics.Mean) * 100); double standardError =0; if(dataDesign.Count>100)standardError = statistics.StandardDeviation / Math.Sqrt(sizeSample - (1 - (sizeSample / sizePopulation))); else standardError = statistics.StandardDeviation / Math.Sqrt(sizeSample); if (n != 0 && N != 0) { if (dataDesign.Count > 100) standardError = statistics.StandardDeviation / Math.Sqrt(n - (1 - (n / N))); else standardError = statistics.StandardDeviation / Math.Sqrt(n); } results.Add("StandardError", standardError); //TODO:Calcular el area bajo la curva y determinar cual es la distribucion adecuada //para un valor t //añadir la confianza como variable al proyecto double t = (double)this.tStudent.VALOR; double absError = t * standardError; results.Add("AbsoulteErrorSample", absError); results.Add("LowLimit", statistics.Mean - absError); results.Add("HightLimit", statistics.Mean + absError); double relativeErrorSample = (absError / statistics.Mean) * 100; results.Add("RelativeErrorSample", relativeErrorSample); return results; }
public void ZeroVarianceSequence() { var stats = new DescriptiveStatistics(new[] { 2.0, 2.0, 2.0, 2.0 }); Assert.That(stats.Skewness, Is.NaN); Assert.That(stats.Kurtosis, Is.NaN); }
public void ShortSequences() { var stats0 = new DescriptiveStatistics(new double[0]); Assert.That(stats0.Skewness, Is.NaN); Assert.That(stats0.Kurtosis, Is.NaN); var stats1 = new DescriptiveStatistics(new[] { 1.0 }); Assert.That(stats1.Skewness, Is.NaN); Assert.That(stats1.Kurtosis, Is.NaN); var stats2 = new DescriptiveStatistics(new[] { 1.0, 2.0 }); Assert.That(stats2.Skewness, Is.NaN); Assert.That(stats2.Kurtosis, Is.NaN); var stats3 = new DescriptiveStatistics(new[] { 1.0, 2.0, -3.0 }); Assert.That(stats3.Skewness, Is.Not.NaN); Assert.That(stats3.Kurtosis, Is.NaN); var stats4 = new DescriptiveStatistics(new[] { 1.0, 2.0, -3.0, -4.0 }); Assert.That(stats4.Skewness, Is.Not.NaN); Assert.That(stats4.Kurtosis, Is.Not.NaN); }
public void IEnumerableNullableDoubleLowAccuracy(string dataSet, int digits, double skewness, double kurtosis, double median, double min, double max, int count) { var data = _data[dataSet]; var stats = new DescriptiveStatistics(data.DataWithNulls, false); AssertHelpers.AlmostEqualRelative(data.Mean, stats.Mean, 14); AssertHelpers.AlmostEqualRelative(data.StandardDeviation, stats.StandardDeviation, digits); AssertHelpers.AlmostEqualRelative(skewness, stats.Skewness, 7); AssertHelpers.AlmostEqualRelative(kurtosis, stats.Kurtosis, 7); Assert.AreEqual(stats.Minimum, min); Assert.AreEqual(stats.Maximum, max); Assert.AreEqual(stats.Count, count); }
public void WriteSummaryDamage(int WeightingschemeId, double bgDamage, IEnumerable<double> damages, WeightingCombination[] WeightingCombinations) { if (SummaryCsv != null) { int gas = (int)_gas; var stats = new DescriptiveStatistics(damages); var sortedDamages = damages.OrderBy(i => i).ToArray(); double count = sortedDamages.Length; int skiptake0_001 = (int)(count * 0.001 / 2.0); int skiptake0_01 = (int)(count * 0.01 / 2.0); int skiptake0_05 = (int)(count * 0.05 / 2.0); var trimmedMean0_001 = sortedDamages.Skip(skiptake0_001).Take(sortedDamages.Length - 2 * skiptake0_001).Mean(); var trimmedMean0_01 = sortedDamages.Skip(skiptake0_01).Take(sortedDamages.Length - 2 * skiptake0_01).Mean(); var trimmedMean0_05 = sortedDamages.Skip(skiptake0_05).Take(sortedDamages.Length - 2 * skiptake0_05).Mean(); SummaryCsv.WriteLine("{0};{1};{2};{3};{4:f15};{5:f15};{6:f15};{7:f15};{8:f15};{9:f15};{10:f15};{11:f15};{12:f15};{13:f15};{14:f15};{15:f15};{16:f15}", OutputVerbal ? ScenarioName : ScenarioId.ToString(), OutputVerbal ? (gas == 0 ? "C" : gas == 1 ? "CH4" : gas == 2 ? "N2O" : gas == 3 ? "SF6" : "ERROR") : ((int)_gas).ToString(), _emissionyear, OutputVerbal ? WeightingCombinations[WeightingschemeId].Name : WeightingschemeId.ToString(), bgDamage, stats.Mean, trimmedMean0_001, trimmedMean0_01, trimmedMean0_05, stats.Median, stats.StandardDeviation, stats.Variance, stats.Skewness, stats.Kurtosis, stats.Minimum, stats.Maximum, Math.Sqrt(stats.Variance) / Math.Sqrt(stats.Count) ); } }
public void SampleTest() { double Mean = 5 * rnd.NextDouble(); double Sdv = 5 * rnd.NextDouble(); Normal dis = new Normal(Mean, Sdv); UnivariateHybridMC Hybrid = new UnivariateHybridMC(0, dis.DensityLn, 10, 0.1, 1000); Hybrid.BurnInterval = 0; double[] Sample = Hybrid.Sample(10000); double Effective = MCMCDiagnostics.EffectiveSize(Sample,x=>x); DescriptiveStatistics Stats = new DescriptiveStatistics(Sample); //Testing the mean using the normal distribution. double MeanConvergence = 3 * Sdv / Math.Sqrt(Effective); Assert.AreEqual(Stats.Mean, Mean, MeanConvergence, "Mean"); double DeviationRation = Math.Pow(Stats.StandardDeviation / Sdv, 2); //Approximating chi-square with normal distribution. (Degree of freedom is large) double DeviationConvergence = 3 * Math.Sqrt(2) / Math.Sqrt(Effective); Assert.AreEqual(DeviationRation, 1, DeviationConvergence, "Standard Deivation"); }
public bool ComputeEigen(double[,] data, out Exception err) { err = null; bool bRet = false; myInit(); try { int nRows = data.GetLength(0); int nVars = data.GetLength(1); m_initialdata = data; m_means = new double[nVars]; m_stds = new double[nVars]; m_corr = new double[nVars, nVars]; List<double[]> oData = new List<double[]>(); for (int ivar = 0; ivar < nVars; ++ivar) { double[] x1 = new double[nRows]; for (int irow = 0; irow < nRows; ++irow) { x1[irow] = m_initialdata[irow, ivar]; }// irow oData.Add(x1); DescriptiveStatistics stst = new DescriptiveStatistics(x1); if (stst.Maximum <= stst.Minimum) { return false; } m_means[ivar] = stst.Mean; m_stds[ivar] = stst.StandardDeviation; m_corr[ivar, ivar] = 1.0; for (int ivar1 = 0; ivar1 < ivar; ++ivar1) { double[] x2 = oData.ElementAt(ivar1); double c = Correlation.Pearson(x1, x2); m_corr[ivar, ivar1] = c; m_corr[ivar1, ivar] = c; }// ivar1 }// ivar m_vals = new double[nVars]; m_vectors = new double[nVars, nVars]; m_vars = new double[nVars, nVars]; m_inds = new double[nRows, nVars]; var matrix = DenseMatrix.OfArray(m_corr); var evd = matrix.Evd(); double[,] dd = evd.D().ToArray(); double[,] de = evd.EigenVectors().ToArray(); for (int i = 0; i < nVars; ++i) { int k = nVars - i - 1; m_vals[k] = dd[i, i]; for (int j = 0; j < nVars; ++j) { m_vectors[j, k] = de[j, i]; } }// i // Recode double act2 = Math.Sqrt((double)nVars); bool bFirst = true; m_vmax = 0; m_vmin = 0; for (int iFact = 0; iFact < nVars; ++iFact) { double v = m_vals[iFact]; v = (v > 0.0)? Math.Sqrt(v) : Math.Sqrt(-v); for (int i = 0; i < nVars; ++i) { double f = v * m_vectors[i, iFact]; f = ((int)(10000.0 * f + 0.5)) / 10000.0; if (bFirst) { m_vmin = f; m_vmax = f; bFirst = false; } if (f < m_vmin) { m_vmin = f; } if (f > m_vmax) { m_vmax = f; } m_vars[i, iFact] = f; }// i for (int irow = 0; irow < nRows; ++irow) { double s = 0; for (int ivar = 0; ivar < nVars; ++ivar) { double vn = (m_initialdata[irow, ivar] - m_means[ivar]) / m_stds[ivar]; s += m_vectors[ivar, iFact] * vn; }// ivar double f = s / act2; f = ((int)(10000.0 * f + 0.5)) / 10000.0; if (bFirst) { m_vmin = f; m_vmax = f; bFirst = false; } if (f < m_vmin) { m_vmin = f; } if (f > m_vmax) { m_vmax = f; } m_inds[irow, iFact] = f; }// irow }// iFact bRet = true; } catch (Exception ex) { err = ex; } return bRet; }
public void SampleTest() { //Variances and Means double[] Sdv = new double[2]; double[] Mean = new double[2]; for (int i = 0; i < 2; i++) { Sdv[i] = RandomVar(); Mean[i] = 5 * rnd.NextDouble(); } //Cross Variance double rho = 1.0 - RandomVar(); DensityLn<double[]> pdfLn = new DensityLn<double[]>(x => LogDen(x, Sdv, Mean, rho)); HybridMC Hybrid = new HybridMC(new double[2] { 0, 0 }, pdfLn, 10, 0.1, 1000); Hybrid.BurnInterval = 0; int SampleSize = 10000; double[][] Sample = Hybrid.Sample(SampleSize); double[][] NewSamples = ArrangeSamples(SampleSize, Sample); double[] Convergence = new double[2]; double[] SampleMean = new double[2]; double[] SampleSdv = new double[2]; for (int i = 0; i < 2; i++) { Convergence[i] = 1 / Math.Sqrt(MCMCDiagnostics.EffectiveSize(Sample,x=>x[i])); DescriptiveStatistics Stats = new DescriptiveStatistics(NewSamples[i]); SampleMean[i] = Stats.Mean; SampleSdv[i] = Stats.StandardDeviation; } double SampleRho = Correlation.Pearson(NewSamples[0], NewSamples[1]); for (int i = 0; i < 2; i++) { string index = i.ToString(); Assert.AreEqual(Mean[i], SampleMean[i], 10 * Convergence[i], index + "Mean"); Assert.AreEqual(SampleSdv[i] * SampleSdv[i], Sdv[i] * Sdv[i], 10 * Convergence[i], index + "Standard Deviation"); } double ConvergenceRho=1/Math.Sqrt(MCMCDiagnostics.EffectiveSize(Sample,x=>(x[0]-SampleMean[0])*(x[1]-SampleMean[1]))); Assert.AreEqual(SampleRho*SampleSdv[0]*SampleSdv[1], rho*Sdv[0]*Sdv[1], 10 * ConvergenceRho, "Rho"); }
private static Tuple<double, double> GetSCGasMonteCarlo(MarginalGas gas, double prtp, bool equityWeights, int monteCarloRuns) { var parameters = new Parameters(); parameters.ReadDirectory(@"Data\Base"); var fm = FundModel.GetModel(); fm.Run(parameters.GetBestGuess()); var rand = new jp.takel.PseudoRandom.MersenneTwister(); var sccs = new System.Collections.Concurrent.ConcurrentBag<double>(); Parallel.ForEach(parameters.GetRandom(rand, monteCarloRuns), pv => { var m = new MarginalDamage3() { EmissionYear = Timestep.FromYear(2010), Eta = 1.0, Gas = gas, Parameters = pv, Prtp = prtp, UseEquityWeights = equityWeights, YearsToAggregate = 290 }; double scc = m.Start(); sccs.Add(scc); }); var stats = new DescriptiveStatistics(sccs); return Tuple.Create(stats.Mean, Math.Sqrt(stats.Variance) / Math.Sqrt(stats.Count)); }
public void IEnumerableDouble(string dataSet, int digits, double skewness, double kurtosis, double median, double min, double max, int count) { StatTestData data = mData[dataSet]; DescriptiveStatistics stats = new DescriptiveStatistics(data.Data); AssertHelpers.AlmostEqual(data.Mean, stats.Mean, 15); AssertHelpers.AlmostEqual(data.StandardDeviation, stats.StandardDeviation, digits); AssertHelpers.AlmostEqual(skewness, stats.Skewness, 7); AssertHelpers.AlmostEqual(kurtosis, stats.Kurtosis, 7); AssertHelpers.AlmostEqual(median, stats.Median, 15); Assert.AreEqual(stats.Minimum, min); Assert.AreEqual(stats.Maximum, max); Assert.AreEqual(stats.Count, count); }
private void LineReceived(string line) { double dTemperature, dTemperatureRound, dTemperatureMean; try { dTemperature = double.Parse(line, CultureInfo.InvariantCulture); dTemperatureRound = Math.Round(dTemperature, 4); listdTemperature.Add(dTemperatureRound); DescriptiveStatistics descrStat = new DescriptiveStatistics(listdTemperature); double dKurtosis = descrStat.Kurtosis; double dSkewness = descrStat.Skewness; dTemperatureMean = Math.Round(listdTemperature.Mean(), 4); if (dTemperatureRound == dTemperatureMean) { label1Temperature.Text = "Temperature: " + String.Format("{0:0.0000}", dTemperature) + " [°C] ▸"; } if (dTemperatureRound < dTemperatureMean) { label1Temperature.Text = "Temperature: " + String.Format("{0:0.0000}", dTemperature) + " [°C] ▾"; } if (dTemperatureRound > dTemperatureMean) { label1Temperature.Text = "Temperature: " + String.Format("{0:0.0000}", dTemperature) + " [°C] ▴"; } label2TempStats.Text = "Mean: " + String.Format("{0:0.0000}", dTemperatureMean) + " [°C]" + Environment.NewLine + "Median: " + String.Format("{0:0.0000}", listdTemperature.Median()) + " [°C]" + Environment.NewLine + "Standard deviation: " + String.Format("{0:0.0000}", listdTemperature.StandardDeviation()) + " [°C]" + Environment.NewLine + "3x Standard deviation: " + String.Format("{0:0.0000}", 3*listdTemperature.StandardDeviation()) + " [°C]" + Environment.NewLine + "Max: " + String.Format("{0:0.0000}", listdTemperature.Max()) + " [°C]" + Environment.NewLine + "Min: " + String.Format("{0:0.0000}", listdTemperature.Min()) + " [°C]" + Environment.NewLine + "Kurtosis: " + String.Format("{0:0.0000}", descrStat.Kurtosis) + "\r\n" + "Skewness: " + String.Format("{0:0.0000}", descrStat.Skewness) + "\r\n" + "Sample number: " + Convert.ToString(i); //PlotVariables.linearAxisX.AbsoluteMaximum = this.i; PlotVariables.linearAxisX.AbsoluteMinimum = -0.1; PlotVariables.linearAxisXTop.AbsoluteMinimum = -0.1; //PlotVariables.linearAxisX.AxisChanged += xAxisDateTime_AxisChanged; PlotVariables.linearAxisY.AbsoluteMaximum = listdTemperature.Max()+0.5; PlotVariables.linearAxisY.AbsoluteMinimum = listdTemperature.Min()-0.5; PlotVariables.areaSeries1.Points.Add(new DataPoint(this.i, dTemperatureRound + (3 * listdTemperature.StandardDeviation()))); PlotVariables.areaSeries1.Points2.Add(new DataPoint(this.i, dTemperatureRound - (3 * listdTemperature.StandardDeviation()))); //PlotVariables.areaSeries1.Points.Add(new DataPoint(this.i, dTemperatureMean + (3 * listdTemperature.StandardDeviation()))); //PlotVariables.areaSeries1.Points2.Add(new DataPoint(this.i, dTemperatureMean - (3 * listdTemperature.StandardDeviation()))); if (checkBox2MedianChart.Checked) { //this.lineSeries3Median.Title = "Median temperature"; this.lineSeries3Median.Points.Add(new DataPoint(this.i, listdTemperature.Median())); plot1.RefreshPlot(true); } this.lineSeries2Mean.Points.Add(new DataPoint(this.i, dTemperatureMean)); this.lineSeries1.Points.Add(new DataPoint(this.i, dTemperatureRound)); plot1.InvalidatePlot(false); //plot1.RefreshPlot(true); if (checkBox1Save.Checked) { TextWriter file = new StreamWriter("c:\\TemperatureLogger.txt", true); // write a line of text to the file file.WriteLine(DateTime.Now + " Sample: " + Convert.ToString(i) + " Temperature: " + String.Format("{0:0.0000}", dTemperature) + " [C]" + " Mean: " + String.Format("{0:0.0000}", dTemperatureMean) + " [C]" + " Standard deviation: " + String.Format("{0:0.0000}", listdTemperature.StandardDeviation()) + " [C]"); // close the stream file.Close(); } this.i++; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private List<Workload> ProcessResultFiles(String results_path) { List<Workload> temp_workloads_data = new List<Workload>(); string[] result_files = Directory.GetFiles(results_path, "inst*.csv"); for (int order_count = 0; order_count < workload_order.Length; order_count++) { for (int count = 0; count < result_files.Length; count++) { // Get the .csv file path. String file_path = result_files[count]; // Get the file name from the file path. String file_name = Path.GetFileNameWithoutExtension(file_path); // Check to see if we have the right workload to run. String temp_file_name = "inst" + workload_order[order_count]; if (file_name != temp_file_name) continue; int worker_num = 0; int maxWorkerNum = 1; bool is_first_entry = true; double intervalSumIOps = 0; double intervalSumMBps = 0; List<double> IOps = new List<double>(); List<double> MBps = new List<double>(); List<double> avgResponseTime = new List<double>(); DescriptiveStatistics statsIOps = new DescriptiveStatistics(IOps, true); DescriptiveStatistics statsMBps = new DescriptiveStatistics(MBps, true); DescriptiveStatistics statsAvgRespTime = new DescriptiveStatistics(avgResponseTime, true); Workload temp_workload = new Workload(); temp_workload.orderNum = order_count; temp_workload.file_name = workload_order[order_count]; // Process the IOmeter generated result files one line at time. StreamReader workload_file_reader = new StreamReader(file_path); while (!workload_file_reader.EndOfStream) { String temp_line = workload_file_reader.ReadLine(); string[] temp_line_parts = temp_line.Split(','); // Check to see if we are at a data row. if (temp_line_parts.Length < 3) continue; // Calculate Workers if (temp_line_parts[(int)Workload.ColumnHeader.TargetType] == "WORKER" && temp_line_parts[(int)Workload.ColumnHeader.TargetName].Contains("Worker")) { // Get the current IOps and MBps measurements. double temp_IOps = Convert.ToDouble(temp_line_parts[(int)Workload.ColumnHeader.IOps]); double temp_MBps = Convert.ToDouble(temp_line_parts[(int)Workload.ColumnHeader.MBps]); double temp_latency = Convert.ToDouble(temp_line_parts[(int)Workload.ColumnHeader.AvgRespTime]); // Store the running sum for the current interval. intervalSumIOps += temp_IOps; intervalSumMBps += temp_MBps; // Check to see if we need to skip the first row worker number. if (worker_num == 0 && is_first_entry) is_first_entry = false; else worker_num = Convert.ToInt32(temp_line_parts[(int)Workload.ColumnHeader.TargetName].Split(' ')[1]); // Check to see if the next value is the start of the next interval. if (worker_num == 1) { // Store the completed interval sum. IOps.Add(intervalSumIOps); MBps.Add(intervalSumMBps); // Reset sum for next interval. intervalSumIOps = 0; intervalSumMBps = 0; } // Find the number of threads used per workload if(maxWorkerNum < worker_num) { maxWorkerNum = worker_num; } // Store the average response time. avgResponseTime.Add(temp_latency); } } workload_file_reader.Close(); // Remove IOmeter generated result files. CleanUpIOmeterFile(file_path); CleanUpIOmeterFile(file_path.Replace(temp_file_name, workload_order[order_count])); statsIOps = new DescriptiveStatistics(IOps, true); statsMBps = new DescriptiveStatistics(MBps, true); statsAvgRespTime = new DescriptiveStatistics(avgResponseTime, true); // Calculate Average IOps. if (!Double.IsNaN(statsIOps.Mean)) temp_workload.meanIOps = statsIOps.Mean; // Calculate IOps Standard Deviation. if (!Double.IsNaN(statsIOps.StandardDeviation)) temp_workload.stdevIOps = statsIOps.StandardDeviation; // Calculate max and min MBps. if (!Double.IsNaN(statsIOps.Minimum)) temp_workload.minIOps = statsIOps.Minimum; if (!Double.IsNaN(statsIOps.Maximum)) temp_workload.maxIOps = statsIOps.Maximum; // Calculate Average MBps. if (!Double.IsNaN(statsMBps.Mean)) temp_workload.meanMBps = statsMBps.Mean; // Calculate MBps Standard Deviation. if (!Double.IsNaN(statsMBps.StandardDeviation)) temp_workload.stdevMBps = statsMBps.StandardDeviation; // Calculate max and min IOps. if (!Double.IsNaN(statsMBps.Minimum)) temp_workload.minMBps = statsMBps.Minimum; if (!Double.IsNaN(statsMBps.Maximum)) temp_workload.maxMBps = statsMBps.Maximum; // Calculate the Average Response Time (Latency). if (!Double.IsNaN(statsAvgRespTime.Mean)) temp_workload.avgResponseTime = statsAvgRespTime.Mean; // Set the number of threads used temp_workload.threadsUsed = maxWorkerNum; // Store the filled out workload. temp_workloads_data.Add(temp_workload); } } return temp_workloads_data; }