mirror of
https://github.com/Relintai/pmlpp.git
synced 2024-11-08 13:12:09 +01:00
Added create_gaussian_noise static helper method to Matrix.
This commit is contained in:
parent
da321e3c57
commit
6558d0d2f6
@ -605,6 +605,25 @@ void MLPPMatrix::gaussian_noise_fill() {
|
||||
}
|
||||
}
|
||||
|
||||
Ref<MLPPMatrix> MLPPMatrix::create_gaussian_noise(int n, int m) {
|
||||
std::random_device rd;
|
||||
std::default_random_engine generator(rd());
|
||||
std::normal_distribution<real_t> distribution(0, 1); // Standard normal distribution. Mean of 0, std of 1.
|
||||
|
||||
Ref<MLPPMatrix> 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<MLPPMatrix> &B) {
|
||||
ERR_FAIL_COND(!B.is_valid());
|
||||
ERR_FAIL_COND(_size != B->size());
|
||||
|
@ -128,6 +128,8 @@ public:
|
||||
Ref<MLPPMatrix> gaussian_noise(int n, int m) const;
|
||||
void gaussian_noise_fill();
|
||||
|
||||
static Ref<MLPPMatrix> create_gaussian_noise(int n, int m);
|
||||
|
||||
void add(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> addn(const Ref<MLPPMatrix> &B) const;
|
||||
void addb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
Loading…
Reference in New Issue
Block a user