StatMath
StatMath - Comprehensive Statistical Functions Library
This is the main autoload singleton that provides access to all statistical functions and mathematical utilities. All core functionality is organized into specialized modules that can be accessed through this central interface.
Usage Examples:
# Generate random numbers from distributions
var normal_sample = StatMath.Distributions.randf_normal(0.0, 1.0)
var poisson_sample = StatMath.Distributions.randi_poisson(3.5)
# Calculate statistical measures
var data = [1.0, 2.0, 3.0, 4.0, 5.0]
var mean = StatMath.BasicStats.mean(data)
var variance = StatMath.BasicStats.variance(data)
# Use distribution functions
var cdf_value = StatMath.CdfFunctions.normal_cdf(1.96, 0.0, 1.0)
var quantile = StatMath.PpfFunctions.normal_ppf(0.975, 0.0, 1.0)
# Advanced sampling
var samples = StatMath.SamplingGen.generate_samples(100, 2, StatMath.SamplingGen.SamplingMethod.SOBOL)
Module Organization:
BasicStats
- Descriptive statistics (mean, variance, quantiles, etc.)Distributions
- Random number generation from various distributionsCdfFunctions
- Cumulative distribution functionsPpfFunctions
- Inverse CDF/quantile functionsPmfPdfFunctions
- Probability mass/density functionsErrorFunctions
- Error functions and special mathematical functionsHelperFunctions
- Core mathematical utilitiesSamplingGen
- Advanced sampling and quasi-random sequences
Usage
# StatMath is the main singleton - access modules through it
var result = StatMath.ModuleName.function_name(parameters)
# Or access constants directly
var epsilon = StatMath.EPSILON
Constants
- GODOT_STAT_MATH_SEED_VARIABLE_NAME
Value:
StringName = &"godot_stat_math_seed"
- _default_seed
Value:
int = 0
- PRIMES
Value:
Array[int] = [
- INT_MAX_REPRESENTING_INF
Value:
= 2147483647
- INT64_MAX_VAL
Value:
int = 9223372036854775807
- FLOAT_EPSILON
Value:
float = 2.220446049250313e-16
- MAX_ITERATIONS
Value:
int = 200
- EPSILON
Value:
float = 1.0e-9
- FLOAT_TOLERANCE
Value:
float = 1.0e-7
- HIGH_PRECISION_TOLERANCE
Value:
float = 1.0e-9
- ERF_APPROX_TOLERANCE
Value:
float = 1.0e-5
- NUMERICAL_DIFFERENTIATION_H
Value:
float = 1.0e-6
- SAMPLE_MEAN_TOLERANCE
Value:
float = 1.0e-6
- SAMPLING_DETERMINISM_TOLERANCE
Value:
float = 1.0e-7
- INVERSE_FUNCTION_TOLERANCE
Value:
float = 2.0e-6
- NUMERICAL_TOLERANCE
Value:
float = 1.0e-5
- CDF_PPF_CONSISTENCY_TOLERANCE
Value:
float = 1.0e-5
- DERIVATIVE_TOLERANCE
Value:
float = 1.0e-3
- PROBABILITY_TOLERANCE
Value:
float = 1.0e-6
- SPECIAL_VALUES_TOLERANCE
Value:
float = 2.0e-6
- BOUNDARY_TOLERANCE
Value:
float = 1.0e-10
- ASYMPTOTIC_TOLERANCE
Value:
float = 1.0e-2
- INTERPOLATION_TOLERANCE
Value:
float = 1.0e-4
- NUMERICAL_INTEGRATION_TOLERANCE
Value:
float = 5.0e-3
- SYMMETRY_TOLERANCE
Value:
float = 1.0e-4
- ERF_INV_TOLERANCE
Value:
float = 2.0e-2
- STATISTICAL_TEST_STD_DEV_MULTIPLIER
Value:
float = 4.0
- DEFAULT_TOLERANCE_FACTOR
Value:
float = 1.0
- SAMPLING_TOLERANCE
Value:
float = 1.0e-6
- INVERSE_CONSISTENCY_TOLERANCE
Value:
float = 1.0e-5
- STABILITY_TOLERANCE
Value:
float = 1.0e-6
- STRESS_TEST_BOUNDARY
Value:
float = 1.0e-17
- STRESS_TEST_SMALL_VALUE
Value:
float = 1.0e-3
- INTERFACE_TOLERANCE
Value:
float = 1.0e-7
- DETERMINISM_TOLERANCE
Value:
float = 1.0e-7
- HYPERGEOMETRIC_TOLERANCE
Value:
float = 0.15
- NEGATIVE_BINOMIAL_TOLERANCE
Value:
float = 0.2
- HIGH_DISTRIBUTION_TOLERANCE
Value:
float = 0.5
- BETA_TOLERANCE
Value:
float = 0.1
- LANCZOS_G
Value:
float = 7.5
- LANCZOS_P
Value:
Array[float] = [
- A1_ERR
Value:
float = 0.254829592
- A2_ERR
Value:
float = -0.284496736
- A3_ERR
Value:
float = 1.421413741
- A4_ERR
Value:
float = -1.453152027
- A5_ERR
Value:
float = 1.061405429
- P_ERR
Value:
float = 0.3275911
- BasicStats
Value:
preload("res://addons/godot-stat-math/core/basic_stats.gd")
- Distributions
Value:
preload("res://addons/godot-stat-math/core/distributions.gd")
- CdfFunctions
Value:
preload("res://addons/godot-stat-math/core/cdf_functions.gd")
- PmfPdfFunctions
Value:
preload("res://addons/godot-stat-math/core/pmf_pdf_functions.gd")
- PpfFunctions
Value:
preload("res://addons/godot-stat-math/core/ppf_functions.gd")
- ErrorFunctions
Value:
preload("res://addons/godot-stat-math/core/error_functions.gd")
- HelperFunctions
Value:
preload("res://addons/godot-stat-math/core/helper_functions.gd")
- SamplingGen
Value:
preload("res://addons/godot-stat-math/core/sampling_gen.gd")
Functions
- _ready() void:
Initializes the StatMath addon and sets up the random number generator.
Automatically called when the addon is loaded as an autoload singleton. Reads the global seed configuration and initializes the RNG system.
- _create_and_seed_rng(seed_val: int) void:
Creates and seeds the internal RandomNumberGenerator instance.
If
seed_val
is 0, Godot will automatically choose a random seed. The actual seed used can be read from_rng.seed
after initialization.
- _initialize_rng() void:
Initializes the RNG system using global project settings.
Checks for the project setting
godot_stat_math_seed
to determine the seed value. Creates the setting with default value if it doesn’t exist.
- get_rng() RandomNumberGenerator:
Returns the addon’s RandomNumberGenerator instance.
This RNG is used by all statistical functions that require randomness. Provides consistent seeding and reproducible results across the addon.
Mathematical Note: All statistical sampling uses this centralized RNG for reproducibility
- set_global_seed(new_seed: int) void:
Changes the global seed and recreates the RandomNumberGenerator.
This affects all subsequent random number generation throughout the addon. Useful for creating reproducible statistical simulations and tests.
Mathematical Note: Changing seed allows reproducible statistical experiments