Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfomunoz committed Jun 5, 2024
2 parents 6d9d2f5 + 8502b56 commit c93cbd3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/control-variates/region-russian-roulette.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ class rr_error_region {
template<typename Norm = NormDefault>
class rr_pdf_region {
Norm norm;
float factor_prob;
public:
rr_pdf_region(const Norm& n = Norm()) : norm(n) {}
rr_pdf_region(float factor_prob_ = 0.01, const Norm& n = Norm()) : norm(n), factor_prob(factor_prob_) {}
class RR {
private:
//This is the MonteCarlo residual, RR among regions
Expand All @@ -120,7 +121,7 @@ class rr_pdf_region {
Norm norm;

template<typename Rs>
RR(const Rs& regions, const Norm& n) : weights(regions.size()), norm(n) {
RR(const Rs& regions, const Norm& n, const float factor_prob = 0.01) : weights(regions.size()), norm(n) {
std::size_t i = 0;
for (const auto& [r,region_bin_range] : regions) {
weights[i++] = r->pdf_integral_subrange(region_bin_range,norm);
Expand All @@ -129,7 +130,7 @@ class rr_pdf_region {
double sum = 0.0;
for (double w : weights) sum += w;
if (sum<=0.0) for(double& w : weights) w = 1.0;
else for (double& w : weights) w = std::max(w,0.01*sum/double(weights.size()));
else for (double& w : weights) w = std::max(w,factor_prob*sum/double(weights.size()));
rr = std::discrete_distribution<std::size_t>(weights.begin(),weights.end());
}

Expand All @@ -143,7 +144,7 @@ class rr_pdf_region {
};
template<typename Regions>
RR russian_roulette(const Regions& regions) const {
return RR(regions,norm);
return RR(regions,norm,factor_prob);
}
};

Expand Down

0 comments on commit c93cbd3

Please sign in to comment.