|
| | PiecewiseLinearDistribution () |
| | Default constructor. Creates uniform distribution over [0, 1).
|
| |
| template<typename InputIteratorB , typename InputIteratorW > |
| | PiecewiseLinearDistribution (InputIteratorB first_b, InputIteratorB last_b, InputIteratorW first_w) |
| | Constructs from interval boundaries and density values.
|
| |
| template<typename UnaryOperation > |
| | PiecewiseLinearDistribution (std::initializer_list< RealType > bl, UnaryOperation fw) |
| | Constructs from interval boundaries and density function.
|
| |
| template<typename UnaryOperation > |
| | PiecewiseLinearDistribution (size_t nw, RealType xmin, RealType xmax, UnaryOperation fw) |
| | Constructs with evenly-spaced intervals and density function.
|
| |
| | PiecewiseLinearDistribution (const param_type ¶m) |
| | Constructs from a parameter set.
|
| |
| void | reset () |
| | Resets the distribution state.
|
| |
| std::vector< RealType > | intervals () const |
| | Returns the interval boundaries.
|
| |
| std::vector< double > | densities () const |
| | Returns the density values at boundaries.
|
| |
| param_type | param () const |
| | Gets the current parameter set.
|
| |
| void | param (const param_type ¶m) |
| | Sets new parameters for the distribution.
|
| |
| result_type | min () const |
| | Gets the minimum value that can be generated.
|
| |
| result_type | max () const |
| | Gets the maximum value that can be generated.
|
| |
| template<typename Generator > |
| result_type | operator() (Generator &g) |
| | Generates the next random value using stored parameters.
|
| |
| template<typename Generator > |
| result_type | operator() (Generator &g, const param_type ¶m) |
| | Generates the next random value using provided parameters.
|
| |
template<typename RealType = double>
class Infinity::Engine::PiecewiseLinearDistribution< RealType >
Platform-independent piecewise linear distribution.
Produces real values from a distribution defined by a piecewise linear density function. The density is specified at interval boundaries and linearly interpolated between them, providing smooth transitions between different probability regions.
This distribution is more flexible than piecewise constant for smooth approximations of continuous distributions. It's ideal for terrain elevation distributions with gradual transitions, probability gradients, smooth weighting functions, or approximating complex probability density functions that require continuity.
- Template Parameters
-
| RealType | Floating point type (float or double) |
Example usage:
std::vector<float>
intervals = {0.0f, 0.5f, 1.0f};
std::vector<double>
densities = {0.0, 1.0, 0.0};
);
float value = triangle(rng);
auto elevation_pdf = [](double x) { return std::exp(-x / 500.0); };
{0.0f, 100.0f, 500.0f, 1000.0f},
[](float dist) { return 1.0 / (1.0 + dist / 100.0); }
);
auto resource_density = [](double x) {
return 0.5 + 0.5 * std::sin(x * 3.14159);
};
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
std::vector< double > densities() const
Returns the density values at boundaries.
Definition PRNGDistribution.hpp:4538
std::vector< RealType > intervals() const
Returns the interval boundaries.
Definition PRNGDistribution.hpp:4535
template class INFINITY_API_PUBLIC PiecewiseLinearDistribution< float >
Definition PRNGDistribution.cpp:68
template class INFINITY_API_PUBLIC PiecewiseLinearDistribution< double >
Definition PRNGDistribution.cpp:69
- Note
- Densities are automatically normalized to integrate to 1.
-
Linear interpolation between specified density values provides smooth transitions.
-
More accurate than piecewise constant for approximating smooth distributions.
-
Uses quadratic formula for inverse CDF, ensuring exact sampling.
template<typename RealType = double>
template<typename Generator >
Generates the next random value using provided parameters.
Uses a three-step process:
- Select an interval based on cumulative probabilities (binary search)
- Compute local cumulative probability within the selected interval
- Invert the linear CDF using quadratic formula to find the value
For a linear density d(x) = d0 + m*(x-x0) in an interval, the CDF is: F(x) = d0*(x-x0) + 0.5*m*(x-x0)²
Solving F(x) = u for x requires the quadratic formula, ensuring exact sampling from the piecewise linear density.
- Template Parameters
-
| Generator | The random number generator type (e.g., PRNG) |
- Parameters
-
| g | The random number generator |
| param | The distribution parameters to use for this generation |
- Returns
- A random value from the piecewise linear distribution