diff --git a/mlpp/lin_alg/mlpp_matrix.cpp b/mlpp/lin_alg/mlpp_matrix.cpp index 2aa0d2f..fcc4941 100644 --- a/mlpp/lin_alg/mlpp_matrix.cpp +++ b/mlpp/lin_alg/mlpp_matrix.cpp @@ -605,6 +605,25 @@ void MLPPMatrix::gaussian_noise_fill() { } } +Ref MLPPMatrix::create_gaussian_noise(int n, int m) { + std::random_device rd; + std::default_random_engine generator(rd()); + std::normal_distribution distribution(0, 1); // Standard normal distribution. Mean of 0, std of 1. + + Ref A; + A.instance(); + A->resize(Size2i(m, n)); + + int a_data_size = A->data_size(); + real_t *a_ptr = A->ptrw(); + + for (int i = 0; i < a_data_size; ++i) { + a_ptr[i] = distribution(generator); + } + + return A; +} + void MLPPMatrix::add(const Ref &B) { ERR_FAIL_COND(!B.is_valid()); ERR_FAIL_COND(_size != B->size()); diff --git a/mlpp/lin_alg/mlpp_matrix.h b/mlpp/lin_alg/mlpp_matrix.h index 378cd68..3449f09 100644 --- a/mlpp/lin_alg/mlpp_matrix.h +++ b/mlpp/lin_alg/mlpp_matrix.h @@ -128,6 +128,8 @@ public: Ref gaussian_noise(int n, int m) const; void gaussian_noise_fill(); + static Ref create_gaussian_noise(int n, int m); + void add(const Ref &B); Ref addn(const Ref &B) const; void addb(const Ref &A, const Ref &B);