Skip to content

Commit

Permalink
fixing numpoly interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathf committed Jul 19, 2021
1 parent 24df1ff commit e61d302
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 28 deletions.
8 changes: 1 addition & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,12 @@ jobs:
key: deps-py38-{{ checksum "poetry.lock" }}
paths:
- /home/circleci/venv
- run:
name: "Ensure the documentation builds"
command: |
source /home/circleci/venv/bin/activate
sphinx-build docs/ docs/.build -b html -n -v --color -T -W
- run:
name: "Run pytest"
command: |
source /home/circleci/venv/bin/activate
coverage run --source=chaospy/ --module pytest --nbval --doctest-modules \
chaospy/ tests/ docs/*.rst docs/*/*.rst \
docs/tutorials/*.ipynb docs/tutorials/*/*.ipynb
chaospy/ tests/ docs/*.rst docs/*/*.rst
bash <(curl -s https://codecov.io/bash)
deploy:
docker:
Expand Down
2 changes: 1 addition & 1 deletion chaospy/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def basis(start, stop=None, dim=1, cross_truncation=1., sort="G"):
out = numpoly.monomial(
start=start,
stop=numpy.array(stop)+1,
dimensions=dim,
reverse="R" not in sort.upper(),
graded="G" in sort.upper(),
cross_truncation=cross_truncation,
names=numpoly.symbols("q:%d" % dim, asarray=True),
)
if "I" in sort.upper():
out = out[::-1]
Expand Down
2 changes: 1 addition & 1 deletion chaospy/descriptives/conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ def E_cond(poly, freeze, dist, **kws):

# Remove frozen coefficients, such that poly == sum(frozen*unfrozen) holds
for key in unfrozen.keys:
unfrozen[key] = unfrozen[key] != 0
unfrozen[key] = unfrozen.values[key] != 0

return numpoly.sum(frozen*E(unfrozen, dist), 0)
2 changes: 1 addition & 1 deletion chaospy/descriptives/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ def E(poly, dist=None, **kws):

out = numpy.zeros(poly.shape)
for idx, key in enumerate(poly.keys):
out += poly[key]*moments[idx]
out += poly.values[key]*moments[idx]
return out
2 changes: 1 addition & 1 deletion chaospy/orthogonal/cholesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def orth_chol(order, dist, normed=False, graded=True, reverse=True,
basis = numpoly.monomial(
start=1,
stop=order+1,
names=numpoly.variable(dim).names,
dimensions=dim,
graded=graded,
reverse=reverse,
cross_truncation=cross_truncation,
Expand Down
2 changes: 1 addition & 1 deletion chaospy/orthogonal/gram_schmidt.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def orth_gs(order, dist, normed=False, graded=True, reverse=True,
basis = numpoly.monomial(
0,
order+1,
names=numpoly.variable(2).names,
dimensions=dim,
graded=graded,
reverse=reverse,
cross_truncation=cross_truncation,
Expand Down
19 changes: 9 additions & 10 deletions chaospy/orthogonal/lagrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,36 @@ def lagrange_polynomial(abscissas, graded=True, reverse=True, sort=None):
raise numpy.linalg.LinAlgError(
"Lagrange abscissas resulted in invertible matrix")

names = numpoly.variable(dim).names
vec = numpoly.monomial(
0, order+1, names=names, graded=graded, reverse=reverse)[:size]
0, order+1, dimensions=dim, graded=graded, reverse=reverse)[:size]

coeffs = numpy.zeros((size, size))

if size == 1:
out = numpoly.monomial(
0, 1, names=names, graded=graded, reverse=reverse)*abscissas.item()
out = numpoly.monomial(0, 1, dimensions=dim, graded=graded,
reverse=reverse)*abscissas.item()

elif size == 2:
coeffs = numpy.linalg.inv(matrix)
out = numpoly.sum(vec*(coeffs.T), 1)

else:
for i in range(size):
if i%2 != 0:
if i % 2 != 0:
k = 1
else:
k=0
k = 0
for j in range(size):
if k%2 == 0:
if k % 2 == 0:
coeffs[i, j] += numpy.linalg.det(matrix[1:, 1:])
else:
if size%2 == 0:
if size % 2 == 0:
coeffs[i, j] += -numpy.linalg.det(matrix[1:, 1:])
else:
coeffs[i, j] += numpy.linalg.det(matrix[1:, 1:])
matrix = numpy.roll(matrix, -1, axis=0)
matrix = numpy.roll(matrix, -1, axis=0)
k += 1
matrix = numpy.roll(matrix, -1, axis=1)
matrix = numpy.roll(matrix, -1, axis=1)
coeffs /= det
out = numpoly.sum(vec*(coeffs.T), 1)

Expand Down
9 changes: 7 additions & 2 deletions chaospy/prange.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ def prange(N=1, dim=1):
polynomial([1, q2, q2**2, q2**3])
"""
logger = logging.getLogger(__name__)
logger.warning("chaospy.prange is deprecated; use chaospy.monomial instead")
return numpoly.monomial(N, names=["q%d" % (dim-1)])
logger.warning(
"chaospy.prange is deprecated; use chaospy.monomial instead")
out = numpoly.monomial(N)
if dim > 1:
out = numpoly.call(
out, kwargs={out.names[0]: numpoly.variable(dim)[-1]})
return out
2 changes: 1 addition & 1 deletion chaospy/quadrature/recurrence/stieltjes.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def analytical_stieljes(order, dist, normed=False):

norms = numpy.cumprod(coeffs[1], 1)
if normed:
orth = numpoly.true_divide(orth, numpy.sqrt(norms))
orth = numpoly.polynomial(orth)/numpy.sqrt(norms)
norms **= 0

return coeffs, orth, norms
6 changes: 3 additions & 3 deletions chaospy/saltelli.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def Sens_m_sample(poly, dist, samples, rule="random"):
Examples:
>>> dist = chaospy.Iid(chaospy.Uniform(), 2)
>>> poly = chaospy.monomial(2, 3, names=2, reverse=False)
>>> poly = chaospy.monomial(2, 3, dimensions=2, reverse=False)
>>> poly
polynomial([q0**2, q0*q1, q1**2])
>>> Sens_m_sample(poly, dist, 10000, rule="hammersley").round(4)
Expand Down Expand Up @@ -157,7 +157,7 @@ def Sens_m2_sample(poly, dist, samples, rule="random"):
Examples:
>>> dist = chaospy.Iid(chaospy.Uniform(), 2)
>>> poly = chaospy.monomial(2, 3, names=2, reverse=False)
>>> poly = chaospy.monomial(2, 3, dimensions=2, reverse=False)
>>> poly
polynomial([q0**2, q0*q1, q1**2])
>>> Sens_m2_sample(poly, dist, 10000, rule="halton").round(4)
Expand Down Expand Up @@ -236,7 +236,7 @@ def Sens_t_sample(poly, dist, samples, rule="random"):
Examples:
>>> dist = chaospy.Iid(chaospy.Uniform(0, 1), 2)
>>> poly = chaospy.monomial(2, 3, names=2, reverse=False)
>>> poly = chaospy.monomial(2, 3, dimensions=2, reverse=False)
>>> poly
polynomial([q0**2, q0*q1, q1**2])
>>> Sens_t_sample(poly, dist, 10000, rule="halton").round(4)
Expand Down

0 comments on commit e61d302

Please sign in to comment.