Browse Source

Inspections/CodeAnalysis Cleanup

pull/163/head
Christoph Ruegg 13 years ago
parent
commit
7d11e73aaa
  1. 1
      .gitattributes
  2. 12
      MathNet.Numerics.sln.DotSettings
  3. 3
      src/Numerics/ArrayExtensions.cs
  4. 8
      src/Numerics/Constants.cs
  5. 7
      src/Numerics/Distributions/Continuous/Beta.cs
  6. 12
      src/Numerics/Distributions/Continuous/Cauchy.cs
  7. 7
      src/Numerics/Distributions/Continuous/Chi.cs
  8. 12
      src/Numerics/Distributions/Continuous/ContinuousUniform.cs
  9. 7
      src/Numerics/Distributions/Continuous/Erlang.cs
  10. 12
      src/Numerics/Distributions/Continuous/Exponential.cs
  11. 12
      src/Numerics/Distributions/Continuous/FisherSnedecor.cs
  12. 7
      src/Numerics/Distributions/Continuous/Gamma.cs
  13. 20
      src/Numerics/Distributions/Continuous/InverseGamma.cs
  14. 12
      src/Numerics/Distributions/Continuous/Laplace.cs
  15. 7
      src/Numerics/Distributions/Continuous/LogNormal.cs
  16. 7
      src/Numerics/Distributions/Continuous/Normal.cs
  17. 12
      src/Numerics/Distributions/Continuous/Pareto.cs
  18. 12
      src/Numerics/Distributions/Continuous/Rayleigh.cs
  19. 22
      src/Numerics/Distributions/Continuous/Stable.cs
  20. 7
      src/Numerics/Distributions/Continuous/StudentT.cs
  21. 7
      src/Numerics/Distributions/Continuous/Weibull.cs
  22. 7
      src/Numerics/Distributions/Discrete/Bernoulli.cs
  23. 12
      src/Numerics/Distributions/Discrete/Binomial.cs
  24. 12
      src/Numerics/Distributions/Discrete/ConwayMaxwellPoisson.cs
  25. 7
      src/Numerics/Distributions/Discrete/DiscreteUniform.cs
  26. 7
      src/Numerics/Distributions/Discrete/Geometric.cs
  27. 12
      src/Numerics/Distributions/Discrete/Hypergeometric.cs
  28. 12
      src/Numerics/Distributions/Discrete/NegativeBinomial.cs
  29. 12
      src/Numerics/Distributions/Discrete/Zipf.cs
  30. 7
      src/Numerics/Distributions/Multivariate/InverseWishart.cs
  31. 9
      src/Numerics/Distributions/Multivariate/NormalGamma.cs
  32. 8
      src/Numerics/Financial/AbsoluteReturnMeasures.cs
  33. 11
      src/Numerics/Financial/AbsoluteRiskMeasures.cs
  34. 13
      src/Numerics/GlobalizationHelper.cs
  35. 4
      src/Numerics/IntegralTransforms/Algorithms/DiscreteFourierTransform.Bluestein.cs
  36. 16
      src/Numerics/IntegralTransforms/Transform.cs
  37. 5
      src/Numerics/Integration/DoubleExponentialTransformation.cs
  38. 8
      src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs
  39. 11
      src/Numerics/Interpolation/CubicSplineInterpolation.cs
  40. 9
      src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs
  41. 4
      src/Numerics/Interpolation/LinearSplineInterpolation.cs
  42. 2
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  43. 4
      src/Numerics/LinearAlgebra/Complex/Factorization/DenseEvd.cs
  44. 4
      src/Numerics/LinearAlgebra/Complex/Factorization/UserEvd.cs
  45. 18
      src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs
  46. 2
      src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs
  47. 1
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  48. 2
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  49. 4
      src/Numerics/LinearAlgebra/Complex32/Factorization/DenseEvd.cs
  50. 4
      src/Numerics/LinearAlgebra/Complex32/Factorization/UserEvd.cs
  51. 18
      src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs
  52. 2
      src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs
  53. 1
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  54. 4
      src/Numerics/LinearAlgebra/Double/Factorization/UserEvd.cs
  55. 18
      src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs
  56. 2
      src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs
  57. 2
      src/Numerics/LinearAlgebra/Factorization/Cholesky.cs
  58. 2
      src/Numerics/LinearAlgebra/Factorization/Evd.cs
  59. 2
      src/Numerics/LinearAlgebra/Matrix.BCL.cs
  60. 2
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  61. 6
      src/Numerics/LinearAlgebra/Single/Factorization/DenseEvd.cs
  62. 4
      src/Numerics/LinearAlgebra/Single/Factorization/UserEvd.cs
  63. 18
      src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs
  64. 2
      src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs
  65. 4
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
  66. 1
      src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
  67. 2
      src/Numerics/LinearAlgebra/Vector.BCL.cs
  68. 8
      src/Numerics/NumberTheory/IntegerTheory.cs
  69. 3
      src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs
  70. 20
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs
  71. 20
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs
  72. 22
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs
  73. 22
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs
  74. 3
      src/Numerics/Random/AbstractRandomNumberGenerator.cs
  75. 18
      src/Numerics/Random/Mcg31m1.cs
  76. 18
      src/Numerics/Random/Mcg59.cs
  77. 52
      src/Numerics/Random/MersenneTwister.cs
  78. 55
      src/Numerics/Random/Mrg32k3a.cs
  79. 8
      src/Numerics/Random/Palf.cs
  80. 24
      src/Numerics/Random/SystemCrypto.cs
  81. 26
      src/Numerics/Random/WH1982.cs
  82. 32
      src/Numerics/Random/WH2006.cs
  83. 103
      src/Numerics/Random/Xorshift.cs
  84. 4
      src/Numerics/RootFinding/Broyden.cs
  85. 4
      src/Numerics/SpecialFunctions/Beta.cs
  86. 171
      src/Numerics/SpecialFunctions/Erf.cs
  87. 18
      src/Numerics/SpecialFunctions/Factorial.cs
  88. 131
      src/Numerics/SpecialFunctions/Gamma.cs
  89. 65
      src/Numerics/SpecialFunctions/ModifiedStruve.cs
  90. 4
      src/Numerics/Statistics/ArrayStatistics.cs
  91. 8
      src/Numerics/Statistics/Correlation.cs
  92. 24
      src/Numerics/Statistics/DescriptiveStatistics.cs
  93. 15
      src/Numerics/Statistics/Histogram.cs
  94. 6
      src/Numerics/Statistics/MCMC/HybridMC.cs
  95. 4
      src/Numerics/Statistics/MCMC/HybridMCGeneric.cs
  96. 4
      src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs
  97. 4
      src/Numerics/Statistics/MCMC/MCMCSampler.cs
  98. 2
      src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs
  99. 4
      src/Numerics/Statistics/SortedArrayStatistics.cs
  100. 23
      src/Numerics/Threading/CommonParallel.cs

1
.gitattributes

@ -6,6 +6,7 @@
*.csdef text
*.xml text
*.js text
*.ps1 text
*.csproj text merge=union
*.fsproj text merge=union

12
MathNet.Numerics.sln.DotSettings

@ -47,7 +47,19 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
&lt;/copyright&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CDF/@EntryIndexedValue">CDF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DFT/@EntryIndexedValue">DFT</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FFT/@EntryIndexedValue">FFT</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LU/@EntryIndexedValue">LU</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MAE/@EntryIndexedValue">MAE</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MC/@EntryIndexedValue">MC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MCMC/@EntryIndexedValue">MCMC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSE/@EntryIndexedValue">MSE</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QR/@EntryIndexedValue">QR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAD/@EntryIndexedValue">SAD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAS/@EntryIndexedValue">SAS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SPSS/@EntryIndexedValue">SPSS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSD/@EntryIndexedValue">SSD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TFQMR/@EntryIndexedValue">TFQMR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WH/@EntryIndexedValue">WH</s:String>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String></wpf:ResourceDictionary>

3
src/Numerics/ArrayExtensions.cs

@ -28,9 +28,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics
{
using System;
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;

8
src/Numerics/Constants.cs

@ -76,15 +76,15 @@ namespace MathNet.Numerics
/// <summary>The number pi</summary>
public const double Pi = 3.1415926535897932384626433832795028841971693993751d;
/// <summary>The number 2*pi</summary>
/// <summary>The number pi*2</summary>
public const double Pi2 = 6.2831853071795864769252867665590057683943387987502d;
/// <summary>The number 1/pi</summary>
public const double OneOverPi = 0.31830988618379067153776752674502872406891929148091d;
/// <summary>The number pi/2</summary>
public const double PiOver2 = 1.5707963267948966192313216916397514420985846996876d;
/// <summary>The number pi*3/2</summary>
public const double Pi3Over2 = 4.71238898038468985769396507491925432629575409906266d;
/// <summary>The number pi/4</summary>
public const double PiOver4 = 0.78539816339744830961566084581987572104929234984378d;

7
src/Numerics/Distributions/Continuous/Beta.cs

@ -105,12 +105,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double a, double b)
{
if (a < 0.0 || b < 0.0 || Double.IsNaN(a) || Double.IsNaN(b))
{
return false;
}
return true;
return a >= 0.0 && b >= 0.0;
}
/// <summary>

12
src/Numerics/Distributions/Continuous/Cauchy.cs

@ -108,17 +108,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>True when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double location, double scale)
{
if (scale <= 0)
{
return false;
}
if (Double.IsNaN(location) || Double.IsNaN(scale))
{
return false;
}
return true;
return scale > 0.0 && !Double.IsNaN(location);
}
/// <summary>

7
src/Numerics/Distributions/Continuous/Chi.cs

@ -97,12 +97,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double dof)
{
if (dof <= 0 || Double.IsNaN(dof))
{
return false;
}
return true;
return dof > 0.0;
}
/// <summary>

12
src/Numerics/Distributions/Continuous/ContinuousUniform.cs

@ -109,17 +109,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double lower, double upper)
{
if (upper < lower)
{
return false;
}
if (Double.IsNaN(upper) || Double.IsNaN(lower))
{
return false;
}
return true;
return upper >= lower && !Double.IsNaN(upper) && !Double.IsNaN(lower);
}
/// <summary>

7
src/Numerics/Distributions/Continuous/Erlang.cs

@ -129,12 +129,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double shape, double invScale)
{
if (shape < 0.0 || invScale < 0.0 || Double.IsNaN(shape) || Double.IsNaN(invScale))
{
return false;
}
return true;
return shape >= 0.0 && invScale >= 0.0;
}
/// <summary>

12
src/Numerics/Distributions/Continuous/Exponential.cs

@ -94,17 +94,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double lambda)
{
if (lambda < 0)
{
return false;
}
if (Double.IsNaN(lambda))
{
return false;
}
return true;
return lambda >= 0.0;
}
/// <summary>

12
src/Numerics/Distributions/Continuous/FisherSnedecor.cs

@ -103,17 +103,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double d1, double d2)
{
if (d1 <= 0 || d2 <= 0)
{
return false;
}
if (Double.IsNaN(d1) || Double.IsNaN(d2))
{
return false;
}
return true;
return d1 > 0.0 && d2 > 0.0;
}
/// <summary>

7
src/Numerics/Distributions/Continuous/Gamma.cs

@ -128,12 +128,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double shape, double invScale)
{
if (shape < 0.0 || invScale < 0.0 || Double.IsNaN(shape) || Double.IsNaN(invScale))
{
return false;
}
return true;
return shape >= 0.0 && invScale >= 0.0;
}
/// <summary>

20
src/Numerics/Distributions/Continuous/InverseGamma.cs

@ -104,26 +104,12 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </summary>
/// <param name="shape">
/// The shape (alpha) parameter of the inverse Gamma distribution.
/// </param>
/// <param name="scale">
/// The scale (beta) parameter of the inverse Gamma distribution.
/// </param>
/// <param name="shape">The shape (alpha) parameter of the inverse Gamma distribution.</param>
/// <param name="scale">The scale (beta) parameter of the inverse Gamma distribution.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double shape, double scale)
{
if (shape <= 0 || scale <= 0)
{
return false;
}
if (Double.IsNaN(shape) || Double.IsNaN(scale))
{
return false;
}
return true;
return shape > 0.0 && scale > 0.0;
}
/// <summary>

12
src/Numerics/Distributions/Continuous/Laplace.cs

@ -129,17 +129,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double location, double scale)
{
if (scale <= 0)
{
return false;
}
if (Double.IsNaN(location) || Double.IsNaN(scale))
{
return false;
}
return true;
return scale > 0.0 && !Double.IsNaN(location);
}
/// <summary>

7
src/Numerics/Distributions/Continuous/LogNormal.cs

@ -125,12 +125,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double mu, double sigma)
{
if (sigma < 0.0 || Double.IsNaN(mu) || Double.IsNaN(mu) || Double.IsNaN(sigma))
{
return false;
}
return true;
return sigma >= 0.0 && !Double.IsNaN(mu) && !Double.IsNaN(mu);
}
/// <summary>

7
src/Numerics/Distributions/Continuous/Normal.cs

@ -166,12 +166,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double mean, double stddev)
{
if (stddev < 0.0 || Double.IsNaN(mean) || Double.IsNaN(stddev))
{
return false;
}
return true;
return stddev >= 0.0 && !Double.IsNaN(mean);
}
/// <summary>

12
src/Numerics/Distributions/Continuous/Pareto.cs

@ -108,17 +108,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double scale, double shape)
{
if (scale <= 0 || shape <= 0)
{
return false;
}
if (Double.IsNaN(scale) || Double.IsNaN(shape))
{
return false;
}
return true;
return scale > 0.0 && shape > 0.0;
}
/// <summary>

12
src/Numerics/Distributions/Continuous/Rayleigh.cs

@ -99,17 +99,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double scale)
{
if (scale <= 0)
{
return false;
}
if (Double.IsNaN(scale))
{
return false;
}
return true;
return scale > 0.0;
}
/// <summary>

22
src/Numerics/Distributions/Continuous/Stable.cs

@ -126,27 +126,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double alpha, double beta, double scale, double location)
{
if (alpha <= 0 || alpha > 2)
{
return false;
}
if (beta < -1 || beta > 1)
{
return false;
}
if (scale <= 0)
{
return false;
}
if (Double.IsNaN(alpha) || Double.IsNaN(beta) || Double.IsNaN(scale) || Double.IsNaN(location))
{
return false;
}
return true;
return alpha > 0.0 && alpha <= 2.0 && beta >= -1.0 && beta <= 1.0 && scale > 0.0 && !Double.IsNaN(location);
}
/// <summary>

7
src/Numerics/Distributions/Continuous/StudentT.cs

@ -129,12 +129,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double location, double scale, double dof)
{
if (scale <= 0.0 || dof <= 0.0 || Double.IsNaN(scale) || Double.IsNaN(location) || Double.IsNaN(dof))
{
return false;
}
return true;
return scale > 0.0 && dof > 0.0 && !Double.IsNaN(location);
}
/// <summary>

7
src/Numerics/Distributions/Continuous/Weibull.cs

@ -111,12 +111,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters positive valid floating point numbers, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double shape, double scale)
{
if (shape <= 0.0 || scale <= 0.0 || Double.IsNaN(shape) || Double.IsNaN(scale))
{
return false;
}
return true;
return shape > 0.0 && scale > 0.0;
}
/// <summary>

7
src/Numerics/Distributions/Discrete/Bernoulli.cs

@ -91,12 +91,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double p)
{
if (p >= 0.0 && p <= 1.0)
{
return true;
}
return false;
return p >= 0.0 && p <= 1.0;
}
/// <summary>

12
src/Numerics/Distributions/Discrete/Binomial.cs

@ -101,17 +101,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>false</c> <paramref name="p"/> is not in the interval [0.0,1.0] or <paramref name="n"/> is negative, <c>true</c> otherwise.</returns>
static bool IsValidParameterSet(double p, int n)
{
if (p < 0.0 || p > 1.0 || Double.IsNaN(p))
{
return false;
}
if (n < 0)
{
return false;
}
return true;
return p >= 0.0 && p <= 1.0 && n >= 0;
}
/// <summary>

12
src/Numerics/Distributions/Discrete/ConwayMaxwellPoisson.cs

@ -132,17 +132,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double lambda, double nu)
{
if (lambda <= 0.0)
{
return false;
}
if (nu < 0.0)
{
return false;
}
return true;
return lambda > 0.0 && nu >= 0.0;
}
/// <summary>

7
src/Numerics/Distributions/Discrete/DiscreteUniform.cs

@ -99,12 +99,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(int lower, int upper)
{
if (lower <= upper)
{
return true;
}
return false;
return lower <= upper;
}
/// <summary>

7
src/Numerics/Distributions/Discrete/Geometric.cs

@ -97,12 +97,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double p)
{
if (p >= 0.0 && p <= 1.0)
{
return true;
}
return false;
return p >= 0.0 && p <= 1.0;
}
/// <summary>

12
src/Numerics/Distributions/Discrete/Hypergeometric.cs

@ -122,17 +122,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(int population, int success, int draws)
{
if (population < 0 || success < 0 || draws < 0)
{
return false;
}
if (success > population || draws > population)
{
return false;
}
return true;
return population >= 0 && success >= 0 && draws >= 0 && (success <= population && draws <= population);
}
/// <summary>

12
src/Numerics/Distributions/Discrete/NegativeBinomial.cs

@ -124,17 +124,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double r, double p)
{
if (r < 0.0 || Double.IsNaN(r))
{
return false;
}
if (p < 0.0 || p > 1.0 || Double.IsNaN(p))
{
return false;
}
return true;
return r >= 0.0 && p >= 0.0 && p <= 1.0;
}
/// <summary>

