1 | <?xml version='1.0' encoding='UTF-8' standalone='no'?> |
---|
2 | <doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.5.6"> |
---|
3 | <compounddef id="libEF_8cpp" kind="file"> |
---|
4 | <compoundname>libEF.cpp</compoundname> |
---|
5 | <includes local="no">itpp/itbase.h</includes> |
---|
6 | <includes local="no">itpp/base/bessel.h</includes> |
---|
7 | <includes refid="libEF_8h" local="yes">libEF.h</includes> |
---|
8 | <includes local="no">math.h</includes> |
---|
9 | <incdepgraph> |
---|
10 | <node id="382"> |
---|
11 | <label>work/git/mixpp/bdm/stat/libEF.cpp</label> |
---|
12 | <link refid="libEF.cpp"/> |
---|
13 | <childnode refid="383" relation="include"> |
---|
14 | </childnode> |
---|
15 | <childnode refid="384" relation="include"> |
---|
16 | </childnode> |
---|
17 | <childnode refid="385" relation="include"> |
---|
18 | </childnode> |
---|
19 | <childnode refid="389" relation="include"> |
---|
20 | </childnode> |
---|
21 | </node> |
---|
22 | <node id="387"> |
---|
23 | <label>libBM.h</label> |
---|
24 | <link refid="libBM_8h"/> |
---|
25 | <childnode refid="383" relation="include"> |
---|
26 | </childnode> |
---|
27 | </node> |
---|
28 | <node id="388"> |
---|
29 | <label>../itpp_ext.h</label> |
---|
30 | <link refid="itpp__ext_8h-source"/> |
---|
31 | <childnode refid="383" relation="include"> |
---|
32 | </childnode> |
---|
33 | </node> |
---|
34 | <node id="385"> |
---|
35 | <label>libEF.h</label> |
---|
36 | <link refid="libEF_8h"/> |
---|
37 | <childnode refid="383" relation="include"> |
---|
38 | </childnode> |
---|
39 | <childnode refid="386" relation="include"> |
---|
40 | </childnode> |
---|
41 | <childnode refid="387" relation="include"> |
---|
42 | </childnode> |
---|
43 | <childnode refid="388" relation="include"> |
---|
44 | </childnode> |
---|
45 | </node> |
---|
46 | <node id="384"> |
---|
47 | <label>itpp/base/bessel.h</label> |
---|
48 | </node> |
---|
49 | <node id="389"> |
---|
50 | <label>math.h</label> |
---|
51 | </node> |
---|
52 | <node id="383"> |
---|
53 | <label>itpp/itbase.h</label> |
---|
54 | </node> |
---|
55 | <node id="386"> |
---|
56 | <label>../math/libDC.h</label> |
---|
57 | <link refid="libDC_8h"/> |
---|
58 | <childnode refid="383" relation="include"> |
---|
59 | </childnode> |
---|
60 | </node> |
---|
61 | </incdepgraph> |
---|
62 | <sectiondef kind="var"> |
---|
63 | <memberdef kind="variable" id="libEF_8cpp_12ae7dcdfebede774dd1b1f16cad10dd9" prot="public" static="no" mutable="no"> |
---|
64 | <type>Uniform_RNG</type> |
---|
65 | <definition>Uniform_RNG UniRNG</definition> |
---|
66 | <argsstring></argsstring> |
---|
67 | <name>UniRNG</name> |
---|
68 | <briefdescription> |
---|
69 | <para>Global Uniform_RNG. </para> </briefdescription> |
---|
70 | <detaileddescription> |
---|
71 | </detaileddescription> |
---|
72 | <inbodydescription> |
---|
73 | </inbodydescription> |
---|
74 | <location file="/home/smidl/work/git/mixpp/bdm/stat/libEF.cpp" line="8" bodyfile="/home/smidl/work/git/mixpp/bdm/stat/libEF.cpp" bodystart="8" bodyend="-1"/> |
---|
75 | </memberdef> |
---|
76 | <memberdef kind="variable" id="libEF_8cpp_1395c5925c8792aef3be4c360e91526c0" prot="public" static="no" mutable="no"> |
---|
77 | <type>Normal_RNG</type> |
---|
78 | <definition>Normal_RNG NorRNG</definition> |
---|
79 | <argsstring></argsstring> |
---|
80 | <name>NorRNG</name> |
---|
81 | <briefdescription> |
---|
82 | <para>Global Normal_RNG. </para> </briefdescription> |
---|
83 | <detaileddescription> |
---|
84 | </detaileddescription> |
---|
85 | <inbodydescription> |
---|
86 | </inbodydescription> |
---|
87 | <location file="/home/smidl/work/git/mixpp/bdm/stat/libEF.cpp" line="9" bodyfile="/home/smidl/work/git/mixpp/bdm/stat/libEF.cpp" bodystart="9" bodyend="-1"/> |
---|
88 | </memberdef> |
---|
89 | <memberdef kind="variable" id="libEF_8cpp_1884a8348c92a49725b78e2b6ab0bb802" prot="public" static="no" mutable="no"> |
---|
90 | <type><ref refid="classitpp_1_1Gamma__RNG" kindref="compound">Gamma_RNG</ref></type> |
---|
91 | <definition>Gamma_RNG GamRNG</definition> |
---|
92 | <argsstring></argsstring> |
---|
93 | <name>GamRNG</name> |
---|
94 | <briefdescription> |
---|
95 | <para>Global Gamma_RNG. </para> </briefdescription> |
---|
96 | <detaileddescription> |
---|
97 | </detaileddescription> |
---|
98 | <inbodydescription> |
---|
99 | </inbodydescription> |
---|
100 | <location file="/home/smidl/work/git/mixpp/bdm/stat/libEF.cpp" line="10" bodyfile="/home/smidl/work/git/mixpp/bdm/stat/libEF.cpp" bodystart="10" bodyend="-1"/> |
---|
101 | </memberdef> |
---|
102 | </sectiondef> |
---|
103 | <briefdescription> |
---|
104 | </briefdescription> |
---|
105 | <detaileddescription> |
---|
106 | </detaileddescription> |
---|
107 | <programlisting> |
---|
108 | <codeline lineno="1"><highlight class="preprocessor">#include<sp/><itpp/itbase.h></highlight><highlight class="normal"></highlight></codeline> |
---|
109 | <codeline lineno="2"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/><itpp/base/bessel.h></highlight><highlight class="normal"></highlight></codeline> |
---|
110 | <codeline lineno="3"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>"<ref refid="libEF_8h" kindref="compound" tooltip="Probability distributions for Exponential Family models.">libEF.h</ref>"</highlight><highlight class="normal"></highlight></codeline> |
---|
111 | <codeline lineno="4"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/><math.h></highlight><highlight class="normal"></highlight></codeline> |
---|
112 | <codeline lineno="5"><highlight class="normal"></highlight></codeline> |
---|
113 | <codeline lineno="6"><highlight class="normal"></highlight><highlight class="keyword">using<sp/>namespace<sp/></highlight><highlight class="normal">itpp;</highlight></codeline> |
---|
114 | <codeline lineno="7"><highlight class="normal"></highlight></codeline> |
---|
115 | <codeline lineno="8" refid="libEF_8h_12ae7dcdfebede774dd1b1f16cad10dd9" refkind="member"><highlight class="normal">Uniform_RNG<sp/>UniRNG;</highlight></codeline> |
---|
116 | <codeline lineno="9" refid="libEF_8h_1395c5925c8792aef3be4c360e91526c0" refkind="member"><highlight class="normal">Normal_RNG<sp/>NorRNG;</highlight></codeline> |
---|
117 | <codeline lineno="10" refid="libEF_8h_1884a8348c92a49725b78e2b6ab0bb802" refkind="member"><highlight class="normal"><ref refid="classitpp_1_1Gamma__RNG" kindref="compound" tooltip="Gamma distribution.">Gamma_RNG</ref><sp/>GamRNG;</highlight></codeline> |
---|
118 | <codeline lineno="11"><highlight class="normal"></highlight></codeline> |
---|
119 | <codeline lineno="12"><highlight class="normal"></highlight><highlight class="keyword">using</highlight><highlight class="normal"><sp/>std::cout;</highlight></codeline> |
---|
120 | <codeline lineno="13"><highlight class="normal"></highlight></codeline> |
---|
121 | <codeline lineno="14" refid="classegiw_13d2c1f2ba0f9966781f1e0ae695e8a6f" refkind="member"><highlight class="normal">vec<sp/><ref refid="classegiw_13d2c1f2ba0f9966781f1e0ae695e8a6f" kindref="member" tooltip="Returns the required moment of the epdf.">egiw::sample</ref>()</highlight><highlight class="keyword"><sp/>const<sp/></highlight><highlight class="normal">{</highlight></codeline> |
---|
122 | <codeline lineno="15"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>it_warning(</highlight><highlight class="stringliteral">"Function<sp/>not<sp/>implemented"</highlight><highlight class="normal">);</highlight></codeline> |
---|
123 | <codeline lineno="16"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>vec_1(0.0);</highlight></codeline> |
---|
124 | <codeline lineno="17"><highlight class="normal">}</highlight></codeline> |
---|
125 | <codeline lineno="18"><highlight class="normal"></highlight></codeline> |
---|
126 | <codeline lineno="19" refid="classegiw_1425cbc53b377274e28c6add942bab62d" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/><ref refid="classegiw_1425cbc53b377274e28c6add942bab62d" kindref="member" tooltip="Compute log-probability of argument val.">egiw::evalpdflog</ref>(<sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/>vec<sp/>&val<sp/>)</highlight><highlight class="keyword"><sp/>const<sp/></highlight><highlight class="normal">{</highlight></codeline> |
---|
127 | <codeline lineno="20"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>nPsi<sp/>=<sp/><ref refid="classepdf_174da992e3f5d598da8850b646b79b9d9" kindref="member" tooltip="Identified of the random variable.">rv</ref>.<ref refid="classRV_1f5c7b8bd589eef09ccdf3329a0addea0" kindref="member" tooltip="Return number of scalars in the RV.">count</ref>()-1;<sp/></highlight><highlight class="comment">//<sp/>assuming<sp/>1dim<sp/>y</highlight><highlight class="normal"></highlight></codeline> |
---|
128 | <codeline lineno="21"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/>k<sp/>=<sp/><ref refid="classegiw_14a2f130b91afe84f6d62fed289d5d453" kindref="member" tooltip="Number of data records (degrees of freedom) of sufficient statistics.">nu</ref><sp/>+<sp/>nPsi<sp/>+<sp/>2;</highlight></codeline> |
---|
129 | <codeline lineno="22"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight></codeline> |
---|
130 | <codeline lineno="23"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/>r<sp/>=<sp/>val(nPsi);<sp/></highlight><highlight class="comment">//last<sp/>entry!</highlight><highlight class="normal"></highlight></codeline> |
---|
131 | <codeline lineno="24"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>vec<sp/>Psi(nPsi+1);</highlight></codeline> |
---|
132 | <codeline lineno="25"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>Psi(0)<sp/>=<sp/>-1.0;</highlight></codeline> |
---|
133 | <codeline lineno="26"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>Psi.set_subvector(1,val);<sp/></highlight><highlight class="comment">//<sp/>fill<sp/>the<sp/>rest</highlight><highlight class="normal"></highlight></codeline> |
---|
134 | <codeline lineno="27"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight></codeline> |
---|
135 | <codeline lineno="28"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-0.5*(<sp/>k*log(r)<sp/>+<sp/><ref refid="classegiw_1f343d03ede89db820edf44a6297fa442" kindref="member" tooltip="Extended information matrix of sufficient statistics.">V</ref>.<ref refid="classldmat_1d64f331b781903e913cb2ee836886f3f" kindref="member" tooltip="Evaluates quadratic form ;.">qform</ref>(Psi))<sp/>-<sp/><ref refid="classegiw_170eb1a0b88459b227f919b425b0d3359" kindref="member" tooltip="logarithm of the normalizing constant, ">lognc</ref>();</highlight></codeline> |
---|
136 | <codeline lineno="29"><highlight class="normal">}</highlight></codeline> |
---|
137 | <codeline lineno="30"><highlight class="normal"></highlight></codeline> |
---|
138 | <codeline lineno="31" refid="classegiw_170eb1a0b88459b227f919b425b0d3359" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/><ref refid="classegiw_170eb1a0b88459b227f919b425b0d3359" kindref="member" tooltip="logarithm of the normalizing constant, ">egiw::lognc</ref>()</highlight><highlight class="keyword"><sp/>const</highlight><highlight class="normal">{</highlight></codeline> |
---|
139 | <codeline lineno="32"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/>vec&<sp/>D<sp/>=<sp/><ref refid="classegiw_1f343d03ede89db820edf44a6297fa442" kindref="member" tooltip="Extended information matrix of sufficient statistics.">V</ref>.<ref refid="classldmat_1282c879f50aa9ef934e7f46d86881582" kindref="member" tooltip="Access functions.">_D</ref>();</highlight></codeline> |
---|
140 | <codeline lineno="33"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>nPsi<sp/>=<sp/>D.length()-1;<sp/></highlight><highlight class="comment">//<sp/>assuming<sp/>1dim<sp/>y</highlight><highlight class="normal"></highlight></codeline> |
---|
141 | <codeline lineno="34"><highlight class="normal"></highlight></codeline> |
---|
142 | <codeline lineno="35"><highlight class="normal"></highlight><highlight class="comment">//<sp/>log(2)<sp/>=<sp/>0.693147180559945286226763983</highlight><highlight class="normal"></highlight></codeline> |
---|
143 | <codeline lineno="36"><highlight class="normal"></highlight><highlight class="comment">//<sp/>log(pi)<sp/>=<sp/>1.144729885849400163877476189</highlight><highlight class="normal"></highlight></codeline> |
---|
144 | <codeline lineno="37"><highlight class="normal"></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>lgamma(0.5*<ref refid="classegiw_14a2f130b91afe84f6d62fed289d5d453" kindref="member" tooltip="Number of data records (degrees of freedom) of sufficient statistics.">nu</ref>)<sp/>+<sp/>0.5*((1.0-<ref refid="classegiw_14a2f130b91afe84f6d62fed289d5d453" kindref="member" tooltip="Number of data records (degrees of freedom) of sufficient statistics.">nu</ref>)*log(D(0))<sp/>-<sp/><ref refid="classegiw_1f343d03ede89db820edf44a6297fa442" kindref="member" tooltip="Extended information matrix of sufficient statistics.">V</ref>.<ref refid="classldmat_12b42750ba4962d439aa52a77ae12949b" kindref="member" tooltip="Logarithm of a determinant.">logdet</ref>()<sp/>+<sp/>(<ref refid="classegiw_14a2f130b91afe84f6d62fed289d5d453" kindref="member" tooltip="Number of data records (degrees of freedom) of sufficient statistics.">nu</ref>+nPsi)*0.693147180559945286226763983<sp/>+<sp/>nPsi*1.144729885849400163877476189);</highlight></codeline> |
---|
145 | <codeline lineno="38"><highlight class="normal">}</highlight></codeline> |
---|
146 | <codeline lineno="39"><highlight class="normal"></highlight></codeline> |
---|
147 | <codeline lineno="40" refid="classegiw_16deb0ff2859f41ef7cbdf6a842cabb29" refkind="member"><highlight class="normal">vec<sp/><ref refid="classegiw_16deb0ff2859f41ef7cbdf6a842cabb29" kindref="member" tooltip="return expected value">egiw::mean</ref>()</highlight><highlight class="keyword"><sp/>const<sp/></highlight><highlight class="normal">{</highlight></codeline> |
---|
148 | <codeline lineno="41"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/>mat<sp/>&L=<sp/><ref refid="classegiw_1f343d03ede89db820edf44a6297fa442" kindref="member" tooltip="Extended information matrix of sufficient statistics.">V</ref>.<ref refid="classldmat_15f44f100248c6627314afaa653b9e5bd" kindref="member" tooltip="Access functions.">_L</ref>();</highlight></codeline> |
---|
149 | <codeline lineno="42"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/>vec<sp/>&D=<sp/><ref refid="classegiw_1f343d03ede89db820edf44a6297fa442" kindref="member" tooltip="Extended information matrix of sufficient statistics.">V</ref>.<ref refid="classldmat_1282c879f50aa9ef934e7f46d86881582" kindref="member" tooltip="Access functions.">_D</ref>();</highlight></codeline> |
---|
150 | <codeline lineno="43"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight></codeline> |
---|
151 | <codeline lineno="44"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>end<sp/>=<sp/>L.rows()-1;</highlight></codeline> |
---|
152 | <codeline lineno="45"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>vec<sp/>L0<sp/>=<sp/>L.get_col(0);</highlight></codeline> |
---|
153 | <codeline lineno="46"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight></codeline> |
---|
154 | <codeline lineno="47"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>vec<sp/>m(D.length());</highlight></codeline> |
---|
155 | <codeline lineno="48"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>mat<sp/>iLsub<sp/>=<sp/>ltuinv(L(1,end,1,end));</highlight></codeline> |
---|
156 | <codeline lineno="49"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>m.set_subvector(0,iLsub*L0(1,end));</highlight></codeline> |
---|
157 | <codeline lineno="50"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>m(end)=<sp/>D(0)/(<ref refid="classegiw_14a2f130b91afe84f6d62fed289d5d453" kindref="member" tooltip="Number of data records (degrees of freedom) of sufficient statistics.">nu</ref>-2.0);</highlight></codeline> |
---|
158 | <codeline lineno="51"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight></codeline> |
---|
159 | <codeline lineno="52"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>m;</highlight></codeline> |
---|
160 | <codeline lineno="53"><highlight class="normal">}</highlight></codeline> |
---|
161 | <codeline lineno="54"><highlight class="normal"></highlight></codeline> |
---|
162 | <codeline lineno="55" refid="classegamma_18e10c0021b5dfdd9cb62c6959b5ef425" refkind="member"><highlight class="normal">vec<sp/><ref refid="classegamma_18e10c0021b5dfdd9cb62c6959b5ef425" kindref="member" tooltip="Returns the required moment of the epdf.">egamma::sample</ref>()</highlight><highlight class="keyword"><sp/>const<sp/></highlight><highlight class="normal">{</highlight></codeline> |
---|
163 | <codeline lineno="56"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>vec<sp/>smp<sp/>(<sp/><ref refid="classepdf_174da992e3f5d598da8850b646b79b9d9" kindref="member" tooltip="Identified of the random variable.">rv</ref>.<ref refid="classRV_1f5c7b8bd589eef09ccdf3329a0addea0" kindref="member" tooltip="Return number of scalars in the RV.">count</ref>()<sp/>);</highlight></codeline> |
---|
164 | <codeline lineno="57"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i;</highlight></codeline> |
---|
165 | <codeline lineno="58"><highlight class="normal"></highlight></codeline> |
---|
166 | <codeline lineno="59"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/>i=0;<sp/>i<<ref refid="classepdf_174da992e3f5d598da8850b646b79b9d9" kindref="member" tooltip="Identified of the random variable.">rv</ref>.<ref refid="classRV_1f5c7b8bd589eef09ccdf3329a0addea0" kindref="member" tooltip="Return number of scalars in the RV.">count</ref>();<sp/>i++<sp/>)<sp/>{</highlight></codeline> |
---|
167 | <codeline lineno="60"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>GamRNG.<ref refid="classitpp_1_1Gamma__RNG_1dfaae19411e39aa87e1f72e409b6babe" kindref="member" tooltip="Set lambda.">setup</ref><sp/>(<sp/><ref refid="classegamma_1376cebd8932546c440f21b182910b01b" kindref="member" tooltip="Vector .">alpha</ref><sp/>(<sp/>i<sp/>),<ref refid="classegamma_1cfc5f136467488a421ab22f886323790" kindref="member" tooltip="Vector .">beta</ref><sp/>(<sp/>i<sp/>)<sp/>);</highlight></codeline> |
---|
168 | <codeline lineno="61"><highlight class="normal"></highlight><highlight class="preprocessor"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>#pragma<sp/>omp<sp/>critical</highlight></codeline> |
---|
169 | <codeline lineno="62"><highlight class="preprocessor"></highlight><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>smp<sp/>(<sp/>i<sp/>)<sp/>=<sp/>GamRNG();</highlight></codeline> |
---|
170 | <codeline lineno="63"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
171 | <codeline lineno="64"><highlight class="normal"></highlight></codeline> |
---|
172 | <codeline lineno="65"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>smp;</highlight></codeline> |
---|
173 | <codeline lineno="66"><highlight class="normal">}</highlight></codeline> |
---|
174 | <codeline lineno="67"><highlight class="normal"></highlight></codeline> |
---|
175 | <codeline lineno="68"><highlight class="normal"></highlight><highlight class="comment">//<sp/>mat<sp/>egamma::sample<sp/>(<sp/>int<sp/>N<sp/>)<sp/>const<sp/>{</highlight><highlight class="normal"></highlight></codeline> |
---|
176 | <codeline lineno="69"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/>mat<sp/>Smp<sp/>(<sp/>rv.count(),N<sp/>);</highlight><highlight class="normal"></highlight></codeline> |
---|
177 | <codeline lineno="70"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/>int<sp/>i,j;</highlight><highlight class="normal"></highlight></codeline> |
---|
178 | <codeline lineno="71"><highlight class="normal"></highlight><highlight class="comment">//<sp/></highlight><highlight class="normal"></highlight></codeline> |
---|
179 | <codeline lineno="72"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/>for<sp/>(<sp/>i=0;<sp/>i<rv.count();<sp/>i++<sp/>)<sp/>{</highlight><highlight class="normal"></highlight></codeline> |
---|
180 | <codeline lineno="73"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>GamRNG.setup<sp/>(<sp/>alpha<sp/>(<sp/>i<sp/>),beta<sp/>(<sp/>i<sp/>)<sp/>);</highlight><highlight class="normal"></highlight></codeline> |
---|
181 | <codeline lineno="74"><highlight class="normal"></highlight><highlight class="comment">//<sp/></highlight><highlight class="normal"></highlight></codeline> |
---|
182 | <codeline lineno="75"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>for<sp/>(<sp/>j=0;<sp/>j<N;<sp/>j++<sp/>)<sp/>{</highlight><highlight class="normal"></highlight></codeline> |
---|
183 | <codeline lineno="76"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>Smp<sp/>(<sp/>i,j<sp/>)<sp/>=<sp/>GamRNG();</highlight><highlight class="normal"></highlight></codeline> |
---|
184 | <codeline lineno="77"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight><highlight class="normal"></highlight></codeline> |
---|
185 | <codeline lineno="78"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/>}</highlight><highlight class="normal"></highlight></codeline> |
---|
186 | <codeline lineno="79"><highlight class="normal"></highlight><highlight class="comment">//<sp/></highlight><highlight class="normal"></highlight></codeline> |
---|
187 | <codeline lineno="80"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/>return<sp/>Smp;</highlight><highlight class="normal"></highlight></codeline> |
---|
188 | <codeline lineno="81"><highlight class="normal"></highlight><highlight class="comment">//<sp/>}</highlight><highlight class="normal"></highlight></codeline> |
---|
189 | <codeline lineno="82"><highlight class="normal"></highlight></codeline> |
---|
190 | <codeline lineno="83" refid="classegamma_1de84faac8f9799dfe2777ddbedf997ef" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/><ref refid="classegamma_1de84faac8f9799dfe2777ddbedf997ef" kindref="member" tooltip="TODO: is it used anywhere?">egamma::evalpdflog</ref><sp/>(<sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/>vec<sp/>&val<sp/>)</highlight><highlight class="keyword"><sp/>const<sp/></highlight><highlight class="normal">{</highlight></codeline> |
---|
191 | <codeline lineno="84"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/>res<sp/>=<sp/>0.0;<sp/></highlight><highlight class="comment">//the<sp/>rest<sp/>will<sp/>be<sp/>added</highlight><highlight class="normal"></highlight></codeline> |
---|
192 | <codeline lineno="85"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i;</highlight></codeline> |
---|
193 | <codeline lineno="86"><highlight class="normal"></highlight></codeline> |
---|
194 | <codeline lineno="87"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/>i=0;<sp/>i<<ref refid="classepdf_174da992e3f5d598da8850b646b79b9d9" kindref="member" tooltip="Identified of the random variable.">rv</ref>.<ref refid="classRV_1f5c7b8bd589eef09ccdf3329a0addea0" kindref="member" tooltip="Return number of scalars in the RV.">count</ref>();<sp/>i++<sp/>)<sp/>{</highlight></codeline> |
---|
195 | <codeline lineno="88"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>res<sp/>+=<sp/>(<sp/><ref refid="classegamma_1376cebd8932546c440f21b182910b01b" kindref="member" tooltip="Vector .">alpha</ref><sp/>(<sp/>i<sp/>)<sp/>-<sp/>1<sp/>)<sp/>*std::log<sp/>(<sp/>val<sp/>(<sp/>i<sp/>)<sp/>)<sp/>-<sp/><ref refid="classegamma_1cfc5f136467488a421ab22f886323790" kindref="member" tooltip="Vector .">beta</ref><sp/>(<sp/>i<sp/>)<sp/>*val<sp/>(<sp/>i<sp/>);</highlight></codeline> |
---|
196 | <codeline lineno="89"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
197 | <codeline lineno="90"><highlight class="normal"></highlight></codeline> |
---|
198 | <codeline lineno="91"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res-<ref refid="classegamma_1d6dbbdb72360f9e54d64501f80318bb6" kindref="member" tooltip="logarithm of the normalizing constant, ">lognc</ref>();</highlight></codeline> |
---|
199 | <codeline lineno="92"><highlight class="normal">}</highlight></codeline> |
---|
200 | <codeline lineno="93"><highlight class="normal"></highlight></codeline> |
---|
201 | <codeline lineno="94" refid="classegamma_1d6dbbdb72360f9e54d64501f80318bb6" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/><ref refid="classegamma_1d6dbbdb72360f9e54d64501f80318bb6" kindref="member" tooltip="logarithm of the normalizing constant, ">egamma::lognc</ref>()</highlight><highlight class="keyword"><sp/>const<sp/></highlight><highlight class="normal">{</highlight></codeline> |
---|
202 | <codeline lineno="95"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/>res<sp/>=<sp/>0.0;<sp/></highlight><highlight class="comment">//will<sp/>be<sp/>added</highlight><highlight class="normal"></highlight></codeline> |
---|
203 | <codeline lineno="96"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i;</highlight></codeline> |
---|
204 | <codeline lineno="97"><highlight class="normal"></highlight></codeline> |
---|
205 | <codeline lineno="98"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/>i=0;<sp/>i<<ref refid="classepdf_174da992e3f5d598da8850b646b79b9d9" kindref="member" tooltip="Identified of the random variable.">rv</ref>.<ref refid="classRV_1f5c7b8bd589eef09ccdf3329a0addea0" kindref="member" tooltip="Return number of scalars in the RV.">count</ref>();<sp/>i++<sp/>)<sp/>{</highlight></codeline> |
---|
206 | <codeline lineno="99"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>res<sp/>+=<sp/>lgamma<sp/>(<sp/><ref refid="classegamma_1376cebd8932546c440f21b182910b01b" kindref="member" tooltip="Vector .">alpha</ref><sp/>(<sp/>i<sp/>)<sp/>)<sp/>-<sp/><ref refid="classegamma_1376cebd8932546c440f21b182910b01b" kindref="member" tooltip="Vector .">alpha</ref><sp/>(<sp/>i<sp/>)<sp/>*std::log<sp/>(<sp/><ref refid="classegamma_1cfc5f136467488a421ab22f886323790" kindref="member" tooltip="Vector .">beta</ref><sp/>(<sp/>i<sp/>)<sp/>)<sp/>;</highlight></codeline> |
---|
207 | <codeline lineno="100"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
208 | <codeline lineno="101"><highlight class="normal"></highlight></codeline> |
---|
209 | <codeline lineno="102"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline> |
---|
210 | <codeline lineno="103"><highlight class="normal">}</highlight></codeline> |
---|
211 | <codeline lineno="104"><highlight class="normal"></highlight></codeline> |
---|
212 | <codeline lineno="105"><highlight class="normal"></highlight><highlight class="comment">//MGamma</highlight><highlight class="normal"></highlight></codeline> |
---|
213 | <codeline lineno="106" refid="classmgamma_1af43e61b86900c0398d5c0ffc83b94e6" refkind="member"><highlight class="normal"><ref refid="classmgamma_1af43e61b86900c0398d5c0ffc83b94e6" kindref="member" tooltip="Constructor.">mgamma::mgamma</ref><sp/>(<sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/><ref refid="classRV" kindref="compound" tooltip="Class representing variables, most often random variables.">RV</ref><sp/>&<ref refid="classepdf_174da992e3f5d598da8850b646b79b9d9" kindref="member" tooltip="Identified of the random variable.">rv</ref>,</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/><ref refid="classRV" kindref="compound" tooltip="Class representing variables, most often random variables.">RV</ref><sp/>&rvc<sp/>)<sp/>:<sp/><ref refid="classmEF" kindref="compound" tooltip="Exponential family model.">mEF</ref><sp/>(<sp/>rv,rvc<sp/>),<sp/><ref refid="classepdf" kindref="compound" tooltip="Probability density function with numerical statistics, e.g. posterior density.">epdf</ref><sp/>(<sp/>rv<sp/>)<sp/>{vec*<sp/>tmp;<sp/><ref refid="classepdf" kindref="compound" tooltip="Probability density function with numerical statistics, e.g. posterior density.">epdf</ref>._param<sp/>(<sp/>tmp,<ref refid="classmgamma_15e90652837448bcc29707e7412f99691" kindref="member" tooltip="cache of epdf.beta">_beta</ref><sp/>);};</highlight></codeline> |
---|
214 | <codeline lineno="107"><highlight class="normal"></highlight></codeline> |
---|
215 | <codeline lineno="108" refid="classmgamma_1a9d646cf758a70126dde7c48790b6e94" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="classmgamma_1a9d646cf758a70126dde7c48790b6e94" kindref="member" tooltip="Set value of k.">mgamma::set_parameters</ref><sp/>(<sp/></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/>k0<sp/>)<sp/>{</highlight></codeline> |
---|
216 | <codeline lineno="109"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classmgamma_143f733cce0245a52363d566099add687" kindref="member" tooltip="Constant .">k</ref>=k0;</highlight></codeline> |
---|
217 | <codeline lineno="110"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classmpdf_17aa894208a32f3487827df6d5054424c" kindref="member" tooltip="pointer to internal epdf">ep</ref><sp/>=<sp/>&<ref refid="classepdf" kindref="compound" tooltip="Probability density function with numerical statistics, e.g. posterior density.">epdf</ref>;</highlight></codeline> |
---|
218 | <codeline lineno="111"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classepdf" kindref="compound" tooltip="Probability density function with numerical statistics, e.g. posterior density.">epdf</ref>.set_parameters<sp/>(<sp/><ref refid="classmgamma_143f733cce0245a52363d566099add687" kindref="member" tooltip="Constant .">k</ref>*ones<sp/>(<sp/><ref refid="classmpdf_1f6687c07ff07d47812dd565368ca59eb" kindref="member" tooltip="modeled random variable">rv</ref>.<ref refid="classRV_1f5c7b8bd589eef09ccdf3329a0addea0" kindref="member" tooltip="Return number of scalars in the RV.">count</ref>()<sp/>),*<ref refid="classmgamma_15e90652837448bcc29707e7412f99691" kindref="member" tooltip="cache of epdf.beta">_beta</ref><sp/>);</highlight></codeline> |
---|
219 | <codeline lineno="112"><highlight class="normal">};</highlight></codeline> |
---|
220 | <codeline lineno="113"><highlight class="normal"></highlight></codeline> |
---|
221 | <codeline lineno="114" refid="classeEmp_177268292fc4465cb73ddbfb1f2932a59" refkind="member"><highlight class="normal">ivec<sp/><ref refid="classeEmp_177268292fc4465cb73ddbfb1f2932a59" kindref="member" tooltip="Function performs resampling, i.e. removal of low-weight samples and duplication...">eEmp::resample</ref><sp/>(<sp/><ref refid="libEF_8h_199497a3ff630f761cf6bff7babd23212" kindref="member" tooltip="Switch between various resampling methods.">RESAMPLING_METHOD</ref><sp/>method<sp/>)<sp/>{</highlight></codeline> |
---|
222 | <codeline lineno="115"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>ivec<sp/>ind=zeros_i<sp/>(<sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref><sp/>);</highlight></codeline> |
---|
223 | <codeline lineno="116"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>ivec<sp/>N_babies<sp/>=<sp/>zeros_i<sp/>(<sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref><sp/>);</highlight></codeline> |
---|
224 | <codeline lineno="117"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>vec<sp/>cumDist<sp/>=<sp/>cumsum<sp/>(<sp/><ref refid="classeEmp_1ae78d144404ddba843c93b171b215de8" kindref="member" tooltip="Sample weights .">w</ref><sp/>);</highlight></codeline> |
---|
225 | <codeline lineno="118"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>vec<sp/>u<sp/>(<sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref><sp/>);</highlight></codeline> |
---|
226 | <codeline lineno="119"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i,j,parent;</highlight></codeline> |
---|
227 | <codeline lineno="120"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">double</highlight><highlight class="normal"><sp/>u0;</highlight></codeline> |
---|
228 | <codeline lineno="121"><highlight class="normal"></highlight></codeline> |
---|
229 | <codeline lineno="122"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">switch</highlight><highlight class="normal"><sp/>(<sp/>method<sp/>)<sp/>{</highlight></codeline> |
---|
230 | <codeline lineno="123"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/>MULTINOMIAL:</highlight></codeline> |
---|
231 | <codeline lineno="124"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>u<sp/>(<sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref><sp/>-<sp/>1<sp/>)<sp/>=<sp/>pow<sp/>(<sp/>UniRNG.sample(),<sp/>1.0<sp/>/<sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref><sp/>);</highlight></codeline> |
---|
232 | <codeline lineno="125"><highlight class="normal"></highlight></codeline> |
---|
233 | <codeline lineno="126"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/>i<sp/>=<sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref><sp/>-<sp/>2;i<sp/>>=<sp/>0;i--<sp/>)<sp/>{</highlight></codeline> |
---|
234 | <codeline lineno="127"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>u<sp/>(<sp/>i<sp/>)<sp/>=<sp/>u<sp/>(<sp/>i<sp/>+<sp/>1<sp/>)<sp/>*<sp/>pow<sp/>(<sp/>UniRNG.sample(),<sp/>1.0<sp/>/<sp/>(<sp/>i<sp/>+<sp/>1<sp/>)<sp/>);</highlight></codeline> |
---|
235 | <codeline lineno="128"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
236 | <codeline lineno="129"><highlight class="normal"></highlight></codeline> |
---|
237 | <codeline lineno="130"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline> |
---|
238 | <codeline lineno="131"><highlight class="normal"></highlight></codeline> |
---|
239 | <codeline lineno="132"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/>STRATIFIED:</highlight></codeline> |
---|
240 | <codeline lineno="133"><highlight class="normal"></highlight></codeline> |
---|
241 | <codeline lineno="134"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/>i<sp/>=<sp/>0;i<sp/><<sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref>;i++<sp/>)<sp/>{</highlight></codeline> |
---|
242 | <codeline lineno="135"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>u<sp/>(<sp/>i<sp/>)<sp/>=<sp/>(<sp/>i<sp/>+<sp/>UniRNG.sample()<sp/>)<sp/>/<sp/>n;</highlight></codeline> |
---|
243 | <codeline lineno="136"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
244 | <codeline lineno="137"><highlight class="normal"></highlight></codeline> |
---|
245 | <codeline lineno="138"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline> |
---|
246 | <codeline lineno="139"><highlight class="normal"></highlight></codeline> |
---|
247 | <codeline lineno="140"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/>SYSTEMATIC:</highlight></codeline> |
---|
248 | <codeline lineno="141"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>u0<sp/>=<sp/>UniRNG.sample();</highlight></codeline> |
---|
249 | <codeline lineno="142"><highlight class="normal"></highlight></codeline> |
---|
250 | <codeline lineno="143"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/>i<sp/>=<sp/>0;i<sp/><<sp/>n;i++<sp/>)<sp/>{</highlight></codeline> |
---|
251 | <codeline lineno="144"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>u<sp/>(<sp/>i<sp/>)<sp/>=<sp/>(<sp/>i<sp/>+<sp/>u0<sp/>)<sp/>/<sp/>n;</highlight></codeline> |
---|
252 | <codeline lineno="145"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
253 | <codeline lineno="146"><highlight class="normal"></highlight></codeline> |
---|
254 | <codeline lineno="147"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline> |
---|
255 | <codeline lineno="148"><highlight class="normal"></highlight></codeline> |
---|
256 | <codeline lineno="149"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">default</highlight><highlight class="normal">:</highlight></codeline> |
---|
257 | <codeline lineno="150"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>it_error<sp/>(<sp/></highlight><highlight class="stringliteral">"PF::resample():<sp/>Unknown<sp/>resampling<sp/>method"</highlight><highlight class="normal"><sp/>);</highlight></codeline> |
---|
258 | <codeline lineno="151"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
259 | <codeline lineno="152"><highlight class="normal"></highlight></codeline> |
---|
260 | <codeline lineno="153"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>U<sp/>is<sp/>now<sp/>full</highlight><highlight class="normal"></highlight></codeline> |
---|
261 | <codeline lineno="154"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>j<sp/>=<sp/>0;</highlight></codeline> |
---|
262 | <codeline lineno="155"><highlight class="normal"></highlight></codeline> |
---|
263 | <codeline lineno="156"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/>i<sp/>=<sp/>0;i<sp/><<sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref>;i++<sp/>)<sp/>{</highlight></codeline> |
---|
264 | <codeline lineno="157"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(<sp/>u<sp/>(<sp/>i<sp/>)<sp/>><sp/>cumDist<sp/>(<sp/>j<sp/>)<sp/>)<sp/>j++;</highlight></codeline> |
---|
265 | <codeline lineno="158"><highlight class="normal"></highlight></codeline> |
---|
266 | <codeline lineno="159"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>N_babies<sp/>(<sp/>j<sp/>)<sp/>++;</highlight></codeline> |
---|
267 | <codeline lineno="160"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
268 | <codeline lineno="161"><highlight class="normal"></highlight></codeline> |
---|
269 | <codeline lineno="162"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>We<sp/>have<sp/>assigned<sp/>new<sp/>babies<sp/>for<sp/>each<sp/>Particle</highlight><highlight class="normal"></highlight></codeline> |
---|
270 | <codeline lineno="163"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Now,<sp/>we<sp/>fill<sp/>the<sp/>resulting<sp/>index<sp/>such<sp/>that:</highlight><highlight class="normal"></highlight></codeline> |
---|
271 | <codeline lineno="164"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>*<sp/>particles<sp/>with<sp/>at<sp/>least<sp/>one<sp/>baby<sp/>should<sp/>not<sp/>move<sp/>*</highlight><highlight class="normal"></highlight></codeline> |
---|
272 | <codeline lineno="165"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>This<sp/>assures<sp/>that<sp/>reassignment<sp/>can<sp/>be<sp/>done<sp/>inplace;</highlight><highlight class="normal"></highlight></codeline> |
---|
273 | <codeline lineno="166"><highlight class="normal"></highlight></codeline> |
---|
274 | <codeline lineno="167"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>find<sp/>the<sp/>first<sp/>parent;</highlight><highlight class="normal"></highlight></codeline> |
---|
275 | <codeline lineno="168"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>parent=0;<sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(<sp/>N_babies<sp/>(<sp/>parent<sp/>)<sp/>==0<sp/>)<sp/>parent++;</highlight></codeline> |
---|
276 | <codeline lineno="169"><highlight class="normal"></highlight></codeline> |
---|
277 | <codeline lineno="170"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Build<sp/>index</highlight><highlight class="normal"></highlight></codeline> |
---|
278 | <codeline lineno="171"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/>i<sp/>=<sp/>0;i<sp/><<sp/>n;i++<sp/>)<sp/>{</highlight></codeline> |
---|
279 | <codeline lineno="172"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<sp/>N_babies<sp/>(<sp/>i<sp/>)<sp/>><sp/>0<sp/>)<sp/>{</highlight></codeline> |
---|
280 | <codeline lineno="173"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>ind<sp/>(<sp/>i<sp/>)<sp/>=<sp/>i;</highlight></codeline> |
---|
281 | <codeline lineno="174"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>N_babies<sp/>(<sp/>i<sp/>)<sp/>--;<sp/></highlight><highlight class="comment">//this<sp/>index<sp/>was<sp/>now<sp/>replicated;</highlight><highlight class="normal"></highlight></codeline> |
---|
282 | <codeline lineno="175"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline> |
---|
283 | <codeline lineno="176"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>test<sp/>if<sp/>the<sp/>parent<sp/>has<sp/>been<sp/>fully<sp/>replicated</highlight><highlight class="normal"></highlight></codeline> |
---|
284 | <codeline lineno="177"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>if<sp/>yes,<sp/>find<sp/>the<sp/>next<sp/>one</highlight><highlight class="normal"></highlight></codeline> |
---|
285 | <codeline lineno="178"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(<sp/>(<sp/>N_babies<sp/>(<sp/>parent<sp/>)<sp/>==0<sp/>)<sp/>||<sp/>(<sp/>N_babies<sp/>(<sp/>parent<sp/>)<sp/>==1<sp/>&&<sp/>parent>i<sp/>)<sp/>)<sp/>parent++;</highlight></codeline> |
---|
286 | <codeline lineno="179"><highlight class="normal"></highlight></codeline> |
---|
287 | <codeline lineno="180"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Replicate<sp/>parent</highlight><highlight class="normal"></highlight></codeline> |
---|
288 | <codeline lineno="181"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>ind<sp/>(<sp/>i<sp/>)<sp/>=<sp/>parent;</highlight></codeline> |
---|
289 | <codeline lineno="182"><highlight class="normal"></highlight></codeline> |
---|
290 | <codeline lineno="183"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>N_babies<sp/>(<sp/>parent<sp/>)<sp/>--;<sp/></highlight><highlight class="comment">//this<sp/>index<sp/>was<sp/>now<sp/>replicated;</highlight><highlight class="normal"></highlight></codeline> |
---|
291 | <codeline lineno="184"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
292 | <codeline lineno="185"><highlight class="normal"></highlight></codeline> |
---|
293 | <codeline lineno="186"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
294 | <codeline lineno="187"><highlight class="normal"></highlight></codeline> |
---|
295 | <codeline lineno="188"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>copy<sp/>the<sp/>internals<sp/>according<sp/>to<sp/>ind</highlight><highlight class="normal"></highlight></codeline> |
---|
296 | <codeline lineno="189"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/>i=0;i<n;i++<sp/>)<sp/>{</highlight></codeline> |
---|
297 | <codeline lineno="190"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<sp/>ind<sp/>(<sp/>i<sp/>)<sp/>!=i<sp/>)<sp/>{</highlight></codeline> |
---|
298 | <codeline lineno="191"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classeEmp_1a4d6f4bbd6a6824fc39f14676701279a" kindref="member" tooltip="Samples .">samples</ref><sp/>(<sp/>i<sp/>)<sp/>=<ref refid="classeEmp_1a4d6f4bbd6a6824fc39f14676701279a" kindref="member" tooltip="Samples .">samples</ref><sp/>(<sp/>ind<sp/>(<sp/>i<sp/>)<sp/>);</highlight></codeline> |
---|
299 | <codeline lineno="192"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
300 | <codeline lineno="193"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classeEmp_1ae78d144404ddba843c93b171b215de8" kindref="member" tooltip="Sample weights .">w</ref><sp/>(<sp/>i<sp/>)<sp/>=<sp/>1.0/n;</highlight></codeline> |
---|
301 | <codeline lineno="194"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline> |
---|
302 | <codeline lineno="195"><highlight class="normal"></highlight></codeline> |
---|
303 | <codeline lineno="196"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>ind;</highlight></codeline> |
---|
304 | <codeline lineno="197"><highlight class="normal">}</highlight></codeline> |
---|
305 | <codeline lineno="198"><highlight class="normal"></highlight></codeline> |
---|
306 | <codeline lineno="199" refid="classeEmp_16606a656c1b28114f7384c25aaf80e8d" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="classeEmp_16606a656c1b28114f7384c25aaf80e8d" kindref="member" tooltip="Set sample.">eEmp::set_parameters</ref><sp/>(<sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/>vec<sp/>&w0,<sp/><ref refid="classepdf" kindref="compound" tooltip="Probability density function with numerical statistics, e.g. posterior density.">epdf</ref>*<sp/>epdf0<sp/>)<sp/>{</highlight></codeline> |
---|
307 | <codeline lineno="200"><highlight class="normal"></highlight><highlight class="comment">//it_assert_debug(rv==epdf0->rv(),"Wrong<sp/>epdf0");</highlight><highlight class="normal"></highlight></codeline> |
---|
308 | <codeline lineno="201"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classeEmp_1ae78d144404ddba843c93b171b215de8" kindref="member" tooltip="Sample weights .">w</ref>=w0;</highlight></codeline> |
---|
309 | <codeline lineno="202"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classeEmp_1ae78d144404ddba843c93b171b215de8" kindref="member" tooltip="Sample weights .">w</ref>/=sum<sp/>(<sp/>w0<sp/>);</highlight><highlight class="comment">//renormalize</highlight><highlight class="normal"></highlight></codeline> |
---|
310 | <codeline lineno="203"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref>=<ref refid="classeEmp_1ae78d144404ddba843c93b171b215de8" kindref="member" tooltip="Sample weights .">w</ref>.length();</highlight></codeline> |
---|
311 | <codeline lineno="204"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classeEmp_1a4d6f4bbd6a6824fc39f14676701279a" kindref="member" tooltip="Samples .">samples</ref>.set_size<sp/>(<sp/><ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref><sp/>);</highlight></codeline> |
---|
312 | <codeline lineno="205"><highlight class="normal"></highlight></codeline> |
---|
313 | <codeline lineno="206"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(<sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i=0;i<<ref refid="classeEmp_18c33034de0e35f03f8bb85d3d67438fd" kindref="member" tooltip="Number of particles.">n</ref>;i++<sp/>)<sp/>{<ref refid="classeEmp_1a4d6f4bbd6a6824fc39f14676701279a" kindref="member" tooltip="Samples .">samples</ref><sp/>(<sp/>i<sp/>)<sp/>=epdf0-><ref refid="classepdf_18019654e494bf5e458f6fb947e11b262" kindref="member" tooltip="Returns the required moment of the epdf.">sample</ref>();}</highlight></codeline> |
---|
314 | <codeline lineno="207"><highlight class="normal">}</highlight></codeline> |
---|
315 | </programlisting> |
---|
316 | <location file="/home/smidl/work/git/mixpp/bdm/stat/libEF.cpp"/> |
---|
317 | </compounddef> |
---|
318 | </doxygen> |
---|