Skip to content

Commit

Permalink
Add possibiblity to access the densities function
Browse files Browse the repository at this point in the history
- sometimes one needs the ability to access data from the densities function -
  if this is the case, then one capture it by simply using
  `multi_channel_point2`.
  • Loading branch information
cschwan committed Dec 17, 2015
1 parent f9f806f commit 6715c73
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/hep/mc/multi_channel.hpp
Expand Up @@ -27,6 +27,7 @@
#include <cstddef>
#include <limits>
#include <random>
#include <type_traits>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -144,8 +145,9 @@ inline multi_channel_result<T> multi_channel_iteration(
total_density += channel_weights[j] * channel_densities[j];
}

multi_channel_point<T> const point(total_calls, random_numbers,
coordinates, channel, total_density);
multi_channel_point2<T, typename std::remove_reference<D>::type> const
point(total_calls, random_numbers, coordinates, channel,
total_density, densities);

T const value = function(point) * point.weight;

Expand Down
27 changes: 27 additions & 0 deletions include/hep/mc/multi_channel_point.hpp
Expand Up @@ -56,6 +56,33 @@ struct multi_channel_point : public mc_point<T>
std::vector<T> const& coordinates;
};

/// Point in the unit-hypercube for multi-channel Monte Carlo integration. This
/// type also captures the density functions that are used to generate
/// `coordinates`.
template <typename T, typename D>
struct multi_channel_point2 : public multi_channel_point<T>
{
/// Constructor.
multi_channel_point2(
std::size_t calls,
std::vector<T> const& point,
std::vector<T> const& coordinates,
std::size_t channel,
T total_density,
D const& density_function
)
: multi_channel_point<T>(calls, point, coordinates, channel,
total_density)
, density_function(density_function)
{
}

/// The density function that constructed this point. See
/// \ref multi_channel_iteration for reference of the signature of this
/// function.
D const& density_function;
};

/// @}

}
Expand Down

0 comments on commit 6715c73

Please sign in to comment.