12
src/Numerics/Distributions/Discrete/Zipf.cs

@ -106,12 +106,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double s, int n)
{
if (n <= 0 || s <= 0 || Double.IsNaN(s))
{
return false;
}
return true;
return n > 0 && s > 0.0;
}
/// <summary>
@ -180,8 +175,9 @@ namespace MathNet.Numerics.Distributions
throw new NotSupportedException();
}
var generalHarmonicsNS = SpecialFunctions.GeneralHarmonic(_n, _s);
return (SpecialFunctions.GeneralHarmonic(_n, _s - 2)*SpecialFunctions.GeneralHarmonic(_n, _s)) - (Math.Pow(SpecialFunctions.GeneralHarmonic(_n, _s - 1), 2)/(generalHarmonicsNS*generalHarmonicsNS));
var ghns = SpecialFunctions.GeneralHarmonic(_n, _s);
return (SpecialFunctions.GeneralHarmonic(_n, _s - 2)*SpecialFunctions.GeneralHarmonic(_n, _s))
- (Math.Pow(SpecialFunctions.GeneralHarmonic(_n, _s - 1), 2)/(ghns*ghns));
}
}

7
src/Numerics/Distributions/Multivariate/InverseWishart.cs

@ -136,12 +136,7 @@ namespace MathNet.Numerics.Distributions
}
}
if (nu <= 0.0 || Double.IsNaN(nu))
{
return false;
}
return true;
return nu > 0.0;
}
/// <summary>

9
src/Numerics/Distributions/Multivariate/NormalGamma.cs

@ -159,14 +159,7 @@ namespace MathNet.Numerics.Distributions
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double meanLocation, double meanScale, double precShape, double precInvScale)
{
if (meanScale <= 0.0 || precShape <= 0.0 || precInvScale <= 0.0
|| Double.IsNaN(meanLocation) || Double.IsNaN(meanScale) || Double.IsNaN(precShape)
|| Double.IsNaN(precInvScale))
{
return false;
}
return true;
return (meanScale > 0.0) && (precShape > 0.0) && (precInvScale > 0.0) && !Double.IsNaN(meanLocation);
}
/// <summary>

8
src/Numerics/Financial/AbsoluteReturnMeasures.cs

