-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new integrator for variance reduction that does not share MC sa…
…mples among control variate and residual.
- Loading branch information
1 parent
2fc71c3
commit c0fc07b
Showing
12 changed files
with
219 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "fubini.h" | ||
|
||
namespace viltrum { | ||
|
||
template<typename BaseGenerator, typename RestIntegrator, std::size_t N> | ||
class RegionsGeneratorFubini { | ||
BaseGenerator base_generator; | ||
RestIntegrator rest_integrator; | ||
|
||
public: | ||
RegionsGeneratorFubini(const BaseGenerator& bg, const RestIntegrator& rs) | ||
: base_generator(bg), rest_integrator(rs) {} | ||
|
||
template<std::size_t DIMBINS, typename F, typename IntegrationRange, typename Logger> | ||
auto generate(const std::array<std::size_t,DIMBINS>& bin_resolution, | ||
const F& f, const IntegrationRange& range, Logger& logger) const { | ||
auto [range_first, range_rest] = range_split_at<N>(range); | ||
auto f_gen = function_split_and_integrate_at<N>(f,rest_integrator,range_rest); | ||
return base_generator.generate(bin_resolution, f_gen, range_first, logger); | ||
} | ||
}; | ||
|
||
template<std::size_t N, typename BaseGenerator, typename RestIntegrator> | ||
auto regions_generator_fubini(const BaseGenerator& bg, const RestIntegrator& ri) { | ||
return RegionsGeneratorFubini<BaseGenerator,RestIntegrator,N>(bg,ri); | ||
} | ||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/control-variates/integrator-adaptive-fubini-variance-reduction.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
#include "integrator-adaptive-variance-reduction.h" | ||
#include "../combination/regions-generator-fubini.h" | ||
#include "../monte-carlo/monte-carlo.h" | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
namespace viltrum { | ||
|
||
template<std::size_t N, typename RR, typename CV, typename RS, typename R, typename EH, typename RNG> | ||
auto integrator_adaptive_fubini_variance_reduction_parallel(const R& rule, const EH& error_heuristic, std::size_t iterations, unsigned long mc_samples, RR&& rr, CV&& cv, RS&& region_sampler, RNG&& rng, unsigned long spp, std::size_t nmutexes = 16) { | ||
RNG rn = rng; | ||
return integrator_region_based( | ||
regions_generator_fubini<N>(regions_generator_adaptive_heap(rule,error_heuristic,iterations),monte_carlo(rn,mc_samples)), | ||
regions_integrator_parallel_variance_reduction(std::forward<RR>(rr),std::forward<CV>(cv), std::forward<RS>(region_sampler), rn,spp,nmutexes)); | ||
} | ||
|
||
template<std::size_t N, typename RR, typename CV, typename RS, typename R, typename EH> | ||
auto integrator_adaptive_fubini_variance_reduction_parallel(const R& rule, const EH& error_heuristic, std::size_t iterations, unsigned long mc_samples, | ||
RR&& rr, CV&& cv, RS&& region_sampler, unsigned long spp, std::size_t seed = std::random_device()(), std::size_t nmutexes = 16) { | ||
return integrator_region_based( | ||
regions_generator_fubini<N>(regions_generator_adaptive_heap(rule,error_heuristic,iterations),monte_carlo(std::mt19937(seed),mc_samples)), | ||
regions_integrator_parallel_variance_reduction(std::forward<RR>(rr),std::forward<CV>(cv), std::forward<RS>(region_sampler), std::mt19937(seed+1),spp,nmutexes)); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include "../range.h" | ||
#include <array> | ||
#include <random> | ||
|
||
namespace viltrum { | ||
|
||
class region_sampling_uniform { | ||
public: | ||
template<typename R, typename Float, std::size_t DIM, typename RNG> | ||
std::tuple<std::array<Float,DIM>,Float> sample(const R& reg, const Range<Float,DIM>& range, RNG& rng) const { | ||
std::array<Float,DIM> sample; | ||
for (std::size_t i=0;i<DIM;++i) { | ||
std::uniform_real_distribution<Float> dis(range.min(i),range.max(i)); | ||
sample[i] = dis(rng); | ||
} | ||
return std::tuple<std::array<Float,DIM>,Float>(sample,range.volume()); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.