|
Oakfield API Documentation 1.0.0
Numerical core APIs
|
Deterministic RNG streams and reusable noise update helpers. More...


Go to the source code of this file.
Classes | |
| struct | SimNoiseSourceRng |
| Mutable deterministic RNG state with cached normal sample. More... | |
Typedefs | |
| typedef struct SimNoiseSourceRng | SimNoiseSourceRng |
| Mutable deterministic RNG state with cached normal sample. | |
Functions | |
| void | sim_noise_source_seed (SimNoiseSourceRng *rng, uint64_t initstate, uint64_t initseq) |
| Seed a deterministic RNG stream. | |
| double | sim_noise_source_uniform (SimNoiseSourceRng *rng) |
| Draw a uniform variate in [0, 1). | |
| void | sim_noise_source_normal_pair (SimNoiseSourceRng *rng, double *n0, double *n1) |
| Draw a pair of independent standard-normal variates. | |
| double | sim_noise_source_normal (SimNoiseSourceRng *rng) |
| Draw one standard-normal variate. | |
| double | sim_noise_source_gaussian_gain (double sigma, double dt, bool scale_by_dt) |
| Compute the finite gain used by Gaussian white-noise updates. | |
| SimResult | sim_noise_source_ensure_capacity (double **real_state, SimComplexDouble **complex_state, size_t *capacity, size_t count, bool is_complex) |
Ensure reusable temporal-noise state storage has at least count entries. | |
| void | sim_noise_source_apply_white_real (double *dst, size_t count, double mean, double gain, SimNoiseSourceRng *rng) |
| Add real-valued white Gaussian noise to an array in place. | |
| void | sim_noise_source_apply_white_complex (SimComplexDouble *dst, size_t count, double mean_re, double mean_im, double gain_re, double gain_im, SimNoiseSourceRng *rng) |
| Add complex white Gaussian noise to an array in place. | |
| void | sim_noise_source_temporal_params (double sigma, double tau, double alpha, double dt, double *out_decay, double *out_variance) |
| Derive decay and innovation scale for temporal correlated noise. | |
| void | sim_noise_source_apply_temporal_real (double *dst, double *noise_state, size_t count, double output_scale, double decay, double variance, SimNoiseSourceRng *rng) |
| Advance real temporal-noise state and add it to a destination array. | |
| void | sim_noise_source_apply_temporal_complex (SimComplexDouble *dst, SimComplexDouble *noise_state, size_t count, double output_scale, double decay, double variance, SimNoiseSourceRng *rng) |
| Advance complex temporal-noise state and add it to a destination array. | |
| void | sim_noise_source_apply_mean_reverting_real (double *dst, size_t count, double mean, double decay, double variance, SimNoiseSourceRng *rng) |
| Apply a real mean-reverting update in place. | |
| void | sim_noise_source_apply_mean_reverting_complex (SimComplexDouble *dst, size_t count, double mean, double decay, double variance, SimNoiseSourceRng *rng) |
| Apply a complex mean-reverting update in place. | |
Deterministic RNG streams and reusable noise update helpers.
This header exposes the shared stochastic primitives used by stimulus and noise operators. Streams are explicitly seeded, output buffers are caller-owned, and helper functions clamp non-finite parameters to deterministic fallbacks rather than propagating NaN through update loops.
| typedef struct SimNoiseSourceRng SimNoiseSourceRng |
Mutable deterministic RNG state with cached normal sample.
The state/inc pair implements the underlying uniform stream. The spare fields cache the second Box-Muller output so repeated scalar-normal calls consume the same sequence as paired normal generation.
| void sim_noise_source_apply_mean_reverting_complex | ( | SimComplexDouble * | dst, |
| size_t | count, | ||
| double | mean, | ||
| double | decay, | ||
| double | variance, | ||
| SimNoiseSourceRng * | rng | ||
| ) |
Apply a complex mean-reverting update in place.
The same real mean is applied to both real and imaginary channels, with independent Gaussian innovations when variance is nonzero.
| [in,out] | dst | Complex values to update in place. |
| count | Number of entries in dst. | |
| mean | Reversion target for both channels. | |
| decay | Distance-from-mean multiplier. | |
| variance | Optional standard-normal innovation multiplier. | |
| rng | RNG state to advance when variance is nonzero. |
| void sim_noise_source_apply_mean_reverting_real | ( | double * | dst, |
| size_t | count, | ||
| double | mean, | ||
| double | decay, | ||
| double | variance, | ||
| SimNoiseSourceRng * | rng | ||
| ) |
Apply a real mean-reverting update in place.
Each element becomes mean + decay * (x - mean) plus optional Gaussian innovation. Non-finite parameters fall back to mean=0, decay=1, variance=0.
| [in,out] | dst | Real values to update in place. |
| count | Number of entries in dst. | |
| mean | Reversion target. | |
| decay | Distance-from-mean multiplier. | |
| variance | Optional standard-normal innovation multiplier. | |
| rng | RNG state to advance when variance is nonzero. |
| void sim_noise_source_apply_temporal_complex | ( | SimComplexDouble * | dst, |
| SimComplexDouble * | noise_state, | ||
| size_t | count, | ||
| double | output_scale, | ||
| double | decay, | ||
| double | variance, | ||
| SimNoiseSourceRng * | rng | ||
| ) |
Advance complex temporal-noise state and add it to a destination array.
Real and imaginary state channels use independent normal innovations.
| [in,out] | dst | Destination values incremented by output_scale * state. |
| [in,out] | noise_state | Persistent per-element complex noise state. |
| count | Number of entries in both arrays. | |
| output_scale | Scale applied to updated channels before adding to dst. | |
| decay | Autoregressive decay factor. | |
| variance | Multiplier for fresh standard-normal innovations. | |
| rng | RNG state to advance. |
| void sim_noise_source_apply_temporal_real | ( | double * | dst, |
| double * | noise_state, | ||
| size_t | count, | ||
| double | output_scale, | ||
| double | decay, | ||
| double | variance, | ||
| SimNoiseSourceRng * | rng | ||
| ) |
Advance real temporal-noise state and add it to a destination array.
| [in,out] | dst | Destination values incremented by output_scale * state. |
| [in,out] | noise_state | Persistent per-element real noise state. |
| count | Number of entries in both arrays. | |
| output_scale | Scale applied to the updated state before adding to dst. | |
| decay | Autoregressive decay factor. | |
| variance | Multiplier for fresh standard-normal innovation. | |
| rng | RNG state to advance. |
| void sim_noise_source_apply_white_complex | ( | SimComplexDouble * | dst, |
| size_t | count, | ||
| double | mean_re, | ||
| double | mean_im, | ||
| double | gain_re, | ||
| double | gain_im, | ||
| SimNoiseSourceRng * | rng | ||
| ) |
Add complex white Gaussian noise to an array in place.
Real and imaginary channels draw independent standard-normal samples. Non- finite means or gains are treated as zero.
| [in,out] | dst | Complex destination values to increment. |
| count | Number of entries in dst. | |
| mean_re | Real-channel deterministic offset. | |
| mean_im | Imaginary-channel deterministic offset. | |
| gain_re | Real-channel normal multiplier. | |
| gain_im | Imaginary-channel normal multiplier. | |
| rng | RNG state to advance. |
| void sim_noise_source_apply_white_real | ( | double * | dst, |
| size_t | count, | ||
| double | mean, | ||
| double | gain, | ||
| SimNoiseSourceRng * | rng | ||
| ) |
Add real-valued white Gaussian noise to an array in place.
Non-finite mean and gain are treated as zero. The destination is unchanged when dst, rng, or count is empty.
| [in,out] | dst | Real destination values to increment. |
| count | Number of entries in dst. | |
| mean | Deterministic offset added to each element. | |
| gain | Multiplier for independent N(0, 1) samples. | |
| rng | RNG state to advance. |
| SimResult sim_noise_source_ensure_capacity | ( | double ** | real_state, |
| SimComplexDouble ** | complex_state, | ||
| size_t * | capacity, | ||
| size_t | count, | ||
| bool | is_complex | ||
| ) |
Ensure reusable temporal-noise state storage has at least count entries.
The selected real or complex state array is allocated or grown with new slots zero-initialized. Passing count zero frees both arrays and resets capacity.
| [in,out] | real_state | Pointer to caller-owned real state storage. |
| [in,out] | complex_state | Pointer to caller-owned complex state storage. |
| [in,out] | capacity | Current and resulting number of allocated entries. |
| count | Required element count; zero releases both arrays. | |
| is_complex | Selects which state array must be grown for nonzero count. |
| double sim_noise_source_gaussian_gain | ( | double | sigma, |
| double | dt, | ||
| bool | scale_by_dt | ||
| ) |
Compute the finite gain used by Gaussian white-noise updates.
Non-finite sigma or dt values are treated as zero. When scale_by_dt is true, the gain is multiplied by sqrt(abs(dt)).
| sigma | Noise amplitude. |
| dt | Simulation timestep. |
| scale_by_dt | Whether to apply sqrt(abs(dt)) scaling. |
| double sim_noise_source_normal | ( | SimNoiseSourceRng * | rng | ) |
Draw one standard-normal variate.
| rng | RNG state to advance. |
rng is NULL. | void sim_noise_source_normal_pair | ( | SimNoiseSourceRng * | rng, |
| double * | n0, | ||
| double * | n1 | ||
| ) |
Draw a pair of independent standard-normal variates.
Uses Box-Muller sampling with the first uniform clamped away from zero to avoid log(0). Output pointers may be NULL.
| rng | RNG state to advance; NULL writes zeroes to non-NULL outputs. | |
| [out] | n0 | Receives the first N(0, 1) sample when non-NULL. |
| [out] | n1 | Receives the second N(0, 1) sample when non-NULL. |
| void sim_noise_source_seed | ( | SimNoiseSourceRng * | rng, |
| uint64_t | initstate, | ||
| uint64_t | initseq | ||
| ) |
Seed a deterministic RNG stream.
| rng | RNG state to initialize; NULL is ignored. |
| initstate | Initial generator state value. |
| initseq | Stream selector; converted to an odd increment internally. |
| void sim_noise_source_temporal_params | ( | double | sigma, |
| double | tau, | ||
| double | alpha, | ||
| double | dt, | ||
| double * | out_decay, | ||
| double * | out_variance | ||
| ) |
Derive decay and innovation scale for temporal correlated noise.
The update convention is state = decay * state + variance * N(0, 1). Invalid dt disables innovation, invalid tau is clamped to a tiny positive value, and alpha is bounded below by 0.1.
| sigma | Innovation amplitude before temporal normalization. | |
| tau | Positive correlation timescale. | |
| alpha | Positive stretch exponent, clamped to at least 0.1. | |
| dt | Simulation timestep. | |
| [out] | out_decay | Receives decay factor when non-NULL. |
| [out] | out_variance | Receives normal multiplier when non-NULL. |
| double sim_noise_source_uniform | ( | SimNoiseSourceRng * | rng | ) |
Draw a uniform variate in [0, 1).
| rng | RNG state to advance. |
rng is NULL.