Browse Source

code style

Signed-off-by: Christoph Ruegg <git@cdrnet.ch>
pull/2/head
Christoph Ruegg 17 years ago
parent
commit
ab1b6a1d39
  1. 16
      src/MathNet.Numerics.4.5.resharper
  2. 200
      src/Numerics/Complex.cs
  3. 6
      src/Numerics/Constants.cs
  4. 5
      src/Numerics/IntegralTransforms/Algorithms/DiscreteFourierTransform.RadixN.cs
  5. 12
      src/Numerics/NumberTheory/IntegerTheory.cs
  6. 64
      src/Numerics/Sorting.cs
  7. 74
      src/Numerics/Statistics/DescriptiveStatistics.cs
  8. 92
      src/Numerics/Statistics/Statistics.cs

16
src/MathNet.Numerics.4.5.resharper

@ -754,6 +754,8 @@ Bluestein
<FORCE_IFELSE_BRACES_STYLE>ALWAYS_ADD</FORCE_IFELSE_BRACES_STYLE>
<FORCE_USING_BRACES_STYLE>ALWAYS_ADD</FORCE_USING_BRACES_STYLE>
<FORCE_WHILE_BRACES_STYLE>ALWAYS_ADD</FORCE_WHILE_BRACES_STYLE>
<INDENT_NESTED_FIXED_STMT>True</INDENT_NESTED_FIXED_STMT>
<INDENT_NESTED_USINGS_STMT>True</INDENT_NESTED_USINGS_STMT>
<INDENT_SIZE>4</INDENT_SIZE>
<INITIALIZER_BRACES>NEXT_LINE</INITIALIZER_BRACES>
<MODIFIERS_ORDER IsNull="False">
@ -773,8 +775,20 @@ Bluestein
<Item>volatile</Item>
</MODIFIERS_ORDER>
<PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE>False</PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE>
<PLACE_TYPE_CONSTRAINTS_ON_SAME_LINE>False</PLACE_TYPE_CONSTRAINTS_ON_SAME_LINE>
<PLACE_WHILE_ON_NEW_LINE>True</PLACE_WHILE_ON_NEW_LINE>
<SPACE_AFTER_TYPECAST_PARENTHESES>False</SPACE_AFTER_TYPECAST_PARENTHESES>
<SPACE_AROUND_MULTIPLICATIVE_OP>True</SPACE_AROUND_MULTIPLICATIVE_OP>
<SPACE_BEFORE_SIZEOF_PARENTHESES>False</SPACE_BEFORE_SIZEOF_PARENTHESES>
<SPACE_BEFORE_TYPEOF_PARENTHESES>False</SPACE_BEFORE_TYPEOF_PARENTHESES>
<SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES>True</SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES>
<WRAP_AFTER_DECLARATION_LPAR>True</WRAP_AFTER_DECLARATION_LPAR>
<WRAP_AFTER_INVOCATION_LPAR>True</WRAP_AFTER_INVOCATION_LPAR>
<WRAP_ARGUMENTS_STYLE>CHOP_IF_LONG</WRAP_ARGUMENTS_STYLE>
<WRAP_BEFORE_BINARY_OPSIGN>True</WRAP_BEFORE_BINARY_OPSIGN>
<WRAP_BEFORE_FIRST_TYPE_PARAMETER_CONSTRAINT>True</WRAP_BEFORE_FIRST_TYPE_PARAMETER_CONSTRAINT>
<WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE>CHOP_ALWAYS</WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE>
<WRAP_PARAMETERS_STYLE>CHOP_IF_LONG</WRAP_PARAMETERS_STYLE>
</FormatSettings>
<UsingsSettings />
<Naming2>
@ -813,7 +827,7 @@ Bluestein
<PredefinedRule Inspect="True" Prefix="T" Suffix="" Style="AaBb" ElementKind="TypeParameters" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="MethodPropertyEvent" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Locals" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="LocalConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="LocalConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Parameters" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PublicFields" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Constants" />

200
src/Numerics/Complex.cs

