Integrands
UML Overview
AbstractIntegrand
Bases: object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dimension_indv
|
tuple
|
Individual solution shape. |
required |
dimension_comb
|
tuple
|
Combined solution shape. |
required |
parallel
|
int
|
Parallelization flag.
Setting |
required |
threadpool
|
bool
|
When
|
False
|
Source code in qmcpy/integrand/abstract_integrand.py
__call__
- If just
n
is supplied, generate samples from the sequence at indices 0,...,n
-1. - If
n_min
andn_max
are supplied, generate samples from the sequence at indicesn_min
,...,n_max
-1. - If
n
andn_min
are supplied, then generate samples from the sequence at indicesn
,...,n_min
-1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
Union[None, int]
|
Number of points to generate. |
None
|
n_min
|
Union[None, int]
|
Starting index of sequence. |
None
|
n_max
|
Union[None, int]
|
Final index of sequence. |
None
|
warn
|
bool
|
If |
True
|
Returns:
Name | Type | Description |
---|---|---|
t |
ndarray
|
Samples from the sequence.
|
weights |
ndarray
|
Only returned when |
Source code in qmcpy/integrand/abstract_integrand.py
g
Abstract method implementing the integrand as a function of the true measure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
ndarray
|
Inputs with shape |
required |
args
|
tuple
|
positional arguments to |
()
|
kwargs
|
dict
|
keyword arguments to Some algorithms will additionally try to pass in a |
{}
|
Returns:
Name | Type | Description |
---|---|---|
y |
ndarray
|
function evaluations with shape |
Source code in qmcpy/integrand/abstract_integrand.py
f
Function to evaluate the transformed integrand as a function of the discrete distribution.
Automatically applies the transformation determined by the true measure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray
|
Inputs with shape |
required |
args
|
tuple
|
positional arguments to |
()
|
kwargs
|
dict
|
keyword arguments to Some algorithms will additionally try to pass in a The keyword argument
|
{}
|
Returns:
Name | Type | Description |
---|---|---|
y |
ndarray
|
function evaluations with shape |
Source code in qmcpy/integrand/abstract_integrand.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
bound_fun
Compute the bounds on the combined function based on bounds for the individual functions.
Defaults to the identity where we essentially do not combine integrands, but instead integrate each function individually.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bound_low
|
ndarray
|
Lower bounds on individual estimates with shape |
required |
bound_high
|
ndarray
|
Upper bounds on individual estimates with shape |
required |
Returns:
Name | Type | Description |
---|---|---|
comb_bound_low |
ndarray
|
Lower bounds on combined estimates with shape |
comb_bound_high |
ndarray
|
Upper bounds on combined estimates with shape |
Source code in qmcpy/integrand/abstract_integrand.py
dependency
Takes a vector of indicators of weather of not the error bound is satisfied for combined integrands and returns flags for individual integrands.
For example, if we are taking the ratio of 2 individual integrands, then getting comb_flags=True
means the ratio
has not been approximated to within the tolerance, so the dependency function should return indv_flags=[True,True]
indicating that both the numerator and denominator integrands need to be better approximated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comb_flags
|
ndarray
|
Flags of shape |
required |
Returns:
Name | Type | Description |
---|---|---|
indv_flags |
ndarray
|
Flags of shape |
Source code in qmcpy/integrand/abstract_integrand.py
spawn
Spawn new instances of the current integrand at different levels with new seeds. Used by multi-level QMC algorithms which require integrands at multiple levels.
Note
Use replications
instead of using spawn
when possible, e.g., when spawning copies which all have the same level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
levels
|
ndarray
|
Levels at which to spawn new integrands. |
required |
Returns:
Name | Type | Description |
---|---|---|
spawned_integrand |
list
|
Integrands with new true measures and discrete distributions. |
Source code in qmcpy/integrand/abstract_integrand.py
dimension_at_level
Abstract method which returns the dimension of the generator required for a given level.
Note
Only used for multilevel problems.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level
|
int
|
Level at which to return the dimension. |
required |
Returns:
Name | Type | Description |
---|---|---|
d |
int
|
Dimension at the given input level. |
Source code in qmcpy/integrand/abstract_integrand.py
FinancialOption
Bases: AbstractIntegrand
Financial options.
- Start price \(S_0\)
- Strike price \(K\)
- Interest rate \(r\)
- Volatility \(\sigma\)
- Equidistant monitoring times \(\boldsymbol{\tau} = (\tau_1,\dots,\tau_d)^T\) with \(\tau_d\) the final (exercise) time and \(\tau_j = \tau_d j/d\).
Define the geometric brownian motion as
where \(\boldsymbol{T}\) is a standard Brownian motion so \(\mathsf{\Sigma} = \left(\min\{\tau_j,\tau_{j'}\}\right)_{j,j'=1}^d\).
The discounted payoff is
where the payoff function \(P\) will be defined depending on the option.
Below we wil luse \(S_{-1}\) to denote the final element of \(\boldsymbol{S}\), the value of the path at exercise time.
European Options
European Call and Put Options have respective payoffs
Asian Options
An asian option considers the average value of an asset path across time. We use the trapezoidal rule to approximate either the arithmetic mean by
or the geometric mean by
Asian Call and Put Option have respective payoffs
Barrier Options
- Barrier \(B\).
In options are activate when the path crosses the barrier \(B\), while out options are activated only if the path never crosses the barrier \(B\). An up option satisfies \(S_0<B\) while a down option satisfies \(S_0>B\), both indicating the direction of the barrier from the start price.
Barrier Up-In Call and Put Options have respective payoffs
Barrier Up-Out Call and Put Options have respective payoffs
Barrier Down-In Call and Put Options have respective payoffs
Barrier Down-Out Call and Put Options have respective payoffs
Lookback Options
Lookback Call and Put Options have respective payoffs
Digital Option
- Payout \(\rho\).
Digital Call and Put Options have respective payoffs
Multilevel Options
- Initial level \(\ell_0 \geq 0\).
- Level \(\ell \geq \ell_0\).
Let \(\boldsymbol{S}_\mathrm{fine}=\boldsymbol{S}\) be the fine full path. For \(\ell>\ell_0\) write the coarse path as \(\boldsymbol{S}_\mathrm{coarse} = (S_j)_{j \text{ even}}\) which only considers every other element of \(\boldsymbol{S}\). In this multilevel setting the payoff is
Cancellations from the telescoping sum allow us to write
Examples:
>>> integrand = FinancialOption(DigitalNetB2(dimension=3,seed=7),option="EUROPEAN")
>>> y = integrand(2**10)
>>> y.shape
(1024,)
>>> print("%.4f"%y.mean())
4.2126
>>> print("%.4f"%integrand.get_exact_value())
4.2115
>>> integrand
FinancialOption (AbstractIntegrand)
option EUROPEAN
call_put CALL
volatility 2^(-1)
start_price 30
strike_price 35
interest_rate 0
t_final 1
>>> integrand.true_measure
BrownianMotion (AbstractTrueMeasure)
time_vec [0.333 0.667 1. ]
drift 0
mean [0. 0. 0.]
covariance [[0.333 0.333 0.333]
[0.333 0.667 0.667]
[0.333 0.667 1. ]]
decomp_type PCA
>>> integrand = FinancialOption(DigitalNetB2(dimension=64,seed=7),option="ASIAN")
>>> y = integrand(2**10)
>>> y.shape
(1024,)
>>> print("%.4f"%y.mean())
1.7782
With independent replications
>>> integrand = FinancialOption(DigitalNetB2(dimension=64,seed=7,replications=2**4),option="ASIAN")
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(16,)
>>> print("%.4f"%muhats.mean())
1.7765
Multi-level options
>>> seed_seq = np.random.SeedSequence(7)
>>> d_coarsest = 8
>>> num_levels = 4
>>> ns = [2**11,2**10,2**9,2**8]
>>> integrands = [FinancialOption(DigitalNetB2(dimension=2**l*d_coarsest,seed=seed_seq.spawn(1)[0]),option="ASIAN",level=l,d_coarsest=d_coarsest) for l in range(num_levels)]
>>> ys = [integrands[l](ns[l]) for l in range(num_levels)]
>>> for l in range(num_levels):
... print("ys[%d].shape = %s"%(l,ys[l].shape))
ys[0].shape = (2, 2048)
ys[1].shape = (2, 1024)
ys[2].shape = (2, 512)
ys[3].shape = (2, 256)
>>> ymeans = np.stack([(ys[l][1]-ys[l][0]).mean(-1) for l in range(num_levels)])
>>> with np.printoptions(formatter={"float": lambda x: "%.2e"%x}):
... ymeans
array([1.78e+00, 2.61e-03, 5.57e-04, 1.10e-03])
>>> print("%.4f"%ymeans.sum())
1.7850
Multi-level options with independent replications
>>> seed_seq = np.random.SeedSequence(7)
>>> d_coarsest = 8
>>> num_levels = 4
>>> ns = [2**7,2**6,2**5,2**4]
>>> integrands = [FinancialOption(DigitalNetB2(dimension=2**l*d_coarsest,seed=seed_seq.spawn(1)[0],replications=2**4),option="ASIAN",level=l,d_coarsest=d_coarsest) for l in range(num_levels)]
>>> ys = [integrands[l](ns[l]) for l in range(num_levels)]
>>> for l in range(num_levels):
... print("ys[%d].shape = %s"%(l,ys[l].shape))
ys[0].shape = (2, 16, 128)
ys[1].shape = (2, 16, 64)
ys[2].shape = (2, 16, 32)
ys[3].shape = (2, 16, 16)
>>> muhats = np.stack([(ys[l][1]-ys[l][0]).mean(-1) for l in range(num_levels)])
>>> muhats.shape
(4, 16)
>>> muhathat = muhats.mean(-1)
>>> with np.printoptions(formatter={"float": lambda x: "%.2e"%x}):
... muhathat
array([1.80e+00, -3.08e-03, 2.64e-03, 1.14e-03])
>>> print("%.4f"%muhathat.sum())
1.7982
References:
- M.B. Giles.
Improved multilevel Monte Carlo convergence using the Milstein scheme.
343-358, in Monte Carlo and Quasi-Monte Carlo Methods 2006, Springer, 2008.
http://people.maths.ox.ac.uk/~gilesm/files/mcqmc06.pdf.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
option
|
str
|
Option type in |
'ASIAN'
|
call_put
|
str
|
Either |
'CALL'
|
volatility
|
float
|
\(\sigma\). |
0.5
|
start_price
|
float
|
\(S_0\). |
30
|
strike_price
|
float
|
\(K\). |
35
|
interest_rate
|
float
|
\(r\). |
0
|
t_final
|
float
|
\(\tau_d\). |
1
|
decomp_type
|
str
|
Method for decomposition for covariance matrix. Options include
|
'PCA'
|
level
|
Union[None, int]
|
Level for multilevel problems |
None
|
d_coarsest
|
Union[None, int]
|
Dimension of the problem on the coarsest level. |
2
|
asian_mean
|
str
|
Either |
'ARITHMETIC'
|
asian_mean_quadrature_rule
|
str
|
Either 'TRAPEZOIDAL' or 'RIGHT'. |
'TRAPEZOIDAL'
|
barrier_in_out
|
str
|
Either |
'IN'
|
barrier_price
|
float
|
\(B\). |
38
|
digital_payout
|
float
|
\(\rho\). |
10
|
Source code in qmcpy/integrand/financial_option.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
get_exact_value
Compute the exact analytic fair price of the option in finite dimensions. Supports
option='EUROPEAN'
option='ASIAN'
withasian_mean='GEOMETRIC'
andasian_mean_quadrature_rule='RIGHT'
Returns:
Name | Type | Description |
---|---|---|
mean |
float
|
Exact value of the integral. |
Source code in qmcpy/integrand/financial_option.py
get_exact_value_inf_dim
Get the exact analytic fair price of the option in infinite dimensions. Supports
option='ASIAN'
withasian_mean='GEOMETRIC'
Returns:
Name | Type | Description |
---|---|---|
mean |
float
|
Exact value of the integral. |
Source code in qmcpy/integrand/financial_option.py
CustomFun
Bases: AbstractIntegrand
User supplied integrand \(g\). In the following example we implement
Examples:
First we will implement
>>> integrand = CustomFun(
... true_measure = Gaussian(DigitalNetB2(2,seed=7),mean=[1,2]),
... g = lambda t: t[...,0]**2*t[...,1])
>>> y = integrand(2**10)
>>> print("%.4f"%y.mean())
3.9991
With independent replications
>>> integrand = CustomFun(
... true_measure = Gaussian(DigitalNetB2(2,seed=7,replications=2**4),mean=[1,2]),
... g = lambda t: t[...,0]**2*t[...,1])
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(1)
>>> muhats.shape
(16,)
>>> print("%.4f"%muhats.mean())
3.9330
Next we will implement the multi-output function
>>> def g(t):
... t1,t2 = t[...,0],t[...,1]
... sint1,cost1,sint2,cost2 = np.sin(t1),np.cos(t1),np.sin(t2),np.cos(t2)
... y1 = sint1*cost2
... y2 = cost1*sint2
... y3 = sint1+cost2
... y4 = cost1+sint2
... y = np.stack([y1,y2,y3,y4])
... return y
>>> integrand = CustomFun(
... true_measure = Uniform(DigitalNetB2(2,seed=7),lower_bound=0,upper_bound=2*np.pi),
... g = g,
... dimension_indv = (4,))
>>> x = integrand.discrete_distrib(2**10)
>>> y = integrand.f(x)
>>> y.shape
(4, 1024)
>>> with np.printoptions(formatter={"float": lambda x: "%.2e"%x}):
... y.mean(-1)
array([8.18e-04, 1.92e-06, -2.26e-10, 5.05e-07])
Stopping criterion which supporting vectorized outputs may pass in Boolean compute_flags
with dimension_indv
shape indicating which output need to evaluated,
i.e. where compute_flags
is False
we do not need to evaluate the integrand. We have not used this in inexpensive example above.
With independent replications
>>> integrand = CustomFun(
... true_measure = Uniform(DigitalNetB2(2,seed=7,replications=2**4),lower_bound=0,upper_bound=2*np.pi),
... g = g,
... dimension_indv = (4,))
>>> x = integrand.discrete_distrib(2**6)
>>> x.shape
(16, 64, 2)
>>> y = integrand.f(x)
>>> y.shape
(4, 16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(4, 16)
>>> with np.printoptions(formatter={"float": lambda x: "%.2e"%x}):
... muhats.mean(-1)
array([3.83e-03, -6.78e-03, -1.56e-03, -5.65e-04])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
true_measure
|
AbstractTrueMeasure
|
The true measure. |
required |
g
|
callable
|
A function handle. |
required |
dimension_indv
|
tuple
|
Shape of individual solution outputs from |
()
|
parallel
|
int
|
Parallelization flag.
Setting |
False
|
Note
For parallel > 1
do not set g
to be anonymous function (i.e. a lambda
function)
Source code in qmcpy/integrand/custom_fun.py
UMBridgeWrapper
Bases: AbstractIntegrand
Wrapper around a UM-Bridge
model. See also the UM-Bridge
documentation for the QMCPy client.
Requires Docker is installed.
Examples:
>>> _ = os.system('docker run --name muqbppytest -dit -p 4243:4243 linusseelinger/benchmark-muq-beam-propagation:latest > /dev/null')
>>> import umbridge
>>> dnb2 = DigitalNetB2(dimension=3,seed=7)
>>> true_measure = Uniform(dnb2,lower_bound=1,upper_bound=1.05)
>>> um_bridge_model = umbridge.HTTPModel('http://localhost:4243','forward')
>>> um_bridge_config = {"d": dnb2.d}
>>> integrand = UMBridgeWrapper(true_measure,um_bridge_model,um_bridge_config,parallel=False)
>>> y = integrand(2**10)
>>> with np.printoptions(formatter={"float":lambda x: "%.1e"%x}):
... y.mean(-1)
array([0.0e+00, 3.9e+00, 1.5e+01, 3.2e+01, 5.5e+01, 8.3e+01, 1.2e+02,
1.5e+02, 2.0e+02, 2.4e+02, 2.9e+02, 3.4e+02, 3.9e+02, 4.3e+02,
4.7e+02, 5.0e+02, 5.3e+02, 5.6e+02, 5.9e+02, 6.2e+02, 6.4e+02,
6.6e+02, 6.9e+02, 7.2e+02, 7.6e+02, 7.9e+02, 8.3e+02, 8.6e+02,
9.0e+02, 9.4e+02, 9.7e+02])
>>> _ = os.system('docker rm -f muqbppytest > /dev/null')
Custom model with independent replications
>>> class TestModel(umbridge.Model):
... def __init__(self):
... super().__init__("forward")
... def get_input_sizes(self, config):
... return [1,2,3]
... def get_output_sizes(self, config):
... return [3,2,1]
... def __call__(self, parameters, config):
... out0 = [parameters[2][0],sum(parameters[2][:2]),sum(parameters[2])]
... out1 = [parameters[1][0],sum(parameters[1])]
... out2 = [parameters[0]]
... return [out0,out1,out2]
... def supports_evaluate(self):
... return True
>>> um_bridge_model = TestModel()
>>> um_bridge_config = {}
>>> d = sum(um_bridge_model.get_input_sizes(config=um_bridge_config))
>>> true_measure = Uniform(DigitalNetB2(dimension=d,seed=7,replications=15),lower_bound=-1,upper_bound=1)
>>> integrand = UMBridgeWrapper(true_measure,um_bridge_model)
>>> y = integrand(2**6)
>>> y.shape
(6, 15, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(6, 15)
>>> muhats_aggregate = muhats.mean(-1)
>>> muhats_aggregate.shape
(6,)
>>> muhats_agg_list_of_lists = integrand.to_umbridge_out_sizes(muhats_aggregate)
>>> [["%.2e"%ii for ii in i] for i in muhats_agg_list_of_lists]
[['-1.59e-08', '1.49e-04', '1.49e-04'], ['8.20e-06', '-1.38e-04'], ['-8.14e-06']]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
true_measure
|
AbstractTrueMeasure
|
The true measure. |
required |
model
|
HTTPModel
|
A |
required |
config
|
dict
|
Configuration keyword argument to |
{}
|
parallel
|
int
|
Parallelization flag.
Setting |
False
|
Source code in qmcpy/integrand/umbridge_wrapper.py
to_umbridge_out_sizes
Convert a data attribute to UM-Bridge
output sized list of lists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray
|
Array of length |
required |
Returns:
Name | Type | Description |
---|---|---|
x_list_list |
list
|
List of lists with sub-list lengths specified by |
Source code in qmcpy/integrand/umbridge_wrapper.py
SensitivityIndices
Bases: AbstractIntegrand
Sensitivity indices i.e. normalized Sobol' Indices.
Examples:
Singleton indices
>>> function = Keister(DigitalNetB2(dimension=4,seed=7))
>>> integrand = SensitivityIndices(function,indices='singletons')
>>> integrand.indices
array([[ True, False, False, False],
[False, True, False, False],
[False, False, True, False],
[False, False, False, True]])
>>> y = integrand(2**10)
>>> y.shape
(2, 3, 4, 1024)
>>> ymean = y.mean(-1)
>>> ymean.shape
(2, 3, 4)
>>> sigma_hat = ymean[:,2,:]-ymean[:,1,:]**2
>>> sigma_hat.shape
(2, 4)
>>> sigma_hat
array([[17.81421941, 17.81421941, 17.81421941, 17.81421941],
[17.81421941, 17.81421941, 17.81421941, 17.81421941]])
>>> closed_total_approx = ymean[:,0]/sigma_hat
>>> closed_total_approx.shape
(2, 4)
>>> closed_total_approx
array([[0.23756849, 0.2423556 , 0.24844127, 0.24771739],
[0.25090825, 0.25344588, 0.24531633, 0.26244379]])
Check what all indices look like for \(d=3\)
>>> integrand = SensitivityIndices(Keister(DigitalNetB2(dimension=3,seed=7)),indices='all')
>>> integrand.indices
array([[ True, False, False],
[False, True, False],
[False, False, True],
[ True, True, False],
[ True, False, True],
[False, True, True]])
Vectorized function for all singletons and pairs of dimensions
>>> function = BoxIntegral(DigitalNetB2(dimension=4,seed=7,replications=2**4),s=np.arange(1,31).reshape((5,6)))
>>> indices = np.zeros((function.d,function.d,function.d),dtype=bool)
>>> r = np.arange(function.d)
>>> indices[r,:,r] = True
>>> indices[:,r,r] = True
>>> integrand = SensitivityIndices(function,indices=indices)
>>> integrand.indices.shape
(4, 4, 4)
>>> integrand.indices
array([[[ True, False, False, False],
[ True, True, False, False],
[ True, False, True, False],
[ True, False, False, True]],
[[ True, True, False, False],
[False, True, False, False],
[False, True, True, False],
[False, True, False, True]],
[[ True, False, True, False],
[False, True, True, False],
[False, False, True, False],
[False, False, True, True]],
[[ True, False, False, True],
[False, True, False, True],
[False, False, True, True],
[False, False, False, True]]])
>>> y = integrand(2**10)
>>> y.shape
(2, 3, 4, 4, 5, 6, 16, 1024)
>>> muhats = y.mean(-1)
>>> muhats.shape
(2, 3, 4, 4, 5, 6, 16)
>>> muhathat = muhats.mean(-1)
>>> muhathat.shape
(2, 3, 4, 4, 5, 6)
>>> sigma_hat = muhathat[:,2,:]-muhathat[:,1,:]**2
>>> sigma_hat.shape
(2, 4, 4, 5, 6)
>>> closed_total_approx = muhathat[:,0]/sigma_hat
>>> closed_total_approx.shape
(2, 4, 4, 5, 6)
References:
-
Aleksei G. Sorokin and Jagadeeswaran Rathinavel.
On Bounding and Approximating Functions of Multiple Expectations Using Quasi-Monte Carlo.
International Conference on Monte Carlo and Quasi-Monte Carlo Methods in Scientific Computing.
Cham: Springer International Publishing, 2022.
https://link.springer.com/chapter/10.1007/978-3-031-59762-6_29. -
Art B. Owen.
Monte Carlo theory, methods and examples.
Appendix A. Equations (A.16) and (A.18). 2013. https://artowen.su.domains/mc/A-anova.pdf.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
integrand
|
AbstractIntegrand
|
Integrand to find sensitivity indices of. |
required |
indices
|
ndarray
|
Bool array with shape \((\dots,d)\) where each length \(d\) vector item indicates which dimensions are active in the subset.
|
'singletons'
|
Source code in qmcpy/integrand/sensitivity_indices.py
Keister
Bases: AbstractIntegrand
Keister function from [1].
Examples:
>>> integrand = Keister(DigitalNetB2(2,seed=7))
>>> y = integrand(2**10)
>>> print("%.4f"%y.mean())
1.8080
>>> integrand.true_measure
Gaussian (AbstractTrueMeasure)
mean 0
covariance 2^(-1)
decomp_type PCA
With independent replications
>>> integrand = Keister(DigitalNetB2(2,seed=7,replications=2**4))
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(16,)
>>> print("%.4f"%muhats.mean())
1.8024
References:
- B. D. Keister.
Multidimensional Quadrature Algorithms.
Computers in Physics, 10, pp. 119-122, 1996.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
Source code in qmcpy/integrand/keister.py
get_exact_value
classmethod
Compute the exact analytic value of the Keister integral with dimension \(d\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
int
|
Dimension. |
required |
Returns:
Name | Type | Description |
---|---|---|
mean |
float
|
Exact value of the integral. |
Source code in qmcpy/integrand/keister.py
Genz
Bases: AbstractIntegrand
Genz function following the DAKOTA
implementation.
or
where
and the coefficients \(\boldsymbol{c}\) are have three kinds
Examples:
>>> for kind_func in ['OSCILLATORY','CORNER PEAK']:
... for kind_coeff in [1,2,3]:
... integrand = Genz(DigitalNetB2(2,seed=7),kind_func=kind_func,kind_coeff=kind_coeff)
... y = integrand(2**14)
... mu_hat = y.mean()
... print('%-15s %-3d %.3f'%(kind_func,kind_coeff,mu_hat))
OSCILLATORY 1 -0.351
OSCILLATORY 2 -0.329
OSCILLATORY 3 -0.217
CORNER PEAK 1 0.713
CORNER PEAK 2 0.714
CORNER PEAK 3 0.720
With independent replications
>>> integrand = Genz(DigitalNetB2(2,seed=7,replications=2**4),kind_func="CORNER PEAK",kind_coeff=3)
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(16,)
>>> print("%.4f"%muhats.mean())
0.7200
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
kind_func
|
str
|
Either |
'OSCILLATORY'
|
kind_coeff
|
int
|
1, 2, or 3 for choice of coefficients |
1
|
Source code in qmcpy/integrand/genz.py
BoxIntegral
Bases: AbstractIntegrand
Box integral from [1], see also
Examples:
Scalar s
>>> integrand = BoxIntegral(DigitalNetB2(2,seed=7),s=7)
>>> y = integrand(2**10)
>>> y.shape
(1024,)
>>> print("%.4f"%y.mean(0))
0.7519
With independent replications
>>> integrand = BoxIntegral(DigitalNetB2(2,seed=7,replications=2**4),s=7)
>>> y = integrand(2**10)
>>> y.shape
(16, 1024)
>>> muhats = y.mean(1)
>>> muhats.shape
(16,)
>>> print("%.4f"%muhats.mean(0))
0.7518
Array s
>>> integrand = BoxIntegral(DigitalNetB2(5,seed=7),s=np.arange(6).reshape((2,3)))
>>> y = integrand(2**10)
>>> y.shape
(2, 3, 1024)
>>> y.mean(-1)
array([[1. , 1.26234461, 1.66666661],
[2.28201516, 3.22195096, 4.67188113]])
With independent replications
>>> integrand = BoxIntegral(DigitalNetB2(2,seed=7,replications=2**4),s=np.arange(6).reshape((2,3)))
>>> y = integrand(2**10)
>>> y.shape
(2, 3, 16, 1024)
>>> muhats = y.mean(-1)
>>> muhats.shape
(2, 3, 16)
>>> muhats.mean(-1)
array([[1. , 0.76519118, 0.66666666],
[0.62718785, 0.62224086, 0.64273341]])
References:
- D.H. Bailey, J.M. Borwein, R.E. Crandall, Box integrals.
Journal of Computational and Applied Mathematics, Volume 206, Issue 1, 2007, Pages 196-208, ISSN 0377-0427.
https://doi.org/10.1016/j.cam.2006.06.010.
https://www.sciencedirect.com/science/article/pii/S0377042706004250.
https://www.davidhbailey.com/dhbpapers/boxintegrals.pdf
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
s
|
Union[float, ndarray]
|
|
1
|
Source code in qmcpy/integrand/box_integral.py
Ishigami
Bases: AbstractIntegrand
Ishigami function in \(d=3\) dimensions from [1] and https://www.sfu.ca/~ssurjano/ishigami.html.
Examples:
>>> integrand = Ishigami(DigitalNetB2(3,seed=7))
>>> y = integrand(2**10)
>>> y.shape
(1024,)
>>> print("%.4f"%y.mean())
3.5000
>>> integrand.true_measure
Uniform (AbstractTrueMeasure)
lower_bound -3.142
upper_bound 3.142
With independent replications
>>> integrand = Ishigami(DigitalNetB2(3,seed=7,replications=2**4))
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(16,)
>>> print("%.4f"%muhats.mean())
3.4646
References:
- Ishigami, T., & Homma, T.
An importance quantification technique in uncertainty analysis for computer models.
In Uncertainty Modeling and Analysis, 1990.
Proceedings, First International Symposium on (pp. 398-403). IEEE.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
a
|
float
|
First parameter \(a\). |
7
|
b
|
float
|
Second parameter \(b\). |
0.1
|
Source code in qmcpy/integrand/ishigami.py
Multimodal2d
Bases: AbstractIntegrand
Multimodal function in \(d=2\) dimensions.
Examples:
>>> integrand = Multimodal2d(DigitalNetB2(2,seed=7))
>>> y = integrand(2**10)
>>> print("%.4f"%y.mean())
-0.7365
>>> integrand.true_measure
Uniform (AbstractTrueMeasure)
lower_bound [-4 -3]
upper_bound [7 8]
With independent replications
>>> integrand = Multimodal2d(DigitalNetB2(2,seed=7,replications=2**4))
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(16,)
>>> print("%.4f"%muhats.mean())
-0.7366
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
Source code in qmcpy/integrand/multimodal2d.py
Hartmann6d
Bases: AbstractIntegrand
Wrapper around BoTorch
's implementation of the Augmented Hartmann function in dimension \(d=6\).
Examples:
>>> integrand = Hartmann6d(DigitalNetB2(6,seed=7))
>>> y = integrand(2**10)
>>> print("%.4f"%y.mean())
-0.2644
>>> integrand.true_measure
Uniform (AbstractTrueMeasure)
lower_bound 0
upper_bound 1
With independent replications
>>> integrand = Hartmann6d(DigitalNetB2(6,seed=7,replications=2**4))
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(16,)
>>> print("%.4f"%muhats.mean())
-0.2599
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
Source code in qmcpy/integrand/hartmann6d.py
FourBranch2d
Bases: AbstractIntegrand
Four Branch function in \(d=2\).
Examples:
>>> integrand = FourBranch2d(DigitalNetB2(2,seed=7))
>>> y = integrand(2**10)
>>> print("%.4f"%y.mean())
-2.4995
>>> integrand.true_measure
Uniform (AbstractTrueMeasure)
lower_bound -8
upper_bound 2^(3)
With independent replications
>>> integrand = FourBranch2d(DigitalNetB2(2,seed=7,replications=2**4))
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(16,)
>>> print("%.4f"%muhats.mean())
-2.5042
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
Source code in qmcpy/integrand/fourbranch2d.py
BayesianLRCoeffs
Bases: AbstractIntegrand
Logistic Regression Coefficients computed as the posterior mean in a Bayesian framework.
Examples:
>>> integrand = BayesianLRCoeffs(DigitalNetB2(3,seed=7),feature_array=np.arange(8).reshape((4,2)),response_vector=[0,0,1,1])
>>> y = integrand(2**10)
>>> y.shape
(2, 3, 1024)
>>> y.mean(-1)
array([[ 0.04517466, -0.01103669, -0.06614381],
[ 0.02162049, 0.02162049, 0.02162049]])
With independent replications
>>> integrand = BayesianLRCoeffs(DigitalNetB2(3,seed=7,replications=2**4),feature_array=np.arange(8).reshape((4,2)),response_vector=[0,0,1,1])
>>> y = integrand(2**6)
>>> y.shape
(2, 3, 16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(2, 3, 16)
>>> muhats.mean(-1)
array([[ 0.0587368 , -0.01718134, -0.07203021],
[ 0.02498059, 0.02498059, 0.02498059]])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
feature_array
|
ndarray
|
Array of features with shape \((N,d-1)\) where \(N\) is the number of observations and \(d\) is the dimension. |
required |
response_vector
|
ndarray
|
Binary responses vector of length \(N\). |
required |
prior_mean
|
ndarray
|
Length \(d\) vector of prior means, one for each coefficient.
|
0
|
prior_covariance
|
ndarray
|
Prior covariance array with shape \((d,d)\) d x d where indexing is consistent with the prior mean. |
10
|
Source code in qmcpy/integrand/bayesian_lr_coeffs.py
Sin1d
Bases: AbstractIntegrand
Sine function in \(d=1\) dimension.
Examples:
>>> integrand = Sin1d(DigitalNetB2(1,seed=7),k=1)
>>> y = integrand(2**10)
>>> print("%.4e"%y.mean())
-1.3582e-10
>>> integrand.true_measure
Uniform (AbstractTrueMeasure)
lower_bound 0
upper_bound 6.283
With independent replications
>>> integrand = Sin1d(DigitalNetB2(1,seed=7,replications=2**4),k=1)
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(16,)
>>> print("%.4e"%muhats.mean())
7.0800e-04
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |
k
|
float
|
The true measure will be uniform between \(0\) and \(2 \pi k\). |
1
|
Source code in qmcpy/integrand/sin1d.py
Linear0
Bases: AbstractIntegrand
Linear Function with analytic mean \(0\).
Examples:
>>> integrand = Linear0(DigitalNetB2(100,seed=7))
>>> y = integrand(2**10)
>>> print("%.4e"%y.mean())
6.0560e-05
With independent replications
>>> integrand = Linear0(DigitalNetB2(100,seed=7,replications=2**4))
>>> y = integrand(2**6)
>>> y.shape
(16, 64)
>>> muhats = y.mean(-1)
>>> muhats.shape
(16,)
>>> print("%.4e"%muhats.mean())
-9.8203e-05
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler
|
Union[AbstractDiscreteDistribution, AbstractTrueMeasure]
|
Either
|
required |