00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef RandomGenerator_H
00029 #define RandomGenerator_H
00030
00031 #include <mrpt/utils/utils_defs.h>
00032 #include <mrpt/math/CMatrixTemplateNumeric.h>
00033
00034 namespace mrpt
00035 {
00036 namespace math
00037 {
00038 class CMatrix;
00039 class CMatrixD;
00040 }
00041
00044 namespace random
00045 {
00046 using namespace mrpt::utils;
00047 using namespace mrpt::math;
00048
00052 double MRPTDLLIMPEXP normalizedGaussian( double *likelihood = NULL);
00053
00058 double MRPTDLLIMPEXP RandomNormal( double mean = 0, double std = 1);
00059
00064 uint32_t MRPTDLLIMPEXP RandomUniInt();
00065
00072 inline double RandomUni( const double &min, const double &max)
00073 {
00074 return min + (max-min)* RandomUniInt() * 2.3283064370807973754314699618685e-10;
00075 }
00076
00077
00081 template <class T>
00082 void matrixRandomUni(
00083 CMatrixTemplateNumeric<T> &matrix,
00084 const T& unif_min = 0,
00085 const T& unif_max = 1 )
00086 {
00087 for (size_t r=0;r<matrix.getRowCount();r++)
00088 for (size_t c=0;c<matrix.getColCount();c++)
00089 matrix.set_unsafe(r,c, RandomUni(unif_min,unif_max) );
00090 }
00091
00095 template <class T>
00096 void vectorRandomUni(
00097 std::vector<T> &v_out,
00098 const T& unif_min = 0,
00099 const T& unif_max = 1 )
00100 {
00101 size_t n = v_out.size();
00102 for (size_t r=0;r<n;r++)
00103 v_out[r] = RandomUni(unif_min,unif_max);
00104 }
00105
00109 template <class T>
00110 void matrixRandomNormal(
00111 CMatrixTemplateNumeric<T> &matrix,
00112 const T& mean = 0,
00113 const T& std = 1 )
00114 {
00115 for (size_t r=0;r<matrix.getRowCount();r++)
00116 for (size_t c=0;c<matrix.getColCount();c++)
00117 matrix.set_unsafe(r,c, mean + std*normalizedGaussian() );
00118 }
00119
00123 template <class T>
00124 void vectorRandomNormal(
00125 std::vector<T> &v_out,
00126 const T& mean = 0,
00127 const T& std = 1 )
00128 {
00129 size_t n = v_out.size();
00130 for (size_t r=0;r<n;r++)
00131 v_out[r] = mean + std*normalizedGaussian();
00132 }
00133
00137 void MRPTDLLIMPEXP Randomize(const uint32_t &seed);
00138 void MRPTDLLIMPEXP Randomize();
00139
00142 template <class T>
00143 void randomPermutation(
00144 const std::vector<T> &in_vector,
00145 std::vector<T> &out_result)
00146 {
00147 out_result = in_vector;
00148 std::random_shuffle( out_result.begin(),out_result.end() );
00149 }
00150
00155 void MRPTDLLIMPEXP randomNormalMultiDimensional(
00156 const CMatrixTemplateNumeric<double> &cov,
00157 std::vector<double> &out_result);
00158
00163 void MRPTDLLIMPEXP randomNormalMultiDimensional(
00164 const CMatrixTemplateNumeric<float> &cov,
00165 std::vector<float> &out_result);
00166
00167
00178 void MRPTDLLIMPEXP randomNormalMultiDimensionalMany(
00179 const CMatrixD &cov,
00180 size_t desiredSamples,
00181 std::vector<vector_double> &ret,
00182 vector_double *samplesLikelihoods = NULL);
00183
00194 void MRPTDLLIMPEXP randomNormalMultiDimensionalMany(
00195 const CMatrix &cov,
00196 size_t desiredSamples,
00197 std::vector<vector_float> &ret,
00198 vector_double *samplesLikelihoods = NULL);
00199
00200 }
00201
00202 }
00203
00204 #endif