@ -1,7 +1,9 @@
// <copyright file="Complex.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://mathnet.opensourcedotnet.info
//
// Copyright (c) 2009 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -10,8 +12,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -28,8 +32,7 @@ namespace MathNet.Numerics
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using MathNet.Numerics.Properties;
using Properties;
/// <summary>
/// Complex numbers class.
@ -40,7 +43,7 @@ namespace MathNet.Numerics
/// on complex numbers. All the operators <c>+</c>, <c>-</c>,
/// <c>*</c>, <c>/</c>, <c>==</c>, <c>!=</c> are defined in the
/// canonical way. Additional complex trigonometric functions such
/// as <see cref="Complex.Cosine"/>, ...
/// as <see cref="Trig.Cosine(Complex)"/>, ...
/// are also provided. Note that the <c>Complex</c> structures
/// has two special constant values <see cref="Complex.NaN"/> and
/// <see cref="Complex.Infinity"/>.
@ -73,35 +76,35 @@ namespace MathNet.Numerics
/// <summary>
/// Regular expression used to parse strings into complex numbers.
/// </summary>
private static readonly Regex ParseExpression =
private static readonly Regex _parseExpression =
new Regex(
@"^((?<r>(([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-9]+)?)|(NaN)|([-+]?Infinity)))|(?<i>(([-+]?((\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-9]+)?)|(NaN)|([-+]?Infinity))?[i]))|(?<r>(([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-9]+)?)|(NaN)|([-+]?Infinity)))(?<i>(([-+]((\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-9]+)?)|[-+](NaN)|([-+]Infinity))?[i])))$",
@"^((?<r>(([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-9]+)?)|(NaN)|([-+]?Infinity)))|(?<i>(([-+]?((\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-9]+)?)|(NaN)|([-+]?Infinity))?[i]))|(?<r>(([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-9]+)?)|(NaN)|([-+]?Infinity)))(?<i>(([-+]((\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-9]+)?)|[-+](NaN)|([-+]Infinity))?[i])))$",
RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
/// <summary>
/// Represents imaginary unit number.
/// </summary>
private static readonly Complex i = new Complex(0, 1);
private static readonly Complex _i = new Complex(0, 1);
/// <summary>
/// Represents a infinite complex number
/// </summary>
private static readonly Complex infinity = new Complex(double.PositiveInfinity, double.PositiveInfinity);
private static readonly Complex _infinity = new Complex(double.PositiveInfinity, double.PositiveInfinity);
/// <summary>
/// Represents not-a-number.
/// </summary>
private static readonly Complex nan = new Complex(Double.NaN, Double.NaN);
private static readonly Complex _nan = new Complex(Double.NaN, Double.NaN);
/// <summary>
/// Representing the one value.
/// </summary>
private static readonly Complex one = new Complex(1.0, 0.0);
private static readonly Complex _one = new Complex(1.0, 0.0);
/// <summary>
/// Representing the zero value.
/// </summary>
private static readonly Complex zero = new Complex(0.0, 0.0);
private static readonly Complex _zero = new Complex(0.0, 0.0);
/// <summary>
/// The real component of the complex number.
@ -129,8 +132,8 @@ namespace MathNet.Numerics
/// </param>
public Complex(double real, double imaginary)
{
this._real = real;
this._imag = imaginary;
_real = real;
_imag = imaginary;
}
#endregion
@ -152,10 +155,7 @@ namespace MathNet.Numerics
/// <value>A value representing the infinity value.</value>
public static Complex Infinity
{
get
{
return infinity;
}
get { return _infinity; }
}
/// <summary>
@ -164,10 +164,7 @@ namespace MathNet.Numerics
/// <value>A value representing not-a-number.</value>
public static Complex NaN
{
get
{
return nan;
}
get { return _nan; }
}
/// <summary>
@ -176,10 +173,7 @@ namespace MathNet.Numerics
/// <value>A value representing the imaginary unit number.</value>
public static Complex I
{
get
{
return i;
}
get { return _i; }
}
/// <summary>
@ -188,10 +182,7 @@ namespace MathNet.Numerics
/// <value>A value representing the zero value.</value>
public static Complex Zero
{
get
{
return new Complex(0.0, 0.0);
}
get { return new Complex(0.0, 0.0); }
}
/// <summary>
@ -200,10 +191,7 @@ namespace MathNet.Numerics
/// <value>A value representing the <c>1</c> value.</value>
public static Complex One
{
get
{
return one;
}
get { return _one; }
}
#endregion Properties
@ -214,10 +202,7 @@ namespace MathNet.Numerics
/// <value>The real component of the complex number.</value>
public double Real
{
get
{
return this._real;
}
get { return _real; }
}
/// <summary>
@ -226,10 +211,7 @@ namespace MathNet.Numerics
/// <value>The real imaginary component of the complex number.</value>
public double Imaginary
{
get
{
return this._imag;
}
get { return _imag; }
}
/// <summary>
@ -238,10 +220,7 @@ namespace MathNet.Numerics
/// <value><c>true</c> if this instance is zero; otherwise, <c>false</c>.</value>
public bool IsZero
{
get
{
return this._real.AlmostZero() && this._imag.AlmostZero();
}
get { return _real.AlmostZero() && _imag.AlmostZero(); }
}
/// <summary>
@ -250,10 +229,7 @@ namespace MathNet.Numerics
/// <value><c>true</c> if this instance is one; otherwise, <c>false</c>.</value>
public bool IsOne
{
get
{
return this._real.AlmostEqual(1.0) && this._imag.AlmostZero();
}
get { return _real.AlmostEqual(1.0) && _imag.AlmostZero(); }
}
/// <summary>
@ -262,10 +238,7 @@ namespace MathNet.Numerics
/// <value><c>true</c> if this instance is I; otherwise, <c>false</c>.</value>
public bool IsI
{
get
{
return this._real.AlmostZero() && this._imag.AlmostEqual(1.0);
}
get { return _real.AlmostZero() && _imag.AlmostEqual(1.0); }
}
/// <summary>
@ -275,10 +248,7 @@ namespace MathNet.Numerics
/// <value><c>true</c> if this instance is NaN; otherwise, <c>false</c>.</value>
public bool IsNaN
{
get
{
return double.IsNaN(this._real) || double.IsNaN(this._imag);
}
get { return double.IsNaN(_real) || double.IsNaN(_imag); }
}
/// <summary>
@ -294,10 +264,7 @@ namespace MathNet.Numerics
/// </remarks>
public bool IsInfinity
{
get
{
return double.IsInfinity(this._real) || double.IsInfinity(this._imag);
}
get { return double.IsInfinity(_real) || double.IsInfinity(_imag); }
}
/// <summary>
@ -306,10 +273,7 @@ namespace MathNet.Numerics
/// <value><c>true</c> if this instance is a real number; otherwise, <c>false</c>.</value>
public bool IsReal
{
get
{
return this._imag.AlmostZero();
}
get { return _imag.AlmostZero(); }
}
/// <summary>
@ -320,10 +284,7 @@ namespace MathNet.Numerics
/// </value>
public bool IsRealNonNegative
{
get
{
return this._imag.AlmostZero() && this._real >= 0;
}
get { return _imag.AlmostZero() && _real >= 0; }
}
/// <summary>
@ -343,10 +304,7 @@ namespace MathNet.Numerics
/// </remarks>
public Complex Conjugate
{
get
{
return new Complex(this._real, -this._imag);
}
get { return new Complex(_real, -_imag); }
}
/// <summary>
@ -355,10 +313,7 @@ namespace MathNet.Numerics
/// <seealso cref="Argument"/>
public double Modulus
{
get
{
return Math.Sqrt((this._real * this._real) + (this._imag * this._imag));
}
get { return Math.Sqrt((_real * _real) + (_imag * _imag)); }
}
/// <summary>
@ -367,10 +322,7 @@ namespace MathNet.Numerics
/// <seealso cref="Argument"/>
public double ModulusSquared
{
get
{
return (this._real * this._real) + (this._imag * this._imag);
}
get { return (_real * _real) + (_imag * _imag); }
}
/// <summary>
@ -379,18 +331,18 @@ namespace MathNet.Numerics
/// <remarks>
/// Argument always returns a value bigger than negative Pi and
/// smaller or equal to Pi. If this <c>Complex</c> is zero, the Complex
/// is assumed to be positive _real with an argument of zero.
/// is assumed to be positive real with an argument of zero.
/// </remarks>
public double Argument
{
get
{
if (this.IsReal && this._real < 0)
if (IsReal && _real < 0)
{
return Math.PI;
}
return this.IsRealNonNegative ? 0 : Math.Atan2(this._imag, this._real);
return IsRealNonNegative ? 0 : Math.Atan2(_imag, _real);
}
}
@ -401,34 +353,34 @@ namespace MathNet.Numerics
{
get
{
if (double.IsPositiveInfinity(this._real) && double.IsPositiveInfinity(this._imag))
if (double.IsPositiveInfinity(_real) && double.IsPositiveInfinity(_imag))
{
return new Complex(Constants.Sqrt1Over2, Constants.Sqrt1Over2);
}
if (double.IsPositiveInfinity(this._real) && double.IsNegativeInfinity(this._imag))
if (double.IsPositiveInfinity(_real) && double.IsNegativeInfinity(_imag))
{
return new Complex(Constants.Sqrt1Over2, -Constants.Sqrt1Over2);
}
if (double.IsNegativeInfinity(this._real) && double.IsPositiveInfinity(this._imag))
if (double.IsNegativeInfinity(_real) && double.IsPositiveInfinity(_imag))
{
return new Complex(-Constants.Sqrt1Over2, -Constants.Sqrt1Over2);
}
if (double.IsNegativeInfinity(this._real) && double.IsNegativeInfinity(this._imag))
if (double.IsNegativeInfinity(_real) && double.IsNegativeInfinity(_imag))
{
return new Complex(-Constants.Sqrt1Over2, Constants.Sqrt1Over2);
}
// don't replace this with "Modulus"!
var mod = SpecialFunctions.Hypotenuse(this._real, this._imag);
var mod = SpecialFunctions.Hypotenuse(_real, _imag);
if (mod.AlmostZero())
{
return Zero;
}
return new Complex(this._real / mod, this._imag / mod);
return new Complex(_real / mod, _imag / mod);
}
}
@ -509,15 +461,15 @@ namespace MathNet.Numerics
/// <summary>
/// Raise this <c>Complex</c> to the inverse of the given value.
/// </summary>
/// <param name="rootexponent">
/// <param name="rootExponent">
/// The root exponent.
/// </param>
/// <returns>
/// The complex raised to the inverse of the given exponent.
/// </returns>
public Complex Root(Complex rootexponent)
public Complex Root(Complex rootExponent)
{
return Power(1 / rootexponent);
return Power(1 / rootExponent);
}
/// <summary>
@ -638,7 +590,7 @@ namespace MathNet.Numerics
/// </returns>
public override string ToString()
{
return this.ToString(null, null);
return ToString(null, null);
}
/// <summary>
@ -653,7 +605,7 @@ namespace MathNet.Numerics
/// </param>
public string ToString(string format)
{
return this.ToString(format, null);
return ToString(format, null);
}
/// <summary>
@ -664,11 +616,11 @@ namespace MathNet.Numerics
/// format provider.
/// </returns>
/// <param name="formatProvider">
/// An IFormatProvider that supplies culture-specific formatting information.
/// An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.
/// </param>
public string ToString(IFormatProvider formatProvider)
{
return this.ToString(null, formatProvider);
return ToString(null, formatProvider);
}
/// <summary>
@ -688,32 +640,32 @@ namespace MathNet.Numerics
/// A format specification.
/// </param>
/// <param name="formatProvider">
/// An IFormatProvider that supplies culture-specific formatting information.
/// An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.
/// </param>
public string ToString(string format, IFormatProvider formatProvider)
{
if (this.IsNaN)
if (IsNaN)
{
return "NaN";
}
if (this.IsInfinity)
if (IsInfinity)
{
return "Infinity";
}
var ret = new StringBuilder();
if (!this._real.AlmostZero())
if (!_real.AlmostZero())
{
ret.Append(this._real.ToString(format, formatProvider));
ret.Append(_real.ToString(format, formatProvider));
}
if (!this._imag.AlmostZero())
if (!_imag.AlmostZero())
{
if (!this._real.AlmostZero())
if (!_real.AlmostZero())
{
if (this._imag < 0)
if (_imag < 0)
{
ret.Append(" ");
}
@ -723,7 +675,7 @@ namespace MathNet.Numerics
}
}
ret.Append(this._imag.ToString(format, formatProvider)).Append("i");
ret.Append(_imag.ToString(format, formatProvider)).Append("i");
}
return ret.ToString();
@ -738,25 +690,25 @@ namespace MathNet.Numerics
/// corresponding real and imaginary components are equal.
/// </summary>
/// <returns>
/// Returns true if the two objects are the same object, or if their corresponding
/// real and imaginary components are equal, false otherwise.
/// Returns <c>true</c> if the two objects are the same object, or if their corresponding
/// real and imaginary components are equal, <c>false</c> otherwise.
/// </returns>
/// <param name="other">
/// The complex number to compare to with.
/// </param>
public bool Equals(Complex other)
{
if (this.IsNaN || other.IsNaN)
if (IsNaN || other.IsNaN)
{
return false;
}
if (this.IsInfinity && other.IsInfinity)
if (IsInfinity && other.IsInfinity)
{
return true;
}
return this._real.AlmostEqual(other._real) && this._imag.AlmostEqual(other._imag);
return _real.AlmostEqual(other._real) && _imag.AlmostEqual(other._imag);
}
/// <summary>
@ -771,7 +723,7 @@ namespace MathNet.Numerics
/// </remarks>
public override int GetHashCode()
{
return this._real.GetHashCode() ^ (-this._imag.GetHashCode());
return _real.GetHashCode() ^ (-_imag.GetHashCode());
}
/// <summary>
@ -779,15 +731,15 @@ namespace MathNet.Numerics
/// corresponding real and imaginary components are equal.
/// </summary>
/// <returns>
/// Returns true if the two objects are the same object, or if their corresponding
/// real and imaginary components are equal, false otherwise.
/// Returns <c>true</c> if the two objects are the same object, or if their corresponding
/// real and imaginary components are equal, <c>false</c> otherwise.
/// </returns>
/// <param name="obj">
/// The complex number to compare to with.
/// </param>
public override bool Equals(object obj)
{
return (obj is Complex) && this.Equals((Complex)obj);
return (obj is Complex) && Equals((Complex)obj);
}
#endregion
@ -799,7 +751,7 @@ namespace MathNet.Numerics
/// </summary>
/// <param name="complex1">One of complex numbers to compare.</param>
/// <param name="complex2">The other complex numbers to compare.</param>
/// <returns>true if the real and imaginary components of the two complex numbers are equal; false otherwise.</returns>
/// <returns><c>true</c> if the real and imaginary components of the two complex numbers are equal; <c>false</c> otherwise.</returns>
public static bool operator ==(Complex complex1, Complex complex2)
{
return complex1.Equals(complex2);
@ -810,7 +762,7 @@ namespace MathNet.Numerics
/// </summary>
/// <param name="complex1">One of complex numbers to compare.</param>
/// <param name="complex2">The other complex numbers to compare.</param>
/// <returns>true if the real or imaginary components of the two complex numbers are not equal; false otherwise.</returns>
/// <returns><c>true</c> if the real or imaginary components of the two complex numbers are not equal; <c>false</c> otherwise.</returns>
public static bool operator !=(Complex complex1, Complex complex2)
{
return !complex1.Equals(complex2);
@ -897,7 +849,7 @@ namespace MathNet.Numerics
public static Complex operator *(Complex multiplicand, Complex multiplier)
{
return new Complex(
(multiplicand._real * multiplier._real) - (multiplicand._imag * multiplier._imag),
(multiplicand._real * multiplier._real) - (multiplicand._imag * multiplier._imag),
(multiplicand._real * multiplier._imag) + (multiplicand._imag * multiplier._real));
}
@ -932,7 +884,7 @@ namespace MathNet.Numerics
var modSquared = divisor.ModulusSquared;
return new Complex(
((dividend._real * divisor._real) + (dividend._imag * divisor._imag)) / modSquared,
((dividend._real * divisor._real) + (dividend._imag * divisor._imag)) / modSquared,
((dividend._imag * divisor._real) - (dividend._real * divisor._imag)) / modSquared);
}
@ -1116,7 +1068,7 @@ namespace MathNet.Numerics
/// the string to parse.
/// </param>
/// <param name="formatProvider">
/// An IFormatProvider that supplies culture-specific formatting information.
/// An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.
/// </param>
public static Complex Parse(string value, IFormatProvider formatProvider)
{
@ -1178,7 +1130,7 @@ namespace MathNet.Numerics
}
else
{
var matchResult = ParseExpression.Match(value);
var matchResult = _parseExpression.Match(value);
if (matchResult.Success)
{
var realStr = matchResult.Groups["r"].Value;
@ -1241,7 +1193,7 @@ namespace MathNet.Numerics
/// A string containing a complex number to convert.
/// </param>
/// <param name="formatProvider">
/// An IFormatProvider that supplies culture-specific formatting information about value.
/// An <see cref="IFormatProvider"/> that supplies culture-specific formatting information about value.
/// </param>
/// <param name="result">
/// The parsed value.
@ -1260,12 +1212,12 @@ namespace MathNet.Numerics
}
catch (ArgumentNullException)
{
result = zero;
result = _zero;
ret = false;
}
catch (FormatException)
{
result = zero;
result = _zero;
ret = false;
}
@ -1274,4 +1226,4 @@ namespace MathNet.Numerics
#endregion
}
}
}

