Skip to content

Commit 3a3119a

Browse files
committed
cleaned up many benchmark functions.
updated example documentations.
1 parent 72803af commit 3a3119a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4341
-697
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Optional dependencies include:
2323
* pytorch (NN surrogates)
2424
* QUiNN (Quantification of Uncertainties in Neural Networks)
2525
* pyswarms (Particle Swarm Optimization)
26+
* dill (for saving python objects)
2627

2728
## Installation
2829

@@ -71,6 +72,13 @@ $ pip install 'pytuq[dev]'
7172
$ pip install .
7273
```
7374

75+
## Contributors
76+
Habib N. Najm (Sandia National Laboratories)
77+
Javier Murgoitio-Esandi (Google)
78+
Cosmin Safta (Sandia National Laboratories)
79+
Joy Bahr-Mueller (Sandia National Laboratories)
80+
Vahan Sargsyan (Stuyvesant High School)
81+
7482
## License
7583
Distributed under BSD 3-Clause License. See `LICENSE.txt` for more information.
7684

apps/create_data.py

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55
import numpy as np
66
import matplotlib.pyplot as plt
77

8-
from pytuq.func import toy, genz, chem, benchmark, poly, oper, func
8+
from pytuq.func import toy, genz, chem, bench, poly, oper, func
9+
from pytuq.utils.xutils import instantiate_classes_from_module
910

1011

12+
fcn_dict = {}
13+
for submod in ['bench', 'bench1d', 'bench2d', 'benchNd', 'chem', 'genz', 'poly', 'toy']:
14+
this_objects = instantiate_classes_from_module(f"pytuq.func.{submod}")
15+
for j in this_objects:
16+
if j.name not in ['GenzBase', 'Poly']:
17+
fcn_dict[j.name] = j
1118

1219

1320
usage_str = 'Script to create input-output data for benchmark functions.'
@@ -16,29 +23,53 @@
1623
# help="indices of requested parameters (count from 0)")
1724

1825
parser.add_argument("-n", "--npts", dest="npts", type=int, default=100, help="Number of points")
19-
parser.add_argument("-f", "--func", dest="func", type=str, default='lj', help="Function name", choices=['lj', 'mb'])
20-
26+
parser.add_argument("-f", "--func", dest="func", type=str, default='Muller-Brown', help="Function name", choices=list(fcn_dict.keys()))
27+
parser.add_argument("-x", "--xtrain", dest="xtrain_file", type=str, default=None, help="Optionally, provide x-sample file")
28+
parser.add_argument("-s", "--sigma", dest="sig", type=float, default=0.0, help="Noise size")
29+
parser.add_argument('-g', dest="grad", action='store_true',
30+
help='Whether to compute gradients (default: False)')
2131

2232
args = parser.parse_args()
2333

2434
fname = args.func
2535
nsam = args.npts
36+
grad = args.grad
37+
sig = args.sig
38+
xtrain_file = args.xtrain_file
2639

27-
if fname == 'lj':
28-
fcn = chem.LennardJones()
29-
elif fname == 'mb':
30-
fcn = chem.MullerBrown()
31-
else:
32-
print(f'Function {fcn} is unknown. Please use -h to see the options. Exiting.')
40+
try:
41+
fcn = fcn_dict[fname]
42+
print(f"{nsam} samples of function {fname} requested.")
43+
except KeyError:
44+
print(f'Function {fname} is unknown. Please use -h to see the options. Exiting.')
3345
sys.exit()
3446

35-
xx = fcn.sample_uniform(nsam)
47+
if xtrain_file is None:
48+
xx = fcn.sample_uniform(nsam)
49+
else:
50+
xx = np.loadtxt(xtrain_file)
51+
if len(xx.shape)==1:
52+
xx = xx.reshape(-1, 1)
53+
print(f"Input data file {xtrain_file} has {xx.shape[0]} samples, ignoring the -n flag.")
54+
55+
nsam, ndim = xx.shape
56+
assert(ndim==fcn.dim)
3657

3758
yy = fcn(xx)
38-
gg = fcn.grad(xx) #nsam, nout, ndim
39-
nsam_, nout, ndim = gg.shape
40-
gg = gg.reshape(nsam, nout*ndim)
59+
yy += sig * np.random.randn(*yy.shape)
60+
print("Data noise sigma =", sig)
61+
_, nout = yy.shape
62+
assert(nout==fcn.outdim)
63+
4164

4265
np.savetxt('xtrain.txt', xx)
4366
np.savetxt('ytrain.txt', yy)
44-
np.savetxt('gtrain.txt', gg)
67+
print("Input data saved to xtrain.txt with shape ", xx.shape)
68+
print("Output data saved to ytrain.txt with shape ", yy.shape)
69+
if grad:
70+
gg = fcn.grad(xx) #nsam, nout, ndim
71+
gg = gg.reshape(nsam, nout*ndim)
72+
np.savetxt('gtrain.txt', gg)
73+
print(f"Gradient data saved to gtrain.txt with shape ({nsam}, {nout}x{ndim})")
74+
75+

apps/uqpc/uq_pc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111

1212
from pytuq.rv.pcrv import PCRV
13-
from pytuq.func.benchmark import Ishigami
13+
from pytuq.func.bench import Ishigami
1414
from pytuq.utils.xutils import savepk
1515
from pytuq.utils.mindex import get_mi, get_npc
1616
from pytuq.workflows.fits import pc_fit
0 Bytes
Binary file not shown.

docs/auto_examples/ex_nn.zip

0 Bytes
Binary file not shown.

docs/auto_examples/ex_pce.zip

0 Bytes
Binary file not shown.

docs/misc/about.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The Python Toolkit for Uncertainty Quantification (PyTUQ) is a Python-only set o
1212
- Methods for Gaussian process regression
1313
- Global sensitivity analysis methods
1414
- SVD-based dimensionality reduction techniques
15-
- Karhunen-Loeve expansions
15+
- Karhunen-Loève expansions
1616
- Various methods for linear regression
1717
- Bayesian compressive sensing techniques
1818
- MCMC classes for calibration and parameter inference
@@ -22,9 +22,18 @@ The Python Toolkit for Uncertainty Quantification (PyTUQ) is a Python-only set o
2222

2323
Authors
2424
--------
25-
- Khachik Sargsyan
26-
- Bert Debusschere
27-
- Emilie Grace Baillo
25+
- Khachik Sargsyan (Sandia National Laboratories)
26+
- Bert Debusschere (Sandia National Laboratories)
27+
- Emilie Grace Baillo (Sandia National Laboratories)
28+
29+
Contributors
30+
-------------
31+
- Habib N. Najm (Sandia National Laboratories)
32+
- Javier Murgoitio-Esandi (Google)
33+
- Cosmin Safta (Sandia National Laboratories)
34+
- Joy Bahr-Mueller (Sandia National Laboratories)
35+
- Vahan Sargsyan (Stuyvesant High School)
36+
2837

2938
Acknowledgements
3039
-----------------

examples/ex_bcs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python
2+
"""Example demonstrating Bayesian Compressive Sensing (BCS) for sparse polynomial chaos regression.
23
3-
"""[summary]
4-
5-
[description]
4+
This script shows how to use BCS to construct a sparse polynomial chaos surrogate model
5+
with specified multiindex and model data, comparing predictions with true function values.
66
"""
77
import numpy as np
88
import matplotlib.pyplot as plt

examples/ex_bcs_mindex_growth.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#!/usr/bin/env python
2-
"""An example demonstrating bcs and multiindex growth.
2+
"""Example demonstrating adaptive multiindex growth with Bayesian Compressive Sensing.
3+
4+
This script shows how to iteratively grow a polynomial chaos surrogate using
5+
adaptive multiindex selection and BCS regression for sparse approximation.
36
"""
47
import numpy as np
58

69

710
from pytuq.rv.pcrv import PCRV
811
from pytuq.utils.mindex import get_mi
9-
from pytuq.utils.plotting import myrc, lighten_color, plot_dm, plot_jsens
12+
from pytuq.utils.plotting import myrc, plot_dm
1013
from pytuq.utils.maps import scale01ToDom
1114
from pytuq.lreg.bcs import bcs
12-
from pytuq.utils.mindex import mi_addfront_cons, mi_addfront
15+
from pytuq.utils.mindex import mi_addfront
1316

1417
import pytuq.utils.funcbank as fcb
1518

examples/ex_colors.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env python
2-
"""Example that creates RGB triples."""
2+
"""Example demonstrating color palette generation and visualization.
3+
4+
This script creates and displays a set of RGB color triples using PyTUQ's
5+
plotting utilities, useful for creating consistent color schemes in plots.
6+
"""
37

48
from matplotlib import pyplot as plt
59

0 commit comments

Comments
 (0)