sgpykit.tools.knots_functions
Functions
|
Calculate the collocation points and weights for the Clenshaw-Curtis integration formula. |
|
Compute collocation points and weights for Genz-Keister quadrature. |
|
Calculate the collocation points (x) and weights (w) for Gaussian integration with respect to the Beta distribution weight function. |
|
Compute the first n collocation points (x) and the corresponding weights (w) for the weighted Leja sequence for integration w.r.t to the weight function rho(x)=Gamma(alpha+beta+2)/ (Gamma(alpha+1)*Gamma(beta+1)*(x_b-x_a)^(alpha+beta+1)) * (x-x_a)^alpha * (x_b-x)^beta i.e. the density of a Beta random variable with range [x_a,x_b], alpha,beta>-1. |
|
Compute collocation points and weights for Gaussian integration with respect to the exponential weight function. |
|
Returns the collocation points (x) and the weights (w) for the weighted Leja sequence for integration with respect to the weight function rho(x) = exp(-lambda * abs(x)), lambda > 0, i.e., the density of an exponential random variable with rate parameter lambda. |
|
Compute collocation points and weights for Gaussian integration w.r.t. |
|
Compute the first n collocation points and corresponding weights for the weighted Leja sequence for integration with respect to the Gamma density. |
|
Compute Leja points and weights for numerical integration. |
|
Generate nodes and weights for the n-point midpoint quadrature rule. |
|
Calculate the collocation points (x) and weights (w) for Gaussian integration with respect to the weight function rho(x) = 1/sqrt(2*pi*sigma^2) * exp(-(x-mi)^2 / (2*sigma^2)), i.e., the density of a Gaussian random variable with mean mi and standard deviation sigma. |
|
Compute collocation points and weights for Gaussian-weighted Leja sequences. |
|
Compute knots and weights for the trapezoidal quadrature rule. |
|
Returns the collocation points (x) and the weights (w) for the weighted Leja sequence for integration with respect to the weight function rho(x) = 2/(b-a)^2 (b-x), i.e., a linear decreasing pdf over the interval [a, b]. |
|
Calculate collocation points and weights for Gaussian integration with respect to a uniform weight function. |
- sgpykit.tools.knots_functions.knots_CC(nn, x_a, x_b, whichrho='prob')[source]
Calculate the collocation points and weights for the Clenshaw-Curtis integration formula.
This function computes the collocation points (x) and weights (w) for the Clenshaw-Curtis integration formula with respect to a specified weight function. The weight function can be either a uniform density (rho(x) = 1/(x_b - x_a)) or a uniform weight (rho(x) = 1).
- Parameters:
- nnint
Number of collocation points. Must be an odd number for efficiency reasons.
- x_afloat
Lower bound of the interval.
- x_bfloat
Upper bound of the interval.
- whichrhostr, optional
Specifies the weight function. Options are: - ‘prob’ : Uniform density (default). - ‘nonprob’ : Uniform weight.
- Returns:
- xnumpy.ndarray
Array of collocation points.
- wnumpy.ndarray
Array of weights corresponding to the collocation points.
- Raises:
- ValueError
If nn is not an odd number or if whichrho is not recognized.
- sgpykit.tools.knots_functions.knots_GK(n, mi, sigma)[source]
Compute collocation points and weights for Genz-Keister quadrature.
This function returns the collocation points (x) and the weights (w) of the Genz-Keister quadrature formula (also known as Kronrod-Patterson-Normal) for approximation of integrals with respect to the weight function: rho(x) = 1/sqrt(2*pi*sigma^2) * exp(-(x-mi)^2 / (2*sigma^2)), i.e., the density of a Gaussian random variable with mean mi and standard deviation sigma.
Knots and weights have been precomputed (up to 35). An error is raised if the number of points requested is not available.
- Parameters:
- nint
Number of collocation points.
- mifloat
Mean of the Gaussian distribution.
- sigmafloat
Standard deviation of the Gaussian distribution.
- Returns:
- xndarray
Collocation points.
- wndarray
Weights corresponding to the collocation points.
References
Florian Heiss, Viktor Winschel, Likelihood approximation by numerical integration on sparse grids, Journal of Econometrics, Volume 144, 2008, pages 62-80.
Alan Genz, Bradley Keister, Fully symmetric interpolatory rules for multiple integrals over infinite regions with Gaussian weight, Journal of Computational and Applied Mathematics, Volume 71, 1996, pages 299-309.
- sgpykit.tools.knots_functions.knots_beta(n, alpha, beta, x_a, x_b)[source]
Calculate the collocation points (x) and weights (w) for Gaussian integration with respect to the Beta distribution weight function.
The weight function is defined as: rho(x) = Gamma(alpha+beta+2)/(Gamma(alpha+1)*Gamma(beta+1)*(x_b-x_a)^(alpha+beta+1)) *
(x-x_a)^alpha * (x_b-x)^beta
This corresponds to the density of a Beta random variable with range [x_a, x_b] and parameters alpha, beta > -1.
- Parameters:
- nint
Number of collocation points.
- alphafloat
First parameter of the Beta distribution.
- betafloat
Second parameter of the Beta distribution.
- x_afloat
Lower bound of the interval.
- x_bfloat
Upper bound of the interval.
- Returns:
- xndarray
Array of collocation points.
- wndarray
Array of corresponding weights.
Notes
For n=1, the standard node and weight are returned directly. For n>1, the points and weights are derived from the eigenvalues and eigenvectors of the Jacobi matrix constructed from recurrence coefficients.
- sgpykit.tools.knots_functions.knots_beta_leja(n, alpha, beta, x_a, x_b, type_, saving_flag=None)[source]
Compute the first n collocation points (x) and the corresponding weights (w) for the weighted Leja sequence for integration w.r.t to the weight function rho(x)=Gamma(alpha+beta+2)/ (Gamma(alpha+1)*Gamma(beta+1)*(x_b-x_a)^(alpha+beta+1)) * (x-x_a)^alpha * (x_b-x)^beta i.e. the density of a Beta random variable with range [x_a,x_b], alpha,beta>-1.
Knots and weights are computed following the work A. Narayan, J. Jakeman, “Adaptive Leja sparse grid constructions for stochastic collocation and high-dimensional approximation” SIAM Journal on Scientific Computing, Vol. 36, No. 6, pp. A2952–A2983, 2014
- Parameters:
- nint
Number of collocation points.
- alphafloat
Shape parameter of the Beta distribution.
- betafloat
Shape parameter of the Beta distribution.
- x_afloat
Lower bound of the interval.
- x_bfloat
Upper bound of the interval.
- type_str
Type of Leja sequence (‘line’ or ‘sym_line’).
- saving_flagstr, optional
Flag to save and load computed knots and weights (‘on_file’).
- Returns:
- xndarray
Collocation points.
- wndarray
Corresponding weights.
Notes
Knots are sorted increasingly before returning (weights are returned in the corresponding order). if <saving_flag> is set to ‘on_file’, the function will compute max(n,50) knots and weights, store them in a MATLAB style .mat file in the local folder and load results at next calls with the same values of alpha and beta. Note that nodes on different intervals [x_a, x_b] can be obtained by linear translations from the reference interval [-1, 1], therefore calls like knots_beta_leja(n,alpha,beta,a1,b1,<type>,’on_file’) knots_beta_leja(n,alpha,beta,a2,b2,<type>,’on_file’) can use the same precomputed file. if no saving flag is provided, i.e., the function is called as knots_beta_leja(n,alpha,beta,x_a,x_b,<type>), computations of nodes and weights will not be saved. This might become time-consuming for large sparse grids (the computation of the Leja knots is done by brute-force optimization). Follows the description of the choices of <type>. ———————————————————– [X,W] = KNOTS_BETA_LEJA(n,alpha,beta,x_a,x_b,’line’) given X(1)=(alpha+1)/(alpha+beta+2)
- recursively defines the n-th point by
X_n= argmax_[x_a,x_b] prod_{k=1}^{n-1} abs(X-X_k)
- [X,W] = KNOTS_BETA_LEJA(N,mi,sigma,’sym_line’) given X(1)=0 recursively
defines the n-th and (n+1)-th point by X_n= argmax prod_{k=1}^{n-1} abs(X-X_k) X_(n+1) = symmetric point of X_n with respect to 0
- sgpykit.tools.knots_functions.knots_exponential(n, lambda_)[source]
Compute collocation points and weights for Gaussian integration with respect to the exponential weight function.
This function returns the collocation points (x) and the weights (w) for Gaussian integration with respect to the weight function rho(x) = lambda * exp(-lambda * x), which is the density of an exponential random variable with rate parameter lambda.
- Parameters:
- nint
Number of collocation points.
- lambda_float
Rate parameter of the exponential distribution.
- Returns:
- xndarray
Collocation points.
- wndarray
Weights for Gaussian integration.
- sgpykit.tools.knots_functions.knots_exponential_leja(n, lambda_)[source]
Returns the collocation points (x) and the weights (w) for the weighted Leja sequence for integration with respect to the weight function rho(x) = exp(-lambda * abs(x)), lambda > 0, i.e., the density of an exponential random variable with rate parameter lambda.
Knots and weights have been precomputed (up to 50) for the case lambda=1 following the work: A. Narayan, J. Jakeman, “Adaptive Leja sparse grid constructions for stochastic collocation and high-dimensional approximation”, SIAM Journal on Scientific Computing, Vol. 36, No. 6, pp. A2952–A2983, 2014.
An error is raised if more than 50 points are requested. Knots are sorted increasingly before returning (weights are returned in the corresponding order).
- Parameters:
- nint
Number of collocation points.
- lambda_float
Rate parameter of the exponential distribution.
- Returns:
- xnumpy.ndarray
Collocation points.
- wnumpy.ndarray
Weights corresponding to the collocation points.
- Raises:
- ValueError
If more than 50 points are requested.
- sgpykit.tools.knots_functions.knots_gamma(n, alpha, beta)[source]
Compute collocation points and weights for Gaussian integration w.r.t. the Gamma density.
Returns the collocation points (x) and the weights (w) for the Gaussian integration with respect to the weight function: rho(x) = beta^(alpha+1)/Gamma(alpha+1) * x^alpha * exp(-beta*x) i.e., the density of a Gamma random variable with range [0,inf), alpha > -1, beta > 0.
- Parameters:
- nint
Number of collocation points.
- alphafloat
Shape parameter of the Gamma distribution.
- betafloat
Rate parameter of the Gamma distribution.
- Returns:
- xndarray
Collocation points.
- wndarray
Weights for Gaussian integration.
- sgpykit.tools.knots_functions.knots_gamma_leja(n, alpha, beta, saving_flag=None)[source]
Compute the first n collocation points and corresponding weights for the weighted Leja sequence for integration with respect to the Gamma density.
This function returns the first n collocation points (x) and the corresponding weights (w), for the weighted Leja sequence for integration with respect to the weight function rho(x) = beta^(alpha+1)/Gamma(alpha+1) * x^alpha * exp(-beta*x), i.e., the density of a standard Gamma random variable with range [0, +inf), alpha > -1, beta > 0.
Knots and weights are computed following the work: A. Narayan, J. Jakeman, “Adaptive Leja sparse grid constructions for stochastic collocation and high-dimensional approximation” SIAM Journal on Scientific Computing, Vol. 36, No. 6, pp. A2952–A2983, 2014.
The knots are computed over the interval [0, 300]. This choice of interval is compatible with -1 < alpha <= 30. If alpha > 30, a larger interval is required and an error is raised. The maximum number of points that can be computed is 50, for compatibility with the interval [0, 300].
If <saving_flag> is set to ‘on_file’, the function will compute 50 knots and weights, store them in a MATLAB style .mat file in the local folder and load results at next calls with the same values of alpha. Note that different values of beta act only as a rescaling factor, therefore the calls knots_gamma_leja(n, alpha, beta1, ‘on_file’) knots_gamma_leja(n, alpha, beta2, ‘on_file’) can use the same precomputed file. If no saving flag is provided, i.e., the function is called as knots_gamma_leja(n, alpha, beta), computations of nodes and weights will not be saved. This might become time-consuming for large sparse grids (the computation of the Leja knots is done by brute-force optimization).
- Parameters:
- nint
Number of collocation points to compute.
- alphafloat
Shape parameter of the Gamma distribution (alpha > -1).
- betafloat
Rate parameter of the Gamma distribution (beta > 0).
- saving_flagstr, optional
Flag to enable saving and loading of precomputed knots and weights. If ‘on_file’, the function will save and load from a .mat file.
- Returns:
- xndarray
Array of collocation points.
- wndarray
Array of corresponding weights.
- Raises:
- AssertionError
If n <= 0.
- NotImplementedError
If alpha > 30.
- Exception
If n > 50.
- ValueError
If saving_flag is not ‘on_file’.
- sgpykit.tools.knots_functions.knots_leja(n, x_a, x_b, type_, whichrho='prob')[source]
Compute Leja points and weights for numerical integration.
This function returns N Leja points of a specified type between A and B, along with corresponding weights for numerical integration. The points and weights can be used to approximate integrals of the form:
For ‘prob’: int_a^b f(x) * 1/(b-a) dx
For ‘nonprob’: int_a^b f(x) dx
- Parameters:
- nint
Number of Leja points to generate.
- x_afloat
Lower bound of the interval.
- x_bfloat
Upper bound of the interval.
- type_str
Type of Leja points to generate. Options are: - ‘line’: Points are generated starting from B, then A, then (A+B)/2, etc. - ‘sym_line’: Points are generated symmetrically around (A+B)/2. - ‘p_disk’: Points are generated on the complex unit ball and projected to [-1,1].
- whichrhostr, optional
Type of weight function. Options are: - ‘prob’: Probabilistic weight function (default). - ‘nonprob’: Non-probabilistic weight function.
- Returns:
- xnumpy.ndarray
Array of Leja points.
- wnumpy.ndarray
Array of corresponding weights.
- Raises:
- Exception
If n > 31, as the precomputed tables only support up to 31 points.
- ValueError
If the specified Leja type is unknown or if the 4th argument is not ‘prob’ or ‘nonprob’.
- sgpykit.tools.knots_functions.knots_midpoint(n, x_a, x_b, whichrho='prob')[source]
Generate nodes and weights for the n-point midpoint quadrature rule.
This function implements the univariate n-points midpoint quadrature rule, dividing the interval [x_a, x_b] into n subintervals of length h = (x_b - x_a)/n and returning the vector of midpoints as nodes. The weights are all equal to 1/n (probability weight function rho(x) = 1/(x_b-x_a)) or (x_b-x_a)/n (non-probability weight function rho(x) = 1).
- Parameters:
- nint
Number of points in the quadrature rule.
- x_afloat
Left endpoint of the interval.
- x_bfloat
Right endpoint of the interval.
- whichrhostr, optional
Type of weight function. Options are: - ‘prob’ (default): Probability weight function (weights sum to 1). - ‘nonprob’: Non-probability weight function (weights sum to (x_b - x_a)).
- Returns:
- xnumpy.ndarray
Array of nodes (midpoints of subintervals).
- wnumpy.ndarray
Array of weights corresponding to the nodes.
- Raises:
- ValueError
If the 4th input (whichrho) is not recognized.
- sgpykit.tools.knots_functions.knots_normal(n, mi, sigma)[source]
Calculate the collocation points (x) and weights (w) for Gaussian integration with respect to the weight function rho(x) = 1/sqrt(2*pi*sigma^2) * exp(-(x-mi)^2 / (2*sigma^2)), i.e., the density of a Gaussian random variable with mean mi and standard deviation sigma.
- Parameters:
- nint
Number of collocation points.
- mifloat
Mean of the Gaussian distribution.
- sigmafloat
Standard deviation of the Gaussian distribution.
- Returns:
- xndarray
Collocation points.
- wndarray
Weights for Gaussian integration.
- sgpykit.tools.knots_functions.knots_normal_leja(n, mi, sigma, type_)[source]
Compute collocation points and weights for Gaussian-weighted Leja sequences.
This function returns the collocation points (x) and the weights (w) for the weighted Leja sequence for integration with respect to the weight function rho(x) = 1/sqrt(2*pi*sigma^2) * exp(-(x-mi)^2 / (2*sigma^2)), i.e., the density of a Gaussian random variable with mean mi and standard deviation sigma.
Knots and weights have been precomputed (up to 150) for the case mi=0 and sigma=1 following the work of A. Narayan and J. Jakeman, “Adaptive Leja sparse grid constructions for stochastic collocation and high-dimensional approximation”, SIAM Journal on Scientific Computing, Vol. 36, No. 6, pp. A2952–A2983, 2014.
If mi != 0 and sigma != 1, the precomputed knots are modified as follows: x = mi + sigma*x. The weights are unaffected.
An error is raised if more than 150 points are requested. Knots are sorted increasingly before returning (weights are returned in the corresponding order).
- Parameters:
- nint
Number of collocation points.
- mifloat
Mean of the Gaussian distribution.
- sigmafloat
Standard deviation of the Gaussian distribution.
- type_str
Type of Leja sequence. Supported types are: - ‘line’: Given X(1)=0, recursively defines the n-th point by
X_n = argmax sqrt(rho(X)) * prod_{k=1}^{n-1} abs(X-X_k)
‘sym_line’: Given X(1)=0, recursively defines the n-th and (n+1)-th point by X_n = argmax sqrt(rho(X)) * prod_{k=1}^{n-1} abs(X-X_k) and X_{n+1} = symmetric point of X_n with respect to 0.
- Returns:
- xnumpy.ndarray
Collocation points.
- wnumpy.ndarray
Weights corresponding to the collocation points.
- Raises:
- Exception
If more than 150 points are requested.
- ValueError
If an unknown Leja type is provided.
- sgpykit.tools.knots_functions.knots_trap(n, x_a, x_b, whichrho='prob')[source]
Compute knots and weights for the trapezoidal quadrature rule.
This function implements the univariate n-points trapezoidal quadrature rule with weight function rho(x) = 1/(x_b-x_a), i.e., x = linspace(x_a,x_b,n) and w = 1/(x_b - x_a) * [h/2 h h … h h/2], with h = (x_b - x_a)/(n-1).
- Parameters:
- nint
Number of points in the quadrature rule.
- x_afloat
Lower bound of the interval.
- x_bfloat
Upper bound of the interval.
- whichrhostr, optional
Type of weight function. Options are: - ‘prob’: weights are normalized by the interval length (default). - ‘nonprob’: weights are not normalized.
- Returns:
- xnumpy.ndarray
Array of knots (quadrature points).
- wnumpy.ndarray
Array of weights.
Notes
For n=1, the midpoint rule is used.
- sgpykit.tools.knots_functions.knots_triangular_leja(n, a, b)[source]
Returns the collocation points (x) and the weights (w) for the weighted Leja sequence for integration with respect to the weight function rho(x) = 2/(b-a)^2 (b-x), i.e., a linear decreasing pdf over the interval [a, b].
Knots and weights have been precomputed (up to 50) following the work of A. Narayan, J. Jakeman, “Adaptive Leja sparse grid constructions for stochastic collocation and high-dimensional approximation”, SIAM Journal on Scientific Computing, Vol. 36, No. 6, pp. A2952–A2983, 2014.
- Parameters:
- nint
Number of collocation points.
- afloat
Lower bound of the interval.
- bfloat
Upper bound of the interval.
- Returns:
- xnumpy.ndarray
Collocation points.
- wnumpy.ndarray
Weights corresponding to the collocation points.
- Raises:
- Exception
If more than 50 points are requested.
- sgpykit.tools.knots_functions.knots_uniform(n, x_a, x_b, whichrho=None)[source]
Calculate collocation points and weights for Gaussian integration with respect to a uniform weight function.
This function computes the collocation points (x) and weights (w) for Gaussian integration with respect to the weight function rho(x) = 1/(b-a), which corresponds to the density of a uniform random variable on the interval [x_a, x_b].
- Parameters:
- nint
Number of collocation points.
- x_afloat
Lower bound of the interval.
- x_bfloat
Upper bound of the interval.
- whichrhostr, optional
Type of weight function. Options are: - ‘prob’ (default): Weight function rho(x) = 1/(b-a). - ‘nonprob’: Weight function rho(x) = 1.
- Returns:
- xndarray
Array of collocation points.
- wndarray
Array of corresponding weights.
Notes
For n=1, the collocation point is the midpoint of the interval, and the weight is 1. For n>1, the collocation points and weights are computed using the eigenvalues and eigenvectors of the Jacobi matrix derived from the recurrence coefficients of the Legendre polynomials.
Modules