diff --git a/src/FSharp/LinearAlgebra.Matrix.fs b/src/FSharp/LinearAlgebra.Matrix.fs index 8f634399..7ad6436c 100644 --- a/src/FSharp/LinearAlgebra.Matrix.fs +++ b/src/FSharp/LinearAlgebra.Matrix.fs @@ -350,6 +350,8 @@ module Matrix = [] 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) diff --git a/src/FSharp/LinearAlgebra.Vector.fs b/src/FSharp/LinearAlgebra.Vector.fs index 9a6be296..e013ce26 100644 --- a/src/FSharp/LinearAlgebra.Vector.fs +++ b/src/FSharp/LinearAlgebra.Vector.fs @@ -221,6 +221,8 @@ module Vector = [] 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) diff --git a/src/Numerics/LinearAlgebra/Builder.cs b/src/Numerics/LinearAlgebra/Builder.cs index 77fafe93..e5220f70 100644 --- a/src/Numerics/LinearAlgebra/Builder.cs +++ b/src/Numerics/LinearAlgebra/Builder.cs @@ -450,6 +450,14 @@ namespace MathNet.Numerics.LinearAlgebra return Random(rows, columns, new Normal(MersenneTwister.Default)); } + /// + /// Create a new dense matrix with values sampled from the standard distribution with a mersenne twister random source. + /// + public Matrix Random(int rows, int columns, int seed) + { + return Random(rows, columns, new Normal(new MersenneTwister(seed, true))); + } + /// /// 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)); } + /// + /// Create a new dense vector with values sampled from the standard distribution with a mersenne twister random source. + /// + public Vector Random(int length, int seed) + { + return Random(length, new Normal(new MersenneTwister(seed, true))); + } + /// /// Create a new dense vector straight from an initialized vector storage instance. /// The storage is used directly without copying.