Browse Source

Cosmetics, code quality

pull/38/head
Christoph Ruegg 14 years ago
parent
commit
5e72d7e5dc
  1. 18
      .gitattributes
  2. 20
      MathNet.Numerics.snl.DotSettings
  3. 4
      src/Numerics/Complex32.cs
  4. 7
      src/Numerics/Complex64.cs
  5. 2
      src/Numerics/ComplexExtensions.cs
  6. 3
      src/Numerics/Constants.cs
  7. 2
      src/Numerics/IPrecisionSupport.cs
  8. 2
      src/Numerics/Interpolation/Algorithms/CubicHermiteSplineInterpolation.cs
  9. 2
      src/Numerics/Interpolation/Algorithms/LinearSplineInterpolation.cs
  10. 2
      src/Numerics/Interpolation/Algorithms/NevillePolynomialInterpolation.cs
  11. 2
      src/Numerics/LinearAlgebra/Complex/DenseVector.cs
  12. 3
      src/Numerics/LinearAlgebra/Complex/Factorization/DenseEvd.cs
  13. 1
      src/Numerics/LinearAlgebra/Complex/Factorization/DenseLU.cs
  14. 3
      src/Numerics/LinearAlgebra/Complex/Factorization/UserEvd.cs
  15. 1
      src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs
  16. 5
      src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs
  17. 2
      src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs
  18. 2
      src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs
  19. 6
      src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs
  20. 18
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  21. 2
      src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
  22. 3
      src/Numerics/LinearAlgebra/Complex32/Factorization/DenseEvd.cs
  23. 1
      src/Numerics/LinearAlgebra/Complex32/Factorization/DenseLU.cs
  24. 3
      src/Numerics/LinearAlgebra/Complex32/Factorization/UserEvd.cs
  25. 2
      src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs
  26. 2
      src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs
  27. 1
      src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs
  28. 6
      src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs
  29. 19
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  30. 2
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  31. 1
      src/Numerics/LinearAlgebra/Double/Factorization/DenseLU.cs
  32. 2
      src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs
  33. 2
      src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs
  34. 2
      src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs
  35. 6
      src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs
  36. 19
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  37. 1
      src/Numerics/LinearAlgebra/Generic/Factorization/QR.cs
  38. 1
      src/Numerics/LinearAlgebra/Generic/Factorization/Svd.cs
  39. 2
      src/Numerics/LinearAlgebra/Single/DenseVector.cs
  40. 1
      src/Numerics/LinearAlgebra/Single/Factorization/DenseLU.cs
  41. 2
      src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs
  42. 2
      src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs
  43. 1
      src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs
  44. 6
      src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs
  45. 18
      src/Numerics/LinearAlgebra/Single/SparseVector.cs
  46. 24
      src/Numerics/Precision.cs
  47. 2
      src/Numerics/Random/Xorshift.cs
  48. 7
      src/Numerics/SerializableAttribute.cs
  49. 4
      src/Numerics/Signals/SignalGenerator.Equidistant.cs
  50. 106
      src/Numerics/SpecialFunctions/Erf.cs
  51. 6
      src/Numerics/SpecialFunctions/Factorial.cs
  52. 71
      src/Numerics/SpecialFunctions/Gamma.cs
  53. 2
      src/Numerics/SpecialFunctions/Stability.cs
  54. 1
      src/Numerics/Statistics/Correlation.cs
  55. 8
      src/Numerics/Statistics/DescriptiveStatistics.cs
  56. 81
      src/Numerics/Statistics/Histogram.cs
  57. 30
      src/Numerics/Statistics/MCMC/MCMCSampler.cs
  58. 10
      src/Numerics/Statistics/MCMC/MetropolisHastingsSampler.cs
  59. 10
      src/Numerics/Statistics/MCMC/MetropolisSampler.cs
  60. 4
      src/Numerics/Statistics/MCMC/RejectionSampler.cs
  61. 16
      src/Numerics/Statistics/MCMC/UnivariateSliceSampler.cs

18
.gitattributes

@ -1,6 +1,4 @@
*.cs text diff=csharp
*.csproj text
*.sln text
*.msbuild text
*.config text
*.conf text
@ -8,4 +6,20 @@
*.csdef text
*.xml text
*.js text
*.csproj text merge=union
*.fsproj text merge=union
*.sln text eol=crlf merge=union
*.jpg binary
*.png binary
*.gif binary
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
* text=auto

20
MathNet.Numerics.snl.DotSettings

@ -0,0 +1,20 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_LINQ_QUERY/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARGUMENT/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARRAY_AND_OBJECT_INITIALIZER/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXPRESSION/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_PARAMETER/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_CONSTRAINS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_LIST/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EXPLICIT_PRIVATE_MODIFIER/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_ANONYMOUS_METHOD_BLOCK/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_EMBRACED_INITIALIZER_BLOCK/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_BINARY_OPSIGN/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
</wpf:ResourceDictionary>

4
src/Numerics/Complex32.cs

@ -417,7 +417,7 @@ namespace MathNet.Numerics
return Zero;
}
return new Complex32((float)(_real / mod), (float)(_imag / mod));
return new Complex32(_real / mod, _imag / mod);
}
}
@ -1103,7 +1103,7 @@ namespace MathNet.Numerics
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

7
src/Numerics/Complex64.cs

@ -28,11 +28,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
#if !SYSNUMERICS
using MathNet.Numerics;
namespace System.Numerics
{
#if !SYSNUMERICS
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
@ -1696,5 +1697,5 @@ namespace System.Numerics
return value.SquareRoot();
}
}
#endif
}
}
#endif

2
src/Numerics/ComplexExtensions.cs

@ -365,7 +365,7 @@ namespace MathNet.Numerics
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

3
src/Numerics/Constants.cs

