Open 3D Engine EMotionFX Gem API Reference  24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
MCore::HaltonSequence Class Reference

#include <Random.h>

Public Member Functions

 HaltonSequence ()
 
 HaltonSequence (uint32 dimensions, uint32 offset=0, uint32 *primes=nullptr)
 
 ~HaltonSequence ()
 
void Init (uint32 dimensions, uint32 offset=0, uint32 *primes=nullptr)
 
void Release ()
 
uint32 GetNumDimensions () const
 
uint32 GetMemoryUsage () const
 
uint32 GetVectorNumber () const
 
double GetNextDimension ()
 
void ResetNextDimension ()
 
void Restart ()
 
void Next ()
 
void SetInstance (uint32 instance)
 
void operator++ ()
 
double operator[] (uint32 j) const
 

Detailed Description

The Halton Sequence class. Halton sequences are pseudo random numbers, actually known as Quasi Random Numbers. They are often used in Monte Carlo sampling methods, because they are very good for that, especially for higher dimensions. The generated numbers are always the same. You can however add some real randomness to it to let the random numbers you get start at a given random offset (instance). The values generated try to keep an as large as possible distance between eachother, to prevent groups of points very close to eachother at some spots. This is one of the reasons why they are so cool. They work basically the same as stratisfied sampling your values, but with the nice feature that you do not have to know upfront how many random numbers you will need. So you can keep asking for the next value in the set. The values returned by the sequence are in range of [0..1]. If for example you want to generate random points in a 2D box, you can create a two dimensional HaltonSequence. Let me demonstrate with some example code:


// create a two dimensional Halton sequence
HaltonSequence seq(2);

// generate 100 random points inside the 1x1 unit 2D box.
for (uint32 i=0; i<100; i++)
{
   float x = seq[0];
   float y = seq[1];
   seq.Next();
}

You now might want to ask, why not just use the Random::RandF() function for this? Well, the answer is that the distribution of the samples is much more evenly with the Halton sequences as with just normal random numbers using Random::RandF(). When not using Random::RandF() you can get areas where there are more points as in other areas, so no even distribution. This can lead to variance in estimates using random values. HaltonSequences converge much faster, so result in a more accurate estimate.

Constructor & Destructor Documentation

◆ HaltonSequence() [1/2]

MCore::HaltonSequence::HaltonSequence ( )

The default constructor. Be sure to call the Init(...) method before using any other methods of this class.

◆ HaltonSequence() [2/2]

MCore::HaltonSequence::HaltonSequence ( uint32  dimensions,
uint32  offset = 0,
uint32 *  primes = nullptr 
)

Extended constructor. This constructor automatically calls the Init method. Please keep in mind that MCore needs to be initialized before doing this, so if you have a global HaltonSequence object that uses this constructor, this will cause a crash. In that case, use the Init method with the default constructor that takes no parameters.

Parameters
dimensionsThe number of dimensions for the sequence.
offsetThe offset to start in the sequence.
primesThe list of prime values. Keep this nullptr when you want to generate them automatically.

◆ ~HaltonSequence()

MCore::HaltonSequence::~HaltonSequence ( )

Destructor.

Member Function Documentation

◆ GetMemoryUsage()

uint32 MCore::HaltonSequence::GetMemoryUsage ( ) const
inline

Get the memory usage in bytes by this sequence.

Returns
The memory usage in bytes by this sequence.

◆ GetNextDimension()

double MCore::HaltonSequence::GetNextDimension ( )
inline

Get the value of current dimension, and go to the next dimension.

Returns
The value of the current dimension, and step to the next dimension.

◆ GetNumDimensions()

uint32 MCore::HaltonSequence::GetNumDimensions ( ) const
inline

Returns the number of dimensions in the sequence.

Returns
The number of dimensions.

◆ GetVectorNumber()

uint32 MCore::HaltonSequence::GetVectorNumber ( ) const
inline

Get the current vector number.

Returns
The vector number.

◆ Init()

void MCore::HaltonSequence::Init ( uint32  dimensions,
uint32  offset = 0,
uint32 *  primes = nullptr 
)

Initialize the sequence. You can also call the Init method multiple times with different parameters to change its settings.

Parameters
dimensionsThe number of dimensions for the sequence.
offsetThe offset to start in the sequence.
primesThe list of prime values. Keep this nullptr when you want to generate them automatically.

◆ Next()

void MCore::HaltonSequence::Next ( )
inline

Get the next values in the sequence. So update the dimension values.

◆ operator++()

void MCore::HaltonSequence::operator++ ( )

Get the next values in the sequence. So update the dimension values.

◆ operator[]()

double MCore::HaltonSequence::operator[] ( uint32  j) const
inline

Get a value for a given dimension. (*sequence[0]) would be the value of the first dimension and (*sequence[1]) would be the value of the second dimension, etc.

◆ Release()

void MCore::HaltonSequence::Release ( )

Release all allocated memory. This is automatically called by the destructor.

◆ ResetNextDimension()

void MCore::HaltonSequence::ResetNextDimension ( )
inline

Reset the dimension stepping (by GetNextDimension()) and go to the first dimension again.

◆ Restart()

void MCore::HaltonSequence::Restart ( )
inline

Restart the sequence.

◆ SetInstance()

void MCore::HaltonSequence::SetInstance ( uint32  instance)

Set the instance in the sequence. So the startpoint/offset in the sequence, where 0 would jump to the beginning again.

Parameters
instanceThe instance value, so the startpoint in the sequence.

The documentation for this class was generated from the following file: