OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
random_utilities.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// R A N D O M U T I L I T I E S
5//
6// Artificial Intelligence Techniques, SL
7// artelnics artelnics.com
8
9#pragma once
10
11#include "pch.h"
12
13namespace opennn
14{
16 void set_seed(unsigned seed);
17
19 [[nodiscard]] long long get_seed();
20
22 [[nodiscard]] float random_uniform(float = -1, float = 1);
23
25 [[nodiscard]] Index random_integer(Index, Index);
26
28 [[nodiscard]] bool random_bool(float = 0.5);
29
31 void set_random_uniform(MatrixR&, float = -0.1, float = 0.1);
32
34 void set_random_uniform(VectorMap, float = -0.1, float = 0.1);
35
37 void set_random_normal(MatrixMap, float = 0, float = 1);
38
40 void set_random_integer(MatrixR&, Index, Index);
41
43 void shuffle(VectorB& vector_to_shuffle);
44
46 template<typename T>
47 void shuffle_vector(vector<T>&);
48
50 void shuffle_vector_blocks(vector<Index>&, size_t = 20);
51
53 [[nodiscard]] Index get_random_element(const vector<Index>&);
54
56 [[nodiscard]] inline float glorot_limit(Index fan_in, Index fan_out)
57 {
58 return sqrt(6.0f / static_cast<float>(fan_in + fan_out));
59 }
60}
61
62// OpenNN: Open Neural Networks Library.
63// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
64// Licensed under the GNU Lesser General Public License v2.1 or later.
Definition adaptive_moment_estimation.h:14
void set_random_normal(MatrixMap, float=0, float=1)
Fills the matrix with normal random values of the given mean and standard deviation.
Index random_integer(Index, Index)
Draws an integer uniformly in [min, max].
void set_random_uniform(MatrixR &, float=-0.1, float=0.1)
Fills the matrix with uniform random values in [min, max].
Index get_random_element(const vector< Index > &)
Picks one element uniformly at random from the given vector.
float glorot_limit(Index fan_in, Index fan_out)
Returns the Glorot/Xavier uniform initialization limit sqrt(6 / (fan_in + fan_out)).
Definition random_utilities.h:56
long long get_seed()
Returns the seed currently used by the library RNG.
float random_uniform(float=-1, float=1)
Draws a float uniformly in [min, max].
void shuffle_vector(vector< T > &)
Randomly permutes the entries of the given vector in place.
bool random_bool(float=0.5)
Draws a boolean that is true with the given probability.
void shuffle_vector_blocks(vector< Index > &, size_t=20)
Shuffles contiguous blocks of the given length while preserving in-block order.
void set_random_integer(MatrixR &, Index, Index)
Fills the matrix with uniform random integers in [min, max].
void set_seed(unsigned seed)
Seeds the library-wide pseudo-random number generator.
void shuffle(VectorB &vector_to_shuffle)
Randomly permutes the entries of a boolean vector in place.
Map< VectorR, AlignedMax > VectorMap
Definition pch.h:185
Matrix< bool, Dynamic, 1 > VectorB
Definition pch.h:183
Matrix< float, Dynamic, Dynamic, Layout > MatrixR
Definition pch.h:177
Map< MatrixR, Layout|AlignedMax > MatrixMap
Definition pch.h:186