Random Sampling Search Algorithm¶
monte_carlo_random¶
Module containing algorithm classes for Monte Carlo random sampling.
-
class
MTfit.algorithms.monte_carlo.
IterationSample
(max_samples=600000, *args, **kwargs)[source]¶ Iteration based sampling algorithm
Algorithm that runs for a fixed number of samples.
Initialisation of IterationSample
- Args
- max_samples:[600000] Maximum time in seconds for the iteration to run for. number_samples:[10000] Number of samples to use per iteration. dc:[False] Boolean to select inversion constrained to double-couple space or over the full moment tensor space.
- Keyword Arguments
- basic_cdc:[False] Boolean to select whether to us the Basic CDC model (inversion constrained to double-couple space or over the full moment tensor space.
-
eigenvectors_mt_2_mt6
(diag, a, b, c)¶ Converts eigenvectors and eigenvalues to moment tensor 6-vector.
Generates moment tensor 6-vector.
- Args
- diag: numpy matrix of eigenvalues. a: numpy array of eigenvectors corresponding to the first eigenvalue. b: numpy array of eigenvectors corresponding to the second eigenvalue. c: numpy array of eigenvectors corresponding to the third eigenvalue.
- Returns
- numpy matrix of moment tensor 6-vectors.
-
get_sampling_model
(kwargs, file_sample, file_safe)¶ Get the sampling model from the entry points
-
initialise
()¶ Initial task for ForwardTask
- Returns
- task,end=False task: the random samples starting the inversion.
-
iterate
(result)¶ Iteration function for BaseMonteCarloRandomSample object
Carries out iteration of random sampling from previous result.
- Args
- result: dictionary result from MTfit.inversion.ForwardTask, added to the pdf
- Returns
- new_samples,end new_samples: New set of random samples to test. end: Boolean flag as to whether inversion has finished, if a MemoryError error is thrown, ends iteration.
-
output
(normalise=True, convert=False, discard=10000)¶ Return the algorithm results for output.
- Returns
- Dictionary containing output.
-
random_clvd
(*args)¶ Generate random CLVD moment tensors (size 6,number_samples)
Generates random CLVD moment tensors with random orientations.
- Returns
- numpy matrix of random CLVD moment tensors, size 6,number_samples
-
random_dc
(*args)¶ Generate random double-couple moment tensors (size 6, number_samples)
Generates random double-couple moment tensors with random orientations.
- Returns
- numpy matrix of random double-couple moment tensors, size 6,number_samples
-
random_orthogonal_eigenvectors
()¶ Generates random orthogonal eigenvectors.
- Returns
- list of numpy arrays of eigenvectors.
-
random_sample
()¶ Return random sample
Extends _BaseAlgorithm.random_sample to account for multiple events, and checks the source type.
-
random_type
(diag)¶ Generate random moment tensors from a given set of eigenvalues.
Generates random moment tensors with a given set of eigenvalues and random orientations.
- Args
- diag: numpy matrix of eigenvalues.
- Returns
- numpy matrix of random moment tensors, size 6,number_samples
members: inherited-members:
The random sampling algorithms inherit from the BaseAlgorithm
class:
-
class
MTfit.algorithms.base.
BaseAlgorithm
(number_samples=10000, dc=False, quality_check=False, file_sample=False, file_safe=True, generate=False, *args, **kwargs)[source]¶ Base class for algorithms including the base methods required for forward modelling based inversions.
BaseAlgorithm initialisation
- Args
number_samples:[10000] Number of samples to use per iteration. dc:[False] Boolean to select inversion constrained to double-couple
space or over the full moment tensor space.- quality_check:[False] Carry out quality check after 40,000 samples.
- If there are too many non-zero samples, the inversion is stopped for that event.
- file_sample:[False] Boolean to select whether to use file sampling
- (saving the output to file).
- file_safe:[False] Boolean to select whether to use file safe outputs
- when using file sampling.
- generate:[False] Boolean to select whether to generate the random
- moment tensors in the forward task or not.
- Keyword Arguments
- basic_cdc:[False] Boolean to select whether to use the Basic CDC
- model (inversion constrained to crack+double-couple space).
- number_events:[1] Integer giving the number of events in this
- inversion (for use with multiple event inversions).
- sampling_prior:[6sphere_prior] string selector for the full moment
- tensor sampling prior (MTfit.sampling_prior entry point)
- sampling:[6sphere] string selector for the full moment tensor
- sampling model (MTfit.sampling entry point)
- model:[False] selector for alternate models using the
- MTfit.sample_distribution entry_point
-
eigenvectors_mt_2_mt6
(diag, a, b, c)[source]¶ Converts eigenvectors and eigenvalues to moment tensor 6-vector.
Generates moment tensor 6-vector.
- Args
- diag: numpy matrix of eigenvalues. a: numpy array of eigenvectors corresponding to the first eigenvalue. b: numpy array of eigenvectors corresponding to the second eigenvalue. c: numpy array of eigenvectors corresponding to the third eigenvalue.
- Returns
- numpy matrix of moment tensor 6-vectors.
-
get_sampling_model
(kwargs, file_sample, file_safe)[source]¶ Get the sampling model from the entry points
-
initialise
()[source]¶ Basic initialisation function
Return the first task
- Returns
- task, False task: New task for forward model
-
iterate
(result)[source]¶ Basic iteration function
- Args
- result: Result from forward Task
- Returns
- task,End task: New task for forward model End: Boolean flag for whether the inversion is finished.
-
output
(normalise=True, convert=False, discard=10000)[source]¶ Return the algorithm results for output.
- Returns
- Dictionary containing output.
-
random_clvd
(*args)[source]¶ Generate random CLVD moment tensors (size 6,number_samples)
Generates random CLVD moment tensors with random orientations.
- Returns
- numpy matrix of random CLVD moment tensors, size 6,number_samples
-
random_dc
(*args)[source]¶ Generate random double-couple moment tensors (size 6, number_samples)
Generates random double-couple moment tensors with random orientations.
- Returns
- numpy matrix of random double-couple moment tensors, size 6,number_samples
They also inherit from the BaseMonteCarloRandomSample
class:
-
class
MTfit.algorithms.monte_carlo.
BaseMonteCarloRandomSample
(*args, **kwargs)[source]¶ Base class for Monte Carlo Random Sampling
Contains base functions for new samples, iteration and initialisation.
Initialisation of BaseMonteCarloRandomSample object
- Args
- number_samples:[10000] Number of samples to use per iteration. dc:[False] Boolean to select inversion constrained to double-couple space or over the full moment tensor space.
- Keyword Arguments
- basic_cdc:[False] Boolean to select whether to us the Basic CDC model (inversion constrained to double-couple space or over the full moment tensor space.
-
initialise
()[source]¶ Initial task for ForwardTask
- Returns
- task,end=False task: the random samples starting the inversion.
-
iterate
(result)[source]¶ Iteration function for BaseMonteCarloRandomSample object
Carries out iteration of random sampling from previous result.
- Args
- result: dictionary result from MTfit.inversion.ForwardTask, added to the pdf
- Returns
- new_samples,end new_samples: New set of random samples to test. end: Boolean flag as to whether inversion has finished, if a MemoryError error is thrown, ends iteration.