@ -30,9 +30,6 @@
namespace MathNet.Numerics
{
using System.Numerics;
using System.Runtime.InteropServices;
/// <summary>
/// A collection of frequently used mathematical constants.
/// </summary>

2
src/Numerics/IPrecisionSupport.cs

@ -34,7 +34,7 @@ namespace MathNet.Numerics
/// Support Interface for Precision Operations (like AlmostEquals).
/// </summary>
/// <typeparam name="T">Type of the implementing class.</typeparam>
public interface IPrecisionSupport<T>
public interface IPrecisionSupport<in T>
{
/// <summary>
/// Returns a Norm of a value of this type, which is appropriate for measuring how

2
src/Numerics/Interpolation/Algorithms/CubicHermiteSplineInterpolation.cs

@ -144,7 +144,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
if (samplePoints.Count != sampleValues.Count
|| samplePoints.Count != sampleDerivatives.Count)
{
throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLength);
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
for (var i = 1; i < samplePoints.Count; ++i)

2
src/Numerics/Interpolation/Algorithms/LinearSplineInterpolation.cs

@ -131,7 +131,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
if (samplePoints.Count != sampleValues.Count)
{
throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLength);
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
for (var i = 1; i < samplePoints.Count; ++i)

2
src/Numerics/Interpolation/Algorithms/NevillePolynomialInterpolation.cs

@ -123,7 +123,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
if (samplePoints.Count != sampleValues.Count)
{
throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLength);
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
for (var i = 1; i < samplePoints.Count; ++i)

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

@ -854,7 +854,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

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

@ -593,7 +593,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
var eps = Precision.DoubleMachinePrecision;
double norm;
Complex s, x, y, z, exshift = Complex.Zero;
Complex x, y, z, exshift = Complex.Zero;
// Outer loop over eigenvalue index
var iter = 0;
@ -624,6 +624,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
else
{
// Form shift
Complex s;
if (iter != 10 && iter != 20)
{
s = matrixH[n, n];

1
src/Numerics/LinearAlgebra/Complex/Factorization/DenseLU.cs

@ -32,7 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
{
using System;
using System.Numerics;
using Algorithms.LinearAlgebra;
using Generic;
using Properties;
using Threading;

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

@ -588,7 +588,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
var eps = Precision.DoubleMachinePrecision;
double norm;
Complex s, x, y, z, exshift = Complex.Zero;
Complex x, y, z, exshift = Complex.Zero;
// Outer loop over eigenvalue index
var iter = 0;
@ -619,6 +619,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
else
{
// Form shift
Complex s;
if (iter != 10 && iter != 20)
{
s = matrixH[n, n];

1
src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs

@ -32,7 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
{
using System;
using System.Numerics;
using Generic;
using Generic.Solvers.Status;
using Preconditioners;
using Properties;

5
src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs

@ -34,10 +34,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using Generic;
using Generic.Solvers;
using Generic.Solvers.Status;
using Properties;
@ -248,7 +245,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
{
if (assembly == null)
{
throw new ArgumentNullException("Assembly");
throw new ArgumentNullException("assembly");
}
if (typesToExclude == null)

2
src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs

@ -337,7 +337,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// Define the temporary scalars
Complex beta = 0;
Complex sigma;
// Define the temporary vectors
// rDash_0 = r_0
@ -418,6 +417,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// if we don't do any so ...
var ctdot = c.DotProduct(t);
Complex eta;
Complex sigma;
if (((_numberOfBiCgStabSteps == 0) && (iterationNumber == 0)) || ShouldRunBiCgStabSteps(iterationNumber))
{
// sigma_k = (c_k * t_k) / (c_k * c_k)

2
src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs

@ -36,8 +36,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
using System.Linq;
using System.Numerics;
using Distributions;
using Generic;
using Generic.Factorization;
using Generic.Solvers.Status;
using Preconditioners;
using Properties;

6
src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs

@ -170,7 +170,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_fillLevel = value;
@ -205,7 +205,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_dropTolerance = value;
@ -242,7 +242,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_pivotTolerance = value;

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

@ -381,24 +381,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (ReferenceEquals(this, result))
{
//populate a new vector with the scalar
var vnonZeroValues = new Complex[this.Count];
var vnonZeroIndices = new int[this.Count];
for (int index = 0; index < this.Count; index++)
var vnonZeroValues = new Complex[Count];
var vnonZeroIndices = new int[Count];
for (int index = 0; index < Count; index++)
{
vnonZeroIndices[index] = index;
vnonZeroValues[index] = scalar;
}
//populate the non zero values from this
for (int j = 0; j < this.NonZerosCount; j++)
for (int j = 0; j < NonZerosCount; j++)
{
vnonZeroValues[this._nonZeroIndices[j]] = this._nonZeroValues[j] + scalar;
vnonZeroValues[_nonZeroIndices[j]] = _nonZeroValues[j] + scalar;
}
//assign this vectors arrary to the new arrays.
this._nonZeroValues = vnonZeroValues;
this._nonZeroIndices = vnonZeroIndices;
this.NonZerosCount = this.Count;
_nonZeroValues = vnonZeroValues;
_nonZeroIndices = vnonZeroIndices;
NonZerosCount = Count;
}
else
{
@ -1155,7 +1155,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

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

@ -907,7 +907,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

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

@ -597,7 +597,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
var eps = (float)Precision.SingleMachinePrecision;
float norm;
Complex32 s, x, y, z, exshift = Complex32.Zero;
Complex32 x, y, z, exshift = Complex32.Zero;
// Outer loop over eigenvalue index
var iter = 0;
@ -628,6 +628,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
else
{
// Form shift
Complex32 s;
if (iter != 10 && iter != 20)
{
s = matrixH[n, n];

1
src/Numerics/LinearAlgebra/Complex32/Factorization/DenseLU.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
{
using System;
using Algorithms.LinearAlgebra;
using Generic;
using Numerics;
using Properties;

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

@ -592,7 +592,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
var eps = (float)Precision.SingleMachinePrecision;
float norm;
Complex32 s, x, y, z, exshift = Complex32.Zero;
Complex32 x, y, z, exshift = Complex32.Zero;
// Outer loop over eigenvalue index
var iter = 0;
@ -623,6 +623,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
else
{
// Form shift
Complex32 s;
if (iter != 10 && iter != 20)
{
s = matrixH[n, n];

2
src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs

@ -245,7 +245,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
{
if (assembly == null)
{
throw new ArgumentNullException("Assembly");
throw new ArgumentNullException("assembly");
}
if (typesToExclude == null)

2
src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs

@ -342,7 +342,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// Define the temporary scalars
Complex32 beta = 0;
Complex32 sigma;
// Define the temporary vectors
// rDash_0 = r_0
@ -423,6 +422,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// if we don't do any so ...
var ctdot = c.DotProduct(t);
Complex32 eta;
Complex32 sigma;
if (((_numberOfBiCgStabSteps == 0) && (iterationNumber == 0)) || ShouldRunBiCgStabSteps(iterationNumber))
{
// sigma_k = (c_k * t_k) / (c_k * c_k)

1
src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs

@ -35,7 +35,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
using System.Diagnostics;
using System.Linq;
using Distributions;
using Generic.Factorization;
using Generic.Solvers.Status;
using Numerics;
using Preconditioners;

6
src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs

@ -170,7 +170,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_fillLevel = value;
@ -205,7 +205,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_dropTolerance = value;
@ -242,7 +242,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_pivotTolerance = value;

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

@ -411,25 +411,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (ReferenceEquals(this, result))
{
//populate a new vector with the scalar
var vnonZeroValues = new Complex32[this.Count];
var vnonZeroIndices = new int[this.Count];
for (int index = 0; index < this.Count; index++)
var vnonZeroValues = new Complex32[Count];
var vnonZeroIndices = new int[Count];
for (int index = 0; index < Count; index++)
{
vnonZeroIndices[index] = index;
vnonZeroValues[index] = scalar;
}
//populate the non zero values from this
for (int j = 0; j < this.NonZerosCount; j++)
for (int j = 0; j < NonZerosCount; j++)
{
vnonZeroValues[this._nonZeroIndices[j]] = this._nonZeroValues[j] + scalar;
vnonZeroValues[_nonZeroIndices[j]] = _nonZeroValues[j] + scalar;
}
//assign this vectors arrary to the new arrays.
this._nonZeroValues = vnonZeroValues;
this._nonZeroIndices = vnonZeroIndices;
this.NonZerosCount = this.Count;
_nonZeroValues = vnonZeroValues;
_nonZeroIndices = vnonZeroIndices;
NonZerosCount = Count;
}
else
{
@ -1186,7 +1185,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

2
src/Numerics/LinearAlgebra/Double/DenseVector.cs

@ -990,7 +990,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

1
src/Numerics/LinearAlgebra/Double/Factorization/DenseLU.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
{
using System;
using Algorithms.LinearAlgebra;
using Generic;
using Properties;

2
src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs

@ -242,7 +242,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
{
if (assembly == null)
{
throw new ArgumentNullException("Assembly");
throw new ArgumentNullException("assembly");
}
if (typesToExclude == null)

2
src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs

@ -341,7 +341,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
// Define the temporary scalars
double beta = 0;
double sigma;
// Define the temporary vectors
// rDash_0 = r_0
@ -422,6 +421,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
// if we don't do any so ...
var ctdot = c.DotProduct(t);
double eta;
double sigma;
if (((_numberOfBiCgStabSteps == 0) && (iterationNumber == 0)) || ShouldRunBiCgStabSteps(iterationNumber))
{
// sigma_k = (c_k * t_k) / (c_k * c_k)

2
src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs

@ -35,8 +35,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
using System.Diagnostics;
using System.Linq;
using Distributions;
using Generic;
using Generic.Factorization;
using Generic.Solvers.Status;
using Preconditioners;
using Properties;

6
src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs

@ -169,7 +169,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_fillLevel = value;
@ -204,7 +204,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_dropTolerance = value;
@ -241,7 +241,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_pivotTolerance = value;

19
src/Numerics/LinearAlgebra/Double/SparseVector.cs

@ -329,25 +329,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if (ReferenceEquals(this, result))
{
//populate a new vector with the scalar
var vnonZeroValues = new double[this.Count];
var vnonZeroIndices = new int[this.Count];
for (int index = 0; index < this.Count; index++)
var vnonZeroValues = new double[Count];
var vnonZeroIndices = new int[Count];
for (int index = 0; index < Count; index++)
{
vnonZeroIndices[index] = index;
vnonZeroValues[index] = scalar;
}
//populate the non zero values from this
for (int j = 0; j < this.NonZerosCount; j++)
for (int j = 0; j < NonZerosCount; j++)
{
vnonZeroValues[this._nonZeroIndices[j]] = this._nonZeroValues[j] + scalar;
vnonZeroValues[_nonZeroIndices[j]] = _nonZeroValues[j] + scalar;
}
//assign this vectors arrary to the new arrays.
this._nonZeroValues = vnonZeroValues;
this._nonZeroIndices = vnonZeroIndices;
this.NonZerosCount = this.Count;
_nonZeroValues = vnonZeroValues;
_nonZeroIndices = vnonZeroIndices;
NonZerosCount = Count;
}
else
{
@ -1215,7 +1214,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

1
src/Numerics/LinearAlgebra/Generic/Factorization/QR.cs

@ -30,7 +30,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Factorization
using System.Numerics;
using Generic;
using Numerics;
using Properties;
/// <summary>
/// <para>A class which encapsulates the functionality of the QR decomposition.</para>

1
src/Numerics/LinearAlgebra/Generic/Factorization/Svd.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.LinearAlgebra.Generic.Factorization
{
using System;
using System.Linq;
using System.Numerics;
using Generic;
using Numerics;

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

@ -991,7 +991,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

1
src/Numerics/LinearAlgebra/Single/Factorization/DenseLU.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
{
using System;
using Algorithms.LinearAlgebra;
using Generic;
using Properties;

2
src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs

@ -245,7 +245,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
{
if (assembly == null)
{
throw new ArgumentNullException("Assembly");
throw new ArgumentNullException("assembly");
}
if (typesToExclude == null)

2
src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs

@ -341,7 +341,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
// Define the temporary scalars
float beta = 0;
float sigma;
// Define the temporary vectors
// rDash_0 = r_0
@ -422,6 +421,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
// if we don't do any so ...
var ctdot = c.DotProduct(t);
float eta;
float sigma;
if (((_numberOfBiCgStabSteps == 0) && (iterationNumber == 0)) || ShouldRunBiCgStabSteps(iterationNumber))
{
// sigma_k = (c_k * t_k) / (c_k * c_k)

1
src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs

@ -34,7 +34,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
using System.Collections.Generic;
using System.Diagnostics;
using Distributions;
using Generic.Factorization;
using Generic.Solvers.Status;
using Preconditioners;
using Properties;

6
src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs

@ -169,7 +169,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_fillLevel = value;
@ -204,7 +204,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_dropTolerance = value;
@ -241,7 +241,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("Value");
throw new ArgumentOutOfRangeException("value");
}
_pivotTolerance = value;

18
src/Numerics/LinearAlgebra/Single/SparseVector.cs

@ -359,24 +359,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if (ReferenceEquals(this, result))
{
//populate a new vector with the scalar
var vnonZeroValues = new float[this.Count];
var vnonZeroIndices = new int[this.Count];
for (int index = 0; index < this.Count; index++)
var vnonZeroValues = new float[Count];
var vnonZeroIndices = new int[Count];
for (int index = 0; index < Count; index++)
{
vnonZeroIndices[index] = index;
vnonZeroValues[index] = scalar;
}
//populate the non zero values from this
for (int j = 0; j < this.NonZerosCount; j++)
for (int j = 0; j < NonZerosCount; j++)
{
vnonZeroValues[this._nonZeroIndices[j]] = this._nonZeroValues[j] + scalar;
vnonZeroValues[_nonZeroIndices[j]] = _nonZeroValues[j] + scalar;
}
//assign this vectors arrary to the new arrays.
this._nonZeroValues = vnonZeroValues;
this._nonZeroIndices = vnonZeroIndices;
this.NonZerosCount = this.Count;
_nonZeroValues = vnonZeroValues;
_nonZeroIndices = vnonZeroIndices;
NonZerosCount = Count;
}
else
@ -1225,7 +1225,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
if (value == null)
{
throw new ArgumentNullException(value);
throw new ArgumentNullException("value");
}
value = value.Trim();

24
src/Numerics/Precision.cs

@ -1291,14 +1291,10 @@ namespace MathNet.Numerics
// on each side of the numbers, e.g. if decimalPlaces == 2,
// then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00
double maxDifference = decimalPlaceMagnitude / 2.0;
if (a > b)
{
return (a * Math.Pow(10, -magnitudeOfFirst)) - maxDifference < (b * Math.Pow(10, -magnitudeOfFirst));
}
else
{
return (b * Math.Pow(10, -magnitudeOfSecond)) - maxDifference < (a * Math.Pow(10, -magnitudeOfSecond));
}
return a > b
? (a*Math.Pow(10, -magnitudeOfFirst)) - maxDifference < (b*Math.Pow(10, -magnitudeOfFirst))
: (b*Math.Pow(10, -magnitudeOfSecond)) - maxDifference < (a*Math.Pow(10, -magnitudeOfSecond));
}
/// <summary>
@ -1333,14 +1329,10 @@ namespace MathNet.Numerics
// on each side of the numbers, e.g. if decimalPlaces == 2,
// then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00
float maxDifference = decimalPlaceMagnitude / 2.0f;
if (a > b)
{
return (a * (float)Math.Pow(10, -magnitudeOfFirst)) - maxDifference < (b * (float)Math.Pow(10, -magnitudeOfFirst));
}
else
{
return (b * (float)Math.Pow(10, -magnitudeOfSecond)) - maxDifference < (a * (float)Math.Pow(10, -magnitudeOfSecond));
}
return a > b
? (a*(float) Math.Pow(10, -magnitudeOfFirst)) - maxDifference < (b*(float) Math.Pow(10, -magnitudeOfFirst))
: (b*(float) Math.Pow(10, -magnitudeOfSecond)) - maxDifference < (a*(float) Math.Pow(10, -magnitudeOfSecond));
}
/// <summary>

2
src/Numerics/Random/Xorshift.cs

@ -247,7 +247,7 @@ namespace MathNet.Numerics.Random
/// <summary>
/// The multiplier.
/// </summary>
private ulong _a;
private readonly ulong _a;
/// <summary>
/// Returns a random number between 0.0 and 1.0.

7
src/Numerics/SerializableAttribute.cs

@ -1,11 +1,12 @@
using System;
#if PORTABLE
using System;
namespace MathNet.Numerics
{
#if PORTABLE
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class SerializableAttribute : Attribute
{
}
#endif
}
#endif

4
src/Numerics/Signals/SignalGenerator.Equidistant.cs

@ -72,7 +72,7 @@ namespace MathNet.Numerics.Signals
if (sampleCount == 1)
{
return new T[] { function(0.5 * (intervalBegin + intervalEnd)) };
return new[] { function(0.5 * (intervalBegin + intervalEnd)) };
}
var samples = new T[sampleCount];
@ -128,7 +128,7 @@ namespace MathNet.Numerics.Signals
if (sampleCount == 1)
{
samplePoints = new[] { 0.5 * (intervalBegin + intervalEnd) };
return new T[] { function(samplePoints[0]) };
return new[] { function(samplePoints[0]) };
}
var samples = new T[sampleCount];

106
src/Numerics/SpecialFunctions/Erf.cs

@ -169,12 +169,12 @@ namespace MathNet.Numerics
{
if (!invert)
{
return -ErfImp(-z, invert);
return -ErfImp(-z, false);
}
if (z < -0.5)
{
return 2 - ErfImp((-z), invert);
return 2 - ErfImp((-z), true);
}
return 1 + ErfImp(-z, false);
@ -199,8 +199,8 @@ namespace MathNet.Numerics
else
{
// Worst case absolute error found: 6.688618532e-21
double[] n = new double[] { 0.00337916709551257388990745, -0.00073695653048167948530905, -0.374732337392919607868241, 0.0817442448733587196071743, -0.0421089319936548595203468, 0.0070165709512095756344528, -0.00495091255982435110337458, 0.000871646599037922480317225 };
double[] d = new double[] { 1, -0.218088218087924645390535, 0.412542972725442099083918, -0.0841891147873106755410271, 0.0655338856400241519690695, -0.0120019604454941768171266, 0.00408165558926174048329689, -0.000615900721557769691924509 };
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 };
result = (z * 1.125) + (z * EvaluatePolynomial(n, z) / EvaluatePolynomial(d, z));
}
@ -215,104 +215,104 @@ namespace MathNet.Numerics
if (z < 0.75)
{
// Worst case absolute error found: 5.582813374e-21
double[] n = new double[] { -0.0361790390718262471360258, 0.292251883444882683221149, 0.281447041797604512774415, 0.125610208862766947294894, 0.0274135028268930549240776, 0.00250839672168065762786937 };
double[] d = new double[] { 1, 1.8545005897903486499845, 1.43575803037831418074962, 0.582827658753036572454135, 0.124810476932949746447682, 0.0113724176546353285778481 };
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 = EvaluatePolynomial(n, z - 0.5) / EvaluatePolynomial(d, z - 0.5);
b = 0.3440242112F;
}
else if (z < 1.25)
{
// Worst case absolute error found: 4.01854729e-21
double[] n = new double[] { -0.0397876892611136856954425, 0.153165212467878293257683, 0.191260295600936245503129, 0.10276327061989304213645, 0.029637090615738836726027, 0.0046093486780275489468812, 0.000307607820348680180548455 };
double[] d = new double[] { 1, 1.95520072987627704987886, 1.64762317199384860109595, 0.768238607022126250082483, 0.209793185936509782784315, 0.0319569316899913392596356, 0.00213363160895785378615014 };
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 = EvaluatePolynomial(n, z - 0.75) / EvaluatePolynomial(d, z - 0.75);
b = 0.419990927F;
}
else if (z < 2.25)
{
// Worst case absolute error found: 2.866005373e-21
double[] n = new double[] { -0.0300838560557949717328341, 0.0538578829844454508530552, 0.0726211541651914182692959, 0.0367628469888049348429018, 0.00964629015572527529605267, 0.00133453480075291076745275, 0.778087599782504251917881e-4 };
double[] d = new double[] { 1, 1.75967098147167528287343, 1.32883571437961120556307, 0.552528596508757581287907, 0.133793056941332861912279, 0.0179509645176280768640766, 0.00104712440019937356634038, -0.106640381820357337177643e-7 };
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 = EvaluatePolynomial(n, z - 1.25) / EvaluatePolynomial(d, z - 1.25);
b = 0.4898625016F;
}
else if (z < 3.5)
{
// Worst case absolute error found: 1.045355789e-21
double[] n = new double[] { -0.0117907570137227847827732, 0.014262132090538809896674, 0.0202234435902960820020765, 0.00930668299990432009042239, 0.00213357802422065994322516, 0.00025022987386460102395382, 0.120534912219588189822126e-4 };
double[] d = new double[] { 1, 1.50376225203620482047419, 0.965397786204462896346934, 0.339265230476796681555511, 0.0689740649541569716897427, 0.00771060262491768307365526, 0.000371421101531069302990367 };
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 = EvaluatePolynomial(n, z - 2.25) / EvaluatePolynomial(d, z - 2.25);
b = 0.5317370892F;
}
else if (z < 5.25)
{
// Worst case absolute error found: 8.300028706e-22
double[] n = new double[] { -0.00546954795538729307482955, 0.00404190278731707110245394, 0.0054963369553161170521356, 0.00212616472603945399437862, 0.000394984014495083900689956, 0.365565477064442377259271e-4, 0.135485897109932323253786e-5 };
double[] d = new double[] { 1, 1.21019697773630784832251, 0.620914668221143886601045, 0.173038430661142762569515, 0.0276550813773432047594539, 0.00240625974424309709745382, 0.891811817251336577241006e-4, -0.465528836283382684461025e-11 };
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 = EvaluatePolynomial(n, z - 3.5) / EvaluatePolynomial(d, z - 3.5);
b = 0.5489973426F;
}
else if (z < 8)
{
// Worst case absolute error found: 1.700157534e-21
double[] n = new double[] { -0.00270722535905778347999196, 0.0013187563425029400461378, 0.00119925933261002333923989, 0.00027849619811344664248235, 0.267822988218331849989363e-4, 0.923043672315028197865066e-6 };
double[] d = new double[] { 1, 0.814632808543141591118279, 0.268901665856299542168425, 0.0449877216103041118694989, 0.00381759663320248459168994, 0.000131571897888596914350697, 0.404815359675764138445257e-11 };
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 = EvaluatePolynomial(n, z - 5.25) / EvaluatePolynomial(d, z - 5.25);
b = 0.5571740866F;
}
else if (z < 11.5)
{
// Worst case absolute error found: 3.002278011e-22
double[] n = new double[] { -0.00109946720691742196814323, 0.000406425442750422675169153, 0.000274499489416900707787024, 0.465293770646659383436343e-4, 0.320955425395767463401993e-5, 0.778286018145020892261936e-7 };
double[] d = new double[] { 1, 0.588173710611846046373373, 0.139363331289409746077541, 0.0166329340417083678763028, 0.00100023921310234908642639, 0.24254837521587225125068e-4 };
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 = EvaluatePolynomial(n, z - 8) / EvaluatePolynomial(d, z - 8);
b = 0.5609807968F;
}
else if (z < 17)
{
// Worst case absolute error found: 6.741114695e-21
double[] n = new double[] { -0.00056907993601094962855594, 0.000169498540373762264416984, 0.518472354581100890120501e-4, 0.382819312231928859704678e-5, 0.824989931281894431781794e-7 };
double[] d = new double[] { 1, 0.339637250051139347430323, 0.043472647870310663055044, 0.00248549335224637114641629, 0.535633305337152900549536e-4, -0.117490944405459578783846e-12 };
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 = EvaluatePolynomial(n, z - 11.5) / EvaluatePolynomial(d, z - 11.5);
b = 0.5626493692F;
}
else if (z < 24)
{
// Worst case absolute error found: 7.802346984e-22
double[] n = new double[] { -0.000241313599483991337479091, 0.574224975202501512365975e-4, 0.115998962927383778460557e-4, 0.581762134402593739370875e-6, 0.853971555085673614607418e-8 };
double[] d = new double[] { 1, 0.233044138299687841018015, 0.0204186940546440312625597, 0.000797185647564398289151125, 0.117019281670172327758019e-4 };
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 = EvaluatePolynomial(n, z - 17) / EvaluatePolynomial(d, z - 17);
b = 0.5634598136F;
}
else if (z < 38)
{
// Worst case absolute error found: 2.414228989e-22
double[] n = new double[] { -0.000146674699277760365803642, 0.162666552112280519955647e-4, 0.269116248509165239294897e-5, 0.979584479468091935086972e-7, 0.101994647625723465722285e-8 };
double[] d = new double[] { 1, 0.165907812944847226546036, 0.0103361716191505884359634, 0.000286593026373868366935721, 0.298401570840900340874568e-5 };
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 = EvaluatePolynomial(n, z - 24) / EvaluatePolynomial(d, z - 24);
b = 0.5638477802F;
}
else if (z < 60)
{
// Worst case absolute error found: 5.896543869e-24
double[] n = new double[] { -0.583905797629771786720406e-4, 0.412510325105496173512992e-5, 0.431790922420250949096906e-6, 0.993365155590013193345569e-8, 0.653480510020104699270084e-10 };
double[] d = new double[] { 1, 0.105077086072039915406159, 0.00414278428675475620830226, 0.726338754644523769144108e-4, 0.477818471047398785369849e-6 };
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 = EvaluatePolynomial(n, z - 38) / EvaluatePolynomial(d, z - 38);
b = 0.5640528202F;
}
else if (z < 85)
{
// Worst case absolute error found: 3.080612264e-21
double[] n = new double[] { -0.196457797609229579459841e-4, 0.157243887666800692441195e-5, 0.543902511192700878690335e-7, 0.317472492369117710852685e-9 };
double[] d = new double[] { 1, 0.052803989240957632204885, 0.000926876069151753290378112, 0.541011723226630257077328e-5, 0.535093845803642394908747e-15 };
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 = EvaluatePolynomial(n, z - 60) / EvaluatePolynomial(d, z - 60);
b = 0.5641309023F;
}
else
{
// Worst case absolute error found: 8.094633491e-22
double[] n = new double[] { -0.789224703978722689089794e-5, 0.622088451660986955124162e-6, 0.145728445676882396797184e-7, 0.603715505542715364529243e-10 };
double[] d = new double[] { 1, 0.0375328846356293715248719, 0.000467919535974625308126054, 0.193847039275845656900547e-5 };
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 = EvaluatePolynomial(n, z - 85) / EvaluatePolynomial(d, z - 85);
b = 0.5641584396F;
}
@ -403,9 +403,9 @@ namespace MathNet.Numerics
// long double: Max error found: 1.017064e-20
// Maximum Deviation Found (actual error term at infinite precision) 8.030e-21
//
float Y = 0.0891314744949340820313f;
double[] P = new double[] { -0.000508781949658280665617, -0.00836874819741736770379, 0.0334806625409744615033, -0.0126926147662974029034, -0.0365637971411762664006, 0.0219878681111168899165, 0.00822687874676915743155, -0.00538772965071242932965 };
double[] Q = new double[] { 1, -0.970005043303290640362, -1.56574558234175846809, 1.56221558398423026363, 0.662328840472002992063, -0.71228902341542847553, -0.0527396382340099713954, 0.0795283687341571680018, -0.00233393759374190016776, 0.000886216390456424707504 };
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 = EvaluatePolynomial(P, p) / EvaluatePolynomial(Q, p);
result = (g * Y) + (g * r);
@ -424,10 +424,10 @@ namespace MathNet.Numerics
// long double : Max error found: 6.084616e-20
// Maximum Deviation Found (error term) 4.811e-20
//
float Y = 2.249481201171875f;
double[] P = new double[] { -0.202433508355938759655, 0.105264680699391713268, 8.37050328343119927838, 17.6447298408374015486, -18.8510648058714251895, -44.6382324441786960818, 17.445385985570866523, 21.1294655448340526258, -3.67192254707729348546 };
double[] Q = new double[] { 1, 6.24264124854247537712, 3.9713437953343869095, -28.6608180499800029974, -20.1432634680485188801, 48.5609213108739935468, 10.8268667355460159008, -22.6436933413139721736, 1.72114765761200282724 };
double g = System.Math.Sqrt(-2 * System.Math.Log(q));
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));
double xs = q - 0.25;
double r = EvaluatePolynomial(P, xs) / EvaluatePolynomial(Q, xs);
result = g / (Y + r);
@ -453,13 +453,13 @@ namespace MathNet.Numerics
// small input values indeed: 80 and 128 bit long double's go all the
// way down to ~ 1e-5000 so the "tail" is rather long...
//
double x = System.Math.Sqrt(-System.Math.Log(q));
double x = Math.Sqrt(-Math.Log(q));
if (x < 3)
{
// Max error found: 1.089051e-20
float Y = 0.807220458984375f;
double[] P = new double[] { -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 double[] { 1, 3.46625407242567245975, 5.38168345707006855425, 4.77846592945843778382, 2.59301921623620271374, 0.848854343457902036425, 0.152264338295331783612, 0.01105924229346489121 };
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 };
double xs = x - 1.125;
double R = EvaluatePolynomial(P, xs) / EvaluatePolynomial(Q, xs);
result = (Y * x) + (R * x);
@ -467,9 +467,9 @@ namespace MathNet.Numerics
else if (x < 6)
{
// Max error found: 8.389174e-21
float Y = 0.93995571136474609375f;
double[] P = new double[] { -0.0350353787183177984712, -0.00222426529213447927281, 0.0185573306514231072324, 0.00950804701325919603619, 0.00187123492819559223345, 0.000157544617424960554631, 0.460469890584317994083e-5, -0.230404776911882601748e-9, 0.266339227425782031962e-11 };
double[] Q = new double[] { 1, 1.3653349817554063097, 0.762059164553623404043, 0.220091105764131249824, 0.0341589143670947727934, 0.00263861676657015992959, 0.764675292302794483503e-4 };
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 };
double xs = x - 3;
double R = EvaluatePolynomial(P, xs) / EvaluatePolynomial(Q, xs);
result = (Y * x) + (R * x);
@ -477,9 +477,9 @@ namespace MathNet.Numerics
else if (x < 18)
{
// Max error found: 1.481312e-19
float Y = 0.98362827301025390625f;
double[] P = new double[] { -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 double[] { 1, 0.591429344886417493481, 0.138151865749083321638, 0.0160746087093676504695, 0.000964011807005165528527, 0.275335474764726041141e-4, 0.282243172016108031869e-6 };
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 };
double xs = x - 6;
double R = EvaluatePolynomial(P, xs) / EvaluatePolynomial(Q, xs);
result = (Y * x) + (R * x);
@ -487,9 +487,9 @@ namespace MathNet.Numerics
else if (x < 44)
{
// Max error found: 5.697761e-20
float Y = 0.99714565277099609375f;
double[] P = new double[] { -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 double[] { 1, 0.207123112214422517181, 0.0169410838120975906478, 0.000690538265622684595676, 0.145007359818232637924e-4, 0.144437756628144157666e-6, 0.509761276599778486139e-9 };
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 };
double xs = x - 18;
double R = EvaluatePolynomial(P, xs) / EvaluatePolynomial(Q, xs);
result = (Y * x) + (R * x);
@ -497,9 +497,9 @@ namespace MathNet.Numerics
else
{
// Max error found: 1.279746e-20
float Y = 0.99941349029541015625f;
double[] P = new double[] { -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 double[] { 1, 0.0845746234001899436914, 0.00282092984726264681981, 0.468292921940894236786e-4, 0.399968812193862100054e-6, 0.161809290887904476097e-8, 0.231558608310259605225e-11 };
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 };
double xs = x - 44;
double R = EvaluatePolynomial(P, xs) / EvaluatePolynomial(Q, xs);
result = (Y * x) + (R * x);

6
src/Numerics/SpecialFunctions/Factorial.cs

@ -64,7 +64,7 @@ namespace MathNet.Numerics
{
if (x < 0)
{
throw new ArgumentOutOfRangeException("x", Properties.Resources.ArgumentPositive);
throw new ArgumentOutOfRangeException("x", Resources.ArgumentPositive);
}
if (x < factorialCache.Length)
@ -83,7 +83,7 @@ namespace MathNet.Numerics
{
if (x < 0)
{
throw new ArgumentOutOfRangeException("x", Properties.Resources.ArgumentPositive);
throw new ArgumentOutOfRangeException("x", Resources.ArgumentPositive);
}
if (x <= 1)
@ -170,7 +170,7 @@ namespace MathNet.Numerics
throw new ArgumentException(Resources.ArgumentParameterSetInvalid , "ni");
}
return System.Math.Floor(0.5 + System.Math.Exp(ret));
return Math.Floor(0.5 + Math.Exp(ret));
}
}
}

71
src/Numerics/SpecialFunctions/Gamma.cs

@ -160,67 +160,48 @@ namespace MathNet.Numerics
/// <returns>The upper incomplete regularized gamma function.</returns>
public static double GammaUpperRegularized(double a, double x)
{
double result = 0;
double igammaepsilon = 0;
double igammabignumber = 0;
double igammabignumberinv = 0;
double ans = 0;
double ax = 0;
double c = 0;
double yc = 0;
double r = 0;
double t = 0;
double y = 0;
double z = 0;
double pk = 0;
double pkm1 = 0;
double pkm2 = 0;
double qk = 0;
double qkm1 = 0;
double qkm2 = 0;
igammaepsilon = 0.000000000000001;
igammabignumber = 4503599627370496.0;
igammabignumberinv = 2.22044604925031308085 * 0.0000000000000001;
double t;
const double igammaepsilon = 0.000000000000001;
const double igammabignumber = 4503599627370496.0;
const double igammabignumberinv = 2.22044604925031308085 * 0.0000000000000001;
if (x <= 0 | a <= 0)
{
result = 1;
return result;
return 1;
}
if (x < 1 | x < a)
{
result = 1 - GammaLowerRegularized(a, x);
return result;
return 1 - GammaLowerRegularized(a, x);
}
ax = a * Math.Log(x) - x - GammaLn(a);
double ax = a * Math.Log(x) - x - GammaLn(a);
if (ax < -709.78271289338399)
{
result = 0;
return result;
return 0;
}
ax = Math.Exp(ax);
y = 1 - a;
z = x + y + 1;
c = 0;
pkm2 = 1;
qkm2 = x;
pkm1 = x + 1;
qkm1 = z * x;
ans = pkm1 / qkm1;
double y = 1 - a;
double z = x + y + 1;
double c = 0;
double pkm2 = 1;
double qkm2 = x;
double pkm1 = x + 1;
double qkm1 = z * x;
double ans = pkm1 / qkm1;
do
{
c = c + 1;
y = y + 1;
z = z + 2;
yc = y * c;
pk = pkm1 * z - pkm2 * yc;
qk = qkm1 * z - qkm2 * yc;
double yc = y * c;
double pk = pkm1 * z - pkm2 * yc;
double qk = qkm1 * z - qkm2 * yc;
if (qk != 0)
{
r = pk / qk;
double r = pk / qk;
t = Math.Abs((ans - r) / r);
ans = r;
}
@ -244,9 +225,7 @@ namespace MathNet.Numerics
}
while (t > igammaepsilon);
result = ans * ax;
return result;
return ans * ax;
}
/// <summary>
@ -307,7 +286,7 @@ namespace MathNet.Numerics
return 0d;
}
double ax = (a * Math.Log(x)) - x - SpecialFunctions.GammaLn(a);
double ax = (a * Math.Log(x)) - x - GammaLn(a);
if (ax < -709.78271289338399)
{
return 1d;
@ -340,7 +319,7 @@ namespace MathNet.Numerics
double q2 = z * x;
double ans = p2 / q2;
double error = 0;
double error;
do
{

2
src/Numerics/SpecialFunctions/Stability.cs

@ -172,7 +172,7 @@ namespace MathNet.Numerics
{
double compensation = 0.0;
double current;
double factor = 1 << 16;
const double factor = 1 << 16;
double sum = nextSummand();

1
src/Numerics/Statistics/Correlation.cs

@ -32,7 +32,6 @@ namespace MathNet.Numerics.Statistics
{
using System;
using System.Collections.Generic;
using Properties;
/// <summary>
/// A class with correlation measures between two datasets.

8
src/Numerics/Statistics/DescriptiveStatistics.cs

@ -198,7 +198,7 @@ namespace MathNet.Numerics.Statistics
Minimum = minimum;
Maximum = maximum;
Variance = (variance - (correction * correction / n)) / (n - 1);
StandardDeviation = System.Math.Sqrt(Variance);
StandardDeviation = Math.Sqrt(Variance);
if (Variance != 0)
{
if (n > 2)
@ -254,7 +254,7 @@ namespace MathNet.Numerics.Statistics
Minimum = minimum;
Maximum = maximum;
Variance = (variance - (correction * correction / n)) / (n - 1);
StandardDeviation = System.Math.Sqrt(Variance);
StandardDeviation = Math.Sqrt(Variance);
if (Variance != 0)
{
if (n > 2)
@ -307,7 +307,7 @@ namespace MathNet.Numerics.Statistics
Minimum = (double)minimum;
Maximum = (double)maximum;
Variance = (double)(variance - (correction * correction / n)) / (n - 1);
StandardDeviation = System.Math.Sqrt(Variance);
StandardDeviation = Math.Sqrt(Variance);
if (Variance != 0)
{
if (n > 2)
@ -364,7 +364,7 @@ namespace MathNet.Numerics.Statistics
Minimum = (double) minimum;
Maximum = (double) maximum;
Variance = (double)(variance - (correction * correction / n)) / (n - 1);
StandardDeviation = System.Math.Sqrt(Variance);
StandardDeviation = Math.Sqrt(Variance);
if (Variance != 0)
{
if (n > 2)

81
src/Numerics/Statistics/Histogram.cs

@ -60,18 +60,13 @@ namespace MathNet.Numerics.Statistics
/// <returns>-1 when the point is less than this bucket, 0 when it is in this bucket and 1 otherwise.</returns>
public int Compare(Bucket bkt1, Bucket bkt2)
{
if (bkt2.Width == 0.0)
{
return -bkt1.Contains(bkt2.UpperBound);
}
else
{
return -bkt2.Contains(bkt1.UpperBound);
}
return bkt2.Width == 0.0
? -bkt1.Contains(bkt2.UpperBound)
: -bkt2.Contains(bkt1.UpperBound);
}
}
private static PointComparer pointComparer = new PointComparer();
private static readonly PointComparer pointComparer = new PointComparer();
/// <summary>
/// Lower Bound of the Bucket.
@ -166,18 +161,18 @@ namespace MathNet.Numerics.Statistics
/// </summary>
public int CompareTo(Bucket bucket)
{
if (this.UpperBound > bucket.LowerBound && this.LowerBound < bucket.LowerBound)
if (UpperBound > bucket.LowerBound && LowerBound < bucket.LowerBound)
{
throw new ArgumentException(Resources.PartialOrderException);
}
if (Precision.AlmostEqual(this.UpperBound, bucket.UpperBound)
&& Precision.AlmostEqual(this.LowerBound, bucket.LowerBound))
if (UpperBound.AlmostEqual(bucket.UpperBound)
&& LowerBound.AlmostEqual(bucket.LowerBound))
{
return 0;
}
if (bucket.UpperBound <= this.LowerBound)
if (bucket.UpperBound <= LowerBound)
{
return 1;
}
@ -196,10 +191,10 @@ namespace MathNet.Numerics.Statistics
return false;
}
Bucket b = (Bucket) obj;
return Precision.AlmostEqual(this.LowerBound, b.LowerBound)
&& Precision.AlmostEqual(this.UpperBound, b.UpperBound)
&& Precision.AlmostEqual(this.Count, b.Count);
var bucket = (Bucket) obj;
return LowerBound.AlmostEqual(bucket.LowerBound)
&& UpperBound.AlmostEqual(bucket.UpperBound)
&& Count.AlmostEqual(bucket.Count);
}
/// <summary>
@ -216,7 +211,7 @@ namespace MathNet.Numerics.Statistics
/// <returns></returns>
public override string ToString()
{
return "(" + this.LowerBound + ";" + this.UpperBound + "] = " + this.Count;
return "(" + LowerBound + ";" + UpperBound + "] = " + Count;
}
}
@ -229,20 +224,20 @@ namespace MathNet.Numerics.Statistics
/// <summary>
/// Contains all the <c>Bucket</c>s of the <c>Histogram</c>.
/// </summary>
private List<Bucket> buckets;
private readonly List<Bucket> _buckets;
/// <summary>
/// Indicates whether the elements of <c>buckets</c> are currently sorted.
/// </summary>
private bool areBucketsSorted;
private bool _areBucketsSorted;
/// <summary>
/// Initializes a new instance of the Histogram class.
/// </summary>
public Histogram()
{
buckets = new List<Bucket>();
areBucketsSorted = true;
_buckets = new List<Bucket>();
_areBucketsSorted = true;
}
/// <summary>
@ -256,7 +251,7 @@ namespace MathNet.Numerics.Statistics
{
if (nbuckets < 1)
{
throw new ArgumentOutOfRangeException("The number of bins in a histogram should be at least 1.");
throw new ArgumentOutOfRangeException("data", "The number of bins in a histogram should be at least 1.");
}
double lower = data.Minimum();
@ -315,20 +310,20 @@ namespace MathNet.Numerics.Statistics
// Sort if needed.
LazySort();
if (d < this.LowerBound)
if (d < LowerBound)
{
// Make the lower bound just slightly smaller than the datapoint so it is contained in this bucket.
buckets[0].LowerBound = d.Decrement();
buckets[0].Count++;
_buckets[0].LowerBound = d.Decrement();
_buckets[0].Count++;
}
else if (d > this.UpperBound)
else if (d > UpperBound)
{
buckets[BucketCount - 1].UpperBound = d;
buckets[BucketCount - 1].Count++;
_buckets[BucketCount - 1].UpperBound = d;
_buckets[BucketCount - 1].Count++;
}
else
{
buckets[GetBucketIndexOf(d)].Count++;
_buckets[GetBucketIndexOf(d)].Count++;
}
}
@ -350,8 +345,8 @@ namespace MathNet.Numerics.Statistics
/// </summary>
public void AddBucket(Bucket bucket)
{
buckets.Add(bucket);
areBucketsSorted = false;
_buckets.Add(bucket);
_areBucketsSorted = false;
}
/// <summary>
@ -359,10 +354,10 @@ namespace MathNet.Numerics.Statistics
/// </summary>
private void LazySort()
{
if (!areBucketsSorted)
if (!_areBucketsSorted)
{
buckets.Sort();
areBucketsSorted = true;
_buckets.Sort();
_areBucketsSorted = true;
}
}
@ -373,7 +368,7 @@ namespace MathNet.Numerics.Statistics
/// <returns>A copy of the bucket containing point <paramref name="v"/>.</returns>
public Bucket GetBucketOf(double v)
{
return (Bucket) buckets[GetBucketIndexOf(v)].Clone();
return (Bucket) _buckets[GetBucketIndexOf(v)].Clone();
}
/// <summary>
@ -388,7 +383,7 @@ namespace MathNet.Numerics.Statistics
LazySort();
// Binary search for the bucket index.
int index = buckets.BinarySearch(new Bucket(v, v), Bucket.DefaultPointComparer);
int index = _buckets.BinarySearch(new Bucket(v, v), Bucket.DefaultPointComparer);
if (index < 0)
{
@ -406,7 +401,7 @@ namespace MathNet.Numerics.Statistics
get
{
LazySort();
return buckets[0].LowerBound;
return _buckets[0].LowerBound;
}
}
@ -418,7 +413,7 @@ namespace MathNet.Numerics.Statistics
get
{
LazySort();
return buckets[buckets.Count - 1].UpperBound;
return _buckets[_buckets.Count - 1].UpperBound;
}
}
@ -432,7 +427,7 @@ namespace MathNet.Numerics.Statistics
get
{
LazySort();
return (Bucket) buckets[n].Clone();
return (Bucket) _buckets[n].Clone();
}
}
@ -441,7 +436,7 @@ namespace MathNet.Numerics.Statistics
/// </summary>
public int BucketCount
{
get { return buckets.Count; }
get { return _buckets.Count; }
}
/// <summary>
@ -453,7 +448,7 @@ namespace MathNet.Numerics.Statistics
{
double totalCount = 0;
for (int i = 0; i < this.BucketCount; i++)
for (int i = 0; i < BucketCount; i++)
{
totalCount += this[i].Count;
}
@ -469,7 +464,7 @@ namespace MathNet.Numerics.Statistics
{
StringBuilder sb = new StringBuilder();
foreach (Bucket b in buckets)
foreach (Bucket b in _buckets)
{
sb.Append(b.ToString());
}

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

@ -40,7 +40,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// </summary>
/// <typeparam name="T">The type of the datapoints.</typeparam>
/// <returns>A sample from the proposal distribution.</returns>
public delegate T GlobalProposalSampler<T>();
public delegate T GlobalProposalSampler<out T>();
/// <summary>
/// A method which samples datapoints from a proposal distribution given an initial sample. The implementation
@ -58,14 +58,14 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// </summary>
/// <typeparam name="T">The type of data the distribution is over.</typeparam>
/// <param name="sample">The sample we want to evaluate the density for.</param>
public delegate double Density<T>(T sample);
public delegate double Density<in T>(T sample);
/// <summary>
/// A function which evaluates a log density.
/// </summary>
/// <typeparam name="T">The type of data the distribution is over.</typeparam>
/// <param name="sample">The sample we want to evaluate the log density for.</param>
public delegate double DensityLn<T>(T sample);
public delegate double DensityLn<in T>(T sample);
/// <summary>
/// A function which evaluates the log of a transition kernel probability.
@ -74,7 +74,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// <param name="to">The new state in the transition.</param>
/// <param name="from">The previous state in the transition.</param>
/// <returns>The log probability of the transition.</returns>
public delegate double TransitionKernelLn<T>(T to, T from);
public delegate double TransitionKernelLn<in T>(T to, T from);
/// <summary>
/// The interface which every sampler must implement.
@ -85,18 +85,18 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// <summary>
/// The random number generator for this class.
/// </summary>
private System.Random mRandomNumberGenerator;
private Random _randomNumberGenerator;
/// <summary>
/// Keeps track of the number of accepted samples.
/// </summary>
protected int mAccepts;
protected int Accepts;
/// <summary>
/// Keeps track of the number of calls to the proposal sampler.
/// </summary>
protected int mSamples;
protected int Samples;
/// <summary>
/// Initializes a new instance of the <see cref="McmcSampler{T}"/> class.
/// </summary>
@ -104,18 +104,18 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// safe classes.</remarks>
protected McmcSampler()
{
mAccepts = 0;
mSamples = 0;
RandomSource = new System.Random();
Accepts = 0;
Samples = 0;
RandomSource = new Random();
}
/// <summary>
/// Gets or sets the random number generator.
/// </summary>
/// <exception cref="ArgumentNullException">When the random number generator is null.</exception>
public System.Random RandomSource
public Random RandomSource
{
get { return mRandomNumberGenerator; }
get { return _randomNumberGenerator; }
set
{
@ -123,7 +123,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
{
throw new ArgumentNullException();
}
mRandomNumberGenerator = value;
_randomNumberGenerator = value;
}
}
@ -154,7 +154,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
/// </summary>
public double AcceptanceRate
{
get { return (double)mAccepts / (double)mSamples; }
get { return Accepts / (double)Samples; }
}
}
}

10
src/Numerics/Statistics/MCMC/MetropolisHastingsSampler.cs

@ -145,20 +145,20 @@ namespace MathNet.Numerics.Statistics.Mcmc
// Evaluate the backward transition probability
double bwd = mKrnlQ(mCurrent, next);
mSamples++;
Samples++;
double acc = System.Math.Min(0.0, p + bwd - mCurrentDensityLn - fwd);
double acc = Math.Min(0.0, p + bwd - mCurrentDensityLn - fwd);
if (acc == 0.0)
{
mCurrent = next;
mCurrentDensityLn = p;
mAccepts++;
Accepts++;
}
else if (Bernoulli.Sample(RandomSource, System.Math.Exp(acc)) == 1)
else if (Bernoulli.Sample(RandomSource, Math.Exp(acc)) == 1)
{
mCurrent = next;
mCurrentDensityLn = p;
mAccepts++;
Accepts++;
}
}
}

10
src/Numerics/Statistics/MCMC/MetropolisSampler.cs

@ -131,20 +131,20 @@ namespace MathNet.Numerics.Statistics.Mcmc
// Evaluate the density at the next sample.
double p = mPdfLnP(next);
mSamples++;
Samples++;
double acc = System.Math.Min(0.0, p - mCurrentDensityLn);
double acc = Math.Min(0.0, p - mCurrentDensityLn);
if (acc == 0.0)
{
mCurrent = next;
mCurrentDensityLn = p;
mAccepts++;
Accepts++;
}
else if (Bernoulli.Sample(RandomSource, System.Math.Exp(acc)) == 1)
else if (Bernoulli.Sample(RandomSource, Math.Exp(acc)) == 1)
{
mCurrent = next;
mCurrentDensityLn = p;
mAccepts++;
Accepts++;
}
}
}

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

@ -87,7 +87,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
// Sample a variable between 0.0 and proposal density.
double u = RandomSource.NextDouble() * q;
mSamples++;
Samples++;
if (q < p)
{
@ -95,7 +95,7 @@ namespace MathNet.Numerics.Statistics.Mcmc
}
if (u < p)
{
mAccepts++;
Accepts++;
return x;
}
}

16
src/Numerics/Statistics/MCMC/UnivariateSliceSampler.cs

@ -139,17 +139,13 @@ namespace MathNet.Numerics.Statistics.Mcmc
{
for (int i = 0; i < n; i++)
{
double x_l = mCurrent;
double x_r = mCurrent;
double xnew = mCurrent;
// The logarithm of the slice height.
double lu = System.Math.Log(RandomSource.NextDouble()) + mCurrentDensityLn;
double lu = Math.Log(RandomSource.NextDouble()) + mCurrentDensityLn;
// Create a horizontal interval (x_l, x_r) enclosing x.
double r = RandomSource.NextDouble();
x_l = mCurrent - r * Scale;
x_r = mCurrent + (1.0 - r) * Scale;
double x_l = mCurrent - r * Scale;
double x_r = mCurrent + (1.0 - r) * Scale;
// Stepping out procedure.
while (mPdfLnP(x_l) > lu) { x_l -= Scale; }
@ -158,13 +154,13 @@ namespace MathNet.Numerics.Statistics.Mcmc
// Shrinking: propose new x and shrink interval until good one found.
while (true)
{
xnew = RandomSource.NextDouble() * (x_r - x_l) + x_l;
double xnew = RandomSource.NextDouble() * (x_r - x_l) + x_l;
mCurrentDensityLn = mPdfLnP(xnew);
if (mCurrentDensityLn > lu)
{
mCurrent = xnew;
mAccepts++;
mSamples++;
Accepts++;
Samples++;
break;
}
if (xnew > mCurrent)

Loading…
Cancel
Save