| 96 | } |
| 97 | |
| 98 | void clear_gammas() |
| 99 | { |
| 100 | positive_gamma_parameters.clear(); |
| 101 | negative_gamma_parameters.clear(); |
| 102 | |
| 103 | |
| 104 | positive_gamma_sum = 0; |
| 105 | negative_gamma_sum = 0; |
| 106 | } |
| 107 | |
| 108 | void insert_gamma(int order, double weight, double beta) |
| 109 | { |
| 110 | if(weight>=0) |
| 111 | { |
| 112 | if(positive_gamma_parameters.size()<order+1) |
| 113 | { |
| 114 | multimap<double,double> map; |
| 115 | positive_gamma_parameters.push_back(map); |
| 116 | } |
| 117 | |
| 118 | positive_gamma_sum += weight; |
| 119 | |
| 120 | positive_gamma_parameters[order].insert(pair<double,double>(weight,beta)); |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | if(negative_gamma_parameters.size()<order+1) |
| 125 | { |
| 126 | multimap<double,double> map; |
| 127 | negative_gamma_parameters.push_back(map); |
| 128 | } |
| 129 | |
| 130 | negative_gamma_sum -= weight; |
| 131 | |
| 132 | negative_gamma_parameters[order].insert(pair<double,double>(-weight,beta)); |
| 133 | } |
1801 | | double sum_g = 0; |
1802 | | for(int i = 0;i<(*s_ref)->gamma_parameters.size();i++) |
1803 | | { |
1804 | | for(multimap<double,double>::iterator g_ref = (*s_ref)->gamma_parameters[i].begin();g_ref != (*s_ref)->gamma_parameters[i].end();g_ref++) |
1805 | | { |
1806 | | sum_g += (*g_ref).first/(*s_ref)->gamma_sum; |
1807 | | |
1808 | | if(sum_g>rnumber) |
1809 | | { |
1810 | | itpp::Gamma_RNG* gamma = new itpp::Gamma_RNG(conditions.size()-number_of_parameters,(*g_ref).second); |
1811 | | sigma = (*gamma)(); |
| 1842 | do |
| 1843 | { |
| 1844 | rnumber = randu(); |
| 1845 | |
| 1846 | double sum_g = 0; |
| 1847 | for(int i = 0;i<(*s_ref)->positive_gamma_parameters.size();i++) |
| 1848 | { |
| 1849 | for(multimap<double,double>::iterator g_ref = (*s_ref)->positive_gamma_parameters[i].begin();g_ref != (*s_ref)->positive_gamma_parameters[i].end();g_ref++) |
| 1850 | { |
| 1851 | sum_g += (*g_ref).first/(*s_ref)->positive_gamma_sum; |
| 1852 | |
| 1853 | if(sum_g>rnumber) |
| 1854 | { |
| 1855 | itpp::Gamma_RNG* gamma = new itpp::Gamma_RNG(conditions.size()-number_of_parameters,1/(*g_ref).second); |
| 1856 | sigma = 1/(*gamma)(); |
| 1857 | break; |
| 1858 | } |
| 1859 | } |
| 1860 | |
| 1861 | if(sigma!=0) |
| 1862 | { |
1813 | | } |
1814 | | } |
1815 | | |
1816 | | if(sigma!=0) |
1817 | | { |
1818 | | break; |
1819 | | } |
1820 | | } |
| 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | rnumber = randu(); |
| 1868 | |
| 1869 | double pg_sum = 0; |
| 1870 | for(vector<multimap<double,double>>::iterator v_ref = (*s_ref)->positive_gamma_parameters.begin();v_ref!=(*s_ref)->positive_gamma_parameters.end();v_ref++) |
| 1871 | { |
| 1872 | for(multimap<double,double>::iterator pg_ref = (*v_ref).begin();pg_ref!=(*v_ref).end();pg_ref++) |
| 1873 | { |
| 1874 | pg_sum += exp(-(*pg_ref).second/sigma)*pow((*pg_ref).second/sigma,(int)conditions.size()-number_of_parameters-1)*(*pg_ref).second/fact(conditions.size()-number_of_parameters-1)*(*pg_ref).first; |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | double ng_sum = 0; |
| 1879 | for(vector<multimap<double,double>>::iterator v_ref = (*s_ref)->negative_gamma_parameters.begin();v_ref!=(*s_ref)->negative_gamma_parameters.end();v_ref++) |
| 1880 | { |
| 1881 | for(multimap<double,double>::iterator ng_ref = (*v_ref).begin();ng_ref!=(*v_ref).end();ng_ref++) |
| 1882 | { |
| 1883 | ng_sum += exp(-(*ng_ref).second/sigma)*pow((*ng_ref).second/sigma,(int)conditions.size()-number_of_parameters-1)*(*ng_ref).second/fact(conditions.size()-number_of_parameters-1)*(*ng_ref).first; |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | if((pg_sum-ng_sum)/pg_sum>rnumber) |
| 1888 | { |
| 1889 | have_sigma = true; |
| 1890 | } |
| 1891 | } |
| 1892 | while(!have_sigma); |