oasislmf.pytools.gul.random¶
This file contains the utilities for generating random numbers in gulpy.
Attributes¶
Functions¶
|
Generate hash for a given group_id, event_id pair for the vulnerability pdf. |
|
Generate hash for a given hazard_group_id, event_id pair for the hazard pdf. |
|
Get the random generator function. |
|
Generate hashes for all peril correlation groups for a given event_id. |
|
|
|
|
|
Calculate the correlated random values with precomputed inv_factor and norm_factor. |
|
Generate random numbers using the default Mersenne Twister algorithm. |
|
Generate random numbers using the Latin Hypercube algorithm. |
|
Latin Hypercube on Philox4x32-7 (random_generator=2). |
Module Contents¶
- oasislmf.pytools.gul.random.generate_hash(group_id, event_id, base_seed=0)[source]¶
Generate hash for a given group_id, event_id pair for the vulnerability pdf.
- oasislmf.pytools.gul.random.generate_hash_hazard(hazard_group_id, event_id, base_seed=0)[source]¶
Generate hash for a given hazard_group_id, event_id pair for the hazard pdf.
- oasislmf.pytools.gul.random.get_random_generator(random_generator)[source]¶
Get the random generator function.
- Parameters:
random_generator (int) – random generator function id.
- Returns:
The random generator function.
Generate hashes for all peril correlation groups for a given event_id.
- oasislmf.pytools.gul.random.get_corr_rval(x_unif, y_unif, rho, x_min, norm_inv_cdf, inv_factor, cdf_min, norm_cdf, norm_factor, Nsamples, z_unif)[source]¶
Calculate the correlated random values with precomputed inv_factor and norm_factor.
inv_factor = (N - 1) / (x_max - x_min) norm_factor = (N - 1) / (cdf_max - cdf_min) Uses fast lookup for the middle values and interpolation for the tail values.
Previously get_corr_rval_float used by GulMC, now shared by both GULs
- oasislmf.pytools.gul.random.random_MersenneTwister(seeds, n, skip_seeds=0)[source]¶
Generate random numbers using the default Mersenne Twister algorithm.
- Parameters:
seeds (List[int64]) – List of seeds.
n (int) – number of random samples to generate for each seed.
skip_seeds (int) – number of seeds to skip starting from the beginning of the seeds array. For skipped seeds no random numbers are generated and the output rndms will contain zeros at their corresponding row. Default is 0, i.e. no seeds are skipped.
- Returns:
- 2-d array of shape (number of seeds, n)
containing the random values generated for each seed.
- rndms_idx (Dict[int64, int]): mapping between seed and the
row in rndms that stores the corresponding random values.
- Return type:
rndms (array[float])
- oasislmf.pytools.gul.random.random_LatinHypercube(seeds, n, skip_seeds=0)[source]¶
Generate random numbers using the Latin Hypercube algorithm.
- Parameters:
seeds (List[int64]) – List of seeds.
n (int) – number of random samples to generate for each seed.
skip_seeds (int) – number of seeds to skip starting from the beginning of the seeds array. For skipped seeds no random numbers are generated and the output rndms will contain zeros at their corresponding row. Default is 0, i.e. no seeds are skipped.
- Returns:
- 2-d array of shape (number of seeds, n)
containing the random values generated for each seed.
- rndms_idx (Dict[int64, int]): mapping between seed and the
row in rndms that stores the corresponding random values.
- Return type:
rndms (array[float])
Notes
Implementation follows scipy.stats.qmc.LatinHypercube v1.8.0. Following scipy notation, here we assume centered=False all the times: instead of taking samples=0.5*np.ones(n), here we always draw uniform random samples in order to initialise samples.
- oasislmf.pytools.gul.random.random_LatinHypercube_Philox7(seeds, n, skip_seeds=0)[source]¶
Latin Hypercube on Philox4x32-7 (random_generator=2).
See the module comment above random_LatinHypercube_Philox7 for the algorithm.
- Parameters:
- Returns:
2-d array of shape (len(seeds), n) of LH samples in (0, 1].
- Return type:
rndms (array[float64])