6
src/Numerics/Constants.cs

@ -130,15 +130,9 @@ namespace MathNet.Numerics
public const double Grad = 0.015707963267948966192313216916397514420985846996876d;
/// <summary>The number ln(10)/20 - factor to convert from Power Decibel (dB) to Neper (Np). Use this version when the Decibel represent a power gain but the compared values are not powers (e.g. amplitude, current, voltage).</summary>
/// <seealso cref="Ratios.RatioToPowerDecibel(double)"/>
/// <seealso cref="Ratios.PowerDecibelToRatio"/>
/// <seealso cref="Ratios.PowerDecibelToValue"/>
public const double PowerDecibel = 0.11512925464970228420089957273421821038005507443144d;
/// <summary>The number ln(10)/10 - factor to convert from Neutral Decibel (dB) to Neper (Np). Use this version when either both or neither of the Decibel and the compared values represent powers.</summary>
/// <seealso cref="Ratios.RatioToDecibel(double)"/>
/// <seealso cref="Ratios.DecibelToRatio"/>
/// <seealso cref="Ratios.DecibelToValue"/>
public const double NeutralDecibel = 0.23025850929940456840179914546843642076011014886288d;
/// <summary>The Catalan constant</summary>

5
src/Numerics/IntegralTransforms/Algorithms/DiscreteFourierTransform.RadixN.cs

