scrypy package¶
Submodules¶
scrypy.jac_estimation_chol module¶
Estimates covariance matrix for KW94 Dataset 1 with Simulated Max. Likelihood.
-
scrypy.jac_estimation_chol.
chol_reindex_params
(params_sdcorr)[source]¶ Creates the params Df with Cholesky factors and the right indices for respy. This transformation holds only true for the parametrization in KW94 Dataset 1. Thus, this function simply changes SD-Corr indices to cholesky indices. Without the slicing and merging, index (‘maximum_exp’, ‘edu’) yields an uniqueness error for the second index when (…, ‘sd_edu’) is set to (…, ‘edu’). Yet, because we have double_indices the indices ARE unique.
- Parameters
- params_sdcorrDataFrame
Parameters DataFrame in respy format with SD-Corr matrix elements
- Returns
- params_cholDataFrame
Parameters DataFrame in respy format with matrix elements from Choleksy decomposition of covariance matrix that underlies the SD-Corr matrix.
-
scrypy.jac_estimation_chol.
jac_estimation_chol
(save=False)[source]¶ Estimates covariance matrix for KW94 Dataset 1 with Simulated Max. Likelihood. The Jacobian matrix is used instead of Hessian because it yields no inversion error. The parameters contain Cholesky factors instead of SD-Corr-Matrix because these factors are unconstrained. Therefore, their distribution can be estimated by an unconstrained normal distribution.
- Parameters
- savebool
Indicates wether to save data.
- Returns
- par_estimates_chol_dfDataFrame
Contains the estimates parameters and the not estimates fixed parameters in respy format.
- rand_par_chol_dfDataFrame
Df containing variable parameters, SDs and lower and upper bound in estimagic format. It can be post-processed with surface/topography plot.
- cov_chol_dfDataFrame
Df containing the covariance matrix.
- corr_chol_dfDataFrame
DF containing the correlation matrix.
scrypy.multi_quantities_of_interest module¶
Besides the difference in mean age of education, this module also generates two Dataframes for a second QoI: The difference in education shares over time for a sample of agents. The second quantity is used to create the cone plot.
-
scrypy.multi_quantities_of_interest.
model_wrapper_kw_94
(input_params, base_options, tuition_subsidy)[source]¶ Wrapper around respy to compute the mean number of years in education.
- Parameters
- input_paramsDataframe
Contains the complete respy vector of input parameters with indices.
- base_optionsdict
Contains the options for the sumulation of agents.
- tuition_subsidyfloat
tuition subsidy that is added to the respective paramter.
- add_qoi_edu_choicesbool
Specifies whether to compute the addition QoIs, education choice shares in the sample over time, to depict a cone plot (confidence interval plot).
- Returns
- edufloat
Mean number of years in education.
- occ_shares_dfDataFrame
Occupation shares over all ages.
- policy_dfDataframe
Dataframe of occupation choices of sample of agents of time.
-
scrypy.multi_quantities_of_interest.
multi_quantities_of_interest
(input_params, *args)[source]¶ Computes the Quantity of Interest.
- Parameters
- input_paramsndarray
Unindexed input parameters.
- multi_qoisbool
Option to compute policy_occ_shares_df and base_occ_shares_df.
- Returns
- change_mean_edufloat
Quantity of Interest. Mean changes in education years of population.
- policy_occ_shares_dfDataFrame
Occupation shares over all ages for the policy scenario.
- base_occ_shares_dfDataFrame
Occupation shares over all ages for the base scenario.
-
scrypy.multi_quantities_of_interest.
transform_params_kw94_respy
(params_idx)[source]¶ Converts indexed Series of non-constant input paramters to a Dataframe and adds three constant factors to achieve respy format.
- Parameters
- params_idxSeries
Non-constant input paramters with correct indices
- Returns
- rp_params_dfDataframe
Input parameters in respy format.
- Raises
- AssertionError
If the lenght of the paramter vector is incorrect.
scrypy.plots module¶
scrypy.sampling_schemes module¶
Functions that create random samples in trajectory and radial design.
-
scrypy.sampling_schemes.
morris_trajectory
(n_inputs, n_levels, seed=123, normal=False, numeric_zero=0.01, step_function=<function stepsize at 0x7f3a908b8ef0>, stairs=True)[source]¶ Creates random sample in trajectory design.
This function creates a random sample for a number of function parameters (columns). The sample itself consists of the number plus one vectors of parameter draws (rows). It also computes the steps taken by each element.
- Parameters
- n_inputsint
Number of input paramters / columns / rows - 1.
- n_levelsint
Number of distict grid points.
- seedint
Random seed.
- normalbool
Indicates whether to transform points by scipy.normal.ppt
- numeric_zerofloat
if normal is True: Prevents scipy.normal.ppt to return -Inf and Inf for 0 and 1.
- step_functionfunction
Constant step as function of n_levels added to lower half of point grid.
- stairsbool
if False: Randomly shuffle columns, dissolves stairs shape.
- Returns
- B_randomndarray
Random sample in trajectory design. Dimension n_inputs x n_inputs + 1.
- trans_stepsndarray
Column vector of steps added to base value point. Sorted by parameter/column. Dimension n_inputs x 1.
See also
stepsize
See parameter step_function.
transform_uniform_stnormal_uncorr
See parameter numeric_zero.
Notes
The method is described in [1]. This function follows the notation therein. The idea is tailored to compute a random sample of function arguments to compute local derivates. First, a random row of paramters is drawn. Then, one parameter is changed by a fixed step in each row. The local derivatives can be computed by subtracting the function evaluations of each row from its upper row, thereby obtaining one local derivative for each parameter. The order of rows and columns may be shuffled. Shuffling rows creates a negative stepsize. By default, the shuffling of columns is turned off to facilitate post-processing.
Importantly, an additional option is to evaluate the points by the inverse normal cdf to account for normally distributed input paramters vice versa uniformly distributed ones. For this purpose, zeros and ones are slighly shifted towards the centre of [0,1], so that no infinite values arise. Given the shape of the inverse cdf, the specific transformation choice has large influences on the stepsize and therefore the Elementary Effects. To account for transformations, the step is recomputed for each parameter by subtracting the last first row from the last row.
References
[1] Morris, M. D. (1991). Factorial sampling plans for preliminary computational experiments. Technometrics 33 (2), 161–174.
-
scrypy.sampling_schemes.
radial_sample
(n_rad, n_inputs, normal=False, sequence='S')[source]¶ Generates sample in radial design as described in [1].
For each subsample, there are n_inputs + 1 rows and n_inputs colums. Each row is identical except of the diagonal of the sample w/o the first row.
- Parameters
- n_radint
Number of subsamples.
- n_inputsint
Number of input paramters / columns / rows - 1.
- seedint
Random seed.
- normalbool
Indicates whether to transform points by scipy.normal.ppt
- numeric_zerofloat
if normal is True: Prevents scipy.normal.ppt to return -Inf and Inf for 0 and 1.
- sequencestring
Type of quasi-random sequence.
- Returns
- samplendarray
Random sample in radial design. Dimension n_inputs x n_inputs + 1.
- trans_stepsndarray
Column vector of steps added to base value point. Sorted by parameter/column. Dimension n_inputs x 1.
Notes
See [2] for abbreviations of the different sequence types.
In contrary to the trajectory design, the stepsize differs right from the start by design and only one element changes in each row compared to the first row.
All distict elements in the whole sample are drawn at once because the default Sobol’ sequence can not be reseeded.
References
[1] Ge, Q. and M. Menendez (2017). Extending morris method for qualitative global sensitivityanalysis of models with dependent inputs. Reliability Engineering & System Safety 100 (162), 28–39.
[1] https://github.com/jonathf/chaospy/blob/master/chaospy/distributions/sampler/generator.py#L62
-
scrypy.sampling_schemes.
stepsize
(n_levels)[source]¶ Computes stepsize to create equiprobable sample points for the trajectory design.
- Parameters
- n_levelsint
Number of points in a trajectory sample.
- Returns
- stepfloat
Step added to each lower half point of the point grid.
- Raises
- AssertionError
If the number of levels is not an even integer.
Notes
This function, published in [1], assumes that the number of sample points called “levels” is an even integer. The first row in the trajectory is initialized with the lower half of the desired equispaced points between 0 and 1. Given the below formula, the step added to the lowest, second lowest, …, highest point in the lower half creates the lowest, second lowest, …, highest point in the upper half of the point grid.
References
[1] Morris, M. D. (1991). Factorial sampling plans for preliminary computational experiments. Technometrics 33 (2), 161–174.
-
scrypy.sampling_schemes.
trajectory_sample
(n_traj, n_inputs, n_levels, seed=123, normal=False, numeric_zero=0.01, step_function=<function stepsize at 0x7f3a908b8ef0>, stairs=True)[source]¶ Loops over morris_sample.
- Parameters
- n_inputsint
Number if input paramters.
- n_levelsint
Number of distict grid points.
- seedint
Random seed.
- normalbool
Indicates whether to transform points by scipy.normal.ppt
- numeric_zerofloat
if normal is True: Prevents scipy.normal.ppt to return -Inf and Inf for 0 and 1.
- step_functionfunction
Constant step as function of n_levels added to lower half of point grid.
- stairsbool
if False: Randomly shuffle columns, dissolves stairs shape.
- Returns
- sample_traj_listlist of ndarrays
Set of trajectories.
- steps_listlist of ndarrays
Set of steps taken by each base row.
scrypy.sandbox module¶
scrypy.screening_measures module¶
Computes the screening measures for correlated inputs that I improved upon [1] by adjusting the step in the denumeroter to the transformed step in the nominator in order to not violate the definition of the function derivative.
References¶
[1] Ge, Q. and M. Menendez (2017). Extending morris method for qualitative global sensitivityanalysis of models with dependent inputs. Reliability Engineering & System Safety 100 (162), 28–39.
-
scrypy.screening_measures.
compute_measures
(ee_i, sd_x=1, sd_y=1, sigma_norm=False, ub=False)[source]¶ Compute aggregate measures based on (individual) Elementary Effects.
- Returns
- measures_list: list
- contains:
- ee_meanndarray
Mean Elementary Effect for each parameter.
- ee_abs_meanndarray
Mean absolute correlated Elementary Effect for each parameter.
- ee_sdndarray
SD of correlated Elementary Effects for each parameter.
Notes
ub follows http://www.andreasaltelli.eu/file/repository/DGSA_MATCOM_2009.pdf.
-
scrypy.screening_measures.
screening_measures
(function, traj_list, step_list, cov, mu, radial=False)[source]¶ Computes screening measures for a set of paramters.
- Parameters
- functionfunction
Function or Model of which its parameters are subject to screening.
- traj_listlist of ndarrays
List of transformed trajectories according to [1].
- step_listlist of ndarrays
List of steps that each parameter takes in each trajectory.
- covndarray
Covariance matrix of the input parameters.
- mundarray
Expectation values of the input parameters.
- radialbool
Sample is in trajectory or radial design.
- Returns
- measures_list: list
- contains:
- ee_uncorrndarray
Mean uncorrelated Elementary Effect for each parameter.
- ee_corrndarray
Mean correlated Elementary Effect for each parameter.
- abs_ee_uncorrndarray
Mean absolute uncorrelated Elementary Effect for each parameter.
- abs_ee_corrndarray
Mean absolute correlated Elementary Effect for each parameter.
- sd_ee_uncorrndarray
SD of uncorrelated Elementary Effects for each parameter.
- sd_ee_corrndarray
SD of correlated Elementary Effects for each parameter.
- obs_list: list
- contains
- ee_uncorr_indarray
Observations of uncorrelated Elementary Effects.
- ee_corr_indarray
Observations of correlated Elementary Effects.
Notes
The samples can be in trajectory or in radial design and the deviates can be from an arbitrary (correlated) normal distribution or an uncorrelated Uniform[0,1] distribution.
Unorrelated uniform paramters require different interpretion of mu as a scaling summand rather than the expectation value.
It might be necessary to multiply the SDs by (n_trajs/(n_trajs - 1)) for the precise formula. However, this leads to problems for the case of only one trajectory - which is used in test_screening_measures_uncorrelated_g_function.
scrypy.script_uncertainty_propagation module¶
Script for Uncertainty Propagation. The structure is adapted to parallel computing.
-
scrypy.script_uncertainty_propagation.
propagate_mean_estimates
()[source]¶ Evaluates the QoI at the mean estimates. Called in run.
- Returns
- mean_edu_dfDataFrame
Difference in mean years of education between policy and base scenario.
- base_occ_shares_dfDataFrame
Occupation shares over all ages for the policy scenario.
- policy_occ_shares_dfDataFrame
Occupation shares over all ages for the base scenario.
-
scrypy.script_uncertainty_propagation.
run
(args)[source]¶ Creates and saves the inputs and the outputs of the Uncertainty Propgation.
In context of parallel computing, this function also protects the “entry point” of new programs to not produce endlessly many entries. See [1].
- Parameters
- number_drawsint
Number of draws of random input paramter vector from the respective distribution.
- seedint
Random seed.
- Raises
- AssertionError
If tempory output array temp_array contains NaNs, and +/- Infs.
References
[1] https://docs.python.org/3/library/multiprocessing.html#multiprocessing-programming.
scrypy.select_sample_set module¶
Functions that decrease a set of sample sets in order to increase its representativeness. These are developed in the context of the trajectory design because it can not cover the space very densely. The methods are taken from the effective screening design in [1] and the efficient screening design in [2]
References¶
[1] Campolongo, F., J. Cariboni, and A. Saltelli (2007). An effective screening design for sensitivity analysis of large models. Environmental modelling & software 22 (10), 1509– 1518. [2] Ge, Q. and M. Menendez (2014). An efficient sensitivity analysis approach for computationally expensive microscopic traffic simulation models. International Journal of Transportation 2 (2), 49–64.
-
scrypy.select_sample_set.
campolongo_2007
(sample_traj_list, n_traj)[source]¶ Implements the post-selected sample set in [1].
Takes a list of Morris trajectories and selects the n_traj trajectories with the largest distance between them. Returns the selection as array with n_inputs at the verical and n_traj at the horizontal axis and as a list. It also returns the diagonal matrix that contains the pair distance between each trajectory pair.
- Parameters
- sample_traj_listlist of ndarrays
Set of samples.
- n_trajint
Number of samples to choose from sample_traj_list.
- Returns
- sample_traj_listlist of ndarrays
Set of trajectories.
- select_dist_matrixndarray
Symmetric distance_matrix of selection.
- select_indiceslist
Indices of selected samples.
-
scrypy.select_sample_set.
combi_wrapper
(iterable, r)[source]¶ Wrapper around itertools.combinations, written in C, see [1].
- Parameters
- iterableiterable object
Hashable container like a list of distinct elements to combine.
- rint
Number to draw from iterable with putting back and regarding the order.
- Returns
- list_listlist of lists
All possible combinations in ascending order.
References
[1] https://docs.python.org/2/library/itertools.html#itertools.combinations.
-
scrypy.select_sample_set.
compute_pair_distance
(sample_0, sample_1)[source]¶ Computes the distance measure between a pair of samples.
The aggregate distance between sum of the root of the square distance between each parameter vector of one sample to each vector of the other sample.
- Parameters
- sample_0ndarray
Sample with paramters in cols and draws as rows.
- sample_1ndarray
Sample with paramters in cols and draws as rows.
- Returns
- distancefloat
Pair distance.
- Raises
- AssertionError
If sample is not in trajectory or radial design shape.
- AssertionError
If the sample shapes differ.
Notes
The distance between two samples is sum of the root of the square distance between each parameter vector of one sample to each vector of the other sample.
-
scrypy.select_sample_set.
distance_matrix
(sample_list)[source]¶ Computes symmetric matrix of pair distances for a list of samples.
- Parameters
- sample_listlist of ndarrays
Set of samples.
- Returns
- distance_matrixndarry
Symmatric matrix of pair distances.
-
scrypy.select_sample_set.
final_ge_menendez_2014
(sample_traj_list, n_traj)[source]¶ Implements both “improvements” in [2] vis-a-vis [1].
- Parameters
- sample_traj_listlist of ndarrays
Set of samples.
- n_trajint
Number of samples to choose from sample_traj_list.
- Returns
- sample_traj_listlist of ndarrays
Set of trajectories.
- select_dist_matrixndarray
Symmetric distance_matrix of selection.
- select_indiceslist
Indices of selected samples.
See also
Notes
This function, is in fact much slower than intermediate_ge_menendez_2014 because it uses more for loops to get the pair distances from the right combinations that must be subtracted from the total distances.
This function selects n_traj trajectories from n_traj_sample trajectories by iteratively selecting n_traj_sample - i for i = 1,…,n_traj_sample - n-traj. For this purpose, next_combi_total_distance_gm14 computes the total distance of each trajectory combination by using the total distance of each combination in the previous step and subtracting each pair distance with the dropped trajectory, that yielded the lowest total distance combinations in the previous step.
-
scrypy.select_sample_set.
intermediate_ge_menendez_2014
(sample_traj_list, n_traj)[source]¶ Implements the essential of the two “improvements” in[2] vis-a-vis [1].
This is basically a wrapper around select_trajectories_wrapper_iteration.
- Parameters
- sample_traj_listlist of ndarrays
Set of samples.
- n_trajint
Number of samples to choose from sample_traj_list.
- Returns
- sample_traj_listlist of ndarrays
Set of trajectories.
- select_dist_matrixndarray
Symmetric distance_matrix of selection.
- select_indiceslist
Indices of selected samples.
Notes
Oftentimes this function leads to diffent combinations than select_trajectories. However, their total distance is very close to the optimal solution.
-
scrypy.select_sample_set.
next_combi_total_distance_gm14
(combi_total_distance, pair_dist_matrix, lost_index)[source]¶ Selects the set of samples minus one sample.
Based on the algorithmic computation of the total_distance proposed by [2]. I.e. by re-using and adjusting the first combi_total_distance matrix each iteration. Used for selecting iteratively rather than by brute force.
- Parameters
- combi_total_distance_nextndarray
Matrix with n_traj + 1 rows. The first n_traj cols are filled with indices of samples and the last column is the total_distance of the combinations of samples marked by indices in the same row and the columns before.
- pair_dist_matrixndarray
Distance matrix of all combinations and their total_distance.
- lost_indexint
index of the sample that will be dropped from the samples in the above objects.
- Returns
- combi_total_distance_nextndarray
combi_total_distance without the dropped sample.
- pair_dist_matrix_nextndarray
pair_dist_matrix without the dropped sample.
- lost_indexndarray
lost_index without the dropped sample one iteration before.
Notes
The function computes the total distance of each trajectory combination by using the total distance of each combination in the previous step and subtracting each pair distance with the dropped trajectory, that yielded the lowest total distance combinations in the previous step.
This function, is in fact much slower than select_trajectories_wrapper_iteration because it uses more for loops to get the pair distances from the right combinations that must be subtracted from the total distances.
-
scrypy.select_sample_set.
select_sample_set_normal
(samp_list, n_select, numeric_zero)[source]¶ Post-select set of samples based on [0,1] and transform it to stnormal space.
- Parameters
- samp_listlist of ndarrays
Sub-samples.
- n_selectint
Number of sub-samples to select from samp_list.
- numeric_zerofloat
if normal is True: Prevents scipy.normal.ppt to return -Inf and Inf for 0 and 1.
- Returns
- samp_listlist of ndarrays
- steps_listlist of ndarrays
See also
Notes
Function for post-selection is intermediate_ge_menendez_2014 because it is the fastest.
-
scrypy.select_sample_set.
select_trajectories
(pair_dist_matrix, n_traj)[source]¶ Computes total distance for each n_traj combinations of a set of samples.
- Parameters
- pair_dist_matrixndarray
distance_matrix for a sample set.
- n_trajint
Number of sample combinations for which the total_distance is computed.
- Returns
- max_dist_indiceslist of ints
Indices of samples in pair_dist_matrix that are part of the combination with the largest total_distance.
- combi_total_distancendarray
Matrix with n_traj + 1 rows. The first n_traj cols are filled with indices of samples and the last column is the total_distance of the combinations of samples marked by indices in the same row and the columns before.
- Raises
- AssertionError
If pair_dist_matrix is not symmetric.
- AssertionError
If the number of combinations does not correspong to the combinations indicated by the size of pair_dist_matrix.
Notes
This function can be very slow because it computes distances between np.binomial(len(pair_dist_matrix, n_traj) pairs of trajectories. Example: np.biomial(30,15) = 155117520.
This selection function yields precise results because each total distance for each possible combination of trajectories is computed directly. The faster, iterative methods can yield different results that are, however, close in the total distance. The total distances tend to differentiate clearly. Therefore, the optimal combination is precisely determined.
-
scrypy.select_sample_set.
select_trajectories_wrapper_iteration
(pair_dist_matrix, n_traj)[source]¶ Selects the set of samples minus one sample.
Used for selecting iteratively rather than by brute force. Implements the main step of the essential of the two “improvements” from [2] to [1].
- Parameters
- pair_dist_matrixndarray
Distance matrix of all combinations and their total_distance.
- n_trajint
number of samples to choose from a set of samples based on their total_distance.
- Returns
- tracker_keep_indiceslist
Indices of samples part of the selection.
- combi_total_distancendarray
Matrix with n_traj + 1 rows. The first n_traj cols are filled with indices of samples and the last column is the total_distance of the combinations of samples marked by indices in the same row and the columns before.
See also
Notes
Oftentimes this function leads to diffent combinations than select_trajectories. The reason seems to be that this function deviates from the optimal path due to numerical reasons as different combinations may be very close (see [2]). However, the total sum of the returned combinations are close. Therefore, the total_distance loss is negligible compared to the speed gain for large numbers of trajectory combinations.
This implies that, combi_total_distance always differs from the one in select_trajectories because it only contains the combination indices from the last iteration if n_traj is smaller than the sample set minus 1.
The trick using tracker_keep_indices is an elegant solution.
-
scrypy.select_sample_set.
total_distance
(distance_matrix)[source]¶ Computes the total distance measure of all pairs of samples in a set.
The equation corresponds to Equation (10) in [2].
- Parameters
- distance_matrixndarray
diagonal matrix of distances for sample pairs.
- Returns
- total_distance: float
total distance measure of all pairs of samples in a set.
scrypy.transform_distributions module¶
Functions for the inverse Rosenblatt / inverse Nataf transformation from uniform to normal distribution.
-
scrypy.transform_distributions.
covariance_to_correlation
(cov)[source]¶ Converts covariance matrix to correlation matrix.
- Parameters
- covndarray
Covariance matrix.
- Returns
- corrndarray
Correlation matrix.
-
scrypy.transform_distributions.
transform_stnormal_normal_corr
(z_row, cov, mu)[source]¶ Transformation from standard normal to multivariate normal space with given correlations following [1], page 77-102.
Step 1) Compute correlation matrix. Step 2) Introduce dependencies to standard normal sample. Step 3) De-standardize sample to normal space.
- Parameters
- z_rowndarray
Row of uncorrelated standard normal deviates.
- covndarray
Covariance matrix of correlated normal deviates.
- mundarray
Expectation values of correlated normal deviates
- Returns
- x_norm_rowndarray
Row of correlated normal deviates.
- correlate_stepfloat
Lower right corner element of the lower Cholesky matrix.
Notes
Importantly, the step in the numerator of the uncorrelated Elementary Effect is multiplied by correlate_step. Therefore, this factor has to multiply the step in the denominator as well to not violate the definition of the function derivation.
This method is equivalent to the one in [2], page 199 which uses the Cholesky decomposition of the covariance matrix directly. This saves the scaling by SD and expectation.
This method is simpler and slightly more precise than the one in [3], page 33, for normally distributed paramters.
[1] explains how Rosenblatt and Nataf transformation are equal for normally distributed deviates.
References
[1] Lemaire, M. (2013). Structural reliability. John Wiley & Sons. [2] Gentle, J. E. (2006). Random number generation and Monte Carlo methods. Springer Science & Business Media. [3] Ge, Q. and M. Menendez (2017). Extending morris method for qualitative global sensitivity analysis of models with dependent inputs. Reliability Engineering & System Safety 100 (162), 28–39.
-
scrypy.transform_distributions.
transform_uniform_stnormal_uncorr
(uniform_deviates, numeric_zero=0.005)[source]¶ Converts sample from uniform distribution to standard normal space without regarding correlations.
- Parameters
- uniform_deviatesndarray
Draws from Uniform[0,1].
- numeric_zerofloat
Used to substitute zeros and ones before applying scipy.stats.norm to not obtain -Inf and Inf.
- Returns
- stnormal_deviatesndarray
uniform deviates converted to standard normal space without correlations.
See also
morris_trajectory
Notes
This transformation is already applied as option in morris_trajectory. The reason is that scipy.stats.norm transforms the random draws from the unit cube non-linearily including the addition of the step. To obtain non-distorted screening measures, it is important to also account for this transformation of the step in the denominator to not violate the definition of the function derivation.
The parameter numeric_zero can be highly influential. I prefer it to be relatively large to put more proportional, i.e. less weight on the extremes.
scrypy.transform_reorder module¶
Functions for reordering the sample rows following [1].
The intuition behind the reordering in general is the following: To compute the uncorrelated Elementary Effects, one moves the sampled elements that have been changed by step to the back of the row. For the correlated EE, one leaves the newly changed element in front, but moves the elements that were changed in rows above to the end. These compose the left parts of the numerator in the EE definition. One then subtracts the same row, except that the changed element is unchanged. The reason for these reorderings is that the correlation technique works hierarchically, like Dominoes. The element before is unaffected by the correlation of the elements thereafter. This implies that the first element is unchanged, as for the correlated EE. Therefore, the step is involved in correlating the other elements without becoming changed itself. The opposite is true for the uncorrelated EE. The above procedure is dervied from the ordering in trajectory samples. It also works for the radial design. Other functions order the expectations and covariance matrix accordingly. They are also used to initialize the correlating loops in the two functions in transform_ee.py in the right order.
References¶
[1] Ge, Q. and M. Menendez (2017). Extending morris method for qualitative global sensitivityanalysis of models with dependent inputs. Reliability Engineering & System Safety 100 (162), 28–39.
-
scrypy.transform_reorder.
ee_corr_reorder_sample
(sample)[source]¶ For each row i (non-pythonic), move the first i-1 elements to the back.
- Parameters
- samplendarray
sample.
- row_plus_onebool
Add 1 to row index, i.e. start with second row.
- Returns
- sample_reorderedndarray
Reordered sample.
Notes
There is no row_plus_one=False option because this is equivalent with uncorr_reorder_sample(sample, row_plus_one=True).
-
scrypy.transform_reorder.
ee_uncorr_reorder_sample
(sample, row_plus_one=True)[source]¶ For each row i (non-pythonic), move the first i elements to the back.
- Parameters
- samplendarray
sample.
- row_plus_onebool
Add 1 to row index, i.e. start with second row.
- Returns
- sample_reorderedndarray
Reordered sample.
-
scrypy.transform_reorder.
reorder_cov
(cov)[source]¶ Arrange covariance matrix according to the expectation vector when the first element is moved to the end.
- Parameters
- covndarray
Covariance matrix of row.
- Returns
- cov_reorderedndarray
Reordered covariance matrix of row.
-
scrypy.transform_reorder.
reorder_mu
(mu)[source]¶ Move the first element of the expectation vector to the end.
- Parameters
- mundarray
Expectation values of row.
- Returns
- mu_reorderedndarray
Reordered expectation values of row.
-
scrypy.transform_reorder.
reverse_ee_corr_reorder_sample
(sample_reordered)[source]¶ Reverse of function corr_reorder_sample.
- Parameters
- sample_reorderedndarray
Reordered sample.
- Returns
- samplendarray
Trjectory in original order.
-
scrypy.transform_reorder.
reverse_ee_uncorr_reorder_sample
(sample_reordered, row_plus_one=True)[source]¶ Reverse of function uncorr_reorder_sample.
- Parameters
- sample_reorderedndarray
Reordered sample.
- Returns
- samplendarray
Trjectory in original order.