Skip to content

Commit 76e5846

Browse files
committed
refactor orthogonal->expansion
1 parent 95c745b commit 76e5846

36 files changed

+691
-354
lines changed

CHANGELOG.rst

+38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
Master Branch
22
=============
33

4+
Version 4.3.1 (2021-03-18)
5+
==========================
6+
7+
Refactoring `orthogonal -> expansion` module.
8+
9+
ADDED:
10+
* Dedicated classical orthogonal expansion schemes:
11+
`chaospy.expansion.{chebyshev_1,chebyshev_2,gegenbauer,hermite,jacobi,laguerre,legendre}`
12+
CHANGED:
13+
* Function renames:
14+
`chaospy.{orth_ttr,orth_chol,orth_gs,lagrange_polynomial} ->
15+
chaospy.expansion.{stieltjes,cholesky,gram_schmidt,lagrange}`
16+
* Docs update.
17+
18+
Version 4.3.0 (2021-01-20)
19+
==========================
20+
21+
Refactoring `quadrature` module.
22+
23+
ADDED:
24+
* `chaospy.quadrature.fejer_1` is added.
25+
* Dedicated classical quadrature schemes:
26+
`chaospy.quadrature.{chebyshev,gegenbauer,hermite,jacobi,laguerre,legendre}`
27+
CHANGED:
28+
* Bound checks for the triangle distribution. (Thanks to @yoelcortes.)
29+
* Refactored hypercube quadrature to common backend. This gives lots of flags
30+
like `seqments` and
31+
* Function renames:
32+
`chaospy.quad_{clenshaw_curtis,discrete,fejer,gaussian,grid,gauss_lengendre,gauss_kronrod,gauss_lobatto,gauss_patterson,gauss_radau} ->
33+
chaospy.quadrature.{clenshaw_curtis,fejer_2,gaussian,grid,legendre_proxy,kronrod,lobatto,patterson,radau}`
34+
* Patterson growth rule changed from `0, 3, 7, ...` to `0, 1, 2, ...` but
35+
maps backwards. Defaults to not have growth parameter, as setting it false
36+
makes no sense.
37+
* Renamed: `chaospy.generate_sparse_grid -> chaospy.quadrature.sparse_grid`
38+
REMOVED:
39+
* Genz-Keister quadrature `quad_genz_keister` is deprecated as it does not
40+
fit the `chaospy` scheme very well.
41+
442
Version 4.2.4 (2021-02-23)
543
==========================
644

chaospy/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
import chaospy.descriptives
1414
import chaospy.distributions
15-
import chaospy.orthogonal
15+
import chaospy.expansion
1616
import chaospy.spectral
1717
import chaospy.quadrature
1818
import chaospy.saltelli
1919
import chaospy.regression
2020
import chaospy.recurrence
2121

2222
from chaospy.distributions import *
23-
from chaospy.orthogonal import *
23+
from chaospy.expansion import *
2424
from chaospy.spectral import *
2525
from chaospy.quadrature import *
2626
from chaospy.saltelli import *