@ -61,7 +61,8 @@ namespace MathNet.Numerics.IntegralTransforms.Algorithms
{
m >>= 1;
j ^= m;
} while ((j & m) == 0);
}
while ((j & m) == 0);
}
}
@ -159,4 +160,4 @@ namespace MathNet.Numerics.IntegralTransforms.Algorithms
InverseScaleByOptions(options, samples);
}
}
}
}

12
src/Numerics/NumberTheory/IntegerTheory.cs

@ -104,13 +104,13 @@ namespace MathNet.Numerics.NumberTheory
/// <exception cref="ArgumentOutOfRangeException"/>
public static int CeilingToPowerOfTwo(this int number)
{
if(number == Int32.MinValue)
if (number == Int32.MinValue)
{
return 0;
}
const int maxPowerOfTwo = 0x40000000;
if(number > maxPowerOfTwo)
const int MaxPowerOfTwo = 0x40000000;
if (number > MaxPowerOfTwo)
{
throw new ArgumentOutOfRangeException("number");
}
@ -138,8 +138,8 @@ namespace MathNet.Numerics.NumberTheory
return 0;
}
const long maxPowerOfTwo = 0x4000000000000000;
if (number > maxPowerOfTwo)
const long MaxPowerOfTwo = 0x4000000000000000;
if (number > MaxPowerOfTwo)
{
throw new ArgumentOutOfRangeException("number");
}
@ -169,7 +169,7 @@ namespace MathNet.Numerics.NumberTheory
return 1 << exponent;
}
/// <summary>
/// Raises 2 to the provided integer exponent (0 &lt;= exponent &lt; 63).
/// </summary>

