Browse Source

Statistics: MeanStandardDeviation (analog to MeanVariance)

provider
Christoph Ruegg 13 years ago
parent
commit
c276df6d05
  1. 4
      src/Numerics/Distributions/LogNormal.cs
  2. 4
      src/Numerics/Distributions/Normal.cs
  3. 11
      src/Numerics/Statistics/ArrayStatistics.cs
  4. 15
      src/Numerics/Statistics/Statistics.cs
  5. 12
      src/Numerics/Statistics/StreamingStatistics.cs

4
src/Numerics/Distributions/LogNormal.cs

@ -110,8 +110,8 @@ namespace MathNet.Numerics.Distributions
/// <remarks>MATLAB: lognfit</remarks>
public static LogNormal Estimate(IEnumerable<double> samples, System.Random randomSource = null)
{
var muSigma2 = samples.Select(s => Math.Log(s)).MeanVariance();
return new LogNormal(muSigma2.Item1, Math.Sqrt(muSigma2.Item2), randomSource);
var muSigma = samples.Select(s => Math.Log(s)).MeanStandardDeviation();
return new LogNormal(muSigma.Item1, muSigma.Item2, randomSource);
}
/// <summary>

4
src/Numerics/Distributions/Normal.cs

@ -139,8 +139,8 @@ namespace MathNet.Numerics.Distributions
/// <remarks>MATLAB: normfit</remarks>
public static Normal Estimate(IEnumerable<double> samples, System.Random randomSource = null)
{
var meanVariance = samples.MeanVariance();
return new Normal(meanVariance.Item1, Math.Sqrt(meanVariance.Item2), randomSource);
var meanStdDev = samples.MeanStandardDeviation();
return new Normal(meanStdDev.Item1, meanStdDev.Item2, randomSource);
}
/// <summary>

11
src/Numerics/Statistics/ArrayStatistics.cs

@ -218,6 +218,17 @@ namespace MathNet.Numerics.Statistics
return new Tuple<double, double>(Mean(samples), Variance(samples));
}
/// <summary>
/// Estimates the arithmetic sample mean and the unbiased population standard deviation from the provided samples as unsorted array.
/// On a dataset of size N will use an N-1 normalizer (Bessel's correction).
/// Returns NaN for mean if data is empty or any entry is NaN and NaN for standard deviation if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample array, no sorting is assumed.</param>
public static Tuple<double, double> MeanStandardDeviation(double[] samples)
{
return new Tuple<double, double>(Mean(samples), StandardDeviation(samples));
}
/// <summary>
/// Estimates the unbiased population covariance from the provided two sample arrays.
/// On a dataset of size N will use an N-1 normalizer (Bessel's correction).

15
src/Numerics/Statistics/Statistics.cs

@ -235,6 +235,21 @@ namespace MathNet.Numerics.Statistics
: StreamingStatistics.MeanVariance(samples);
}
/// <summary>
/// Estimates the sample mean and the unbiased population standard deviation from the provided samples.
/// On a dataset of size N will use an N-1 normalizer (Bessel's correction).
/// Returns NaN for mean if data is empty or if any entry is NaN and NaN for standard deviation if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">The data to calculate the mean of.</param>
/// <returns>The mean of the sample.</returns>
public static Tuple<double, double> MeanStandardDeviation(this IEnumerable<double> samples)
{
var array = samples as double[];
return array != null
? ArrayStatistics.MeanStandardDeviation(array)
: StreamingStatistics.MeanStandardDeviation(samples);
}
/// <summary>
/// Estimates the unbiased population covariance from the provided samples.
/// On a dataset of size N will use an N-1 normalizer (Bessel's correction).

12
src/Numerics/Statistics/StreamingStatistics.cs

@ -220,6 +220,18 @@ namespace MathNet.Numerics.Statistics
count > 1 ? variance/(count - 1) : double.NaN);
}
/// <summary>
/// Estimates the arithmetic sample mean and the unbiased population standard deviation from the provided samples as enumerable sequence, in a single pass without memoization.
/// On a dataset of size N will use an N-1 normalizer (Bessel's correction).
/// Returns NaN for mean if data is empty or any entry is NaN, and NaN for standard deviation if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample stream, no sorting is assumed.</param>
public static Tuple<double, double> MeanStandardDeviation(IEnumerable<double> samples)
{
var meanVariance = MeanVariance(samples);
return new Tuple<double, double>(meanVariance.Item1, Math.Sqrt(meanVariance.Item2));
}
/// <summary>
/// Estimates the unbiased population covariance from the provided two sample enumerable sequences, in a single pass without memoization.
/// On a dataset of size N will use an N-1 normalizer (Bessel's correction).

Loading…
Cancel
Save