Matrix.randomSPD constructor

Matrix.randomSPD(
  1. int size, {
  2. DType dtype = DType.float32,
  3. num min = -1000,
  4. num max = 1000,
  5. int? seed,
})

Returns randomly filled symmetric and positive definite matrix of sizexsize dimension

Keep in mind that min and max are constraints for a random intermediate matrix which is used to build the result matrix

Implementation

factory Matrix.randomSPD(int size,
    {DType dtype = DType.float32,
    num min = -1000,
    num max = 1000,
    int? seed}) {
  final A =
      Matrix.random(size, size, dtype: dtype, max: max, min: min, seed: seed);

  return A * A.transpose() + Matrix.scalar(size * 1.0, size, dtype: dtype);
}