64
src/Numerics/Sorting.cs

@ -37,7 +37,7 @@ namespace MathNet.Numerics
public static class Sorting
{
/// <summary>
/// Sort a list of keys, inplace using the quick sort algorithm.
/// Sort a list of keys, in place using the quick sort algorithm.
/// </summary>
/// <typeparam name="T">The type of elements stored in the list.</typeparam>
/// <param name="keys">List to sort.</param>
@ -47,33 +47,33 @@ namespace MathNet.Numerics
}
/// <summary>
/// Sort a list of keys and items with respect to the keys, inplace using the quick sort algorithm.
/// Sort a list of keys and items with respect to the keys, in place using the quick sort algorithm.
/// </summary>
/// <typeparam name="TKey">The type of elements stored in the key list.</typeparam>
/// <typeparam name="TItem">The type of elements stored in the item list.</typeparam>
/// <param name="keys">List to sort.</param>
/// <param name="items">List to permutate the same way as the key list.</param>
/// <param name="items">List to permute the same way as the key list.</param>
public static void Sort<TKey, TItem>(IList<TKey> keys, IList<TItem> items)
{
Sort(keys, items, Comparer<TKey>.Default);
}
/// <summary>
/// Sort a list of keys, items1 and items2 with respect to the keys, inplace using the quick sort algorithm.
/// Sort a list of keys, items1 and items2 with respect to the keys, in place using the quick sort algorithm.
/// </summary>
/// <typeparam name="TKey">The type of elements stored in the key list.</typeparam>
/// <typeparam name="TItem1">The type of elements stored in the first item list.</typeparam>
/// <typeparam name="TItem2">The type of elements stored in the second item list.</typeparam>
/// <param name="keys">List to sort.</param>
/// <param name="items1">First list to permutate the same way as the key list.</param>
/// <param name="items2">Second list to permutate the same way as the key list.</param>
/// <param name="items1">First list to permute the same way as the key list.</param>
/// <param name="items2">Second list to permute the same way as the key list.</param>
public static void Sort<TKey, TItem1, TItem2>(IList<TKey> keys, IList<TItem1> items1, IList<TItem2> items2)
{
Sort(keys, items1, items2, Comparer<TKey>.Default);
}
/// <summary>
/// Sort a range of a list of keys, inplace using the quick sort algorithm.
/// Sort a range of a list of keys, in place using the quick sort algorithm.
/// </summary>
/// <typeparam name="T">The type of elements in the key list.</typeparam>
/// <param name="keys">List to sort.</param>
@ -85,7 +85,7 @@ namespace MathNet.Numerics
}
/// <summary>
/// Sort a list of keys, inplace using the quick sort algorithm using the quick sort algorithm.
/// Sort a list of keys, in place using the quick sort algorithm using the quick sort algorithm.
/// </summary>
/// <typeparam name="T">The type of elements in the key list.</typeparam>
/// <param name="keys">List to sort.</param>
@ -139,12 +139,12 @@ namespace MathNet.Numerics
}
/// <summary>
/// Sort a list of keys and items with respect to the keys, inplace using the quick sort algorithm.
/// Sort a list of keys and items with respect to the keys, in place using the quick sort algorithm.
/// </summary>
/// <typeparam name="TKey">The type of elements in the key list.</typeparam>
/// <typeparam name="TItem">The type of elements in the item list.</typeparam>
/// <param name="keys">List to sort.</param>
/// <param name="items">List to permutate the same way as the key list.</param>
/// <param name="items">List to permute the same way as the key list.</param>
/// <param name="comparer">Comparison, defining the sort order.</param>
public static void Sort<TKey, TItem>(IList<TKey> keys, IList<TItem> items, IComparer<TKey> comparer)
{
@ -177,14 +177,14 @@ namespace MathNet.Numerics
}
/// <summary>
/// Sort a list of keys, items1 and items2 with respect to the keys, inplace using the quick sort algorithm.
/// Sort a list of keys, items1 and items2 with respect to the keys, in place using the quick sort algorithm.
/// </summary>
/// <typeparam name="TKey">The type of elements in the key list.</typeparam>
/// <typeparam name="TItem1">The type of elements in the first item list.</typeparam>
/// <typeparam name="TItem2">The type of elements in the second item list.</typeparam>
/// <param name="keys">List to sort.</param>
/// <param name="items1">First list to permutate the same way as the key list.</param>
/// <param name="items2">Second list to permutate the same way as the key list.</param>
/// <param name="items1">First list to permute the same way as the key list.</param>
/// <param name="items2">Second list to permute the same way as the key list.</param>
/// <param name="comparer">Comparison, defining the sort order.</param>
public static void Sort<TKey, TItem1, TItem2>(
IList<TKey> keys, IList<TItem1> items1, IList<TItem2> items2, IComparer<TKey> comparer)
@ -214,7 +214,7 @@ namespace MathNet.Numerics
}
/// <summary>
/// Sort a range of a list of keys, inplace using the quick sort algorithm.
/// Sort a range of a list of keys, in place using the quick sort algorithm.
/// </summary>
/// <typeparam name="T">The type of element in the list.</typeparam>
/// <param name="keys">List to sort.</param>
@ -280,7 +280,7 @@ namespace MathNet.Numerics
}
/// <summary>
/// Recursive implementation for an inplace quick sort on a list.
/// Recursive implementation for an in place quick sort on a list.
/// </summary>
/// <typeparam name="T">The type of the list on which the quick sort is performed.</typeparam>
/// <param name="keys">The list which is sorted using quick sort.</param>
@ -342,7 +342,8 @@ namespace MathNet.Numerics
a++;
b--;
} while (a <= b);
}
while (a <= b);
// In order to limit the recusion depth to log(n), we sort the
// shorter partition recusively and the longer partition iteratively.
@ -364,11 +365,12 @@ namespace MathNet.Numerics
right = b;
}
} while (left < right);
}
while (left < right);
}
/// <summary>
/// Recursive implementation for an inplace quick sort on a list while reordering one other list accordingly.
/// Recursive implementation for an in place quick sort on a list while reordering one other list accordingly.
/// </summary>
/// <typeparam name="T">The type of the list on which the quick sort is performed.</typeparam>
/// <typeparam name="TItems">The type of the list which is automatically reordered accordingly.</typeparam>
@ -437,7 +439,8 @@ namespace MathNet.Numerics
a++;
b--;
} while (a <= b);
}
while (a <= b);
// In order to limit the recusion depth to log(n), we sort the
// shorter partition recusively and the longer partition iteratively.
@ -459,11 +462,12 @@ namespace MathNet.Numerics
right = b;
}
} while (left < right);
}
while (left < right);
}
/// <summary>
/// Recursive implementation for an inplace quick sort on one list while reordering two other lists accordingly.
/// Recursive implementation for an in place quick sort on one list while reordering two other lists accordingly.
/// </summary>
/// <typeparam name="T">The type of the list on which the quick sort is performed.</typeparam>
/// <typeparam name="TItems1">The type of the first list which is automatically reordered accordingly.</typeparam>
@ -539,7 +543,8 @@ namespace MathNet.Numerics
a++;
b--;
} while (a <= b);
}
while (a <= b);
// In order to limit the recusion depth to log(n), we sort the
// shorter partition recusively and the longer partition iteratively.
@ -561,7 +566,8 @@ namespace MathNet.Numerics
right = b;
}
} while (left < right);
}
while (left < right);
}
/// <summary>
@ -573,12 +579,14 @@ namespace MathNet.Numerics
/// <param name="b">The index of the second element of the swap.</param>
internal static void Swap<T>(IList<T> keys, int a, int b)
{
if (a != b)
if (a == b)
{
T local = keys[a];
keys[a] = keys[b];
keys[b] = local;
return;
}
T local = keys[a];
keys[a] = keys[b];
keys[b] = local;
}
}
}
}

