GestureRecognitionToolkit  Version: 0.2.5
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
Random.h
Go to the documentation of this file.
1 
7 /*
8  GRT MIT License
9  Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
10 
11  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
12  and associated documentation files (the "Software"), to deal in the Software without restriction,
13  including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
15  subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included in all copies or substantial
18  portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
21  LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 
27 #ifndef GRT_RANDOM_HEADER
28 #define GRT_RANDOM_HEADER
29 
30 #include <assert.h>
31 #include <cstring>
32 #include "../Util/GRTVersionInfo.h"
33 #include "Timer.h"
34 #include "../DataStructures/Vector.h"
35 #include "../DataStructures/VectorFloat.h"
36 #include "IndexedDouble.h"
37 #include <random>
38 #define GRT_USE_CXX11_RANDOM_ALGO 0
39 
40 GRT_BEGIN_NAMESPACE
41 
46 class Random{
47 public:
54 #if GRT_USE_CXX11_RANDOM_ALGO
55  Random( );
56 #else
57  Random(unsigned long long seed = 0);
58 #endif
59 
63  ~Random();
64 
71  bool setSeed(const unsigned long long seed = 0);
72 
80  int getRandomNumberInt(int minRange,int maxRange);
81 
95  int getRandomNumberWeighted(const Vector< int > &values,const VectorFloat &weights);
96 
108 
125 
133  Float getRandomNumberUniform(Float minRange=0.0,Float maxRange=1.0);
134 
142  Float getUniform(const Float &minRange=0.0,const Float &maxRange=1.0);
143 
151  Float getRandomNumberGauss(Float mu=0.0,Float sigma=1.0);
152 
160  Float getGauss(const Float &mu=0.0,const Float &sigma=1.0);
161 
170  VectorFloat getRandomVectorUniform(UINT numDimensions,Float minRange=0.0,Float maxRange=1.0);
171 
180  VectorFloat getRandomVectorGauss(UINT numDimensions,Float mu=0.0,Float sigma=1.0);
181 
190  Vector< unsigned int > getRandomSubset( const unsigned int startRange, const unsigned int endRange, const unsigned int subsetSize );
191 
192 private:
193 
194 #if GRT_USE_CXX11_RANDOM_ALGO
195  std::default_random_engine generator;
196  std::uniform_real_distribution< Float > uniformRealDistribution;
197  std::normal_distribution< Float > normalDistribution;
198 #else
199  inline unsigned long long int64() {
200  u = u * 2862933555777941757LL + 7046029254386353087LL;
201  v ^= v >> 17; v ^= v << 31; v ^= v >> 8;
202  w = 4294957665U*(w & 0xffffffff) + (w >> 32);
203  unsigned long long x = u ^ (u << 21); x ^= x >> 35; x ^= x << 4;
204  return (x + v) ^ w;
205  }
206  inline Float doub() { return 5.42101086242752217E-20 * int64(); }
207  inline unsigned int int32() { return (unsigned int)int64(); }
208 
209  unsigned long long u;
210  unsigned long long v;
211  unsigned long long w;
212  Float storedval; //This is for the Gauss Box-Muller
213 #endif
214 };
215 
216 GRT_END_NAMESPACE
217 
218 #endif //GRT_RANDOM_HEADER
VectorFloat getRandomVectorGauss(UINT numDimensions, Float mu=0.0, Float sigma=1.0)
Definition: Random.cpp:177
This file contains the Random class, a useful wrapper for generating cross platform random functions...
Definition: Random.h:46
Float getGauss(const Float &mu=0.0, const Float &sigma=1.0)
Definition: Random.cpp:146
Float getRandomNumberGauss(Float mu=0.0, Float sigma=1.0)
Definition: Random.cpp:142
Random(unsigned long long seed=0)
Definition: Random.cpp:29
Vector< unsigned int > getRandomSubset(const unsigned int startRange, const unsigned int endRange, const unsigned int subsetSize)
Definition: Random.cpp:185
int getRandomNumberWeighted(const Vector< int > &values, const VectorFloat &weights)
Definition: Random.cpp:68
bool setSeed(const unsigned long long seed=0)
Definition: Random.cpp:40
Float getRandomNumberUniform(Float minRange=0.0, Float maxRange=1.0)
Definition: Random.cpp:129
int getRandomNumberInt(int minRange, int maxRange)
Definition: Random.cpp:59
VectorFloat getRandomVectorUniform(UINT numDimensions, Float minRange=0.0, Float maxRange=1.0)
Definition: Random.cpp:169
Float getUniform(const Float &minRange=0.0, const Float &maxRange=1.0)
Definition: Random.cpp:133
~Random()
Definition: Random.cpp:38