Browse Source

LA: build random with standard distribution, seed

optimization-3
Christoph Ruegg 13 years ago
parent
commit
5e997534ad
  1. 10
      src/FSharp/LinearAlgebra.Matrix.fs
  2. 10
      src/FSharp/LinearAlgebra.Vector.fs
  3. 16
      src/Numerics/LinearAlgebra/Builder.cs

10
src/FSharp/LinearAlgebra.Matrix.fs

@ -350,6 +350,8 @@ module Matrix =
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module DenseMatrix =
open MathNet.Numerics.Distributions
/// Create a matrix that directly binds to a storage object.
let inline ofStorage storage = Matrix<'T>.Build.Dense(storage)
@ -360,7 +362,13 @@ module DenseMatrix =
let inline zero (rows: int) (cols: int) = Matrix<'T>.Build.Dense(rows, cols)
/// Create a random matrix with the given dimension and value distribution.
let inline random (rows: int) (cols: int) dist = Matrix<'T>.Build.Random(rows, cols, dist)
let inline random (rows: int) (cols: int) (dist: IContinuousDistribution) = Matrix<'T>.Build.Random(rows, cols, dist)
/// Create a random matrix with the given dimension and standard distributed values.
let inline randomStandard (rows: int) (cols: int) = Matrix<'T>.Build.Random(rows, cols)
/// Create a random matrix with the given dimension and standard distributed values using the provided seed.
let inline randomSeed (rows: int) (cols: int) (seed: int) = Matrix<'T>.Build.Random(rows, cols, seed)
/// Create a matrix with the given dimension and set all values to x.
let inline create (rows: int) (cols: int) (x: 'T) = Matrix<'T>.Build.Dense(rows, cols, x)

10
src/FSharp/LinearAlgebra.Vector.fs

@ -221,6 +221,8 @@ module Vector =
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module DenseVector =
open MathNet.Numerics.Distributions
/// Create a vector that directly binds to a storage object.
let inline ofStorage (storage: Storage.DenseVectorStorage<'T>) = Vector<'T>.Build.Dense(storage)
@ -231,7 +233,13 @@ module DenseVector =
let inline zero (n: int) = Vector<'T>.Build.Dense(n)
/// Initialize a random vector with the given dimension and distribution.
let inline random (n: int) dist = Vector<'T>.Build.Random(n, dist)
let inline random (n: int) (dist: IContinuousDistribution) = Vector<'T>.Build.Random(n, dist)
/// Initialize a random vector with the given dimension and standard distributed values.
let inline randomStandard (n: int) = Vector<'T>.Build.Random(n)
/// Initialize a random vector with the given dimension and standard distributed values using the provided seed.
let inline randomSeed (n: int) (seed: int) = Vector<'T>.Build.Random(n, seed)
/// Initialize an x-valued vector with the given dimension.
let inline create (n: int) (x: 'T) = Vector<'T>.Build.Dense(n, x)

16
src/Numerics/LinearAlgebra/Builder.cs

@ -450,6 +450,14 @@ namespace MathNet.Numerics.LinearAlgebra
return Random(rows, columns, new Normal(MersenneTwister.Default));
}
/// <summary>
/// Create a new dense matrix with values sampled from the standard distribution with a mersenne twister random source.
/// </summary>
public Matrix<T> Random(int rows, int columns, int seed)
{
return Random(rows, columns, new Normal(new MersenneTwister(seed, true)));
}
/// <summary>
/// Create a new positive definite dense matrix where each value is the product
/// of two samples from the provided random distribution.
@ -1380,6 +1388,14 @@ namespace MathNet.Numerics.LinearAlgebra
return Random(length, new Normal(MersenneTwister.Default));
}
/// <summary>
/// Create a new dense vector with values sampled from the standard distribution with a mersenne twister random source.
/// </summary>
public Vector<T> Random(int length, int seed)
{
return Random(length, new Normal(new MersenneTwister(seed, true)));
}
/// <summary>
/// Create a new dense vector straight from an initialized vector storage instance.
/// The storage is used directly without copying.

Loading…
Cancel
Save