74
src/Numerics/Statistics/DescriptiveStatistics.cs

@ -58,10 +58,14 @@ namespace MathNet.Numerics.Statistics
/// Initializes a new instance of the <see cref="DescriptiveStatistics"/> class.
/// </summary>
/// <param name="data">The sample data.</param>
/// <param name="increasedAccuracy">if set to <c>true</c>, increased accuracy mode used.
/// Increased accuracy mode uses <see cref="decimal"/> types for internal calculations.</param>
/// <remarks>Don't use increased accuracy for data sets containing large values (in absolute value).
/// This may cause the calculations to overflow.</remarks>
/// <param name="increasedAccuracy">
/// If set to <c>true</c>, increased accuracy mode used.
/// Increased accuracy mode uses <see cref="decimal"/> types for internal calculations.
/// </param>
/// <remarks>
/// Don't use increased accuracy for data sets containing large values (in absolute value).
/// This may cause the calculations to overflow.
/// </remarks>
public DescriptiveStatistics(IEnumerable<double> data, bool increasedAccuracy)
{
if (increasedAccuracy)
@ -82,10 +86,14 @@ namespace MathNet.Numerics.Statistics
/// Initializes a new instance of the <see cref="DescriptiveStatistics"/> class.
/// </summary>
/// <param name="data">The sample data.</param>
/// <param name="increasedAccuracy">if set to <c>true</c>, increased accuracy mode used.
/// Increased accuracy mode uses <see cref="decimal"/> types for internal calculations.</param>
/// <remarks>Don't use increased accuracy for data sets containing large values (in absolute value).
/// This may cause the calculations to overflow.</remarks>
/// <param name="increasedAccuracy">
/// If set to <c>true</c>, increased accuracy mode used.
/// Increased accuracy mode uses <see cref="decimal"/> types for internal calculations.
/// </param>
/// <remarks>
/// Don't use increased accuracy for data sets containing large values (in absolute value).
/// This may cause the calculations to overflow.
/// </remarks>
public DescriptiveStatistics(IEnumerable<double?> data, bool increasedAccuracy)
{
if (increasedAccuracy)
@ -174,7 +182,7 @@ namespace MathNet.Numerics.Statistics
{
double diff = xi - Mean;
correction += diff;
double tmp = diff*diff;
double tmp = diff * diff;
variance += tmp;
tmp *= diff;
skewness += tmp;
@ -184,18 +192,21 @@ namespace MathNet.Numerics.Statistics
}
Count = n;
Variance = (variance - (correction*correction)/n)/(n - 1);
Variance = (variance - (correction * correction / n)) / (n - 1);
StandardDeviation = System.Math.Sqrt(Variance);
if (Variance != 0)
{
if (n > 2)
{
Skewness = (double) n/((n - 1)*(n - 2))*(skewness/(Variance*StandardDeviation));
Skewness = (double)n / ((n - 1) * (n - 2)) * (skewness / (Variance * StandardDeviation));
}
if (n > 3)
{
Kurtosis = ((double) n*(n + 1))/((n - 1)*(n - 2)*(n - 3))*(kurtosis/(Variance*Variance)) - (3.0*(n - 1)*(n - 1))/((n - 2)*(n - 3));
Kurtosis = (((double)n * (n + 1))
/ ((n - 1) * (n - 2) * (n - 3))
* (kurtosis / (Variance * Variance)))
- ((3.0 * (n - 1) * (n - 1)) / ((n - 2) * (n - 3)));
}
}
}
@ -217,7 +228,7 @@ namespace MathNet.Numerics.Statistics
if (xi.HasValue)
{
double diff = xi.Value - Mean;
double tmp = diff*diff;
double tmp = diff * diff;
correction += diff;
variance += tmp;
tmp *= diff;
@ -231,18 +242,21 @@ namespace MathNet.Numerics.Statistics
Count = n;
if (n > 0)
{
Variance = (variance - (correction*correction)/n)/(n - 1);
Variance = (variance - (correction * correction / n)) / (n - 1);
StandardDeviation = System.Math.Sqrt(Variance);
if (Variance != 0)
{
if (n > 2)
{
Skewness = (double) n/((n - 1)*(n - 2))*(skewness/(Variance*StandardDeviation));
Skewness = (double)n / ((n - 1) * (n - 2)) * (skewness / (Variance * StandardDeviation));
}
if (n > 3)
{
Kurtosis = ((double) n*(n + 1))/((n - 1)*(n - 2)*(n - 3))*(kurtosis/(Variance*Variance)) - (3.0*(n - 1)*(n - 1))/((n - 2)*(n - 3));
Kurtosis = (((double)n * (n + 1))
/ ((n - 1) * (n - 2) * (n - 3))
* (kurtosis / (Variance * Variance)))
- ((3.0 * (n - 1) * (n - 1)) / ((n - 2) * (n - 3)));
}
}
}
@ -255,7 +269,7 @@ namespace MathNet.Numerics.Statistics
private void ComputeHA(IEnumerable<double> data)
{
Mean = data.Mean();
decimal mean = (decimal) Mean;
decimal mean = (decimal)Mean;
decimal variance = 0;
decimal correction = 0;
decimal skewness = 0;
@ -264,7 +278,7 @@ namespace MathNet.Numerics.Statistics
foreach (decimal xi in data)
{
decimal diff = xi - mean;
decimal tmp = diff*diff;
decimal tmp = diff * diff;
correction += diff;
variance += tmp;
tmp *= diff;
@ -275,18 +289,21 @@ namespace MathNet.Numerics.Statistics
}
Count = n;
Variance = (double) (variance - (correction*correction)/n)/(n - 1);
Variance = (double)(variance - (correction * correction / n)) / (n - 1);
StandardDeviation = System.Math.Sqrt(Variance);
if (Variance != 0)
{
if (n > 2)
{
Skewness = (double) n/((n - 1)*(n - 2))*((double) skewness/(Variance*StandardDeviation));
Skewness = (double)n / ((n - 1) * (n - 2)) * ((double)skewness / (Variance * StandardDeviation));
}
if (n > 3)
{
Kurtosis = ((double) n*(n + 1))/((n - 1)*(n - 2)*(n - 3))*((double) kurtosis/(Variance*Variance)) - (3.0*(n - 1)*(n - 1))/((n - 2)*(n - 3));
Kurtosis = (((double)n * (n + 1))
/ ((n - 1) * (n - 2) * (n - 3))
* ((double)kurtosis / (Variance * Variance)))
- ((3.0 * (n - 1) * (n - 1)) / ((n - 2) * (n - 3)));
}
}
}
@ -298,7 +315,7 @@ namespace MathNet.Numerics.Statistics
private void ComputeHA(IEnumerable<double?> data)
{
Mean = data.Mean();
decimal mean = (decimal) Mean;
decimal mean = (decimal)Mean;
decimal variance = 0;
decimal correction = 0;
decimal skewness = 0;
@ -309,7 +326,7 @@ namespace MathNet.Numerics.Statistics
if (xi.HasValue)
{
decimal diff = xi.Value - mean;
decimal tmp = diff*diff;
decimal tmp = diff * diff;
correction += diff;
variance += tmp;
tmp *= diff;
@ -323,21 +340,24 @@ namespace MathNet.Numerics.Statistics
Count = n;
if (n > 0)
{
Variance = (double) (variance - (correction*correction)/n)/(n - 1);
Variance = (double)(variance - (correction * correction / n)) / (n - 1);
StandardDeviation = System.Math.Sqrt(Variance);
if (Variance != 0)
{
if (n > 2)
{
Skewness = (double) n/((n - 1)*(n - 2))*((double) skewness/(Variance*StandardDeviation));
Skewness = (double)n / ((n - 1) * (n - 2)) * ((double)skewness / (Variance * StandardDeviation));
}
if (n > 3)
{
Kurtosis = ((double) n*(n + 1))/((n - 1)*(n - 2)*(n - 3))*((double) kurtosis/(Variance*Variance)) - (3.0*(n - 1)*(n - 1))/((n - 2)*(n - 3));
Kurtosis = (((double)n * (n + 1))
/ ((n - 1) * (n - 2) * (n - 3))
* ((double)kurtosis / (Variance * Variance)))
- ((3.0 * (n - 1) * (n - 1)) / ((n - 2) * (n - 3)));
}
}
}
}
}
}
}