@ -40,8 +40,6 @@ namespace MathNet.Numerics.Financial
/// <summary>
/// Compound Monthly Return or Geometric Return or Annualized Return
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static double CompoundMonthlyReturn(this IEnumerable<double> data)
{
if (data == null)
@ -58,7 +56,7 @@ namespace MathNet.Numerics.Financial
{
compoundReturn *= (1 + item);
}
return Math.Pow(compoundReturn, 1.0 / (double)samples) - 1.0;
return Math.Pow(compoundReturn, 1.0 / samples) - 1.0;
}
/// <summary>
@ -66,8 +64,6 @@ namespace MathNet.Numerics.Financial
/// This is a simple average (arithmetic mean) of the periods with a gain. It is calculated by summing the returns for gain periods (return 0)
/// and then dividing the total by the number of gain periods.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
/// <remarks>http://www.offshore-library.com/kb/statistics.php</remarks>
public static double GainMean(this IEnumerable<double> data)
{
@ -85,8 +81,6 @@ namespace MathNet.Numerics.Financial
/// This is a simple average (arithmetic mean) of the periods with a loss. It is calculated by summing the returns for loss periods (return &lt; 0)
/// and then dividing the total by the number of loss periods.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
/// <remarks>http://www.offshore-library.com/kb/statistics.php</remarks>
public static double LossMean(this IEnumerable<double> data)
{

11
src/Numerics/Financial/AbsoluteRiskMeasures.cs

@ -49,8 +49,6 @@ namespace MathNet.Numerics.Financial
/// and measures the variation of only the gain periods around the gain mean. Measures the volatility of upside performance.
/// © Copyright 1996, 1999 Gary L.Gastineau. First Edition. © 1992 Swiss Bank Corporation.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static double GainStandardDeviation(this IEnumerable<double> data)
{
if (data == null)
@ -66,8 +64,6 @@ namespace MathNet.Numerics.Financial
/// Similar to standard deviation, except this statistic calculates an average (mean) return for only the periods with a loss and then
/// measures the variation of only the losing periods around this loss mean. This statistic measures the volatility of downside performance.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
/// <remarks>http://www.offshore-library.com/kb/statistics.php</remarks>
public static double LossStandardDeviation(this IEnumerable<double> data)
{
@ -87,9 +83,6 @@ namespace MathNet.Numerics.Financial
/// 7%. (The loss standard deviation, on the other hand, would take only losing periods, calculate an average return for
/// the losing periods, and then measure the variation between each losing return and the losing return average).
/// </summary>
/// <param name="data"></param>
/// <param name="minimalAcceptableReturn"></param>
/// <returns></returns>
public static double DownsideDeviation(this IEnumerable<double> data, double minimalAcceptableReturn)
{
if (data == null)
@ -105,8 +98,6 @@ namespace MathNet.Numerics.Financial
/// A measure of volatility in returns below the mean. It's similar to standard deviation, but it only
/// looks at periods where the investment return was less than average return.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static double SemiDeviation(this IEnumerable<double> data)
{
if (data == null)
@ -123,8 +114,6 @@ namespace MathNet.Numerics.Financial
/// Measures a fund’s average gain in a gain period divided by the fund’s average loss in a losing
/// period. Periods can be monthly or quarterly depending on the data frequency.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static double GainLossRatio(this IEnumerable<double> data)
{
if (data == null)

13
src/Numerics/GlobalizationHelper.cs

@ -56,8 +56,8 @@ namespace MathNet.Numerics
}
return (formatProvider as CultureInfo)
?? (formatProvider.GetFormat(typeof(CultureInfo)) as CultureInfo)
?? CultureInfo.CurrentCulture;
?? (formatProvider.GetFormat(typeof (CultureInfo)) as CultureInfo)
?? CultureInfo.CurrentCulture;
}
/// <summary>
@ -84,8 +84,13 @@ namespace MathNet.Numerics
/// <returns>A <see cref="TextInfo"/> instance.</returns>
internal static TextInfo GetTextInfo(this IFormatProvider formatProvider)
{
return (formatProvider as TextInfo)
?? GetCultureInfo(formatProvider).TextInfo;
if (formatProvider == null)
{
return CultureInfo.CurrentCulture.TextInfo;
}
return (formatProvider.GetFormat(typeof (TextInfo)) as TextInfo)
?? GetCultureInfo(formatProvider).TextInfo;
}
/// <summary>

4
src/Numerics/IntegralTransforms/Algorithms/DiscreteFourierTransform.Bluestein.cs

@ -73,8 +73,8 @@ namespace MathNet.Numerics.IntegralTransforms.Algorithms
// Padding to power of two >= 2N–1 so we can apply Radix-2 FFT.
int m = ((n << 1) - 1).CeilingToPowerOfTwo();
Complex[] b = new Complex[m];
Complex[] a = new Complex[m];
var b = new Complex[m];
var a = new Complex[m];
CommonParallel.Invoke(
() =>

16
src/Numerics/IntegralTransforms/Transform.cs

@ -28,9 +28,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.IntegralTransforms.Algorithms;
namespace MathNet.Numerics.IntegralTransforms
{
using Algorithms;
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
@ -41,10 +42,7 @@ namespace MathNet.Numerics.IntegralTransforms
/// </summary>
public static class Transform
{
/// <summary>
/// Shared internal DET algorithm.
/// </summary>
private static readonly DiscreteFourierTransform _dft = new DiscreteFourierTransform();
private static readonly DiscreteFourierTransform DFT = new DiscreteFourierTransform();
/// <summary>
/// Applies the forward Fast Fourier Transform (FFT) to arbitrary-length sample vectors.
@ -52,7 +50,7 @@ namespace MathNet.Numerics.IntegralTransforms
/// <param name="samples">Sample vector, where the FFT is evaluated in place.</param>
public static void FourierForward(Complex[] samples)
{
_dft.BluesteinForward(samples, FourierOptions.Default);
DFT.BluesteinForward(samples, FourierOptions.Default);
}
/// <summary>
@ -62,7 +60,7 @@ namespace MathNet.Numerics.IntegralTransforms
/// <param name="options">Fourier Transform Convention Options.</param>
public static void FourierForward(Complex[] samples, FourierOptions options)
{
_dft.BluesteinForward(samples, options);
DFT.BluesteinForward(samples, options);
}
/// <summary>
@ -71,7 +69,7 @@ namespace MathNet.Numerics.IntegralTransforms
/// <param name="samples">Sample vector, where the FFT is evaluated in place.</param>
public static void FourierInverse(Complex[] samples)
{
_dft.BluesteinInverse(samples, FourierOptions.Default);
DFT.BluesteinInverse(samples, FourierOptions.Default);
}
/// <summary>
@ -81,7 +79,7 @@ namespace MathNet.Numerics.IntegralTransforms
/// <param name="options">Fourier Transform Convention Options.</param>
public static void FourierInverse(Complex[] samples, FourierOptions options)
{
_dft.BluesteinInverse(samples, options);
DFT.BluesteinInverse(samples, options);
}
}
}

5
src/Numerics/Integration/DoubleExponentialTransformation.cs

@ -119,7 +119,7 @@ namespace MathNet.Numerics.Integration
int length = level == 0 ? 4 : (3 << (level - 1));
double t = 0;
double[] abcissas = new double[length];
var abcissas = new double[length];
for (int i = 0; i < abcissas.Length; i++)
{
double arg = offset + t;
@ -148,7 +148,7 @@ namespace MathNet.Numerics.Integration
int length = level == 0 ? 4 : (3 << (level - 1));
double t = 0;
double[] weights = new double[length];
var weights = new double[length];
for (int i = 0; i < weights.Length; i++)
{
double arg = offset + t;
@ -158,7 +158,6 @@ namespace MathNet.Numerics.Integration
double abcissa = Math.Tanh(Constants.PiOver2*Math.Sinh(arg));
weights[i] = Constants.PiOver2*(1 - (abcissa*abcissa))*Math.Cosh(arg);
}
return weights;
}

8
src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs

@ -127,11 +127,11 @@ namespace MathNet.Numerics.Interpolation
/// <returns>Interpolated value x(t).</returns>
public double Interpolate(double t)
{
const double Tiny = 1.0e-25;
const double tiny = 1.0e-25;
int n = _points.Count;
double[] c = new double[n];
double[] d = new double[n];
var c = new double[n];
var d = new double[n];
int nearestIndex = 0;
double nearestDistance = Math.Abs(t - _points[0]);
@ -151,7 +151,7 @@ namespace MathNet.Numerics.Interpolation
}
c[i] = _values[i];
d[i] = _values[i] + Tiny;
d[i] = _values[i] + tiny;
}
double x = _values[nearestIndex];

11
src/Numerics/Interpolation/CubicSplineInterpolation.cs

@ -206,10 +206,10 @@ namespace MathNet.Numerics.Interpolation
rightBoundary = 0d;
}
double[] a1 = new double[n];
double[] a2 = new double[n];
double[] a3 = new double[n];
double[] b = new double[n];
var a1 = new double[n];
var a2 = new double[n];
var a3 = new double[n];
var b = new double[n];
// Left Boundary
switch (leftBoundaryCondition)
@ -307,8 +307,6 @@ namespace MathNet.Numerics.Interpolation
/// <returns>The x-vector[n]</returns>
static double[] SolveTridiagonal(double[] a, double[] b, double[] c, double[] d)
{
double[] x = new double[a.Length];
for (int k = 1; k < a.Length; k++)
{
double t = a[k]/b[k - 1];
@ -316,6 +314,7 @@ namespace MathNet.Numerics.Interpolation
d[k] = d[k] - (t*d[k - 1]);
}
var x = new double[a.Length];
x[x.Length - 1] = d[d.Length - 1]/b[b.Length - 1];
for (int k = x.Length - 2; k >= 0; k--)
{

9
src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs

@ -173,15 +173,15 @@ namespace MathNet.Numerics.Interpolation
throw new ArgumentOutOfRangeException("order");
}
double[] sortedWeights = new double[sampleValues.Count];
double[] sortedPoints = new double[samplePoints.Count];
var sortedWeights = new double[sampleValues.Count];
var sortedPoints = new double[samplePoints.Count];
samplePoints.CopyTo(sortedPoints, 0);
// order: odd -> negative, even -> positive
double sign = ((order & 0x1) == 0x1) ? -1.0 : 1.0;
// init permutation vector
int[] perm = new int[sortedWeights.Length];
var perm = new int[sortedWeights.Length];
for (int i = 0; i < perm.Length; i++)
{
perm[i] = i;
@ -227,12 +227,11 @@ namespace MathNet.Numerics.Interpolation
}
// reorder back to original order, based on the permutation vector.
double[] weights = new double[sortedWeights.Length];
var weights = new double[sortedWeights.Length];
for (int i = 0; i < weights.Length; i++)
{
weights[perm[i]] = sortedWeights[i];
}
return weights;
}

4
src/Numerics/Interpolation/LinearSplineInterpolation.cs

@ -129,8 +129,7 @@ namespace MathNet.Numerics.Interpolation
if (samplePoints[i] <= samplePoints[i - 1])
throw new ArgumentException(Resources.Interpolation_Initialize_SamplePointsNotStrictlyAscendingOrder, "samplePoints");
double[] coefficients = new double[4*(samplePoints.Count - 1)];
var coefficients = new double[4*(samplePoints.Count - 1)];
for (int i = 0, j = 0; i < samplePoints.Count - 1; i++, j += 4)
{
coefficients[j] = sampleValues[i];
@ -138,7 +137,6 @@ namespace MathNet.Numerics.Interpolation
coefficients[j + 2] = 0;
coefficients[j + 3] = 0;
}
return coefficients;
}

2
src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs

@ -403,7 +403,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
var diagResult = result as DiagonalMatrix;
if (diagResult == null)
{
base.Multiply(scalar, result);
base.DoMultiply(scalar, result);
}
else
{

4
src/Numerics/LinearAlgebra/Complex/Factorization/DenseEvd.cs

@ -235,7 +235,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
/// <exception cref="NonConvergenceException"></exception>
internal static void SymmetricDiagonalize(Complex[] dataEv, double[] d, double[] e, int order)
{
const int Maxiter = 1000;
const int maxiter = 1000;
for (var i = 1; i < order; i++)
{
@ -329,7 +329,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
// Check for convergence. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}

4
src/Numerics/LinearAlgebra/Complex/Factorization/UserEvd.cs

@ -255,7 +255,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
/// <exception cref="NonConvergenceException"></exception>
private void SymmetricDiagonalize(double[] d, double[] e, int order)
{
const int Maxiter = 1000;
const int maxiter = 1000;
for (var i = 1; i < order; i++)
{
@ -349,7 +349,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
// Check for convergence. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}

18
src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs

@ -79,14 +79,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
MatrixU = matrixCopy.CreateMatrix(matrixCopy.RowCount, matrixCopy.RowCount);
MatrixVT = matrixCopy.CreateMatrix(matrixCopy.ColumnCount, matrixCopy.ColumnCount);
const int Maxiter = 1000;
const int maxiter = 1000;
var e = new Complex[matrixCopy.ColumnCount];
var work = new Complex[matrixCopy.RowCount];
int i, j;
int l, lp1;
var cs = 0.0;
var sn = 0.0;
Complex t;
var ncu = matrixCopy.RowCount;
@ -360,7 +358,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
{
// Quit if all the singular values have been found. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}
@ -433,6 +431,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
// Perform the task indicated by kase.
int k;
double f;
double cs;
double sn;
switch (kase)
{
// Deflate negligible VectorS[m].
@ -444,7 +444,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
{
k = m - 2 - kk + l;
t1 = VectorS[k].Real;
Srotg(ref t1, ref f, ref cs, ref sn);
Srotg(ref t1, ref f, out cs, out sn);
VectorS[k] = t1;
if (k != l)
{
@ -467,7 +467,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
for (k = l; k < m; k++)
{
t1 = VectorS[k].Real;
Srotg(ref t1, ref f, ref cs, ref sn);
Srotg(ref t1, ref f, out cs, out sn);
VectorS[k] = t1;
f = -sn * e[k].Real;
e[k] = cs * e[k];
@ -514,7 +514,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
// Chase zeros.
for (k = l; k < m - 1; k++)
{
Srotg(ref f, ref g, ref cs, ref sn);
Srotg(ref f, ref g, out cs, out sn);
if (k != l)
{
e[k - 1] = f;
@ -529,7 +529,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
Csrot(MatrixVT, matrixCopy.ColumnCount, k, k + 1, cs, sn);
}
Srotg(ref f, ref g, ref cs, ref sn);
Srotg(ref f, ref g, out cs, out sn);
VectorS[k] = f;
f = (cs * e[k].Real) + (sn * VectorS[k + 1].Real);
VectorS[k + 1] = (-sn * e[k]) + (cs * VectorS[k + 1]);
@ -675,7 +675,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
/// <param name="c">Contains the parameter c associated with the Givens rotation</param>
/// <param name="s">Contains the parameter s associated with the Givens rotation</param>
/// <remarks>This is equivalent to the DROTG LAPACK routine.</remarks>
private static void Srotg(ref double da, ref double db, ref double c, ref double s)
private static void Srotg(ref double da, ref double db, out double c, out double s)
{
double r, z;

2
src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs

@ -44,7 +44,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
/// This sort algorithm is used to sort the columns in a sparse matrix based on
/// the value of the element on the diagonal of the matrix.
/// </remarks>
internal class IlutpElementSorter
internal static class IlutpElementSorter
{
/// <summary>
/// Sorts the elements of the <paramref name="values"/> vector in decreasing

1
src/Numerics/LinearAlgebra/Complex/SparseVector.cs

@ -33,7 +33,6 @@ using MathNet.Numerics.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace MathNet.Numerics.LinearAlgebra.Complex
{

2
src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs

@ -398,7 +398,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
var diagResult = result as DiagonalMatrix;
if (diagResult == null)
{
base.Multiply(scalar, result);
base.DoMultiply(scalar, result);
}
else
{

4
src/Numerics/LinearAlgebra/Complex32/Factorization/DenseEvd.cs

@ -228,7 +228,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
/// <exception cref="NonConvergenceException"></exception>
internal static void SymmetricDiagonalize(Numerics.Complex32[] dataEv, float[] d, float[] e, int order)
{
const int Maxiter = 1000;
const int maxiter = 1000;
for (var i = 1; i < order; i++)
{
@ -322,7 +322,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
// Check for convergence. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}

4
src/Numerics/LinearAlgebra/Complex32/Factorization/UserEvd.cs

@ -257,7 +257,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
/// <exception cref="NonConvergenceException"></exception>
private void SymmetricDiagonalize(float[] d, float[] e, int order)
{
const int Maxiter = 1000;
const int maxiter = 1000;
for (var i = 1; i < order; i++)
{
@ -351,7 +351,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
// Check for convergence. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}

18
src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs

@ -74,14 +74,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
MatrixU = matrixCopy.CreateMatrix(matrixCopy.RowCount, matrixCopy.RowCount);
MatrixVT = matrixCopy.CreateMatrix(matrixCopy.ColumnCount, matrixCopy.ColumnCount);
const int Maxiter = 1000;
const int maxiter = 1000;
var e = new Complex32[matrixCopy.ColumnCount];
var work = new Complex32[matrixCopy.RowCount];
int i, j;
int l, lp1;
var cs = 0.0f;
var sn = 0.0f;
Complex32 t;
var ncu = matrixCopy.RowCount;
@ -355,7 +353,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
{
// Quit if all the singular values have been found. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}
@ -428,6 +426,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
// Perform the task indicated by kase.
int k;
float f;
float sn;
float cs;
switch (kase)
{
// Deflate negligible VectorS[m].
@ -439,7 +439,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
{
k = m - 2 - kk + l;
t1 = VectorS[k].Real;
Srotg(ref t1, ref f, ref cs, ref sn);
Srotg(ref t1, ref f, out cs, out sn);
VectorS[k] = t1;
if (k != l)
{
@ -462,7 +462,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
for (k = l; k < m; k++)
{
t1 = VectorS[k].Real;
Srotg(ref t1, ref f, ref cs, ref sn);
Srotg(ref t1, ref f, out cs, out sn);
VectorS[k] = t1;
f = -sn * e[k].Real;
e[k] = cs * e[k];
@ -509,7 +509,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
// Chase zeros.
for (k = l; k < m - 1; k++)
{
Srotg(ref f, ref g, ref cs, ref sn);
Srotg(ref f, ref g, out cs, out sn);
if (k != l)
{
e[k - 1] = f;
@ -524,7 +524,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
Csrot(MatrixVT, matrixCopy.ColumnCount, k, k + 1, cs, sn);
}
Srotg(ref f, ref g, ref cs, ref sn);
Srotg(ref f, ref g, out cs, out sn);
VectorS[k] = f;
f = (cs * e[k].Real) + (sn * VectorS[k + 1].Real);
VectorS[k + 1] = (-sn * e[k]) + (cs * VectorS[k + 1]);
@ -670,7 +670,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
/// <param name="c">Contains the parameter c associated with the Givens rotation</param>
/// <param name="s">Contains the parameter s associated with the Givens rotation</param>
/// <remarks>This is equivalent to the DROTG LAPACK routine.</remarks>
private static void Srotg(ref float da, ref float db, ref float c, ref float s)
private static void Srotg(ref float da, ref float db, out float c, out float s)
{
float r, z;

2
src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs

@ -37,7 +37,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
/// This sort algorithm is used to sort the columns in a sparse matrix based on
/// the value of the element on the diagonal of the matrix.
/// </remarks>
internal class IlutpElementSorter
internal static class IlutpElementSorter
{
/// <summary>
/// Sorts the elements of the <paramref name="values"/> vector in decreasing

1
src/Numerics/LinearAlgebra/Complex32/SparseVector.cs

@ -33,7 +33,6 @@ using MathNet.Numerics.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace MathNet.Numerics.LinearAlgebra.Complex32
{

4
src/Numerics/LinearAlgebra/Double/Factorization/UserEvd.cs

@ -297,7 +297,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
/// <exception cref="NonConvergenceException"></exception>
private void SymmetricDiagonalize(double[] d, double[] e, int order)
{
const int Maxiter = 1000;
const int maxiter = 1000;
for (var i = 1; i < order; i++)
{
@ -391,7 +391,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
// Check for convergence. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}

18
src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs

@ -72,14 +72,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
MatrixU = matrixCopy.CreateMatrix(matrixCopy.RowCount, matrixCopy.RowCount);
MatrixVT = matrixCopy.CreateMatrix(matrixCopy.ColumnCount, matrixCopy.ColumnCount);
const int Maxiter = 1000;
const int maxiter = 1000;
var e = new double[matrixCopy.ColumnCount];
var work = new double[matrixCopy.RowCount];
int i, j;
int l, lp1;
var cs = 0.0;
var sn = 0.0;
double t;
var ncu = matrixCopy.RowCount;
@ -339,7 +337,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
{
// Quit if all the singular values have been found. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}
@ -412,6 +410,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
// Perform the task indicated by kase.
int k;
double f;
double sn;
double cs;
switch (kase)
{
// Deflate negligible VectorS[m].
@ -423,7 +423,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
{
k = m - 2 - kk + l;
t1 = VectorS[k];
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
VectorS[k] = t1;
if (k != l)
{
@ -446,7 +446,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
for (k = l; k < m; k++)
{
t1 = VectorS[k];
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
VectorS[k] = t1;
f = -sn * e[k];
e[k] = cs * e[k];
@ -492,7 +492,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
// Chase zeros.
for (k = l; k < m - 1; k++)
{
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
if (k != l)
{
e[k - 1] = f;
@ -507,7 +507,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
Drot(MatrixVT, matrixCopy.ColumnCount, k, k + 1, cs, sn);
}
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
VectorS[k] = f;
f = (cs * e[k]) + (sn * VectorS[k + 1]);
VectorS[k + 1] = (-sn * e[k]) + (cs * VectorS[k + 1]);
@ -653,7 +653,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
/// <param name="c">Contains the parameter c associated with the Givens rotation</param>
/// <param name="s">Contains the parameter s associated with the Givens rotation</param>
/// <remarks>This is equivalent to the DROTG LAPACK routine.</remarks>
private static void Drotg(ref double da, ref double db, ref double c, ref double s)
private static void Drotg(ref double da, ref double db, out double c, out double s)
{
double r, z;

2
src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs

@ -37,7 +37,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
/// This sort algorithm is used to sort the columns in a sparse matrix based on
/// the value of the element on the diagonal of the matrix.
/// </remarks>
internal class IlutpElementSorter
internal static class IlutpElementSorter
{
/// <summary>
/// Sorts the elements of the <paramref name="values"/> vector in decreasing

2
src/Numerics/LinearAlgebra/Factorization/Cholesky.cs

@ -99,7 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Factorization
return new LinearAlgebra.Complex32.Factorization.DenseCholesky(dense) as Cholesky<T>;
}
return new LinearAlgebra.Complex32.Factorization.UserCholesky(matrix as Matrix<Numerics.Complex32>) as Cholesky<T>;
return new LinearAlgebra.Complex32.Factorization.UserCholesky(matrix as Matrix<Complex32>) as Cholesky<T>;
}
throw new NotSupportedException();

2
src/Numerics/LinearAlgebra/Factorization/Evd.cs

@ -167,7 +167,7 @@ namespace MathNet.Numerics.LinearAlgebra.Factorization
return new LinearAlgebra.Complex32.Factorization.DenseEvd(dense) as Evd<T>;
}
return new LinearAlgebra.Complex32.Factorization.UserEvd(matrix as Matrix<Numerics.Complex32>) as Evd<T>;
return new LinearAlgebra.Complex32.Factorization.UserEvd(matrix as Matrix<Complex32>) as Evd<T>;
}
throw new NotSupportedException();

2
src/Numerics/LinearAlgebra/Matrix.BCL.cs

@ -213,7 +213,7 @@ namespace MathNet.Numerics.LinearAlgebra
/// </summary>
public override sealed string ToString()
{
return string.Concat(ToTypeString(), Environment.NewLine, ToMatrixString(Control.MaxToStringRows, Control.MaxToStringColumns, null));
return string.Concat(ToTypeString(), Environment.NewLine, ToMatrixString(Control.MaxToStringRows, Control.MaxToStringColumns));
}
/// <summary>

2
src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs

@ -397,7 +397,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
var diagResult = result as DiagonalMatrix;
if (diagResult == null)
{
base.Multiply(scalar, result);
base.DoMultiply(scalar, result);
}
else
{

6
src/Numerics/LinearAlgebra/Single/Factorization/DenseEvd.cs

@ -264,7 +264,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
/// <exception cref="NonConvergenceException"></exception>
internal static void SymmetricDiagonalize(float[] a, float[] d, float[] e, int order)
{
const int Maxiter = 1000;
const int maxiter = 1000;
for (var i = 1; i < order; i++)
{
@ -358,7 +358,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
// Check for convergence. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}
@ -1038,7 +1038,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
var vi = (d[i] - p)*2.0f*q;
if ((vr == 0.0f) && (vi == 0.0f))
{
vr = eps*norm*(float) (Math.Abs(w) + Math.Abs(q) + Math.Abs(x) + Math.Abs(y) + Math.Abs(z));
vr = eps*norm*(Math.Abs(w) + Math.Abs(q) + Math.Abs(x) + Math.Abs(y) + Math.Abs(z));
}
var res = Cdiv((x*r) - (z*ra) + (q*sa), (x*s) - (z*sa) - (q*ra), vr, vi);

4
src/Numerics/LinearAlgebra/Single/Factorization/UserEvd.cs

@ -296,7 +296,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
/// <exception cref="NonConvergenceException"></exception>
private void SymmetricDiagonalize(float[] d, float[] e, int order)
{
const int Maxiter = 1000;
const int maxiter = 1000;
for (var i = 1; i < order; i++)
{
@ -390,7 +390,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
// Check for convergence. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}

18
src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs

@ -72,14 +72,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
MatrixU = matrixCopy.CreateMatrix(matrixCopy.RowCount, matrixCopy.RowCount);
MatrixVT = matrixCopy.CreateMatrix(matrixCopy.ColumnCount, matrixCopy.ColumnCount);
const int Maxiter = 1000;
const int maxiter = 1000;
var e = new float[matrixCopy.ColumnCount];
var work = new float[matrixCopy.RowCount];
int i, j;
int l, lp1;
var cs = 0.0f;
var sn = 0.0f;
float t;
var ncu = matrixCopy.RowCount;
@ -339,7 +337,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
{
// Quit if all the singular values have been found. If too many iterations have been performed,
// throw exception that Convergence Failed
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}
@ -412,6 +410,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
// Perform the task indicated by kase.
int k;
float f;
float sn;
float cs;
switch (kase)
{
// Deflate negligible VectorS[m].
@ -423,7 +423,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
{
k = m - 2 - kk + l;
t1 = VectorS[k];
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
VectorS[k] = t1;
if (k != l)
{
@ -446,7 +446,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
for (k = l; k < m; k++)
{
t1 = VectorS[k];
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
VectorS[k] = t1;
f = -sn * e[k];
e[k] = cs * e[k];
@ -492,7 +492,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
// Chase zeros.
for (k = l; k < m - 1; k++)
{
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
if (k != l)
{
e[k - 1] = f;
@ -507,7 +507,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
Drot(MatrixVT, matrixCopy.ColumnCount, k, k + 1, cs, sn);
}
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
VectorS[k] = f;
f = (cs * e[k]) + (sn * VectorS[k + 1]);
VectorS[k + 1] = (-sn * e[k]) + (cs * VectorS[k + 1]);
@ -653,7 +653,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
/// <param name="c">Contains the parameter c associated with the Givens rotation</param>
/// <param name="s">Contains the parameter s associated with the Givens rotation</param>
/// <remarks>This is equivalent to the DROTG LAPACK routine.</remarks>
private static void Drotg(ref float da, ref float db, ref float c, ref float s)
private static void Drotg(ref float da, ref float db, out float c, out float s)
{
float r, z;

2
src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs

@ -37,7 +37,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
/// This sort algorithm is used to sort the columns in a sparse matrix based on
/// the value of the element on the diagonal of the matrix.
/// </remarks>
internal class IlutpElementSorter
internal static class IlutpElementSorter
{
/// <summary>
/// Sorts the elements of the <paramref name="values"/> vector in decreasing

4
src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

@ -1116,9 +1116,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single
var lastRow = rowPointers.Length - 1;
if (rowPointers[lastRow] < NonZerosCount)
if (rowPointers[lastRow] < valueCount)
{
for (var index = rowPointers[lastRow]; index < NonZerosCount; index++)
for (var index = rowPointers[lastRow]; index < valueCount; index++)
{
yield return new Tuple<int, int, float>(lastRow, columnIndices[index], values[index]);
}

1
src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs

@ -30,7 +30,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics.LinearAlgebra.Storage

2
src/Numerics/LinearAlgebra/Vector.BCL.cs

@ -336,7 +336,7 @@ namespace MathNet.Numerics.LinearAlgebra
/// </summary>
public override sealed string ToString()
{
return string.Concat(ToTypeString(), Environment.NewLine, ToVectorString(Control.MaxToStringRows, Control.MaxToStringColumns, null));
return string.Concat(ToTypeString(), Environment.NewLine, ToVectorString(Control.MaxToStringRows, Control.MaxToStringColumns));
}
/// <summary>

8
src/Numerics/NumberTheory/IntegerTheory.cs

@ -111,8 +111,8 @@ namespace MathNet.Numerics.NumberTheory
return 0;
}
const int MaxPowerOfTwo = 0x40000000;
if (number > MaxPowerOfTwo)
const int maxPowerOfTwo = 0x40000000;
if (number > maxPowerOfTwo)
{
throw new ArgumentOutOfRangeException("number");
}
@ -140,8 +140,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");
}

3
src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs

@ -100,7 +100,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
/// <summary>
/// Interface to linear algebra algorithms that work off 1-D arrays.
/// </summary>
/// <typeparam name="T">Supported data types are double, single, Complex, and Complex32.</typeparam>
/// <typeparam name="T">Supported data types are Double, Single, Complex, and Complex32.</typeparam>
/// <typeparam name="TNorm">Supported data types are Double and Single, must correspond to T.</typeparam>
public interface ILinearAlgebraProvider<T, TNorm>
where T : struct
where TNorm : struct

20
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs

@ -1689,12 +1689,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
if (a == null)
{
throw new ArgumentNullException("q");
throw new ArgumentNullException("a");
}
if (work == null)
{
throw new ArgumentNullException("q");
throw new ArgumentNullException("work");
}
if (a.Length != rowsA*columnsA)
@ -2236,7 +2236,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
throw new ArgumentException(Resources.WorkArrayTooSmall, "work");
}
const int Maxiter = 1000;
const int maxiter = 1000;
var e = new Complex[columnsA];
var v = new Complex[vt.Length];
@ -2244,8 +2244,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
int i, j, l, lp1;
var cs = 0.0;
var sn = 0.0;
Complex t;
var ncu = rowsA;
@ -2566,7 +2564,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
// Quit if all the singular values have been found.
// If too many iterations have been performed throw exception.
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}
@ -2639,6 +2637,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
// Perform the task indicated by kase.
int k;
double f;
double cs;
double sn;
switch (kase)
{
// Deflate negligible s[m].
@ -2650,7 +2650,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
k = m - 2 - kk + l;
t1 = stemp[k].Real;
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
stemp[k] = t1;
if (k != l)
{
@ -2679,7 +2679,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
for (k = l; k < m; k++)
{
t1 = stemp[k].Real;
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
stemp[k] = t1;
f = -sn*e[k].Real;
e[k] = cs*e[k];
@ -2731,7 +2731,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
// Chase zeros
for (k = l; k < m - 1; k++)
{
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
if (k != l)
{
e[k - 1] = f;
@ -2751,7 +2751,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
}
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
stemp[k] = f;
f = (cs*e[k].Real) + (sn*stemp[k + 1].Real);
stemp[k + 1] = -(sn*e[k]) + (cs*stemp[k + 1]);

20
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs

@ -1687,12 +1687,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
if (a == null)
{
throw new ArgumentNullException("q");
throw new ArgumentNullException("a");
}
if (work == null)
{
throw new ArgumentNullException("q");
throw new ArgumentNullException("work");
}
if (a.Length != rowsA*columnsA)
@ -2234,7 +2234,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
throw new ArgumentException(Resources.WorkArrayTooSmall, "work");
}
const int Maxiter = 1000;
const int maxiter = 1000;
var e = new Complex32[columnsA];
var v = new Complex32[vt.Length];
@ -2242,8 +2242,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
int i, j, l, lp1;
var cs = 0.0f;
var sn = 0.0f;
Complex32 t;
var ncu = rowsA;
@ -2564,7 +2562,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
// Quit if all the singular values have been found.
// If too many iterations have been performed throw exception.
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}
@ -2637,6 +2635,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
// Perform the task indicated by kase.
int k;
float f;
float sn;
float cs;
switch (kase)
{
// Deflate negligible s[m].
@ -2648,7 +2648,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
k = m - 2 - kk + l;
t1 = stemp[k].Real;
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
stemp[k] = t1;
if (k != l)
{
@ -2677,7 +2677,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
for (k = l; k < m; k++)
{
t1 = stemp[k].Real;
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
stemp[k] = t1;
f = -sn*e[k].Real;
e[k] = cs*e[k];
@ -2729,7 +2729,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
// Chase zeros
for (k = l; k < m - 1; k++)
{
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
if (k != l)
{
e[k - 1] = f;
@ -2749,7 +2749,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
}
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
stemp[k] = f;
f = (cs*e[k].Real) + (sn*stemp[k + 1].Real);
stemp[k + 1] = -(sn*e[k]) + (cs*stemp[k + 1]);

22
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs

@ -1575,12 +1575,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
if (a == null)
{
throw new ArgumentNullException("q");
throw new ArgumentNullException("a");
}
if (work == null)
{
throw new ArgumentNullException("q");
throw new ArgumentNullException("work");
}
if (a.Length != rowsA*columnsA)
@ -2122,7 +2122,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
throw new ArgumentException(Resources.WorkArrayTooSmall, "work");
}
const int Maxiter = 1000;
const int maxiter = 1000;
var e = new double[columnsA];
var v = new double[vt.Length];
@ -2130,8 +2130,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
int i, j, l, lp1;
var cs = 0.0;
var sn = 0.0;
double t;
var ncu = rowsA;
@ -2454,7 +2452,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
// Quit if all the singular values have been found.
// If too many iterations have been performed throw exception.
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}
@ -2527,6 +2525,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
// Perform the task indicated by kase.
int k;
double f;
double cs;
double sn;
switch (kase)
{
// Deflate negligible s[m].
@ -2539,7 +2539,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
k = m - 2 - kk + l;
t1 = stemp[k];
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
stemp[k] = t1;
if (k != l)
{
@ -2568,7 +2568,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
for (k = l; k < m; k++)
{
t1 = stemp[k];
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
stemp[k] = t1;
f = -sn*e[k];
e[k] = cs*e[k];
@ -2621,7 +2621,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
// Chase zeros
for (k = l; k < m - 1; k++)
{
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
if (k != l)
{
e[k - 1] = f;
@ -2641,7 +2641,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
}
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
stemp[k] = f;
f = (cs*e[k]) + (sn*stemp[k + 1]);
stemp[k + 1] = -(sn*e[k]) + (cs*stemp[k + 1]);
@ -2752,7 +2752,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
/// <param name="c">Contains the parameter c associated with the Givens rotation</param>
/// <param name="s">Contains the parameter s associated with the Givens rotation</param>
/// <remarks>This is equivalent to the DROTG LAPACK routine.</remarks>
static void Drotg(ref double da, ref double db, ref double c, ref double s)
static void Drotg(ref double da, ref double db, out double c, out double s)
{
double r, z;

22
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs

@ -1575,12 +1575,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
if (a == null)
{
throw new ArgumentNullException("q");
throw new ArgumentNullException("a");
}
if (work == null)
{
throw new ArgumentNullException("q");
throw new ArgumentNullException("work");
}
if (a.Length != rowsA*columnsA)
@ -2122,7 +2122,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
throw new ArgumentException(Resources.WorkArrayTooSmall, "work");
}
const int Maxiter = 1000;
const int maxiter = 1000;
var e = new float[columnsA];
var v = new float[vt.Length];
@ -2130,8 +2130,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
int i, j, l, lp1;
var cs = 0.0f;
var sn = 0.0f;
float t;
var ncu = rowsA;
@ -2456,7 +2454,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
// Quit if all the singular values have been found.
// If too many iterations have been performed throw exception.
if (iter >= Maxiter)
if (iter >= maxiter)
{
throw new NonConvergenceException();
}
@ -2529,6 +2527,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
// Perform the task indicated by kase.
int k;
float f;
float cs;
float sn;
switch (kase)
{
// Deflate negligible s[m].
@ -2541,7 +2541,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
k = m - 2 - kk + l;
t1 = stemp[k];
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
stemp[k] = t1;
if (k != l)
{
@ -2570,7 +2570,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
for (k = l; k < m; k++)
{
t1 = stemp[k];
Drotg(ref t1, ref f, ref cs, ref sn);
Drotg(ref t1, ref f, out cs, out sn);
stemp[k] = t1;
f = -sn*e[k];
e[k] = cs*e[k];
@ -2623,7 +2623,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
// Chase zeros
for (k = l; k < m - 1; k++)
{
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
if (k != l)
{
e[k - 1] = f;
@ -2643,7 +2643,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
}
Drotg(ref f, ref g, ref cs, ref sn);
Drotg(ref f, ref g, out cs, out sn);
stemp[k] = f;
f = (cs*e[k]) + (sn*stemp[k + 1]);
stemp[k + 1] = -(sn*e[k]) + (cs*stemp[k + 1]);
@ -2754,7 +2754,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
/// <param name="c">Contains the parameter c associated with the Givens rotation</param>
/// <param name="s">Contains the parameter s associated with the Givens rotation</param>
/// <remarks>This is equivalent to the DROTG LAPACK routine.</remarks>
static void Drotg(ref float da, ref float db, ref float c, ref float s)
static void Drotg(ref float da, ref float db, out float c, out float s)
{
float r, z;

3
src/Numerics/Random/AbstractRandomNumberGenerator.cs

@ -28,10 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.Properties;
namespace MathNet.Numerics.Random
{
using System;
using Properties;
/// <summary>
/// Abstract class for random number generators. This class introduces a layer between <see cref="System.Random"/>

18
src/Numerics/Random/Mcg31m1.cs

@ -28,18 +28,18 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics.Random
{
using System;
/// <summary>
/// Multiplicative congruential generator using a modulus of 2^31-1 and a multiplier of 1132489760.
/// </summary>
public partial class Mcg31m1 : AbstractRandomNumberGenerator
public class Mcg31m1 : AbstractRandomNumberGenerator
{
private const ulong _modulus = 2147483647;
private const ulong _multiplier = 1132489760;
private const double _reciprocal = 1.0 / _modulus;
private const ulong Modulus = 2147483647;
private const ulong Multiplier = 1132489760;
private const double Reciprocal = 1.0 / Modulus;
private ulong _xn;
/// <summary>
@ -82,7 +82,7 @@ namespace MathNet.Numerics.Random
{
seed = 1;
}
_xn = (uint) seed%_modulus;
_xn = (uint) seed%Modulus;
}
/// <summary>
@ -93,8 +93,8 @@ namespace MathNet.Numerics.Random
/// </returns>
protected override double DoSample()
{
double ret = _xn*_reciprocal;
_xn = (_xn*_multiplier)%_modulus;
double ret = _xn*Reciprocal;
_xn = (_xn*Multiplier)%Modulus;
return ret;
}
}

18
src/Numerics/Random/Mcg59.cs

@ -28,18 +28,18 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics.Random
{
using System;
/// <summary>
/// Multiplicative congruential generator using a modulus of 2^59 and a multiplier of 13^13.
/// </summary>
public partial class Mcg59 : AbstractRandomNumberGenerator
public class Mcg59 : AbstractRandomNumberGenerator
{
private const double _reciprocal = 1.0 / _modulus;
private const ulong _modulus = 576460752303423488;
private const ulong _multiplier = 302875106592253;
private const double Reciprocal = 1.0 / Modulus;
private const ulong Modulus = 576460752303423488;
private const ulong Multiplier = 302875106592253;
private ulong _xn;
/// <summary>
@ -83,7 +83,7 @@ namespace MathNet.Numerics.Random
{
seed = 1;
}
_xn = (uint) seed % _modulus;
_xn = (uint) seed % Modulus;
}
/// <summary>
@ -94,8 +94,8 @@ namespace MathNet.Numerics.Random
/// </returns>
protected override double DoSample()
{
double ret = _xn * _reciprocal;
_xn = (_xn * _multiplier) % _modulus;
double ret = _xn * Reciprocal;
_xn = (_xn * Multiplier) % Modulus;
return ret;
}
}

52
src/Numerics/Random/MersenneTwister.cs

@ -66,10 +66,10 @@
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
*/
using System;
namespace MathNet.Numerics.Random
{
using System;
/// <summary>
/// Random number generator using Mersenne Twister 19937 algorithm.
/// </summary>
@ -78,37 +78,37 @@ namespace MathNet.Numerics.Random
/// <summary>
/// Mersenne twister constant.
/// </summary>
private const uint _lower_mask = 0x7fffffff;
private const uint LowerMask = 0x7fffffff;
/// <summary>
/// Mersenne twister constant.
/// </summary>
private const int _m = 397;
private const int M = 397;
/// <summary>
/// Mersenne twister constant.
/// </summary>
private const uint _matrix_a = 0x9908b0df;
private const uint MatrixA = 0x9908b0df;
/// <summary>
/// Mersenne twister constant.
/// </summary>
private const int _n = 624;
private const int N = 624;
/// <summary>
/// Mersenne twister constant.
/// </summary>
private const double _reciprocal = 1.0/4294967296.0;
private const double Reciprocal = 1.0/4294967296.0;
/// <summary>
/// Mersenne twister constant.
/// </summary>
private const uint _upper_mask = 0x80000000;
private const uint UpperMask = 0x80000000;
/// <summary>
/// Mersenne twister constant.
/// </summary>
private static readonly uint[] _mag01 = {0x0U, _matrix_a};
private static readonly uint[] Mag01 = {0x0U, MatrixA};
/// <summary>
/// Mersenne twister constant.
@ -118,7 +118,7 @@ namespace MathNet.Numerics.Random
/// <summary>
/// Mersenne twister constant.
/// </summary>
private int mti = _n + 1;
private int _mti = N + 1;
/// <summary>
/// Initializes a new instance of the <see cref="MersenneTwister"/> class using
@ -183,14 +183,14 @@ namespace MathNet.Numerics.Random
private void init_genrand(uint s)
{
_mt[0] = s & 0xffffffff;
for (mti = 1; mti < _n; mti++)
for (_mti = 1; _mti < N; _mti++)
{
_mt[mti] = (1812433253*(_mt[mti - 1] ^ (_mt[mti - 1] >> 30)) + (uint) mti);
_mt[_mti] = (1812433253*(_mt[_mti - 1] ^ (_mt[_mti - 1] >> 30)) + (uint) _mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array _mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
_mt[mti] &= 0xffffffff;
_mt[_mti] &= 0xffffffff;
/* for >32 bit machines */
}
}
@ -243,31 +243,31 @@ namespace MathNet.Numerics.Random
/* mag01[x] = x * MATRIX_A for x=0,1 */
if (mti >= _n)
if (_mti >= N)
{
/* generate _n words at one time */
int kk;
if (mti == _n + 1) /* if init_genrand() has not been called, */
if (_mti == N + 1) /* if init_genrand() has not been called, */
init_genrand(5489); /* a default initial seed is used */
for (kk = 0; kk < _n - _m; kk++)
for (kk = 0; kk < N - M; kk++)
{
y = (_mt[kk] & _upper_mask) | (_mt[kk + 1] & _lower_mask);
_mt[kk] = _mt[kk + _m] ^ (y >> 1) ^ _mag01[y & 0x1];
y = (_mt[kk] & UpperMask) | (_mt[kk + 1] & LowerMask);
_mt[kk] = _mt[kk + M] ^ (y >> 1) ^ Mag01[y & 0x1];
}
for (; kk < _n - 1; kk++)
for (; kk < N - 1; kk++)
{
y = (_mt[kk] & _upper_mask) | (_mt[kk + 1] & _lower_mask);
_mt[kk] = _mt[kk + (_m - _n)] ^ (y >> 1) ^ _mag01[y & 0x1];
y = (_mt[kk] & UpperMask) | (_mt[kk + 1] & LowerMask);
_mt[kk] = _mt[kk + (M - N)] ^ (y >> 1) ^ Mag01[y & 0x1];
}
y = (_mt[_n - 1] & _upper_mask) | (_mt[0] & _lower_mask);
_mt[_n - 1] = _mt[_m - 1] ^ (y >> 1) ^ _mag01[y & 0x1];
y = (_mt[N - 1] & UpperMask) | (_mt[0] & LowerMask);
_mt[N - 1] = _mt[M - 1] ^ (y >> 1) ^ Mag01[y & 0x1];
mti = 0;
_mti = 0;
}
y = _mt[mti++];
y = _mt[_mti++];
/* Tempering */
y ^= (y >> 11);
@ -286,7 +286,7 @@ namespace MathNet.Numerics.Random
/// </returns>
protected override double DoSample()
{
return genrand_int32() * _reciprocal;
return genrand_int32() * Reciprocal;
}
/* /// <summary>

55
src/Numerics/Random/Mrg32k3a.cs

@ -28,16 +28,31 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics.Random
{
using System;
/// <summary>
/// A 32-bit combined multiple recursive generator with 2 components of order 3.
/// </summary>
///<remarks>Based off of P. L'Ecuyer, "Combined Multiple Recursive Random Number Generators," Operations Research, 44, 5 (1996), 816--822. </remarks>
public partial class Mrg32k3a : AbstractRandomNumberGenerator
public class Mrg32k3a : AbstractRandomNumberGenerator
{
private const double A12 = 1403580;
private const double A13 = 810728;
private const double A21 = 527612;
private const double A23 = 1370589;
private const double Modulus1 = 4294967087;
private const double Modulus2 = 4294944443;
private const double Reciprocal = 1.0 / Modulus1;
private double _xn1 = 1;
private double _xn2 = 1;
private double _xn3;
private double _yn1 = 1;
private double _yn2 = 1;
private double _yn3 = 1;
/// <summary>
/// Initializes a new instance of the <see cref="Mcg31m1"/> class using
/// the current time as the seed.
@ -57,20 +72,6 @@ namespace MathNet.Numerics.Random
public Mrg32k3a(bool threadSafe) : this((int)DateTime.Now.Ticks, threadSafe)
{
}
private const double _a12 = 1403580;
private const double _a13 = 810728;
private const double _a21 = 527612;
private const double _a23 = 1370589;
private const double _modulus1 = 4294967087;
private const double _modulus2 = 4294944443;
private const double _reciprocal = 1.0/_modulus1;
private double _xn1 = 1;
private double _xn2 = 1;
private double _xn3;
private double _yn1 = 1;
private double _yn2 = 1;
private double _yn3 = 1;
/// <summary>
/// Initializes a new instance of the <see cref="Mrg32k3a"/> class.
@ -106,20 +107,20 @@ namespace MathNet.Numerics.Random
/// </returns>
protected override double DoSample()
{
double xn = _a12*_xn2 - _a13*_xn3;
double k = (long) (xn/_modulus1);
xn -= k*_modulus1;
double xn = A12*_xn2 - A13*_xn3;
double k = (long) (xn/Modulus1);
xn -= k*Modulus1;
if (xn < 0)
{
xn += _modulus1;
xn += Modulus1;
}
double yn = _a21*_yn1 - _a23*_yn3;
k = (long) (yn/_modulus2);
yn -= k*_modulus2;
double yn = A21*_yn1 - A23*_yn3;
k = (long) (yn/Modulus2);
yn -= k*Modulus2;
if (yn < 0)
{
yn += _modulus2;
yn += Modulus2;
}
_xn3 = _xn2;
_xn2 = _xn1;
@ -130,9 +131,9 @@ namespace MathNet.Numerics.Random
if (xn <= yn)
{
return (xn - yn + _modulus1)*_reciprocal;
return (xn - yn + Modulus1)*Reciprocal;
}
return (xn - yn)*_reciprocal;
return (xn - yn)*Reciprocal;
}
}
}

8
src/Numerics/Random/Palf.cs

@ -28,12 +28,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Threading;
namespace MathNet.Numerics.Random
{
using System;
using Properties;
using Threading;
/// <summary>
/// Represents a Parallel Additive Lagged Fibonacci pseudo-random number generator.
/// </summary>

24
src/Numerics/Random/SystemCrypto.cs

@ -29,18 +29,19 @@
// </copyright>
#if !PORTABLE
using System;
using System.Security.Cryptography;
namespace MathNet.Numerics.Random
{
using System;
using System.Security.Cryptography;
/// <summary>
/// A random number generator based on the <see cref="System.Security.Cryptography.RandomNumberGenerator"/> class in the .NET library.
/// </summary>
public class SystemCryptoRandomNumberGenerator : AbstractRandomNumberGenerator, IDisposable
{
private const double mReciprocal = 1.0 / uint.MaxValue;
private readonly RandomNumberGenerator mRandom;
private const double Reciprocal = 1.0 / uint.MaxValue;
private readonly RandomNumberGenerator _random;
/// <summary>
/// Construct a new random number generator with a random seed.
@ -49,7 +50,7 @@ namespace MathNet.Numerics.Random
/// <see cref="Control.ThreadSafeRandomNumberGenerators"/> to set whether the instance is thread safe.</remarks>
public SystemCryptoRandomNumberGenerator(): this(new RNGCryptoServiceProvider(), Control.ThreadSafeRandomNumberGenerators)
{
mRandom = new RNGCryptoServiceProvider();
_random = new RNGCryptoServiceProvider();
}
/// <summary>
@ -81,7 +82,7 @@ namespace MathNet.Numerics.Random
{
throw new ArgumentNullException("rng");
}
mRandom = rng;
_random = rng;
}
@ -93,15 +94,16 @@ namespace MathNet.Numerics.Random
/// </returns>
protected override double DoSample()
{
byte[] bytes = new byte[4];
mRandom.GetBytes(bytes);
return BitConverter.ToUInt32(bytes, 0) * mReciprocal;
var bytes = new byte[4];
_random.GetBytes(bytes);
return BitConverter.ToUInt32(bytes, 0) * Reciprocal;
}
public void Dispose()
{
mRandom.Dispose();
_random.Dispose();
}
}
}
#endif

26
src/Numerics/Random/WH1982.cs

@ -28,10 +28,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics.Random
{
using System;
/// <summary>
/// Wichmann-Hill’s 1982 combined multiplicative congruential generator.
/// </summary>
@ -40,12 +40,12 @@ namespace MathNet.Numerics.Random
///</remarks>
public class WH1982 : AbstractRandomNumberGenerator
{
private const uint _modx = 30269;
private const double _modx_recip = 1.0/_modx;
private const uint _mody = 30307;
private const double _mody_recip = 1.0/_mody;
private const uint _modz = 30323;
private const double _modz_recip = 1.0/_modz;
private const uint Modx = 30269;
private const double ModxRecip = 1.0/Modx;
private const uint Mody = 30307;
private const double ModyRecip = 1.0/Mody;
private const uint Modz = 30323;
private const double ModzRecip = 1.0/Modz;
private uint _xn;
private uint _yn = 1;
private uint _zn = 1;
@ -92,7 +92,7 @@ namespace MathNet.Numerics.Random
{
seed = 1;
}
_xn = (uint) seed%_modx;
_xn = (uint) seed%Modx;
}
/// <summary>
@ -103,11 +103,11 @@ namespace MathNet.Numerics.Random
/// </returns>
protected override double DoSample()
{
_xn = (171*_xn)%_modx;
_yn = (172*_yn)%_mody;
_zn = (170*_zn)%_modz;
_xn = (171*_xn)%Modx;
_yn = (172*_yn)%Mody;
_zn = (170*_zn)%Modz;
double w = _xn*_modx_recip + _yn*_mody_recip + _zn*_modz_recip;
double w = _xn*ModxRecip + _yn*ModyRecip + _zn*ModzRecip;
w -= (int) w;
return w;
}

32
src/Numerics/Random/WH2006.cs

@ -28,10 +28,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics.Random
{
using System;
/// <summary>
/// Wichmann-Hill’s 2006 combined multiplicative congruential generator.
/// </summary>
@ -40,14 +40,14 @@ namespace MathNet.Numerics.Random
/// </remarks>
public class WH2006 : AbstractRandomNumberGenerator
{
private const uint _modw = 2147483123;
private const double _modw_recip = 1.0/_modw;
private const uint _modx = 2147483579;
private const double _modx_recip = 1.0/_modx;
private const uint _mody = 2147483543;
private const double _mody_recip = 1.0/_mody;
private const uint _modz = 2147483423;
private const double _modz_recip = 1.0/_modz;
private const uint Modw = 2147483123;
private const double ModwRecip = 1.0/Modw;
private const uint Modx = 2147483579;
private const double ModxRecip = 1.0/Modx;
private const uint Mody = 2147483543;
private const double ModyRecip = 1.0/Mody;
private const uint Modz = 2147483423;
private const double ModzRecip = 1.0/Modz;
private ulong _wn = 1;
private ulong _xn;
private ulong _yn = 1;
@ -95,7 +95,7 @@ namespace MathNet.Numerics.Random
{
seed = 1;
}
_xn = (uint) seed%_modx;
_xn = (uint) seed%Modx;
}
/// <summary>
@ -106,12 +106,12 @@ namespace MathNet.Numerics.Random
/// </returns>
protected override double DoSample()
{
_xn = 11600*_xn%_modx;
_yn = 47003*_yn%_mody;
_zn = 23000*_zn%_modz;
_wn = 33000*_wn%_modw;
_xn = 11600*_xn%Modx;
_yn = 47003*_yn%Mody;
_zn = 23000*_zn%Modz;
_wn = 33000*_wn%Modw;
double u = _xn*_modx_recip + _yn*_mody_recip + _zn*_modz_recip + _wn*_modw_recip;
double u = _xn*ModxRecip + _yn*ModyRecip + _zn*ModzRecip + _wn*ModwRecip;
u -= (int) u;
return u;
}

103
src/Numerics/Random/Xorshift.cs

@ -29,11 +29,10 @@
// </copyright>
using MathNet.Numerics.Properties;
using System;
namespace MathNet.Numerics.Random
{
using System;
/// <summary>
/// Implements a multiply-with-carry Xorshift pseudo random number generator (RNG) specified in Marsaglia, George. (2003). Xorshift RNGs.
/// <code>Xn = a * Xn−3 + c mod 2^32</code>
@ -41,6 +40,56 @@ namespace MathNet.Numerics.Random
/// </summary>
public class Xorshift : AbstractRandomNumberGenerator
{
/// <summary>
/// The default value for X1.
/// </summary>
private const uint YSeed = 362436069;
/// <summary>
/// The default value for X2.
/// </summary>
private const uint ZSeed = 77465321;
/// <summary>
/// The default value for the multiplier.
/// </summary>
private const uint ASeed = 916905990;
/// <summary>
/// The default value for the carry over.
/// </summary>
private const uint CSeed = 13579;
/// <summary>
/// The multiplier to compute a double-precision floating point number [0, 1)
/// </summary>
private const double UlongToDoubleMultiplier = 1.0 / (uint.MaxValue + 1.0);
/// <summary>
/// Seed or last but three unsigned random number.
/// </summary>
private ulong _x;
/// <summary>
/// Last but two unsigned random number.
/// </summary>
private ulong _y;
/// <summary>
/// Last but one unsigned random number.
/// </summary>
private ulong _z;
/// <summary>
/// The value of the carry over.
/// </summary>
private ulong _c;
/// <summary>
/// The multiplier.
/// </summary>
private readonly ulong _a;
/// <summary>
/// Initializes a new instance of the <see cref="Xorshift"/> class using
/// the current time as the seed.
@ -202,56 +251,6 @@ namespace MathNet.Numerics.Random
_c = (ulong)c;
}
/// <summary>
/// The default value for X1.
/// </summary>
private const uint YSeed = 362436069;
/// <summary>
/// The default value for X2.
/// </summary>
private const uint ZSeed = 77465321;
/// <summary>
/// The default value for the multiplier.
/// </summary>
private const uint ASeed = 916905990;
/// <summary>
/// The default value for the carry over.
/// </summary>
private const uint CSeed = 13579;
/// <summary>
/// The multiplier to compute a double-precision floating point number [0, 1)
/// </summary>
private const double UlongToDoubleMultiplier = 1.0 / (uint.MaxValue + 1.0);
/// <summary>
/// Seed or last but three unsigned random number.
/// </summary>
private ulong _x;
/// <summary>
/// Last but two unsigned random number.
/// </summary>
private ulong _y;
/// <summary>
/// Last but one unsigned random number.
/// </summary>
private ulong _z;
/// <summary>
/// The value of the carry over.
/// </summary>
private ulong _c;
/// <summary>
/// The multiplier.
/// </summary>
private readonly ulong _a;
/// <summary>
/// Returns a random number between 0.0 and 1.0.
/// </summary>

4
src/Numerics/RootFinding/Broyden.cs

@ -117,8 +117,8 @@ namespace MathNet.Numerics.RootFinding
/// Helper method to calculate an approxiamtion of the Jacobian.
/// </summary>
/// <param name="f">The function.</param>
/// <param name="x0">The argument.</param>
/// <returns></returns>
/// <param name="x0">The argument (initial guess).</param>
/// <param name="y0">The result (of initial guess).</param>
static Matrix<double> CalculateApproximateJacobian(Func<double[], double[]> f, double[] x0, double[] y0)
{
int dim = x0.Length;

4
src/Numerics/SpecialFunctions/Beta.cs

@ -121,7 +121,7 @@ namespace MathNet.Numerics
var symmetryTransformation = x >= (a + 1.0) / (a + b + 2.0);
/* Continued fraction representation */
const int MaxIterations = 100;
const int maxIterations = 100;
var eps = Precision.DoubleMachinePrecision;
var fpmin = 0.0.Increment() / eps;
@ -147,7 +147,7 @@ namespace MathNet.Numerics
d = 1.0 / d;
var h = d;
for (int m = 1, m2 = 2; m <= MaxIterations; m++, m2 += 2)
for (int m = 1, m2 = 2; m <= maxIterations; m++, m2 += 2)
{
var aa = m * (b - m) * x / ((qam + m2) * (a + m2));
d = 1.0 + (aa * d);

171
src/Numerics/SpecialFunctions/Erf.cs

@ -115,6 +115,7 @@ namespace MathNet.Numerics
return ErfImp(x, true);
}
///<summary>Calculates the inverse error function evaluated at z.</summary>
/// <returns>The inverse error function evaluated at given value.</returns>
/// <remarks>
@ -165,7 +166,7 @@ namespace MathNet.Numerics
/// <param name="z">Where to evaluate the error function.</param>
/// <param name="invert">Whether to compute 1 - the error function.</param>
/// <returns>the error function.</returns>
private static double ErfImp(double z, bool invert)
static double ErfImp(double z, bool invert)
{
if (z < 0)
{
@ -196,15 +197,15 @@ namespace MathNet.Numerics
//
if (z < 1e-10)
{
result = (z * 1.125) + (z * 0.003379167095512573896158903121545171688);
result = (z*1.125) + (z*0.003379167095512573896158903121545171688);
}
else
{
// Worst case absolute error found: 6.688618532e-21
double[] n = new[] { 0.00337916709551257388990745, -0.00073695653048167948530905, -0.374732337392919607868241, 0.0817442448733587196071743, -0.0421089319936548595203468, 0.0070165709512095756344528, -0.00495091255982435110337458, 0.000871646599037922480317225 };
double[] d = new[] { 1, -0.218088218087924645390535, 0.412542972725442099083918, -0.0841891147873106755410271, 0.0655338856400241519690695, -0.0120019604454941768171266, 0.00408165558926174048329689, -0.000615900721557769691924509 };
double[] nc = {0.00337916709551257388990745, -0.00073695653048167948530905, -0.374732337392919607868241, 0.0817442448733587196071743, -0.0421089319936548595203468, 0.0070165709512095756344528, -0.00495091255982435110337458, 0.000871646599037922480317225};
double[] dc = {1, -0.218088218087924645390535, 0.412542972725442099083918, -0.0841891147873106755410271, 0.0655338856400241519690695, -0.0120019604454941768171266, 0.00408165558926174048329689, -0.000615900721557769691924509};
result = (z * 1.125) + (z * Evaluate.Polynomial(z, n) / Evaluate.Polynomial(z, d));
result = (z*1.125) + (z*Evaluate.Polynomial(z, nc)/Evaluate.Polynomial(z, dc));
}
}
else if ((z < 110) || ((z < 110) && invert))
@ -217,110 +218,110 @@ namespace MathNet.Numerics
if (z < 0.75)
{
// Worst case absolute error found: 5.582813374e-21
double[] n = new[] { -0.0361790390718262471360258, 0.292251883444882683221149, 0.281447041797604512774415, 0.125610208862766947294894, 0.0274135028268930549240776, 0.00250839672168065762786937 };
double[] d = new[] { 1, 1.8545005897903486499845, 1.43575803037831418074962, 0.582827658753036572454135, 0.124810476932949746447682, 0.0113724176546353285778481 };
r = Evaluate.Polynomial(z - 0.5, n) / Evaluate.Polynomial(z - 0.5, d);
double[] nc = {-0.0361790390718262471360258, 0.292251883444882683221149, 0.281447041797604512774415, 0.125610208862766947294894, 0.0274135028268930549240776, 0.00250839672168065762786937};
double[] dc = {1, 1.8545005897903486499845, 1.43575803037831418074962, 0.582827658753036572454135, 0.124810476932949746447682, 0.0113724176546353285778481};
r = Evaluate.Polynomial(z - 0.5, nc)/Evaluate.Polynomial(z - 0.5, dc);
b = 0.3440242112F;
}
else if (z < 1.25)
{
// Worst case absolute error found: 4.01854729e-21
double[] n = new[] { -0.0397876892611136856954425, 0.153165212467878293257683, 0.191260295600936245503129, 0.10276327061989304213645, 0.029637090615738836726027, 0.0046093486780275489468812, 0.000307607820348680180548455 };
double[] d = new[] { 1, 1.95520072987627704987886, 1.64762317199384860109595, 0.768238607022126250082483, 0.209793185936509782784315, 0.0319569316899913392596356, 0.00213363160895785378615014 };
r = Evaluate.Polynomial(z - 0.75, n) / Evaluate.Polynomial(z - 0.75, d);
double[] nc = {-0.0397876892611136856954425, 0.153165212467878293257683, 0.191260295600936245503129, 0.10276327061989304213645, 0.029637090615738836726027, 0.0046093486780275489468812, 0.000307607820348680180548455};
double[] dc = {1, 1.95520072987627704987886, 1.64762317199384860109595, 0.768238607022126250082483, 0.209793185936509782784315, 0.0319569316899913392596356, 0.00213363160895785378615014};
r = Evaluate.Polynomial(z - 0.75, nc)/Evaluate.Polynomial(z - 0.75, dc);
b = 0.419990927F;
}
else if (z < 2.25)
{
// Worst case absolute error found: 2.866005373e-21
double[] n = new[] { -0.0300838560557949717328341, 0.0538578829844454508530552, 0.0726211541651914182692959, 0.0367628469888049348429018, 0.00964629015572527529605267, 0.00133453480075291076745275, 0.778087599782504251917881e-4 };
double[] d = new[] { 1, 1.75967098147167528287343, 1.32883571437961120556307, 0.552528596508757581287907, 0.133793056941332861912279, 0.0179509645176280768640766, 0.00104712440019937356634038, -0.106640381820357337177643e-7 };
r = Evaluate.Polynomial(z - 1.25, n) / Evaluate.Polynomial(z - 1.25, d);
double[] nc = {-0.0300838560557949717328341, 0.0538578829844454508530552, 0.0726211541651914182692959, 0.0367628469888049348429018, 0.00964629015572527529605267, 0.00133453480075291076745275, 0.778087599782504251917881e-4};
double[] dc = {1, 1.75967098147167528287343, 1.32883571437961120556307, 0.552528596508757581287907, 0.133793056941332861912279, 0.0179509645176280768640766, 0.00104712440019937356634038, -0.106640381820357337177643e-7};
r = Evaluate.Polynomial(z - 1.25, nc)/Evaluate.Polynomial(z - 1.25, dc);
b = 0.4898625016F;
}
else if (z < 3.5)
{
// Worst case absolute error found: 1.045355789e-21
double[] n = new[] { -0.0117907570137227847827732, 0.014262132090538809896674, 0.0202234435902960820020765, 0.00930668299990432009042239, 0.00213357802422065994322516, 0.00025022987386460102395382, 0.120534912219588189822126e-4 };
double[] d = new[] { 1, 1.50376225203620482047419, 0.965397786204462896346934, 0.339265230476796681555511, 0.0689740649541569716897427, 0.00771060262491768307365526, 0.000371421101531069302990367 };
r = Evaluate.Polynomial(z - 2.25, n) / Evaluate.Polynomial(z - 2.25, d);
double[] nc = {-0.0117907570137227847827732, 0.014262132090538809896674, 0.0202234435902960820020765, 0.00930668299990432009042239, 0.00213357802422065994322516, 0.00025022987386460102395382, 0.120534912219588189822126e-4};
double[] dc = {1, 1.50376225203620482047419, 0.965397786204462896346934, 0.339265230476796681555511, 0.0689740649541569716897427, 0.00771060262491768307365526, 0.000371421101531069302990367};
r = Evaluate.Polynomial(z - 2.25, nc)/Evaluate.Polynomial(z - 2.25, dc);
b = 0.5317370892F;
}
else if (z < 5.25)
{
// Worst case absolute error found: 8.300028706e-22
double[] n = new[] { -0.00546954795538729307482955, 0.00404190278731707110245394, 0.0054963369553161170521356, 0.00212616472603945399437862, 0.000394984014495083900689956, 0.365565477064442377259271e-4, 0.135485897109932323253786e-5 };
double[] d = new[] { 1, 1.21019697773630784832251, 0.620914668221143886601045, 0.173038430661142762569515, 0.0276550813773432047594539, 0.00240625974424309709745382, 0.891811817251336577241006e-4, -0.465528836283382684461025e-11 };
r = Evaluate.Polynomial(z - 3.5, n) / Evaluate.Polynomial(z - 3.5, d);
double[] nc = {-0.00546954795538729307482955, 0.00404190278731707110245394, 0.0054963369553161170521356, 0.00212616472603945399437862, 0.000394984014495083900689956, 0.365565477064442377259271e-4, 0.135485897109932323253786e-5};
double[] dc = {1, 1.21019697773630784832251, 0.620914668221143886601045, 0.173038430661142762569515, 0.0276550813773432047594539, 0.00240625974424309709745382, 0.891811817251336577241006e-4, -0.465528836283382684461025e-11};
r = Evaluate.Polynomial(z - 3.5, nc)/Evaluate.Polynomial(z - 3.5, dc);
b = 0.5489973426F;
}
else if (z < 8)
{
// Worst case absolute error found: 1.700157534e-21
double[] n = new[] { -0.00270722535905778347999196, 0.0013187563425029400461378, 0.00119925933261002333923989, 0.00027849619811344664248235, 0.267822988218331849989363e-4, 0.923043672315028197865066e-6 };
double[] d = new[] { 1, 0.814632808543141591118279, 0.268901665856299542168425, 0.0449877216103041118694989, 0.00381759663320248459168994, 0.000131571897888596914350697, 0.404815359675764138445257e-11 };
r = Evaluate.Polynomial(z - 5.25, n) / Evaluate.Polynomial(z - 5.25, d);
double[] nc = {-0.00270722535905778347999196, 0.0013187563425029400461378, 0.00119925933261002333923989, 0.00027849619811344664248235, 0.267822988218331849989363e-4, 0.923043672315028197865066e-6};
double[] dc = {1, 0.814632808543141591118279, 0.268901665856299542168425, 0.0449877216103041118694989, 0.00381759663320248459168994, 0.000131571897888596914350697, 0.404815359675764138445257e-11};
r = Evaluate.Polynomial(z - 5.25, nc)/Evaluate.Polynomial(z - 5.25, dc);
b = 0.5571740866F;
}
else if (z < 11.5)
{
// Worst case absolute error found: 3.002278011e-22
double[] n = new[] { -0.00109946720691742196814323, 0.000406425442750422675169153, 0.000274499489416900707787024, 0.465293770646659383436343e-4, 0.320955425395767463401993e-5, 0.778286018145020892261936e-7 };
double[] d = new[] { 1, 0.588173710611846046373373, 0.139363331289409746077541, 0.0166329340417083678763028, 0.00100023921310234908642639, 0.24254837521587225125068e-4 };
r = Evaluate.Polynomial(z - 8, n) / Evaluate.Polynomial(z - 8, d);
double[] nc = {-0.00109946720691742196814323, 0.000406425442750422675169153, 0.000274499489416900707787024, 0.465293770646659383436343e-4, 0.320955425395767463401993e-5, 0.778286018145020892261936e-7};
double[] dc = {1, 0.588173710611846046373373, 0.139363331289409746077541, 0.0166329340417083678763028, 0.00100023921310234908642639, 0.24254837521587225125068e-4};
r = Evaluate.Polynomial(z - 8, nc)/Evaluate.Polynomial(z - 8, dc);
b = 0.5609807968F;
}
else if (z < 17)
{
// Worst case absolute error found: 6.741114695e-21
double[] n = new[] { -0.00056907993601094962855594, 0.000169498540373762264416984, 0.518472354581100890120501e-4, 0.382819312231928859704678e-5, 0.824989931281894431781794e-7 };
double[] d = new[] { 1, 0.339637250051139347430323, 0.043472647870310663055044, 0.00248549335224637114641629, 0.535633305337152900549536e-4, -0.117490944405459578783846e-12 };
r = Evaluate.Polynomial(z - 11.5, n) / Evaluate.Polynomial(z - 11.5, d);
double[] nc = {-0.00056907993601094962855594, 0.000169498540373762264416984, 0.518472354581100890120501e-4, 0.382819312231928859704678e-5, 0.824989931281894431781794e-7};
double[] dc = {1, 0.339637250051139347430323, 0.043472647870310663055044, 0.00248549335224637114641629, 0.535633305337152900549536e-4, -0.117490944405459578783846e-12};
r = Evaluate.Polynomial(z - 11.5, nc)/Evaluate.Polynomial(z - 11.5, dc);
b = 0.5626493692F;
}
else if (z < 24)
{
// Worst case absolute error found: 7.802346984e-22
double[] n = new[] { -0.000241313599483991337479091, 0.574224975202501512365975e-4, 0.115998962927383778460557e-4, 0.581762134402593739370875e-6, 0.853971555085673614607418e-8 };
double[] d = new[] { 1, 0.233044138299687841018015, 0.0204186940546440312625597, 0.000797185647564398289151125, 0.117019281670172327758019e-4 };
r = Evaluate.Polynomial(z - 17, n) / Evaluate.Polynomial(z - 17, d);
double[] nc = {-0.000241313599483991337479091, 0.574224975202501512365975e-4, 0.115998962927383778460557e-4, 0.581762134402593739370875e-6, 0.853971555085673614607418e-8};
double[] dc = {1, 0.233044138299687841018015, 0.0204186940546440312625597, 0.000797185647564398289151125, 0.117019281670172327758019e-4};
r = Evaluate.Polynomial(z - 17, nc)/Evaluate.Polynomial(z - 17, dc);
b = 0.5634598136F;
}
else if (z < 38)
{
// Worst case absolute error found: 2.414228989e-22
double[] n = new[] { -0.000146674699277760365803642, 0.162666552112280519955647e-4, 0.269116248509165239294897e-5, 0.979584479468091935086972e-7, 0.101994647625723465722285e-8 };
double[] d = new[] { 1, 0.165907812944847226546036, 0.0103361716191505884359634, 0.000286593026373868366935721, 0.298401570840900340874568e-5 };
r = Evaluate.Polynomial(z - 24, n) / Evaluate.Polynomial(z - 24, d);
double[] nc = {-0.000146674699277760365803642, 0.162666552112280519955647e-4, 0.269116248509165239294897e-5, 0.979584479468091935086972e-7, 0.101994647625723465722285e-8};
double[] dc = {1, 0.165907812944847226546036, 0.0103361716191505884359634, 0.000286593026373868366935721, 0.298401570840900340874568e-5};
r = Evaluate.Polynomial(z - 24, nc)/Evaluate.Polynomial(z - 24, dc);
b = 0.5638477802F;
}
else if (z < 60)
{
// Worst case absolute error found: 5.896543869e-24
double[] n = new[] { -0.583905797629771786720406e-4, 0.412510325105496173512992e-5, 0.431790922420250949096906e-6, 0.993365155590013193345569e-8, 0.653480510020104699270084e-10 };
double[] d = new[] { 1, 0.105077086072039915406159, 0.00414278428675475620830226, 0.726338754644523769144108e-4, 0.477818471047398785369849e-6 };
r = Evaluate.Polynomial(z - 38, n) / Evaluate.Polynomial(z - 38, d);
double[] nc = {-0.583905797629771786720406e-4, 0.412510325105496173512992e-5, 0.431790922420250949096906e-6, 0.993365155590013193345569e-8, 0.653480510020104699270084e-10};
double[] dc = {1, 0.105077086072039915406159, 0.00414278428675475620830226, 0.726338754644523769144108e-4, 0.477818471047398785369849e-6};
r = Evaluate.Polynomial(z - 38, nc)/Evaluate.Polynomial(z - 38, dc);
b = 0.5640528202F;
}
else if (z < 85)
{
// Worst case absolute error found: 3.080612264e-21
double[] n = new[] { -0.196457797609229579459841e-4, 0.157243887666800692441195e-5, 0.543902511192700878690335e-7, 0.317472492369117710852685e-9 };
double[] d = new[] { 1, 0.052803989240957632204885, 0.000926876069151753290378112, 0.541011723226630257077328e-5, 0.535093845803642394908747e-15 };
r = Evaluate.Polynomial(z - 60, n) / Evaluate.Polynomial(z - 60, d);
double[] nc = {-0.196457797609229579459841e-4, 0.157243887666800692441195e-5, 0.543902511192700878690335e-7, 0.317472492369117710852685e-9};
double[] dc = {1, 0.052803989240957632204885, 0.000926876069151753290378112, 0.541011723226630257077328e-5, 0.535093845803642394908747e-15};
r = Evaluate.Polynomial(z - 60, nc)/Evaluate.Polynomial(z - 60, dc);
b = 0.5641309023F;
}
else
{
// Worst case absolute error found: 8.094633491e-22
double[] n = new[] { -0.789224703978722689089794e-5, 0.622088451660986955124162e-6, 0.145728445676882396797184e-7, 0.603715505542715364529243e-10 };
double[] d = new[] { 1, 0.0375328846356293715248719, 0.000467919535974625308126054, 0.193847039275845656900547e-5 };
r = Evaluate.Polynomial(z - 85, n) / Evaluate.Polynomial(z - 85, d);
double[] nc = {-0.789224703978722689089794e-5, 0.622088451660986955124162e-6, 0.145728445676882396797184e-7, 0.603715505542715364529243e-10};
double[] dc = {1, 0.0375328846356293715248719, 0.000467919535974625308126054, 0.193847039275845656900547e-5};
r = Evaluate.Polynomial(z - 85, nc)/Evaluate.Polynomial(z - 85, dc);
b = 0.5641584396F;
}
double g = Math.Exp(-z * z) / z;
result = (g * b) + (g * r);
double g = Math.Exp(-z*z)/z;
result = (g*b) + (g*r);
}
else
{
@ -387,7 +388,7 @@ namespace MathNet.Numerics
/// <param name="q">Second intermediate parameter.</param>
/// <param name="s">Third intermediate parameter.</param>
/// <returns>the inverse error function.</returns>
private static double ErfInvImpl(double p, double q, double s)
static double ErfInvImpl(double p, double q, double s)
{
double result;
@ -405,12 +406,12 @@ namespace MathNet.Numerics
// long double: Max error found: 1.017064e-20
// Maximum Deviation Found (actual error term at infinite precision) 8.030e-21
//
const float Y = 0.0891314744949340820313f;
double[] P = new[] { -0.000508781949658280665617, -0.00836874819741736770379, 0.0334806625409744615033, -0.0126926147662974029034, -0.0365637971411762664006, 0.0219878681111168899165, 0.00822687874676915743155, -0.00538772965071242932965 };
double[] Q = new[] { 1, -0.970005043303290640362, -1.56574558234175846809, 1.56221558398423026363, 0.662328840472002992063, -0.71228902341542847553, -0.0527396382340099713954, 0.0795283687341571680018, -0.00233393759374190016776, 0.000886216390456424707504 };
double g = p * (p + 10);
double r = Evaluate.Polynomial(p, P) / Evaluate.Polynomial(p, Q);
result = (g * Y) + (g * r);
const float y = 0.0891314744949340820313f;
double[] nc = {-0.000508781949658280665617, -0.00836874819741736770379, 0.0334806625409744615033, -0.0126926147662974029034, -0.0365637971411762664006, 0.0219878681111168899165, 0.00822687874676915743155, -0.00538772965071242932965};
double[] dc = {1, -0.970005043303290640362, -1.56574558234175846809, 1.56221558398423026363, 0.662328840472002992063, -0.71228902341542847553, -0.0527396382340099713954, 0.0795283687341571680018, -0.00233393759374190016776, 0.000886216390456424707504};
double g = p*(p + 10);
double r = Evaluate.Polynomial(p, nc)/Evaluate.Polynomial(p, dc);
result = (g*y) + (g*r);
}
else if (q >= 0.25)
{
@ -426,13 +427,13 @@ namespace MathNet.Numerics
// long double : Max error found: 6.084616e-20
// Maximum Deviation Found (error term) 4.811e-20
//
const float Y = 2.249481201171875f;
double[] P = new[] { -0.202433508355938759655, 0.105264680699391713268, 8.37050328343119927838, 17.6447298408374015486, -18.8510648058714251895, -44.6382324441786960818, 17.445385985570866523, 21.1294655448340526258, -3.67192254707729348546 };
double[] Q = new[] { 1, 6.24264124854247537712, 3.9713437953343869095, -28.6608180499800029974, -20.1432634680485188801, 48.5609213108739935468, 10.8268667355460159008, -22.6436933413139721736, 1.72114765761200282724 };
double g = Math.Sqrt(-2 * Math.Log(q));
const float y = 2.249481201171875f;
double[] nc = {-0.202433508355938759655, 0.105264680699391713268, 8.37050328343119927838, 17.6447298408374015486, -18.8510648058714251895, -44.6382324441786960818, 17.445385985570866523, 21.1294655448340526258, -3.67192254707729348546};
double[] dc = {1, 6.24264124854247537712, 3.9713437953343869095, -28.6608180499800029974, -20.1432634680485188801, 48.5609213108739935468, 10.8268667355460159008, -22.6436933413139721736, 1.72114765761200282724};
double g = Math.Sqrt(-2*Math.Log(q));
double xs = q - 0.25;
double r = Evaluate.Polynomial(xs, P) / Evaluate.Polynomial(xs, Q);
result = g / (Y + r);
double r = Evaluate.Polynomial(xs, nc)/Evaluate.Polynomial(xs, dc);
result = g/(y + r);
}
else
{
@ -459,56 +460,56 @@ namespace MathNet.Numerics
if (x < 3)
{
// Max error found: 1.089051e-20
const float Y = 0.807220458984375f;
double[] P = new[] { -0.131102781679951906451, -0.163794047193317060787, 0.117030156341995252019, 0.387079738972604337464, 0.337785538912035898924, 0.142869534408157156766, 0.0290157910005329060432, 0.00214558995388805277169, -0.679465575181126350155e-6, 0.285225331782217055858e-7, -0.681149956853776992068e-9 };
double[] Q = new[] { 1, 3.46625407242567245975, 5.38168345707006855425, 4.77846592945843778382, 2.59301921623620271374, 0.848854343457902036425, 0.152264338295331783612, 0.01105924229346489121 };
const float y = 0.807220458984375f;
double[] nc = {-0.131102781679951906451, -0.163794047193317060787, 0.117030156341995252019, 0.387079738972604337464, 0.337785538912035898924, 0.142869534408157156766, 0.0290157910005329060432, 0.00214558995388805277169, -0.679465575181126350155e-6, 0.285225331782217055858e-7, -0.681149956853776992068e-9};
double[] dc = {1, 3.46625407242567245975, 5.38168345707006855425, 4.77846592945843778382, 2.59301921623620271374, 0.848854343457902036425, 0.152264338295331783612, 0.01105924229346489121};
double xs = x - 1.125;
double R = Evaluate.Polynomial(xs, P) / Evaluate.Polynomial(xs, Q);
result = (Y * x) + (R * x);
double r = Evaluate.Polynomial(xs, nc)/Evaluate.Polynomial(xs, dc);
result = (y*x) + (r*x);
}
else if (x < 6)
{
// Max error found: 8.389174e-21
const float Y = 0.93995571136474609375f;
double[] P = new[] { -0.0350353787183177984712, -0.00222426529213447927281, 0.0185573306514231072324, 0.00950804701325919603619, 0.00187123492819559223345, 0.000157544617424960554631, 0.460469890584317994083e-5, -0.230404776911882601748e-9, 0.266339227425782031962e-11 };
double[] Q = new[] { 1, 1.3653349817554063097, 0.762059164553623404043, 0.220091105764131249824, 0.0341589143670947727934, 0.00263861676657015992959, 0.764675292302794483503e-4 };
const float y = 0.93995571136474609375f;
double[] nc = {-0.0350353787183177984712, -0.00222426529213447927281, 0.0185573306514231072324, 0.00950804701325919603619, 0.00187123492819559223345, 0.000157544617424960554631, 0.460469890584317994083e-5, -0.230404776911882601748e-9, 0.266339227425782031962e-11};
double[] dc = {1, 1.3653349817554063097, 0.762059164553623404043, 0.220091105764131249824, 0.0341589143670947727934, 0.00263861676657015992959, 0.764675292302794483503e-4};
double xs = x - 3;
double R = Evaluate.Polynomial(xs, P) / Evaluate.Polynomial(xs, Q);
result = (Y * x) + (R * x);
double r = Evaluate.Polynomial(xs, nc)/Evaluate.Polynomial(xs, dc);
result = (y*x) + (r*x);
}
else if (x < 18)
{
// Max error found: 1.481312e-19
const float Y = 0.98362827301025390625f;
double[] P = new[] { -0.0167431005076633737133, -0.00112951438745580278863, 0.00105628862152492910091, 0.000209386317487588078668, 0.149624783758342370182e-4, 0.449696789927706453732e-6, 0.462596163522878599135e-8, -0.281128735628831791805e-13, 0.99055709973310326855e-16 };
double[] Q = new[] { 1, 0.591429344886417493481, 0.138151865749083321638, 0.0160746087093676504695, 0.000964011807005165528527, 0.275335474764726041141e-4, 0.282243172016108031869e-6 };
const float y = 0.98362827301025390625f;
double[] nc = {-0.0167431005076633737133, -0.00112951438745580278863, 0.00105628862152492910091, 0.000209386317487588078668, 0.149624783758342370182e-4, 0.449696789927706453732e-6, 0.462596163522878599135e-8, -0.281128735628831791805e-13, 0.99055709973310326855e-16};
double[] dc = {1, 0.591429344886417493481, 0.138151865749083321638, 0.0160746087093676504695, 0.000964011807005165528527, 0.275335474764726041141e-4, 0.282243172016108031869e-6};
double xs = x - 6;
double R = Evaluate.Polynomial(xs, P) / Evaluate.Polynomial(xs, Q);
result = (Y * x) + (R * x);
double r = Evaluate.Polynomial(xs, nc)/Evaluate.Polynomial(xs, dc);
result = (y*x) + (r*x);
}
else if (x < 44)
{
// Max error found: 5.697761e-20
const float Y = 0.99714565277099609375f;
double[] P = new[] { -0.0024978212791898131227, -0.779190719229053954292e-5, 0.254723037413027451751e-4, 0.162397777342510920873e-5, 0.396341011304801168516e-7, 0.411632831190944208473e-9, 0.145596286718675035587e-11, -0.116765012397184275695e-17 };
double[] Q = new[] { 1, 0.207123112214422517181, 0.0169410838120975906478, 0.000690538265622684595676, 0.145007359818232637924e-4, 0.144437756628144157666e-6, 0.509761276599778486139e-9 };
const float y = 0.99714565277099609375f;
double[] nc = {-0.0024978212791898131227, -0.779190719229053954292e-5, 0.254723037413027451751e-4, 0.162397777342510920873e-5, 0.396341011304801168516e-7, 0.411632831190944208473e-9, 0.145596286718675035587e-11, -0.116765012397184275695e-17};
double[] dc = {1, 0.207123112214422517181, 0.0169410838120975906478, 0.000690538265622684595676, 0.145007359818232637924e-4, 0.144437756628144157666e-6, 0.509761276599778486139e-9};
double xs = x - 18;
double R = Evaluate.Polynomial(xs, P) / Evaluate.Polynomial(xs, Q);
result = (Y * x) + (R * x);
double r = Evaluate.Polynomial(xs, nc)/Evaluate.Polynomial(xs, dc);
result = (y*x) + (r*x);
}
else
{
// Max error found: 1.279746e-20
const float Y = 0.99941349029541015625f;
double[] P = new[] { -0.000539042911019078575891, -0.28398759004727721098e-6, 0.899465114892291446442e-6, 0.229345859265920864296e-7, 0.225561444863500149219e-9, 0.947846627503022684216e-12, 0.135880130108924861008e-14, -0.348890393399948882918e-21 };
double[] Q = new[] { 1, 0.0845746234001899436914, 0.00282092984726264681981, 0.468292921940894236786e-4, 0.399968812193862100054e-6, 0.161809290887904476097e-8, 0.231558608310259605225e-11 };
const float y = 0.99941349029541015625f;
double[] nc = {-0.000539042911019078575891, -0.28398759004727721098e-6, 0.899465114892291446442e-6, 0.229345859265920864296e-7, 0.225561444863500149219e-9, 0.947846627503022684216e-12, 0.135880130108924861008e-14, -0.348890393399948882918e-21};
double[] dc = {1, 0.0845746234001899436914, 0.00282092984726264681981, 0.468292921940894236786e-4, 0.399968812193862100054e-6, 0.161809290887904476097e-8, 0.231558608310259605225e-11};
double xs = x - 44;
double R = Evaluate.Polynomial(xs, P) / Evaluate.Polynomial(xs, Q);
result = (Y * x) + (R * x);
double r = Evaluate.Polynomial(xs, nc)/Evaluate.Polynomial(xs, dc);
result = (y*x) + (r*x);
}
}
return s * result;
return s*result;
}
}
}

18
src/Numerics/SpecialFunctions/Factorial.cs

@ -38,7 +38,7 @@ namespace MathNet.Numerics
public partial class SpecialFunctions
{
private const int FactorialMaxArgument = 170;
private static double[] factorialCache;
private static double[] _factorialCache;
/// <summary>
/// Initializes static members of the SpecialFunctions class.
@ -50,11 +50,11 @@ namespace MathNet.Numerics
private static void InitializeFactorial()
{
factorialCache = new double[FactorialMaxArgument + 1];
factorialCache[0] = 1.0;
for (int i = 1; i < factorialCache.Length; i++)
_factorialCache = new double[FactorialMaxArgument + 1];
_factorialCache[0] = 1.0;
for (int i = 1; i < _factorialCache.Length; i++)
{
factorialCache[i] = factorialCache[i - 1] * i;
_factorialCache[i] = _factorialCache[i - 1] * i;
}
}
@ -77,9 +77,9 @@ namespace MathNet.Numerics
throw new ArgumentOutOfRangeException("x", Resources.ArgumentPositive);
}
if (x < factorialCache.Length)
if (x < _factorialCache.Length)
{
return factorialCache[x];
return _factorialCache[x];
}
return Double.PositiveInfinity;
@ -101,9 +101,9 @@ namespace MathNet.Numerics
return 0d;
}
if (x < factorialCache.Length)
if (x < _factorialCache.Length)
{
return Math.Log(factorialCache[x]);
return Math.Log(_factorialCache[x]);
}
return GammaLn(x + 1.0);

131
src/Numerics/SpecialFunctions/Gamma.cs

@ -44,31 +44,30 @@ namespace MathNet.Numerics
/// <summary>
/// The order of the <see cref="GammaLn"/> approximation.
/// </summary>
private const int Gamma_n = 10;
private const int GammaN = 10;
/// <summary>
/// Auxiliary variable when evaluating the <see cref="GammaLn"/> function.
/// </summary>
private const double Gamma_r = 10.900511;
private const double GammaR = 10.900511;
/// <summary>
/// Polynomial coefficients for the <see cref="GammaLn"/> approximation.
/// </summary>
private static readonly double[] Gamma_dk =
new[]
{
2.48574089138753565546e-5,
1.05142378581721974210,
-3.45687097222016235469,
4.51227709466894823700,
-2.98285225323576655721,
1.05639711577126713077,
-1.95428773191645869583e-1,
1.70970543404441224307e-2,
-5.71926117404305781283e-4,
4.63399473359905636708e-6,
-2.71994908488607703910e-9
};
static readonly double[] GammaDk =
{
2.48574089138753565546e-5,
1.05142378581721974210,
-3.45687097222016235469,
4.51227709466894823700,
-2.98285225323576655721,
1.05639711577126713077,
-1.95428773191645869583e-1,
1.70970543404441224307e-2,
-5.71926117404305781283e-4,
4.63399473359905636708e-6,
-2.71994908488607703910e-9
};
/// <summary>
/// Computes the logarithm of the Gamma function.
@ -86,29 +85,29 @@ namespace MathNet.Numerics
{
if (z < 0.5)
{
double s = Gamma_dk[0];
for (int i = 1; i <= Gamma_n; i++)
double s = GammaDk[0];
for (int i = 1; i <= GammaN; i++)
{
s += Gamma_dk[i] / (i - z);
s += GammaDk[i] / (i - z);
}
return Constants.LnPi
- Math.Log(Math.Sin(Math.PI * z))
- Math.Log(s)
- Constants.LogTwoSqrtEOverPi
- ((0.5 - z) * Math.Log((0.5 - z + Gamma_r) / Math.E));
- ((0.5 - z) * Math.Log((0.5 - z + GammaR) / Math.E));
}
else
{
double s = Gamma_dk[0];
for (int i = 1; i <= Gamma_n; i++)
double s = GammaDk[0];
for (int i = 1; i <= GammaN; i++)
{
s += Gamma_dk[i] / (z + i - 1.0);
s += GammaDk[i] / (z + i - 1.0);
}
return Math.Log(s)
+ Constants.LogTwoSqrtEOverPi
+ ((z - 0.5) * Math.Log((z - 0.5 + Gamma_r) / Math.E));
+ ((z - 0.5) * Math.Log((z - 0.5 + GammaR) / Math.E));
}
}
@ -130,26 +129,26 @@ namespace MathNet.Numerics
{
if (z < 0.5)
{
double s = Gamma_dk[0];
for (int i = 1; i <= Gamma_n; i++)
double s = GammaDk[0];
for (int i = 1; i <= GammaN; i++)
{
s += Gamma_dk[i] / (i - z);
s += GammaDk[i] / (i - z);
}
return Math.PI / (Math.Sin(Math.PI * z)
* s
* Constants.TwoSqrtEOverPi
* Math.Pow((0.5 - z + Gamma_r) / Math.E, 0.5 - z));
* Math.Pow((0.5 - z + GammaR) / Math.E, 0.5 - z));
}
else
{
double s = Gamma_dk[0];
for (int i = 1; i <= Gamma_n; i++)
double s = GammaDk[0];
for (int i = 1; i <= GammaN; i++)
{
s += Gamma_dk[i] / (z + i - 1.0);
s += GammaDk[i] / (z + i - 1.0);
}
return s * Constants.TwoSqrtEOverPi * Math.Pow((z - 0.5 + Gamma_r) / Math.E, z - 0.5);
return s * Constants.TwoSqrtEOverPi * Math.Pow((z - 0.5 + GammaR) / Math.E, z - 0.5);
}
}
@ -162,9 +161,9 @@ namespace MathNet.Numerics
/// <returns>The upper incomplete regularized gamma function.</returns>
public static double GammaUpperRegularized(double a, double x)
{
const double Epsilon = 0.000000000000001;
const double BigNumber = 4503599627370496.0;
const double BigNumberInverse = 2.22044604925031308085e-16;
const double epsilon = 0.000000000000001;
const double big = 4503599627370496.0;
const double bigInv = 2.22044604925031308085e-16;
if (x <= 0d || a <= 0d)
{
@ -216,15 +215,15 @@ namespace MathNet.Numerics
qkm2 = qkm1;
qkm1 = qk;
if (Math.Abs(pk) > BigNumber)
if (Math.Abs(pk) > big)
{
pkm2 = pkm2 * BigNumberInverse;
pkm1 = pkm1 * BigNumberInverse;
qkm2 = qkm2 * BigNumberInverse;
qkm1 = qkm1 * BigNumberInverse;
pkm2 = pkm2 * bigInv;
pkm1 = pkm1 * bigInv;
qkm2 = qkm2 * bigInv;
qkm1 = qkm1 * bigInv;
}
}
while (t > Epsilon);
while (t > epsilon);
return ans * ax;
}
@ -262,9 +261,9 @@ namespace MathNet.Numerics
/// <returns>The lower incomplete gamma function.</returns>
public static double GammaLowerRegularized(double a, double x)
{
const double Epsilon = 0.000000000000001;
const double BigNumber = 4503599627370496.0;
const double BigNumberInverse = 2.22044604925031308085e-16;
const double epsilon = 0.000000000000001;
const double big = 4503599627370496.0;
const double bigInv = 2.22044604925031308085e-16;
if (a < 0d || x < 0d)
{
@ -305,7 +304,7 @@ namespace MathNet.Numerics
c2 = c2 * x / r2;
ans2 += c2;
}
while ((c2 / ans2) > Epsilon);
while ((c2 / ans2) > epsilon);
return Math.Exp(ax) * ans2 / a;
}
@ -351,15 +350,15 @@ namespace MathNet.Numerics
q2 = q;
// normalize fraction when the numerator becomes large
if (Math.Abs(p) > BigNumber)
if (Math.Abs(p) > big)
{
p3 *= BigNumberInverse;
p2 *= BigNumberInverse;
q3 *= BigNumberInverse;
q2 *= BigNumberInverse;
p3 *= bigInv;
p2 *= bigInv;
q3 *= bigInv;
q2 *= bigInv;
}
}
while (error > Epsilon);
while (error > epsilon);
return 1d - (Math.Exp(ax) * ans);
}
@ -378,15 +377,15 @@ namespace MathNet.Numerics
/// <returns>The value of the DiGamma function at <paramref name="x"/>.</returns>
public static double DiGamma(double x)
{
const double C = 12.0;
const double D1 = -0.57721566490153286;
const double D2 = 1.6449340668482264365;
const double S = 1e-6;
const double S3 = 1.0 / 12.0;
const double S4 = 1.0 / 120.0;
const double S5 = 1.0 / 252.0;
const double S6 = 1.0 / 240.0;
const double S7 = 1.0 / 132.0;
const double c = 12.0;
const double d1 = -0.57721566490153286;
const double d2 = 1.6449340668482264365;
const double s = 1e-6;
const double s3 = 1.0 / 12.0;
const double s4 = 1.0 / 120.0;
const double s5 = 1.0 / 252.0;
const double s6 = 1.0 / 240.0;
const double s7 = 1.0 / 132.0;
if (Double.IsNegativeInfinity(x) || Double.IsNaN(x))
{
@ -405,25 +404,25 @@ namespace MathNet.Numerics
return DiGamma(1.0 - x) + (Math.PI / Math.Tan(-Math.PI * x));
}
if (x <= S)
if (x <= s)
{
return D1 - (1 / x) + (D2 * x);
return d1 - (1 / x) + (d2 * x);
}
double result = 0;
while (x < C)
while (x < c)
{
result -= 1 / x;
x++;
}
if (x >= C)
if (x >= c)
{
var r = 1 / x;
result += Math.Log(x) - (0.5 * r);
r *= r;
result -= r * (S3 - (r * (S4 - (r * (S5 - (r * (S6 - (r * S7))))))));
result -= r * (s3 - (r * (s4 - (r * (s5 - (r * (s6 - (r * s7))))))));
}
return result;

65
src/Numerics/SpecialFunctions/ModifiedStruve.cs

@ -59,7 +59,6 @@ namespace MathNet.Numerics
/// Returns the modified Struve function of order 0.
/// </summary>
/// <param name="x">The value to compute the function of.</param>
/// <returns></returns>
public static double StruveL0(double x)
{
//*********************************************************************72
@ -159,9 +158,6 @@ namespace MathNet.Numerics
return -StruveL0(-x);
}
const double LNR2PI = 0.91893853320467274178;
const double TWOBPI = 0.63661977236758134308;
double[] ARL0 = new double[28];
ARL0[0] = 0.42127458349979924863;
ARL0[1] = -0.33859536391220612188;
@ -237,36 +233,36 @@ namespace MathNet.Numerics
AI0ML0[23] = 0.16e-18;
// MACHINE-DEPENDENT VALUES (Suitable for IEEE-arithmetic machines)
const int NTERM1 = 25; const int NTERM2 = 14; const int NTERM3 = 21;
const double XLOW = 4.4703484e-8; const double XMAX = 1.797693e308;
const double XHIGH1 = 5.1982303e8; const double XHIGH2 = 2.5220158e17;
const int nterm1 = 25; const int nterm2 = 14; const int nterm3 = 21;
const double xlow = 4.4703484e-8; const double xmax = 1.797693e308;
const double xhigh1 = 5.1982303e8; const double xhigh2 = 2.5220158e17;
// Code for |xvalue| <= 16
if (x <= 16.0)
{
if (x < XLOW)
if (x < xlow)
{
return TWOBPI * x;
return Constants.TwoInvPi * x;
}
double T = (4.0 * x - 24.0) / (x + 24.0);
return TWOBPI * x * Evaluate.ChebyshevSum(NTERM1, ARL0, T) * Math.Exp(x);
return Constants.TwoInvPi * x * Evaluate.ChebyshevSum(nterm1, ARL0, T) * Math.Exp(x);
}
// Code for |xvalue| > 16
double ch1;
if (x > XHIGH2)
if (x > xhigh2)
{
ch1 = 1.0;
}
else
{
double T = (x - 28.0) / (4.0 - x);
ch1 = Evaluate.ChebyshevSum(NTERM2, ARL0AS, T);
ch1 = Evaluate.ChebyshevSum(nterm2, ARL0AS, T);
}
double ch2;
if (x > XHIGH1)
if (x > xhigh1)
{
ch2 = 1.0;
}
@ -274,23 +270,22 @@ namespace MathNet.Numerics
{
double xsq = x * x;
double T = (800.0 - xsq) / (288.0 + xsq);
ch2 = Evaluate.ChebyshevSum(NTERM3, AI0ML0, T);
ch2 = Evaluate.ChebyshevSum(nterm3, AI0ML0, T);
}
double test = Math.Log(ch1) - LNR2PI - Math.Log(x) / 2.0 + x;
if (test > Math.Log(XMAX))
double test = Math.Log(ch1) - Constants.LogSqrt2Pi - Math.Log(x) / 2.0 + x;
if (test > Math.Log(xmax))
{
throw new ArithmeticException("ERROR IN MISCFUN FUNCTION STRVL0: ARGUMENT CAUSES OVERFLOW");
}
return Math.Exp(test) - TWOBPI * ch2 / x;
return Math.Exp(test) - Constants.TwoInvPi * ch2 / x;
}
/// <summary>
/// Returns the modified Struve function of order 1.
/// </summary>
/// <param name="x">The value to compute the function of.</param>
/// <returns></returns>
public static double StruveL1(double x)
{
//*********************************************************************72
@ -395,10 +390,6 @@ namespace MathNet.Numerics
return StruveL1(-x);
}
const double LNR2PI = 0.91893853320467274178;
const double PI3BY2 = 4.71238898038468985769;
const double TWOBPI = 0.63661977236758134308;
double[] ARL1 = new double[27];
ARL1[0] = 0.38996027351229538208;
ARL1[1] = -0.33658096101975749366;
@ -476,42 +467,42 @@ namespace MathNet.Numerics
AI1ML1[25] = -0.1e-19;
// MACHINE-DEPENDENT VALUES (Suitable for IEEE-arithmetic machines)
const int NTERM1 = 24; const int NTERM2 = 13; const int NTERM3 = 22;
const double XLOW1 = 5.7711949e-8; const double XLOW2 = 3.3354714e-154; const double XMAX = 1.797693e308;
const double XHIGH1 = 5.19823025e8; const double XHIGH2 = 2.7021597e17;
const int nterm1 = 24; const int nterm2 = 13; const int nterm3 = 22;
const double xlow1 = 5.7711949e-8; const double xlow2 = 3.3354714e-154; const double xmax = 1.797693e308;
const double xhigh1 = 5.19823025e8; const double xhigh2 = 2.7021597e17;
// CODE FOR |x| <= 16
if (x <= 16.0)
{
if (x <= XLOW2)
if (x <= xlow2)
{
return 0.0;
}
double xsq = x * x;
if (x < XLOW1)
if (x < xlow1)
{
return xsq / PI3BY2;
return xsq / Constants.Pi3Over2;
}
double t = (4.0 * x - 24.0) / (x + 24.0);
return xsq * Evaluate.ChebyshevSum(NTERM1, ARL1, t) * Math.Exp(x) / PI3BY2;
return xsq * Evaluate.ChebyshevSum(nterm1, ARL1, t) * Math.Exp(x) / Constants.Pi3Over2;
}
// CODE FOR |x| > 16
double ch1;
if (x > XHIGH2)
if (x > xhigh2)
{
ch1 = 1.0;
}
else
{
double t = (x - 30.0) / (2.0 - x);
ch1 = Evaluate.ChebyshevSum(NTERM2, ARL1AS, t);
ch1 = Evaluate.ChebyshevSum(nterm2, ARL1AS, t);
}
double ch2;
if (x > XHIGH1)
if (x > xhigh1)
{
ch2 = 1.0;
}
@ -519,23 +510,22 @@ namespace MathNet.Numerics
{
double xsq = x * x;
double t = (800.0 - xsq) / (288.0 + xsq);
ch2 = Evaluate.ChebyshevSum(NTERM3, AI1ML1, t);
ch2 = Evaluate.ChebyshevSum(nterm3, AI1ML1, t);
}
double test = Math.Log(ch1) - LNR2PI - Math.Log(x) / 2.0 + x;
if (test > Math.Log(XMAX))
double test = Math.Log(ch1) - Constants.LogSqrt2Pi - Math.Log(x) / 2.0 + x;
if (test > Math.Log(xmax))
{
throw new ArithmeticException("ERROR IN MISCFUN FUNCTION STRVL1: ARGUMENT CAUSES OVERFLOW");
}
return Math.Exp(test) - TWOBPI * ch2;
return Math.Exp(test) - Constants.TwoInvPi * ch2;
}
/// <summary>
/// Returns the difference between the Bessel I0 and Struve L0 functions.
/// </summary>
/// <param name="x">The value to compute the function of.</param>
/// <returns></returns>
public static double BesselI0MStruveL0(double x)
{
// TODO: way off for large x (e.g. 100) - needs direct approximation
@ -546,7 +536,6 @@ namespace MathNet.Numerics
/// Returns the difference between the Bessel I1 and Struve L1 functions.
/// </summary>
/// <param name="x">The value to compute the function of.</param>
/// <returns></returns>
public static double BesselI1MStruveL1(double x)
{
// TODO: way off for large x (e.g. 100) - needs direct approximation

4
src/Numerics/Statistics/ArrayStatistics.cs

@ -368,6 +368,10 @@ namespace MathNet.Numerics.Statistics
/// </summary>
/// <param name="data">Sample array, no sorting is assumed. Will be reordered.</param>
/// <param name="tau">Quantile selector, between 0.0 and 1.0 (inclusive)</param>
/// <param name="a">a-parameter</param>
/// <param name="b">b-parameter</param>
/// <param name="c">c-parameter</param>
/// <param name="d">d-parameter</param>
public static double QuantileCustomInplace(double[] data, double tau, double a, double b, double c, double d)
{
if (data == null) throw new ArgumentNullException("data");

8
src/Numerics/Statistics/Correlation.cs

@ -64,13 +64,13 @@ namespace MathNet.Numerics.Statistics
{
throw new ArgumentOutOfRangeException("dataB", "Datasets dataA and dataB need to have the same length. dataB is shorter.");
}
double Acurrent = ieA.Current;
double Bcurrent = ieB.Current;
double currentA = ieA.Current;
double currentB = ieB.Current;
double deltaA = Acurrent - meanA;
double deltaA = currentA - meanA;
double scaleDeltaA = deltaA / ++n;
double deltaB = Bcurrent - meanB;
double deltaB = currentB - meanB;
double scaleDeltaB = deltaB / n;
meanA += scaleDeltaA;

24
src/Numerics/Statistics/DescriptiveStatistics.cs

@ -80,7 +80,7 @@ namespace MathNet.Numerics.Statistics
if (increasedAccuracy)
{
ComputeHA(data);
ComputeDecimal(data);
}
else
{
@ -109,7 +109,7 @@ namespace MathNet.Numerics.Statistics
if (increasedAccuracy)
{
ComputeHA(data);
ComputeDecimal(data);
}
else
{
@ -184,15 +184,15 @@ namespace MathNet.Numerics.Statistics
{
double delta = xi - mean;
double scaleDelta = delta / ++n;
double scaleDeltaSQR = scaleDelta * scaleDelta;
double scaleDeltaSqr = scaleDelta * scaleDelta;
double tmpDelta = delta * (n - 1);
mean += scaleDelta;
kurtosis += tmpDelta * scaleDelta * scaleDeltaSQR * (n * n - 3 * n + 3)
+ 6 * scaleDeltaSQR * variance - 4 * scaleDelta * skewness;
kurtosis += tmpDelta * scaleDelta * scaleDeltaSqr * (n * n - 3 * n + 3)
+ 6 * scaleDeltaSqr * variance - 4 * scaleDelta * skewness;
skewness += tmpDelta * scaleDeltaSQR * (n - 2) - 3 * scaleDelta * variance;
skewness += tmpDelta * scaleDeltaSqr * (n - 2) - 3 * scaleDelta * variance;
variance += tmpDelta * scaleDelta;
if (minimum > xi) { minimum = xi; }
@ -222,15 +222,15 @@ namespace MathNet.Numerics.Statistics
{
double delta = xi.Value - mean;
double scaleDelta = delta / ++n;
double scaleDeltaSQR = scaleDelta * scaleDelta;
double scaleDeltaSqr = scaleDelta * scaleDelta;
double tmpDelta = delta * (n - 1);
mean += scaleDelta;
kurtosis += tmpDelta * scaleDelta * scaleDeltaSQR * (n * n - 3 * n + 3)
+ 6 * scaleDeltaSQR * variance - 4 * scaleDelta * skewness;
kurtosis += tmpDelta * scaleDelta * scaleDeltaSqr * (n * n - 3 * n + 3)
+ 6 * scaleDeltaSqr * variance - 4 * scaleDelta * skewness;
skewness += tmpDelta * scaleDeltaSQR * (n - 2) - 3 * scaleDelta * variance;
skewness += tmpDelta * scaleDeltaSqr * (n - 2) - 3 * scaleDelta * variance;
variance += tmpDelta * scaleDelta;
if (minimum > xi) { minimum = xi.Value; }
if (maximum < xi) { maximum = xi.Value; }
@ -245,7 +245,7 @@ namespace MathNet.Numerics.Statistics
/// Computes descriptive statistics from a stream of data values using high accuracy.
/// </summary>
/// <param name="data">A sequence of datapoints.</param>
private void ComputeHA(IEnumerable<double> data)
private void ComputeDecimal(IEnumerable<double> data)
{
decimal mean = 0;
decimal variance = 0;
@ -280,7 +280,7 @@ namespace MathNet.Numerics.Statistics
/// Computes descriptive statistics from a stream of nullable data values using high accuracy.
/// </summary>
/// <param name="data">A sequence of datapoints.</param>
private void ComputeHA(IEnumerable<double?> data)
private void ComputeDecimal(IEnumerable<double?> data)
{
decimal mean = 0;
decimal variance = 0;

15
src/Numerics/Statistics/Histogram.cs

@ -66,7 +66,7 @@ namespace MathNet.Numerics.Statistics
}
}
private static readonly PointComparer pointComparer = new PointComparer();
private static readonly PointComparer Comparer = new PointComparer();
/// <summary>
/// Lower Bound of the Bucket.
@ -132,7 +132,7 @@ namespace MathNet.Numerics.Statistics
/// </summary>
public static IComparer<Bucket> DefaultPointComparer
{
get { return pointComparer; }
get { return Comparer; }
}
/// <summary>
@ -208,7 +208,6 @@ namespace MathNet.Numerics.Statistics
/// <summary>
/// Formats a human-readable string for this bucket.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "(" + LowerBound + ";" + UpperBound + "] = " + Count;
@ -286,12 +285,12 @@ namespace MathNet.Numerics.Statistics
{
if (lower > upper)
{
throw new ArgumentOutOfRangeException("The histogram lowerbound must be smaller than the upper bound.");
throw new ArgumentOutOfRangeException("upper", "The histogram lowerbound must be smaller than the upper bound.");
}
if (nbuckets < 1)
{
throw new ArgumentOutOfRangeException("The number of bins in a histogram should be at least 1.");
throw new ArgumentOutOfRangeException("nbuckets", "The number of bins in a histogram should be at least 1.");
}
double width = (upper - lower) / nbuckets;
@ -467,13 +466,11 @@ namespace MathNet.Numerics.Statistics
/// </summary>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();
foreach (Bucket b in _buckets)
{
sb.Append(b.ToString());
sb.Append(b);
}
return sb.ToString();
}
}

6
src/Numerics/Statistics/MCMC/HybridMC.cs

@ -198,15 +198,15 @@ namespace MathNet.Numerics.Statistics.Mcmc
{
if (pSdv == null)
{
throw new ArgumentNullException("Standard deviation cannot be null.");
throw new ArgumentNullException("pSdv", "Standard deviation cannot be null.");
}
if (pSdv.Count() != _length)
{
throw new ArgumentOutOfRangeException("Standard deviation of momentum must have same length as sample.");
throw new ArgumentOutOfRangeException("pSdv", "Standard deviation of momentum must have same length as sample.");
}
if (pSdv.Any(sdv => sdv < 0))
{
throw new ArgumentOutOfRangeException("Standard deviation must be positive.");
throw new ArgumentOutOfRangeException("pSdv", "Standard deviation must be positive.");
}
}

4
src/Numerics/Statistics/MCMC/HybridMCGeneric.cs

@ -49,7 +49,6 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// </summary>
/// <param name="f">Function to be differentiated.</param>
/// <param name="x">Value where the derivative is computed.</param>
/// <returns></returns>
public delegate T DiffMethod(DensityLn<T> f, T x);
/// <summary>
@ -133,7 +132,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// <param name="diff">The method used for differentiation.</param>
/// <exception cref="ArgumentOutOfRangeException">When the number of burnInterval iteration is negative.</exception>
/// <exception cref="ArgumentNullException">When either x0, pdfLnP or diff is null.</exception>
public HybridMCGeneric(T x0, DensityLn<T> pdfLnP, int frogLeapSteps, double stepSize, int burnInterval, Random randomSource, DiffMethod diff)
protected HybridMCGeneric(T x0, DensityLn<T> pdfLnP, int frogLeapSteps, double stepSize, int burnInterval, Random randomSource, DiffMethod diff)
{
_energy = x => -pdfLnP(x);
FrogLeapSteps = frogLeapSteps;
@ -226,7 +225,6 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// </summary>
/// <param name="first">First vector/scalar in the product.</param>
/// <param name="second">Second vector/scalar in the product.</param>
/// <returns></returns>
abstract protected double DoProduct(T first, T second);
/// <summary>

4
src/Numerics/Statistics/MCMC/MCMCDiagnostics.cs

@ -53,13 +53,13 @@ namespace MathNet.Numerics.Statistics.Mcmc.Diagnostics
{
if (lag < 0)
{
throw new ArgumentOutOfRangeException("Lag must be positive");
throw new ArgumentOutOfRangeException("lag", "Lag must be positive");
}
int length = series.Count();
if (lag >= length)
{
throw new ArgumentOutOfRangeException("Lag must be smaller than the sample size");
throw new ArgumentOutOfRangeException("lag", "Lag must be smaller than the sample size");
}
var transformedSeries = series.Select(f);

4
src/Numerics/Statistics/MCMC/MCMCSampler.cs

@ -138,13 +138,11 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// <returns>An array of samples.</returns>
public virtual T[] Sample(int n)
{
T[] ret = new T[n];
var ret = new T[n];
for (int i = 0; i < n; i++)
{
ret[i] = Sample();
}
return ret;
}

2
src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs

@ -137,7 +137,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// <param name="randomSource">Random number generator used to sample the momentum.</param>
/// <exception cref="ArgumentOutOfRangeException">When the number of burnInterval iteration is negative.</exception>
public UnivariateHybridMC(double x0, DensityLn<double> pdfLnP, int frogLeapSteps, double stepSize, int burnInterval, double pSdv, Random randomSource)
: this(x0, pdfLnP, frogLeapSteps, stepSize, burnInterval, pSdv, randomSource, new DiffMethod(UnivariateHybridMC.Grad))
: this(x0, pdfLnP, frogLeapSteps, stepSize, burnInterval, pSdv, randomSource, Grad)
{
}

4
src/Numerics/Statistics/SortedArrayStatistics.cs

@ -176,6 +176,10 @@ namespace MathNet.Numerics.Statistics
/// </summary>
/// <param name="data">Sample array, must be sorted ascendingly.</param>
/// <param name="tau">Quantile selector, between 0.0 and 1.0 (inclusive).</param>
/// <param name="a">a-parameter</param>
/// <param name="b">b-parameter</param>
/// <param name="c">c-parameter</param>
/// <param name="d">d-parameter</param>
public static double QuantileCustom(double[] data, double tau, double a, double b, double c, double d)
{
if (data == null) throw new ArgumentNullException("data");

23
src/Numerics/Threading/CommonParallel.cs

@ -62,6 +62,7 @@ namespace MathNet.Numerics.Threading
/// </summary>
/// <param name="fromInclusive">The start index, inclusive.</param>
/// <param name="toExclusive">The end index, exclusive.</param>
/// <param name="rangeSize">The partition size for splitting work into smaller pieces.</param>
/// <param name="body">The body to be invoked for each iteration range.</param>
public static void For(int fromInclusive, int toExclusive, int rangeSize, Action<int, int> body)
{
@ -282,7 +283,7 @@ namespace MathNet.Numerics.Threading
/// <param name="select">The function to select items over a subset.</param>
/// <param name="reduce">The function to select the item of selection from the subsets.</param>
/// <returns>The selected value.</returns>
public static U Aggregate<T, U>(T[] array, Func<int, T, U> select, Func<U[], U> reduce)
public static TOut Aggregate<T, TOut>(T[] array, Func<int, T, TOut> select, Func<TOut[], TOut> reduce)
{
if (select == null)
{
@ -296,7 +297,7 @@ namespace MathNet.Numerics.Threading
// Special case: no action
if (array == null || array.Length == 0)
{
return reduce(new U[0]);
return reduce(new TOut[0]);
}
// Special case: single action, inline
@ -308,7 +309,7 @@ namespace MathNet.Numerics.Threading
// Special case: straight execution without parallelism
if (Control.DisableParallelization || Control.NumberOfParallelWorkerThreads < 2)
{
var mapped = new U[array.Length];
var mapped = new TOut[array.Length];
for (int k = 0; k < mapped.Length; k++)
{
mapped[k] = select(k, array[k]);
@ -317,7 +318,7 @@ namespace MathNet.Numerics.Threading
}
#if PORTABLE
var tasks = new Task<U>[Control.NumberOfParallelWorkerThreads];
var tasks = new Task<TOut>[Control.NumberOfParallelWorkerThreads];
var size = array.Length / tasks.Length;
// partition the jobs into separate sets for each but the last worked thread
@ -328,7 +329,7 @@ namespace MathNet.Numerics.Threading
tasks[i] = Task.Factory.StartNew(() =>
{
var mapped = new U[stop - start];
var mapped = new TOut[stop - start];
for (int k = 0; k < mapped.Length; k++)
{
mapped[k] = select(k + start, array[k + start]);
@ -341,7 +342,7 @@ namespace MathNet.Numerics.Threading
tasks[tasks.Length - 1] = Task.Factory.StartNew(() =>
{
var start = ((tasks.Length - 1) * size);
var mapped = new U[array.Length - start];
var mapped = new TOut[array.Length - start];
for (int k = 0; k < mapped.Length; k++)
{
mapped[k] = select(k + start, array[k + start]);
@ -353,16 +354,16 @@ namespace MathNet.Numerics.Threading
.ContinueWhenAll(tasks, tsk => reduce(tsk.Select(t => t.Result).ToArray()))
.Result;
#else
var intermediateResults = new List<U>();
var intermediateResults = new List<TOut>();
var syncLock = new object();
var maxThreads = Control.DisableParallelization ? 1 : Control.NumberOfParallelWorkerThreads;
Parallel.ForEach(
Partitioner.Create(0, array.Length),
new ParallelOptions {MaxDegreeOfParallelism = maxThreads},
() => new List<U>(),
() => new List<TOut>(),
(range, loop, localData) =>
{
var mapped = new U[range.Item2 - range.Item1];
var mapped = new TOut[range.Item2 - range.Item1];
for (int k = 0; k < mapped.Length; k++)
{
mapped[k] = select(k + range.Item1, array[k + range.Item1]);
@ -421,7 +422,7 @@ namespace MathNet.Numerics.Threading
/// <param name="reducePair">The function to select the item of selection from the subsets.</param>
/// <param name="reduceDefault">Default result of the reduce function on an empty set.</param>
/// <returns>The selected value.</returns>
public static U Aggregate<T, U>(T[] array, Func<int, T, U> select, Func<U, U, U> reducePair, U reduceDefault)
public static TOut Aggregate<T, TOut>(T[] array, Func<int, T, TOut> select, Func<TOut, TOut, TOut> reducePair, TOut reduceDefault)
{
return Aggregate(array, select, results =>
{
@ -435,7 +436,7 @@ namespace MathNet.Numerics.Threading
return results[0];
}
U result = results[0];
TOut result = results[0];
for (int i = 1; i < results.Length; i++)
{
result = reducePair(result, results[i]);

Loading…
Cancel
Save