chaospy/distributions/approximation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ def approximate_moment(
171171
k_loc (Sequence[int, ...]):
172172
The exponents of the moments of interest with ``shape == (dim,)``.
173173
order (int):
174-
The quadrature order used in approximation. If omitted, calculated
175-
to be ``1000/log2(len(distribution)+1)``.
174+
The quadrature order used in approximation. If omitted, defaults to
175+
``1e5**(1./len(distribution))``.
176176
rule (str):
177177
Quadrature rule for integrating moments.
178178
kwargs:
179-
Extra args passed to `chaospy.generate_quadrature`.
179+
Extra args passed to :func:`chaospy.generate_quadrature`.
180180
181181
Examples:
182182
>>> distribution = chaospy.Uniform(1, 4)

chaospy/distributions/operators/joint.py

-15
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,3 @@ def _cache(self, idx, cache):
225225
if isinstance(out, chaospy.Distribution):
226226
return self
227227
return out
228-
229-
230-
# def J(*args, **kwargs):
231-
# """
232-
# Joint random variable.
233-
234-
# Too be deprecated, use `chaospy.J` instead.
235-
236-
# Args:
237-
# args (chaospy.Distribution):
238-
# Distribution to join together.
239-
# """
240-
# logger = logging.getLogger(__name__)
241-
# logger.warning("DepricationWarning: J to be replaced with Joint.")
242-
# return Joint(*args, **kwargs)

chaospy/distributions/sampler/sequences/chebyshev.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
def create_chebyshev_samples(order, dim=1):
5151
"""
52-
Chebyshev sampling function.
52+
Generate Chebyshev pseudo-random samples.
5353
5454
Args:
5555
order (int):
@@ -60,6 +60,16 @@ def create_chebyshev_samples(order, dim=1):
6060
Returns:
6161
samples following Chebyshev sampling scheme mapped to the
6262
``[0, 1]^dim`` hyper-cube and ``shape == (dim, order)``.
63+
64+
Examples:
65+
>>> samples = chaospy.create_chebyshev_samples(6, 1)
66+
>>> samples.round(4)
67+
array([[0.0495, 0.1883, 0.3887, 0.6113, 0.8117, 0.9505]])
68+
>>> samples = chaospy.create_chebyshev_samples(3, 2)
69+
>>> samples.round(3)
70+
array([[0.146, 0.146, 0.146, 0.5 , 0.5 , 0.5 , 0.854, 0.854, 0.854],
71+
[0.146, 0.5 , 0.854, 0.146, 0.5 , 0.854, 0.146, 0.5 , 0.854]])
72+
6373
"""
6474
x_data = .5*numpy.cos(numpy.arange(order, 0, -1)*numpy.pi/(order+1)) + .5
6575
x_data = utils.combine([x_data]*dim)

chaospy/distributions/sampler/sequences/halton.py

+24-31
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,4 @@
1-
"""
2-
Create samples from the `Halton sequence`_.
3-
4-
In statistics, Halton sequences are sequences used to generate points in space
5-
for numerical methods such as Monte Carlo simulations. Although these sequences
6-
are deterministic, they are of low discrepancy, that is, appear to be random
7-
for many purposes. They were first introduced in 1960 and are an example of
8-
a quasi-random number sequence. They generalise the one-dimensional van der
9-
Corput sequences.
10-
11-
Example usage
12-
-------------
13-
14-
Standard usage::
15-
16-
>>> distribution = chaospy.J(chaospy.Uniform(0, 1), chaospy.Uniform(0, 1))
17-
>>> samples = distribution.sample(3, rule="halton")
18-
>>> samples.round(4)
19-
array([[0.125 , 0.625 , 0.375 ],
20-
[0.4444, 0.7778, 0.2222]])
21-
>>> samples = distribution.sample(4, rule="halton")
22-
>>> samples.round(4)
23-
array([[0.125 , 0.625 , 0.375 , 0.875 ],
24-
[0.4444, 0.7778, 0.2222, 0.5556]])
25-
26-
.. _Halton sequence: https://en.wikipedia.org/wiki/Halton_sequence
27-
"""
1+
"""Create samples from the Halton sequence."""
282
import numpy
293

304
from .van_der_corput import create_van_der_corput_samples
@@ -33,9 +7,15 @@
337

348
def create_halton_samples(order, dim=1, burnin=-1, primes=()):
359
"""
36-
Create Halton sequence.
10+
Create samples from the Halton sequence.
3711
38-
For ``dim == 1`` the sequence falls back to Van Der Corput sequence.
12+
In statistics, Halton sequences are sequences used to generate points in
13+
space for numerical methods such as Monte Carlo simulations. Although these
14+
sequences are deterministic, they are of low discrepancy, that is, appear
15+
to be random for many purposes. They were first introduced in 1960 and are
16+
an example of a quasi-random number sequence. They generalise the
17+
one-dimensional van der Corput sequences. For ``dim == 1`` the sequence
18+
falls back to Van Der Corput sequence.
3919
4020
Args:
4121
order (int):
@@ -49,8 +29,21 @@ def create_halton_samples(order, dim=1, burnin=-1, primes=()):
4929
The (non-)prime base to calculate values along each axis. If
5030
empty, growing prime values starting from 2 will be used.
5131
52-
Returns (numpy.ndarray):
53-
Halton sequence with ``shape == (dim, order)``.
32+
Returns:
33+
(numpy.ndarray):
34+
Halton sequence with ``shape == (dim, order)``.
35+
36+
Examples:
37+
>>> distribution = chaospy.J(chaospy.Uniform(0, 1), chaospy.Uniform(0, 1))
38+
>>> samples = distribution.sample(3, rule="halton")
39+
>>> samples.round(4)
40+
array([[0.125 , 0.625 , 0.375 ],
41+
[0.4444, 0.7778, 0.2222]])
42+
>>> samples = distribution.sample(4, rule="halton")
43+
>>> samples.round(4)
44+
array([[0.125 , 0.625 , 0.375 , 0.875 ],
45+
[0.4444, 0.7778, 0.2222, 0.5556]])
46+
5447
"""
5548
primes = list(primes)
5649
if not primes:

chaospy/distributions/sampler/sequences/hammersley.py

+15-24
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
1-
"""
2-
Create samples from the `Hammersley set`_.
3-
4-
The Hammersley set is equivalent to the Halton sequence, except for one
5-
dimension is replaced with a regular grid.
6-
7-
Example usage
8-
-------------
9-
10-
Standard usage::
11-
12-
>>> distribution = chaospy.J(chaospy.Uniform(0, 1), chaospy.Uniform(0, 1))
13-
>>> samples = distribution.sample(3, rule="hammersley")
14-
>>> samples.round(4)
15-
array([[0.75 , 0.125, 0.625],
16-
[0.25 , 0.5 , 0.75 ]])
17-
>>> samples = distribution.sample(4, rule="hammersley")
18-
>>> samples.round(4)
19-
array([[0.75 , 0.125, 0.625, 0.375],
20-
[0.2 , 0.4 , 0.6 , 0.8 ]])
21-
22-
.. _Hammersley set: https://en.wikipedia.org/wiki/Low-discrepancy_sequence#Hammersley_set
23-
"""
1+
"""Create samples from the Hammersley set."""
242
import numpy
253

264
from .halton import create_halton_samples
@@ -30,7 +8,8 @@ def create_hammersley_samples(order, dim=1, burnin=-1, primes=()):
308
"""
319
Create samples from the Hammersley set.
3210
33-
For ``dim == 1`` the sequence falls back to Van Der Corput sequence.
11+
The Hammersley set is equivalent to the Halton sequence, except for one
12+
dimension is replaced with a regular grid.
3413
3514
Args:
3615
order (int):
@@ -47,6 +26,18 @@ def create_hammersley_samples(order, dim=1, burnin=-1, primes=()):
4726
Returns:
4827
(numpy.ndarray):
4928
Hammersley set with ``shape == (dim, order)``.
29+
30+
Examples:
31+
>>> distribution = chaospy.J(chaospy.Uniform(0, 1), chaospy.Uniform(0, 1))
32+
>>> samples = distribution.sample(3, rule="hammersley")
33+
>>> samples.round(4)
34+
array([[0.75 , 0.125, 0.625],
35+
[0.25 , 0.5 , 0.75 ]])
36+
>>> samples = distribution.sample(4, rule="hammersley")
37+
>>> samples.round(4)
38+
array([[0.75 , 0.125, 0.625, 0.375],
39+
[0.2 , 0.4 , 0.6 , 0.8 ]])
40+
5041
"""
5142
if dim == 1:
5243
return create_halton_samples(

chaospy/distributions/sampler/sequences/sobol.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
"""
2-
3-
Example usage
4-
-------------
5-
6-
Standard usage::
7-
2+
Generates samples from the Sobol sequence.
83
94
Papers::
105
@@ -35,7 +30,6 @@
3530
Preprint IPM Akad. Nauk SSSR,
3631
Number 40, Moscow 1976.
3732
38-
.. _Sobel sequence: https://en.wikipedia.org/wiki/Sobol_sequence
3933
"""
4034
import math
4135

chaospy/distributions/sampler/sequences/van_der_corput.py

+21-29
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
1-
"""
2-
Create `Van Der Corput` low discrepancy sequence samples.
3-
4-
A van der Corput sequence is an example of the simplest one-dimensional
5-
low-discrepancy sequence over the unit interval; it was first described in 1935
6-
by the Dutch mathematician J. G. van der Corput. It is constructed by reversing
7-
the base-n representation of the sequence of natural numbers (1, 2, 3, ...).
8-
9-
In practice, use Halton sequence instead of Van Der Corput, as it is the
10-
same, but generalized to work in multiple dimensions.
11-
12-
Example usage
13-
-------------
14-
15-
Using base 10::
16-
17-
>>> create_van_der_corput_samples(range(11), number_base=10)
18-
array([0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9 , 0.01, 0.11])
19-
20-
Using base 2::
21-
22-
>>> create_van_der_corput_samples(range(8), number_base=2)
23-
array([0.5 , 0.25 , 0.75 , 0.125 , 0.625 , 0.375 , 0.875 , 0.0625])
24-
25-
.. Van Der Corput: https://en.wikipedia.org/wiki/Van_der_Corput_sequence
26-
"""
1+
"""Create Van Der Corput low discrepancy sequence samples."""
272
from __future__ import division
283
import numpy
294

305

316
def create_van_der_corput_samples(idx, number_base=2):
327
"""
33-
Van der Corput samples.
8+
Create Van Der Corput low discrepancy sequence samples.
9+
10+
A van der Corput sequence is an example of the simplest one-dimensional
11+
low-discrepancy sequence over the unit interval; it was first described in
12+
1935 by the Dutch mathematician J. G. van der Corput. It is constructed by
13+
reversing the base-n representation of the sequence of natural numbers
14+
:math:`(1, 2, 3, ...)`.
15+
16+
In practice, use Halton sequence instead of Van Der Corput, as it is the
17+
same, but generalized to work in multiple dimensions.
3418
3519
Args:
3620
idx (int, numpy.ndarray):
@@ -39,8 +23,16 @@ def create_van_der_corput_samples(idx, number_base=2):
3923
number_base (int):
4024
The numerical base from where to create the samples from.
4125
42-
Returns (float, numpy.ndarray):
43-
Van der Corput samples.
26+
Returns:
27+
(numpy.ndarray):
28+
Van der Corput samples.
29+
30+
Examples:
31+
#>>> chaospy.create_van_der_corput_samples(range(11), number_base=10)
32+
#array([0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9 , 0.01, 0.11])
33+
#>>> chaospy.create_van_der_corput_samples(range(8), number_base=2)
34+
#array([0.5 , 0.25 , 0.75 , 0.125 , 0.625 , 0.375 , 0.875 , 0.0625])
35+
4436
"""
4537
assert number_base > 1
4638

chaospy/expansion/__init__.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
r"""Collection of polynomial expansion constructors."""
2+
import logging
3+
from functools import wraps
4+
5+
from .chebyshev import chebyshev_1, chebyshev_2
6+
from .cholesky import cholesky
7+
from .frontend import generate_expansion
8+
from .gegenbauer import gegenbauer
9+
from .gram_schmidt import gram_schmidt
10+
from .hermite import hermite
11+
from .jacobi import jacobi
12+
from .stieltjes import stieltjes
13+
from .lagrange import lagrange
14+
from .laguerre import laguerre
15+
from .legendre import legendre
16+
17+
__all__ = ["generate_expansion"]
18+
19+
20+
def expansion_deprecation_warning(name, func):
21+
22+
@wraps(func)
23+
def wrapped(*args, **kwargs):
24+
"""Function wrapper adds warnings."""
25+
logger = logging.getLogger(__name__)
26+
logger.warning("chaospy.%s name is to be deprecated; "
27+
"Use chaospy.expansion.%s instead",
28+
name, func.__name__)
29+
return func(*args, **kwargs)
30+
31+
globals()[name] = wrapped
32+
__all__.append(name)
33+
34+
35+
expansion_deprecation_warning("orth_ttr", stieltjes)
36+
expansion_deprecation_warning("orth_chol", cholesky)
37+
expansion_deprecation_warning("orth_gs", gram_schmidt)
38+
expansion_deprecation_warning("lagrange_polynomial", lagrange)

0 commit comments

Comments
 (0)