98 | | <a name="l00040"></a>00040 <span class="comment">// /*!</span> |
99 | | <a name="l00041"></a>00041 <span class="comment">// \brief Gamma distribution</span> |
100 | | <a name="l00042"></a>00042 <span class="comment">// \ingroup randgen</span> |
101 | | <a name="l00043"></a>00043 <span class="comment">// */</span> |
102 | | <a name="l00044"></a>00044 <span class="comment">// class Gamma_RNG {</span> |
103 | | <a name="l00045"></a>00045 <span class="comment">// public:</span> |
104 | | <a name="l00046"></a>00046 <span class="comment">// //! constructor. Set lambda.</span> |
105 | | <a name="l00047"></a>00047 <span class="comment">// Gamma_RNG ( double a=1.0, double b=1.0 );</span> |
106 | | <a name="l00048"></a>00048 <span class="comment">// //! Set lambda</span> |
107 | | <a name="l00049"></a>00049 <span class="comment">// void setup ( double a0, double b0 ) { alpha=a0; beta=b0;}</span> |
108 | | <a name="l00050"></a>00050 <span class="comment">// //! get lambda</span> |
109 | | <a name="l00051"></a>00051 <span class="comment">// double get_setup() const;</span> |
110 | | <a name="l00052"></a>00052 <span class="comment">// //! Get one sample.</span> |
111 | | <a name="l00053"></a>00053 <span class="comment">// double operator() () { return sample(); }</span> |
112 | | <a name="l00054"></a>00054 <span class="comment">// //! Get a sample vector.</span> |
113 | | <a name="l00055"></a>00055 <span class="comment">// vec operator() ( int n );</span> |
114 | | <a name="l00056"></a>00056 <span class="comment">// //! Get a sample matrix.</span> |
115 | | <a name="l00057"></a>00057 <span class="comment">// mat operator() ( int h, int w );</span> |
116 | | <a name="l00058"></a>00058 <span class="comment">// protected:</span> |
117 | | <a name="l00059"></a>00059 <span class="comment">// private:</span> |
118 | | <a name="l00060"></a>00060 <span class="comment">// //!</span> |
119 | | <a name="l00061"></a>00061 <span class="comment">// double sample();</span> |
120 | | <a name="l00062"></a>00062 <span class="comment">// //!</span> |
121 | | <a name="l00063"></a>00063 <span class="comment">// double alpha;</span> |
122 | | <a name="l00064"></a>00064 <span class="comment">// //!</span> |
123 | | <a name="l00065"></a>00065 <span class="comment">// double beta;</span> |
124 | | <a name="l00066"></a>00066 <span class="comment">// //!</span> |
125 | | <a name="l00067"></a>00067 <span class="comment">// Random_Generator RNG;</span> |
126 | | <a name="l00068"></a>00068 <span class="comment">// Normal_RNG NRNG;</span> |
127 | | <a name="l00069"></a>00069 <span class="comment">// //! compatibility with R</span> |
128 | | <a name="l00070"></a>00070 <span class="comment">// inline double exp_rand() {return -std::log ( RNG.random_01() );}</span> |
129 | | <a name="l00071"></a>00071 <span class="comment">// inline double unif_rand() {return RNG.random_01();}</span> |
130 | | <a name="l00072"></a>00072 <span class="comment">// inline double norm_rand() {return NRNG.sample();}</span> |
131 | | <a name="l00073"></a>00073 <span class="comment">// </span> |
132 | | <a name="l00074"></a>00074 <span class="comment">// };</span> |
133 | | <a name="l00075"></a>00075 <span class="comment">// bool qr ( const mat &A, mat &R );</span> |
134 | | <a name="l00076"></a>00076 <span class="comment">// </span> |
135 | | <a name="l00077"></a>00077 <span class="comment">// //! reimplementation of matlab num2str</span> |
136 | | <a name="l00078"></a>00078 <span class="comment">// std::string num2str(double d);</span> |
137 | | <a name="l00079"></a>00079 <span class="comment">// </span> |
138 | | <a name="l00080"></a>00080 <span class="comment">// //! reimplementation of matlabs num2str</span> |
139 | | <a name="l00081"></a>00081 <span class="comment">// std::string num2str(int i);</span> |
140 | | <a name="l00082"></a>00082 } |
| 104 | <a name="l00044"></a><a class="code" href="classitpp_1_1Gamma__RNG.html">00044</a> <span class="keyword">class </span><a class="code" href="classitpp_1_1Gamma__RNG.html" title="Gamma distribution.">Gamma_RNG</a> { |
| 105 | <a name="l00045"></a>00045 <span class="keyword">public</span>: |
| 106 | <a name="l00047"></a>00047 <a class="code" href="classitpp_1_1Gamma__RNG.html#e132860f825f427d63652edd02c25b54" title="constructor. Set lambda.">Gamma_RNG</a> ( <span class="keywordtype">double</span> a=1.0, <span class="keywordtype">double</span> b=1.0 ); |
| 107 | <a name="l00049"></a><a class="code" href="classitpp_1_1Gamma__RNG.html#dfaae19411e39aa87e1f72e409b6babe">00049</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Gamma__RNG.html#dfaae19411e39aa87e1f72e409b6babe" title="Set lambda.">setup</a> ( <span class="keywordtype">double</span> a0, <span class="keywordtype">double</span> b0 ) { alpha=a0; beta=b0;} |
| 108 | <a name="l00051"></a>00051 <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1Gamma__RNG.html#8e666953249038f262cece2d3ed952d6" title="get lambda">get_setup</a>() <span class="keyword">const</span>; |
| 109 | <a name="l00053"></a><a class="code" href="classitpp_1_1Gamma__RNG.html#98e2e65456bca33fca602b2bd607235e">00053</a> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1Gamma__RNG.html#98e2e65456bca33fca602b2bd607235e" title="Get one sample.">operator() </a>() { <span class="keywordflow">return</span> sample(); } |
| 110 | <a name="l00055"></a>00055 vec <a class="code" href="classitpp_1_1Gamma__RNG.html#98e2e65456bca33fca602b2bd607235e" title="Get one sample.">operator() </a>( <span class="keywordtype">int</span> n ); |
| 111 | <a name="l00057"></a>00057 mat <a class="code" href="classitpp_1_1Gamma__RNG.html#98e2e65456bca33fca602b2bd607235e" title="Get one sample.">operator() </a>( <span class="keywordtype">int</span> h, <span class="keywordtype">int</span> w ); |
| 112 | <a name="l00058"></a>00058 <span class="keyword">protected</span>: |
| 113 | <a name="l00059"></a>00059 <span class="keyword">private</span>: |
| 114 | <a name="l00061"></a>00061 <span class="keywordtype">double</span> sample(); |
| 115 | <a name="l00063"></a>00063 <span class="keywordtype">double</span> alpha; |
| 116 | <a name="l00065"></a>00065 <span class="keywordtype">double</span> beta; |
| 117 | <a name="l00067"></a>00067 Random_Generator RNG; |
| 118 | <a name="l00068"></a>00068 Normal_RNG NRNG; |
| 119 | <a name="l00070"></a>00070 <span class="keyword">inline</span> <span class="keywordtype">double</span> exp_rand() {<span class="keywordflow">return</span> -std::log ( RNG.random_01() );} |
| 120 | <a name="l00071"></a>00071 <span class="keyword">inline</span> <span class="keywordtype">double</span> unif_rand() {<span class="keywordflow">return</span> RNG.random_01();} |
| 121 | <a name="l00072"></a>00072 <span class="keyword">inline</span> <span class="keywordtype">double</span> norm_rand() {<span class="keywordflow">return</span> NRNG.sample();} |
| 122 | <a name="l00073"></a>00073 |
| 123 | <a name="l00074"></a>00074 }; |
| 124 | <a name="l00075"></a>00075 <span class="keywordtype">bool</span> qr ( <span class="keyword">const</span> mat &A, mat &R ); |
| 125 | <a name="l00076"></a>00076 |
| 126 | <a name="l00078"></a>00078 std::string num2str(<span class="keywordtype">double</span> d); |
| 127 | <a name="l00079"></a>00079 |
| 128 | <a name="l00081"></a>00081 std::string num2str(<span class="keywordtype">int</span> i); |
| 129 | <a name="l00082"></a>00082 } |