Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Engine::ChiSquaredDistribution< RealType > Class Template Reference

Platform-independent chi-squared distribution. More...

#include <PRNGDistribution.hpp>

Classes

struct  param_type
 Parameter set for the distribution. More...
 

Public Types

using result_type = RealType
 The type of values produced by the distribution.
 

Public Member Functions

 ChiSquaredDistribution ()
 Default constructor. Creates ChiSquared(1) distribution.
 
 ChiSquaredDistribution (RealType n)
 Constructs a chi-squared distribution with specified degrees of freedom.
 
 ChiSquaredDistribution (const param_type &param)
 Constructs from a parameter set.
 
void reset ()
 Resets the distribution state.
 
RealType n () const
 Gets the degrees of freedom.
 
param_type param () const
 Gets the current parameter set.
 
void param (const param_type &param)
 Sets new parameters for the distribution.
 
result_type min () const
 Gets the minimum value that can be generated (approaches 0).
 
result_type max () const
 Gets the theoretical maximum value (positive infinity).
 
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 &param)
 Generates the next random value using provided parameters.
 

Friends

bool operator== (const ChiSquaredDistribution &lhs, const ChiSquaredDistribution &rhs)
 
bool operator!= (const ChiSquaredDistribution &lhs, const ChiSquaredDistribution &rhs)
 

Detailed Description

template<typename RealType = double>
class Infinity::Engine::ChiSquaredDistribution< RealType >

Platform-independent chi-squared distribution.

Produces values according to the chi-squared distribution with n degrees of freedom. The chi-squared distribution is a special case of the gamma distribution: ChiSquared(n) = Gamma(n/2, 2).

This distribution is fundamental in statistics, appearing in hypothesis testing, confidence intervals, and goodness-of-fit tests. It represents the distribution of the sum of squares of n independent standard normal random variables.

Template Parameters
RealTypeFloating point type (float or double)

Example usage:

PRNG rng(12345);
// Chi-squared with 5 degrees of freedom
float value = chi2(rng);
// Generate test statistics for goodness-of-fit
for (int i = 0; i < 1000; ++i) {
double chi2_value = test_stat(rng);
}
// Model sum of squared standard normals
float sum_of_squares = squared_sum(rng);
Platform-independent chi-squared distribution.
Definition PRNGDistribution.hpp:1332
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
Note
All values are strictly positive.
Mean = n, Variance = 2n
As n increases, the distribution approaches normal with mean n and variance 2n.
Related to normal: if Z ~ N(0,1), then Z² ~ ChiSquared(1)

Member Typedef Documentation

◆ result_type

template<typename RealType = double>
using Infinity::Engine::ChiSquaredDistribution< RealType >::result_type = RealType

The type of values produced by the distribution.

Constructor & Destructor Documentation

◆ ChiSquaredDistribution() [1/3]

template<typename RealType = double>
Infinity::Engine::ChiSquaredDistribution< RealType >::ChiSquaredDistribution ( )
inline

Default constructor. Creates ChiSquared(1) distribution.

◆ ChiSquaredDistribution() [2/3]

template<typename RealType = double>
Infinity::Engine::ChiSquaredDistribution< RealType >::ChiSquaredDistribution ( RealType  n)
inlineexplicit

Constructs a chi-squared distribution with specified degrees of freedom.

Parameters
nDegrees of freedom

◆ ChiSquaredDistribution() [3/3]

template<typename RealType = double>
Infinity::Engine::ChiSquaredDistribution< RealType >::ChiSquaredDistribution ( const param_type param)
inlineexplicit

Constructs from a parameter set.

Parameters
paramThe distribution parameters

Member Function Documentation

◆ max()

template<typename RealType = double>
result_type Infinity::Engine::ChiSquaredDistribution< RealType >::max ( ) const
inline

Gets the theoretical maximum value (positive infinity).

◆ min()

template<typename RealType = double>
result_type Infinity::Engine::ChiSquaredDistribution< RealType >::min ( ) const
inline

Gets the minimum value that can be generated (approaches 0).

◆ n()

template<typename RealType = double>
RealType Infinity::Engine::ChiSquaredDistribution< RealType >::n ( ) const
inline

Gets the degrees of freedom.

◆ operator()() [1/2]

template<typename RealType = double>
template<typename Generator >
result_type Infinity::Engine::ChiSquaredDistribution< RealType >::operator() ( Generator &  g)
inline

Generates the next random value using stored parameters.

Uses the relationship ChiSquared(n) = Gamma(n/2, 2) by generating from the underlying gamma distribution.

Template Parameters
GeneratorThe random number generator type (e.g., PRNG)
Parameters
gThe random number generator
Returns
A positive random value from the chi-squared distribution

◆ operator()() [2/2]

template<typename RealType = double>
template<typename Generator >
result_type Infinity::Engine::ChiSquaredDistribution< RealType >::operator() ( Generator &  g,
const param_type param 
)
inline

Generates the next random value using provided parameters.

Creates a temporary gamma distribution and generates a chi-squared value.

Template Parameters
GeneratorThe random number generator type (e.g., PRNG)
Parameters
gThe random number generator
paramThe distribution parameters to use for this generation
Returns
A positive random value from ChiSquared(param.n())

◆ param() [1/2]

template<typename RealType = double>
param_type Infinity::Engine::ChiSquaredDistribution< RealType >::param ( ) const
inline

Gets the current parameter set.

◆ param() [2/2]

template<typename RealType = double>
void Infinity::Engine::ChiSquaredDistribution< RealType >::param ( const param_type param)
inline

Sets new parameters for the distribution.

Recreates the underlying gamma distribution with the new degrees of freedom.

Parameters
paramThe new distribution parameters

◆ reset()

template<typename RealType = double>
void Infinity::Engine::ChiSquaredDistribution< RealType >::reset ( )
inline

Resets the distribution state.

Resets the underlying gamma distribution.

Friends And Related Symbol Documentation

◆ operator!=

template<typename RealType = double>
bool operator!= ( const ChiSquaredDistribution< RealType > &  lhs,
const ChiSquaredDistribution< RealType > &  rhs 
)
friend

◆ operator==

template<typename RealType = double>
bool operator== ( const ChiSquaredDistribution< RealType > &  lhs,
const ChiSquaredDistribution< RealType > &  rhs 
)
friend