92
src/Numerics/Statistics/Statistics.cs

@ -30,8 +30,7 @@ namespace MathNet.Numerics.Statistics
{
using System;
using System.Collections.Generic;
using MathNet.Numerics.Properties;
using MathNet.Numerics.NumberTheory;
using Properties;
/// <summary>
/// Extension methods to return basic statistics on set of data.
@ -54,7 +53,7 @@ namespace MathNet.Numerics.Statistics
int m = 0;
foreach (var item in data)
{
mean += (item - mean)/++m;
mean += (item - mean) / ++m;
}
return mean;
@ -78,7 +77,7 @@ namespace MathNet.Numerics.Statistics
{
if (item.HasValue)
{
mean += (item.Value - mean)/++m;
mean += (item.Value - mean) / ++m;
}
}
@ -113,11 +112,11 @@ namespace MathNet.Numerics.Statistics
j++;
double xi = iterator.Current;
t += xi;
double diff = j*xi - t;
variance += (diff*diff)/(j*(j - 1));
double diff = (j * xi) - t;
variance += (diff * diff) / (j * (j - 1));
}
return variance/(j - 1);
return variance / (j - 1);
}
/// <summary>
@ -145,6 +144,7 @@ namespace MathNet.Numerics.Statistics
{
break;
}
if (iterator.Current.HasValue)
{
j++;
@ -160,12 +160,12 @@ namespace MathNet.Numerics.Statistics
j++;
double xi = iterator.Current.Value;
t += xi;
double diff = j*xi - t;
variance += (diff*diff)/(j*(j - 1));
double diff = (j * xi) - t;
variance += (diff * diff) / (j * (j - 1));
}
}
return variance/(j - 1);
return variance / (j - 1);
}
/// <summary>
@ -196,7 +196,7 @@ namespace MathNet.Numerics.Statistics
j++;
double xi = iterator.Current;
t += xi;
double diff = j * xi - t;
double diff = (j * xi) - t;
variance += (diff * diff) / (j * (j - 1));
}
@ -228,6 +228,7 @@ namespace MathNet.Numerics.Statistics
{
break;
}
if (iterator.Current.HasValue)
{
j++;
@ -243,7 +244,7 @@ namespace MathNet.Numerics.Statistics
j++;
double xi = iterator.Current.Value;
t += xi;
double diff = j * xi - t;
double diff = (j * xi) - t;
variance += (diff * diff) / (j * (j - 1));
}
}
@ -263,7 +264,7 @@ namespace MathNet.Numerics.Statistics
throw new ArgumentNullException("data");
}
return System.Math.Sqrt(Variance(data));
return Math.Sqrt(Variance(data));
}
/// <summary>
@ -278,7 +279,7 @@ namespace MathNet.Numerics.Statistics
throw new ArgumentNullException("data");
}
return System.Math.Sqrt(Variance(data));
return Math.Sqrt(Variance(data));
}
/// <summary>
@ -293,7 +294,7 @@ namespace MathNet.Numerics.Statistics
throw new ArgumentNullException("data");
}
return System.Math.Sqrt(PopulationVariance(data));
return Math.Sqrt(PopulationVariance(data));
}
/// <summary>
@ -308,7 +309,7 @@ namespace MathNet.Numerics.Statistics
throw new ArgumentNullException("data");
}
return System.Math.Sqrt(PopulationVariance(data));
return Math.Sqrt(PopulationVariance(data));
}
/// <summary>
@ -329,7 +330,7 @@ namespace MathNet.Numerics.Statistics
{
if (d.HasValue)
{
min = System.Math.Min(min, d.Value);
min = Math.Min(min, d.Value);
count++;
}
}
@ -360,7 +361,7 @@ namespace MathNet.Numerics.Statistics
{
if (d.HasValue)
{
max = System.Math.Max(max, d.Value);
max = Math.Max(max, d.Value);
count++;
}
}
@ -389,7 +390,7 @@ namespace MathNet.Numerics.Statistics
int count = 0;
foreach (double d in data)
{
min = System.Math.Min(min, d);
min = Math.Min(min, d);
count++;
}
@ -417,7 +418,7 @@ namespace MathNet.Numerics.Statistics
int count = 0;
foreach (double d in data)
{
max = System.Math.Max(max, d);
max = Math.Max(max, d);
count++;
}
@ -441,18 +442,16 @@ namespace MathNet.Numerics.Statistics
throw new ArgumentNullException("data");
}
List<double> dataArray = new List<double>(data);
int index = dataArray.Count/2 + 1;
var dataArray = new List<double>(data);
int index = (dataArray.Count / 2) + 1;
if (dataArray.Count % 2 == 0)
{
double lower = OrderSelect(dataArray, 0, dataArray.Count - 1, index - 1);
double upper = OrderSelect(dataArray, 0, dataArray.Count - 1, index);
return (lower + upper) / 2.0;
}
else
{
return OrderSelect(dataArray, 0, dataArray.Count - 1, index);
}
return OrderSelect(dataArray, 0, dataArray.Count - 1, index);
}
/// <summary>
@ -467,7 +466,7 @@ namespace MathNet.Numerics.Statistics
throw new ArgumentNullException("data");
}
List<double> nonNull = new List<double>();
var nonNull = new List<double>();
foreach (double? value in data)
{
if (value.HasValue)
@ -487,7 +486,8 @@ namespace MathNet.Numerics.Statistics
/// <summary>
/// Evaluate the i-order (1..N) statistic of the provided samples.
/// </summary>
/// <param name="data">The sample data.</param>
/// <param name="samples">The sample data.</param>
/// <param name="order">Order of the statistic to evaluate.</param>
/// <returns>The i'th order statistic in the sample data.</returns>
public static double OrderStatistic(IEnumerable<double> samples, int order)
{
@ -497,7 +497,7 @@ namespace MathNet.Numerics.Statistics
return Minimum(samples);
}
List<double> list = new List<double>(samples);
var list = new List<double>(samples);
if (order < 1 || order > list.Count)
{
throw new ArgumentOutOfRangeException("order", Resources.ArgumentInIntervalXYInclusive);
@ -521,16 +521,12 @@ namespace MathNet.Numerics.Statistics
/// <param name="right">The right bound in which to order select.</param>
/// <param name="order">The order we are trying to find.</param>
/// <returns>The <paramref name="order"/> order statistic.</returns>
static double OrderSelect(IList<double> samples, int left, int right, int order)
private static double OrderSelect(IList<double> samples, int left, int right, int order)
{
// Order most always be positive.
System.Diagnostics.Debug.Assert(order > 0);
// Left side must always be positive and smaller than right side.
System.Diagnostics.Debug.Assert(left >= 0 && left <= right);
// Right side must always be smaller than number of elements in list.
System.Diagnostics.Debug.Assert(right < samples.Count);
// Make sure there are at least order items in the segment [left, right].
System.Diagnostics.Debug.Assert(right - left + 1 >= order);
System.Diagnostics.Debug.Assert(order > 0, "Order must always be positive.");
System.Diagnostics.Debug.Assert(left >= 0 && left <= right, "Left side must always be positive and smaller than right side.");
System.Diagnostics.Debug.Assert(right < samples.Count, "Right side must always be smaller than number of elements in list.");
System.Diagnostics.Debug.Assert(right - left + 1 >= order, "Make sure there are at least order items in the segment [left, right].");
if (left == right)
{
@ -542,29 +538,29 @@ namespace MathNet.Numerics.Statistics
// The partioning code.
int i = left - 1;
for(int j = left; j <= right - 1; j++)
for (int j = left; j <= right - 1; j++)
{
if(samples[j] <= pivot)
if (samples[j] <= pivot)
{
i++;
Sorting.Swap(samples, i, j);
}
}
Sorting.Swap(samples, i+1, right);
Sorting.Swap(samples, i + 1, right);
// Recursive order finding algorithm.
if(order == (i-left)+2)
if (order == (i - left) + 2)
{
return pivot;
}
else if (order < (i-left)+2)
if (order < (i - left) + 2)
{
return OrderSelect(samples, left, i, order);
}
else
{
return OrderSelect(samples, i+2, right, order - i + left - 2);
}
return OrderSelect(samples, i + 2, right, order - i + left - 2);
}
}
}
}

Loading…
Cancel
Save