/// <summary> /// Creates a <c>UserDefinedMatrix</c> with random values. /// </summary> /// <param name="row">The number of rows.</param> /// <param name="col">The number of columns.</param> /// <returns>A <c>UserDefinedMatrix</c> with the given dimensions and random values.</returns> public static Matrix GenerateRandomUserDefinedMatrix(int row, int col) { // Fill a matrix with standard random numbers. var normal = new Normal { RandomSource = new MersenneTwister(1) }; var matrixA = new UserDefinedMatrix(row, col); for (var i = 0; i < row; i++) { for (var j = 0; j < col; j++) { matrixA[i, j] = (float)normal.Sample(); } } return(matrixA); }
public static Matrix <float> GenerateRandomPositiveDefiniteUserDefinedMatrix(int order) { // Fill a matrix with standard random numbers. var normal = new Distributions.Normal(); normal.RandomSource = new Numerics.Random.MersenneTwister(1); var matrixA = new UserDefinedMatrix(order); for (int i = 0; i < order; i++) { for (int j = 0; j < order; j++) { matrixA[i, j] = (float)normal.Sample(); } } // Generate a matrix which is positive definite. return(matrixA.Transpose() * matrixA); }
/// <summary> /// Creates a positive definite <c>UserDefinedMatrix</c> with random values. /// </summary> /// <param name="order">The order of the matrix.</param> /// <returns>A positive definite <c>UserDefinedMatrix</c> with the given order and random values.</returns> public static Matrix<float> GenerateRandomPositiveDefiniteUserDefinedMatrix(int order) { // Fill a matrix with standard random numbers. var normal = new Normal { RandomSource = new MersenneTwister(1) }; var matrixA = new UserDefinedMatrix(order); for (var i = 0; i < order; i++) { for (var j = 0; j < order; j++) { matrixA[i, j] = (float) normal.Sample(); } } // Generate a matrix which is positive definite. return matrixA.Transpose()*matrixA; }
/// <summary> /// Creates a <c>UserDefinedMatrix</c> with random values. /// </summary> /// <param name="row">The number of rows.</param> /// <param name="col">The number of columns.</param> /// <returns>A <c>UserDefinedMatrix</c> with the given dimensions and random values.</returns> public static Matrix GenerateRandomUserDefinedMatrix(int row, int col) { // Fill a matrix with standard random numbers. var normal = new Normal { RandomSource = new MersenneTwister(1) }; var matrixA = new UserDefinedMatrix(row, col); for (var i = 0; i < row; i++) { for (var j = 0; j < col; j++) { matrixA[i, j] = (float) normal.Sample(); } } return matrixA; }
/// <summary> /// Initializes a square matrix with all zero's except for ones on the diagonal. /// </summary> /// <param name="order">the size of the square matrix.</param> /// <returns>A identity matrix.</returns> public static UserDefinedMatrix Identity(int order) { var m = new UserDefinedMatrix(order, order); for (var i = 0; i < order; i++) { m[i, i] = 1.0f; } return m; }
public static Matrix<float> GenerateRandomUserDefinedMatrix(int row, int col) { // Fill a matrix with standard random numbers. var normal = new Distributions.Normal(); normal.RandomSource = new Random.MersenneTwister(1); var matrixA = new UserDefinedMatrix(row, col); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { matrixA[i, j] = (float)normal.Sample(); } } // Generate a matrix which is positive definite. return matrixA; }