Title: | Systematic Scenario Selection for Stress Testing |
---|---|
Description: | Quasi-Monte-Carlo algorithm for systematic generation of shock scenarios from an arbitrary multivariate elliptical distribution. The algorithm selects a systematic mesh of arbitrary fineness that approximately evenly covers an isoprobability ellipsoid in d dimensions (Flood, Mark D. & Korenko, George G. (2013) <doi:10.1080/14697688.2014.926018>). This package is the 'R' analogy to the 'Matlab' code published by Flood & Korenko in above-mentioned paper. |
Authors: | Merlin Kopfmann |
Maintainer: | Merlin Kopfmann <[email protected]> |
License: | CC0 |
Version: | 1.0.2 |
Built: | 2024-12-18 06:49:46 UTC |
Source: | CRAN |
Adds the next base-b element to an existing base-b sequence
baseb_expansion(ain, b)
baseb_expansion(ain, b)
ain |
Either a an array containing an existing base-b expansion, or a scalar integer indicating the length for a new base-b expansion |
b |
Base for integer expansions used in the sequence |
An expanded base-b expansion
Calculates the number of points in a mesh of fineness phi, covering a hypercube in d dimensions
calc_mesh_size(phi, d)
calc_mesh_size(phi, d)
phi |
The scalar fineness of the mesh |
d |
The number of dimensions for the unit spheroid |
A list of: corner_pts - Count of points extreme (+/- 1) in all dim, edge_pts - Count of points extreme in all but one dimen, face_pts - Count of points extreme in all but two dimen, total_pts - Sum of: corner_pts + edge_pts + face_pts
Creates a new ellipsoid object equivalent to the given hyperellipsoid (hellipse), but centered at the origin.
center_at_origin(hellip)
center_at_origin(hellip)
hellip |
The original object, to be shifted |
list of two: hellip2 - the re-centered hyperellipsoid and mu - the amount of the translation
Creates a phi x phi grid (i.e., the mesh on a single two-dimensional face of a larger hypercube) of d-dimensional points, where the regularity of the grid has been adjusted to avoid clustering in the corners.
fill_adj_2Dface(d, phi)
fill_adj_2Dface(d, phi)
d |
The number of dimensions for the unit spheroid |
phi |
Fineness of the mesh along each dimension of the 2D face |
A phi x phi x d array of points. The points (each facemesh2D(i,j,:)) are identically equal to one in the first d-2 dimensions, so that the mesh varies only in the final two dimensions.
Calculates the factor, beta in [0, 1], that interpolates the pth equidistant point between the two endpoints, z_one and z_phi, for and adjusted 2D mesh of fineness phi in d dimensions.
fill_adj_2Dface_beta(p, phi, z_one, z_phi)
fill_adj_2Dface_beta(p, phi, z_one, z_phi)
p |
... |
phi |
Fineness of the mesh along each dimension of the 2D face |
z_one |
... |
z_phi |
... |
beta
Systematically fills a given mesh array (cmesh) with d-dimensional points representing every corner of a d-dimensional hypercube. The function fills the successive dimensions of each point via depth-first recursion across all d dimensions.
fill_corners(cmesh, shock, shk_curs, dim_curs)
fill_corners(cmesh, shock, shk_curs, dim_curs)
cmesh |
The mesh to be filled with corner points |
shock |
The current shock vector being filled |
shk_curs |
Index in cmesh of the shock currently being filled |
dim_curs |
Index in the current shock of the dimension being filled |
A list of: cmesh - d x 2^d array of corner points being filled, shk_curs - last point in cmesh that was filled
Get hyperellipsoid property from the specified object and return the value. Property names are: center, shape, and size
get(hellip, propName)
get(hellip, propName)
hellip |
A valid hyperellipsoid object |
propName |
A string of the desired property |
The value of the indicated property
Generates a Cartesian mesh of d-dimensional scenarios based on the given ellipsoid. This function does not assume that the ellipsoid is centered at the origin.
hypercube_mesh(phi, hellip, normalize)
hypercube_mesh(phi, hellip, normalize)
phi |
The scalar fineness of the mesh |
hellip |
The basis for the shocks; it must have measurable width in every dimension |
normalize |
Whether to normalize points from the cube onto the sphere or not (TRUE/FALSE) |
A d x N array, with each column a scenario
hellip <- hyperellipsoid() hypercube_mesh(3,hellip,TRUE)
hellip <- hyperellipsoid() hypercube_mesh(3,hellip,TRUE)
Hyperellipsoid class constructor
hyperellipsoid(...)
hyperellipsoid(...)
... |
mu - The vector for the center point, sig - The matrix determining the shape; for elliptical probability distributions, sig will be the inverse dispersion matrix, c - The scalar determining the size |
A new hyperellipsoid object
hyperellipsoid()
hyperellipsoid()
Fills a mesh (corn_mesh) with d-dimensional points representing all corners of a d-dimensional cube encompassing a d-dimensional unit spheroid.
make_corners(d, normalize)
make_corners(d, normalize)
d |
The number of dimensions for the unit spheroid |
normalize |
Whether to scale the corner points onto the sphere or not |
A d x 2^d array of corner points
Fills a mesh with d-dimensional points representing all non-corner edge points of a d-dimensional cube encompassing a d-dimensional unit spheroid.
make_edges(d, phi, normalize)
make_edges(d, phi, normalize)
d |
The number of dimensions for the unit spheroid |
phi |
Fineness of the mesh along the edge (i.e., the total number of points, "including" the corners) |
normalize |
Whether to scale the corner points onto the sphere or not |
A d x d*2^(d-1)*(phi-2) array of edge points
Constructs a new d-dimensional ellipsoid with the given "positive vertices", and size parameter, c. The constructed ellipsoid is centered at the origin.Note that the input vertices (i.e., the columns of V) must therefore be orthogonal vectors, themselves centered at the origin.The size parameter, c, may be needed because the points alone only determine the eigenvalues up to a positive constant. For vertices which fall on the constructed ellipsoid, choose as the size parameterc = 1.The new ellipsoid is centered at the origin.
make_ellipsoid_from_vertices(V, c)
make_ellipsoid_from_vertices(V, c)
V |
A d x d array of positive vertices (in columns) |
c |
The size parameter of the new ellipsoid |
A new ellipsoid, centered at the origin, with the given vertices
hellip <- hyperellipsoid() V <- vertices(hellip) c <- 4 make_ellipsoid_from_vertices(V,c)
hellip <- hyperellipsoid() V <- vertices(hellip) c <- 4 make_ellipsoid_from_vertices(V,c)
Fills a mesh with d-dimensional points representing all non-edge face points of a d-dimensional cube encompassing a d-dimensional unit spheroid.
make_faces(d, phi, normalize)
make_faces(d, phi, normalize)
d |
The number of dimensions for the unit spheroid |
phi |
Fineness of the mesh along each dimension of the 2D face |
normalize |
Whether to scale the corner points onto the sphere or not |
A d x d*(d-1)*2^(d-3)*(phi-2)^2 array of face points
Creates a new base-b sequence of a designated length
new_baseb_expansion(k, b)
new_baseb_expansion(k, b)
k |
The integer to expand |
b |
Base for integer expansions used in the sequence |
The expansion of the integer k
Rotates the ellipsoid (hellip) so its principal axes align with the coordinate axes. Both ellipsoids are centered at the origin. Note that there are (2^d)*d! valid ways to rotate the ellipsoid to the axes. This algorithm does not prescribe which solution will be provided.
rotate_to_coordaxes(hellip)
rotate_to_coordaxes(hellip)
hellip |
The shape to be rotated, must be centered at the origin |
A list of: hellip2 - A new hyperellipsoid, rotated to the coordinate axes and tfm - the transformation matrix that creates the rotation
Calculates the size paramater for a d-dimensional hyperellipsoid conforming to a normal (i.e., Gaussian) distribution.
sizeparam_normal_distn(prob, d)
sizeparam_normal_distn(prob, d)
prob |
The target probability threshold |
d |
Number of dimensions in the multivariate distribution |
The appropriate (scalar) size parameter
sizeparam_normal_distn(0.95, 6)
sizeparam_normal_distn(0.95, 6)
Calculates the size paramater for a d-dimensional hyperellipsoid conforming to a Student's t distribution.
sizeparam_t_distn(prob, d, nu)
sizeparam_t_distn(prob, d, nu)
prob |
The target probability threshold |
d |
Number of dimensions in the multivariate distribution |
nu |
Degrees of freedom parameter for the t distribution |
The appropriate (scalar) size parameter
sizeparam_t_distn(0.95, 6, 5)
sizeparam_t_distn(0.95, 6, 5)
Generates a Cartesian mesh of d-dimensional scenarios based on the given ellipsoid. This function does not assume that the ellipsoid is centered at the origin.
spheroid_mesh(d, phi, normalize)
spheroid_mesh(d, phi, normalize)
d |
The number of dimensions for the unit spheroid |
phi |
The scalar fineness of the mesh |
normalize |
Whether to normalize points from the cube onto the sphere or not (TRUE/FALSE) |
A d x N array with each column a scenario
Stretches the ellipsoid (hellip) to the unit spheroid of the same dimension. Both the input ellipsoid and unit spheroid are centered at the origin.
stretch_to_unitspheroid(hellip)
stretch_to_unitspheroid(hellip)
hellip |
The original shape to be stretched |
A list of: hellip1 - a new unit spheroid, mapped from the ellipsoid and tfm - transformation matrix that creates the stretching
Applies the given linear transformation, tfm, to the given ellipsoid. The ellipsoid (hellip) must be centered at the origin.
transform_ellipsoid(hellip, tfm)
transform_ellipsoid(hellip, tfm)
hellip |
The original shape to be transformed |
tfm |
A d x d linear transformation matrix |
A transformed ellipsoid, centered at the origin
Calculates 2d d-dimensional univariate shocks (up and down in each of the d dimensions) based on the given ellipsoid. Univariate shocks are points on the surface of the ellipsoid that differ from the center of the ellipsoid in only one dimension. Thus, for an ellipsoid centered at the origin, only one element of a d-dimensional shock will be non-zero.This function does not assume that the ellipsoid is centered at the origin.
univariate_shocks(hellip)
univariate_shocks(hellip)
hellip |
the basis for the shocks; it must have measurable width in every dimension |
A d x 2d array, [dx2d], with each column a shock; the first d columns are positive univariate shocks, and final d columns are matching negative univariate shocks
hellip <- hyperellipsoid() univariate_shocks(hellip)
hellip <- hyperellipsoid() univariate_shocks(hellip)
Finds the d d-dimensional positive vertices for the given ellipsoid. A "positive" vertex is one where a principal axis for the ellipsoid intersects the surface of the ellipsoid in the direction of the corresponding eigenvector. (Recall that each of the eigenvectors of the ellipsoid's shape matrix is collinear with one of the principal axes.) This function does not assume that the ellipsoid is centered at the origin. Because the direction of each unit eigenvector is arbitrary (i.e., multiplication by -1 still yields a unit eigenvector), a simple algorithm is used to pick a consistent orientation for the vertex points.
vertices(hellip)
vertices(hellip)
hellip |
defines the polar vertices |
A d x d array with each column a positive vertex
hellip <- hyperellipsoid() vertices(hellip)
hellip <- hyperellipsoid() vertices(hellip)