Skip to content

Commit a886a8b

Browse files
committed
'1214'
1 parent a090911 commit a886a8b

File tree

10 files changed

+108
-235
lines changed

10 files changed

+108
-235
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44

55
[![PyPI version](https://badge.fury.io/py/UQPyL.svg?icon=si%3Apython&icon_color=%2331aadd)](https://badge.fury.io/py/UQPyL) ![PyPI - Downloads](https://img.shields.io/pypi/dm/UQPyL) ![PyPI - License](https://img.shields.io/pypi/l/UQPyL) ![GitHub last commit](https://img.shields.io/github/last-commit/smasky/UQPyL) ![Static Badge](https://img.shields.io/badge/Author-wmtSky-orange) ![Static Badge](https://img.shields.io/badge/Contact-wmtsmasky%40gmail.com-blue)
66

7-
**UQPyL** is a Python package for **Uncertainty Quantification** and **Optimization** of computational models and their associated problems (e.g., model calibration, resource scheduling, product design). It includes a wide range of methods and algorithms for Design of Experiments, Sensitivity Analysis, Optimization (Single- and Multi-objective). Additionally, **Surrogate Models** are built-in for solving computationally expensive problems.
7+
**UQPyL** is a Python package for **Uncertainty Quantification** and **Optimization** of computational models and their associated problems (e.g., model calibration, resource scheduling, product design). It includes a wide range of methods and algorithms for Design of Experiments, Sensitivity Analysis, Bayesian Inference, Optimization (Single- and Multi-objective). Additionally, **Surrogate Models** are built-in for solving computationally expensive problems.
88

99
👉[中文简介](https://github.com/smasky/UQPyL/blob/dev/README_CN.md)
1010

1111
👉[中文文档](https://swat-uq.readthedocs.io/en/latest/zh/index.html)
1212

1313
👉[Documentation](https://uqpyl.readthedocs.io)
1414

15+
## Changelog
16+
17+
- 2025.12.14: Added the **inference** module. And results are now saved in **NetCDF** format, replacing the previous HDF output.
18+
19+
1520
## Contents
1621

1722
- [Main Features](#-main-features)

docs/quick_start.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ def objFunc_(X):
9595
# Array Mode
9696
def conFunc(X):
9797

98-
cons = X[:, 0]**2 + X[:, 1]**2 + X[:, 2]**2 - 4
98+
cons = 4 - X[:, 0]**2 + X[:, 1]**2 + X[:, 2]**2
9999

100100
return cons[:, None] #keep 2D numpy array
101101

102102
# Single-run Mode
103103
@singleFunc
104104
def conFunc(X):
105105

106-
con = X[0]**2 + X[1]**2 + X[2]**2 - 4
106+
con = 4 - X[0]**2 + X[1]**2 + X[2]**2
107107

108108
return con # scaler value is feasible
109109

examples/temp.py

Lines changed: 0 additions & 142 deletions
This file was deleted.

examples/test_inference.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
sys.path.insert(0, '.')
31
import numpy as np
42
import xarray as xr
53

@@ -33,43 +31,47 @@ def objFunc(X):
3331

3432
gauss = Problem(nInput = 2, nOutput = 1, objFunc = objFunc, ub = 10, lb = -10)
3533

36-
3734
# ------------------------------- #
3835
# Gaussian Mixture 4D #
3936
# ------------------------------- #
4037

41-
def objFunc(X):
38+
# def objFunc(X):
4239

43-
X = np.atleast_2d(X)
44-
_, D = X.shape
40+
# X = np.atleast_2d(X)
41+
# _, D = X.shape
4542

46-
mu1 = np.array([-5.0, 0.0, 0.0, 0.0])
47-
mu2 = np.array([ 5.0, 0.0, 0.0, 0.0])
43+
# mu1 = np.array([-5.0, 0.0, 0.0, 0.0])
44+
# mu2 = np.array([ 5.0, 0.0, 0.0, 0.0])
4845

49-
Sigma1 = np.eye(D)
50-
Sigma2 = np.eye(D)
46+
# Sigma1 = np.eye(D)
47+
# Sigma2 = np.eye(D)
5148

52-
inv1 = np.linalg.inv(Sigma1)
53-
inv2 = np.linalg.inv(Sigma2)
49+
# inv1 = np.linalg.inv(Sigma1)
50+
# inv2 = np.linalg.inv(Sigma2)
5451

55-
e1 = 0.5 * np.sum((X - mu1) @ inv1 * (X - mu1), axis=1)
56-
e2 = 0.5 * np.sum((X - mu2) @ inv2 * (X - mu2), axis=1)
52+
# e1 = 0.5 * np.sum((X - mu1) @ inv1 * (X - mu1), axis=1)
53+
# e2 = 0.5 * np.sum((X - mu2) @ inv2 * (X - mu2), axis=1)
5754

58-
f = -np.log(0.5 * np.exp(-e1) + 0.5 * np.exp(-e2))
55+
# f = -np.log(0.5 * np.exp(-e1) + 0.5 * np.exp(-e2))
5956

60-
return f[:, np.newaxis]
57+
# return f[:, np.newaxis]
6158

62-
gauss4 = Problem(nInput = 4, nOutput = 1, objFunc = objFunc, ub = 10, lb = -10, name = "Gaussian4")
59+
# gauss4 = Problem(nInput = 4, nOutput = 1, objFunc = objFunc, ub = 10, lb = -10, name = "Gaussian4")
6360

6461
# ------------------------------------------- #
6562
# Metropolis-Hastings #
6663
# ------------------------------------------- #
6764

68-
from UQPyL.inference import MH
65+
# from UQPyL.inference import MH
66+
67+
# mh = MH(nChains = 10, warmUp = 10, maxIters = 1000, propDist = 'gauss',
68+
# verboseFlag = True, verboseFreq = 1)
6969

70-
mh = MH(nChains = 10, warmUp = 10, maxIters = 1000, propDist = 'gauss', verboseFlag = True, verboseFreq = 1)
70+
# res = mh.run(problem = gauss)
7171

72-
res = mh.run(problem = gauss4)
72+
# print(res['posterior'].info)
73+
# print(res['stats'].info)
74+
# print(res['optimization'].info)
7375

7476
# ------------------------------------------- #
7577
# MH-Gibbs #

examples/test_optimization.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
import sys
2-
sys.path.insert(0, '.')
3-
41
#---------------------------------------------#
52
# Single Objective Optimization
63
from UQPyL.problem.sop import Sphere
74

8-
problem = Sphere(30)
5+
problem = Sphere(4)
96

107
# ------------------------------------------- #
118
# GA #
129
# ------------------------------------------- #
1310

1411
# from UQPyL.optimization.soea import GA
1512

16-
# for i in range(9):
17-
# ga = GA()
18-
# res = ga.run(problem)
13+
# ga = GA()
14+
# res = ga.run(problem)
1915

16+
# A=1
2017
# ------------------------------------------- #
2118
# PSO #
2219
# ------------------------------------------- #
@@ -37,16 +34,16 @@
3734
# CSA #
3835
# ------------------------------------------- #
3936

40-
# from UQPyL.optimization.soea import CSA
41-
# csa = CSA()
42-
# res = csa.run(problem)
37+
from UQPyL.optimization.soea import CSA
38+
csa = CSA()
39+
res = csa.run(problem)
4340

4441
# ------------------------------------------- #
4542
# SCE-UA #
4643
# ------------------------------------------- #
4744

4845
# from UQPyL.optimization.soea import SCE_UA
49-
# sce_ua = SCE_UA()
46+
# sce_ua = SCE_UA(verboseFreq = 10)
5047
# res = sce_ua.run(problem)
5148

5249
# ------------------------------------------- #

examples/test_plot.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import sys
2-
sys.path.insert(0, '.')
3-
41
from UQPyL.util import plot_op_curve, plot_op_curve_stat, plot_op_pareto, plot_sa, plot_surrogate
52

63
# source = {
@@ -10,6 +7,12 @@
107
# "ABC": "./Result/Data/ABC_Sphere_D30_M1_1.nc",
118
# }
129

10+
# source = {
11+
# "SCE-UA" : "./Result/Data/SCE-UA_Sphere_D4_M1_1.nc",
12+
# "PSO" : "./Result/Data/PSO_Sphere_D4_M1_1.nc",
13+
# "GA" : "./Result/Data/GA_Sphere_D4_M1_1.nc",
14+
# }
15+
1316
# plot_op_curve(source = source, yLog = True, ySmooth = True, markevery = 40, xlim = [0, 1000], xMajorLocator = 100)
1417

1518
# folder = "./Result/Data"
@@ -31,13 +34,13 @@
3134

3235
# three-objective problems
3336

34-
# from UQPyL.problem import DTLZ7
37+
# from UQPyL.problem import DTLZ2
3538

36-
# dtlz = DTLZ7(10)
39+
# dtlz = DTLZ2(10)
3740

3841
# optima = dtlz.getPF()
3942

40-
# filepath = "./Result/Data/NSGAII_DTLZ7_D10_M3_1.nc"
43+
# filepath = "./Result/Data/NSGAII_DTLZ2_D10_M3_1.nc"
4144

4245
# plot_op_pareto(filepath = filepath, optima = optima, xlim = [0, 1], xMajorLocator = 0.1, ylim = [0, 1], yMajorLocator = 0.1)
4346

@@ -48,6 +51,13 @@
4851
# "MARS" : "./Result/Data/MARS_Problem_D8_M1_1.nc",
4952
# }
5053

54+
# source = {
55+
# "Sobol" : "./Result/Data/Sobol_Problem_D3_M1_1.nc",
56+
# "RBD-FAST" : "./Result/Data/RBDFAST_Problem_D3_M1_1.nc",
57+
# "FAST" : "./Result/Data/FAST_Problem_D3_M1_1.nc",
58+
# "MARS" : "./Result/Data/MARS_Problem_D3_M1_1.nc",
59+
# }
60+
5161
# plot_sa(source = source, fontsize = 20)
5262

5363
# from UQPyL.problem import Sphere
@@ -83,10 +93,8 @@
8393

8494
# from UQPyL.util import plot_infer_stat, plot_infer_stat_combined
8595

86-
# filepath = "./Result/Data/MH_Gaussian4_D4_M1_1.nc"
96+
# filepath = "./Result/Data/MH_Problem_D2_M1_1.nc"
8797

8898
# plot_infer_stat(filepath = filepath, fontsize = 20, burnIn = 100)
8999

90100
# plot_infer_stat_combined(filepath = filepath, fontsize = 20, burnIn = 100, showCI = True, CI = 0.95)
91-
92-

examples/test_problem.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import sys
2-
sys.path.insert(0, '.')
3-
41
import numpy as np
52
from UQPyL.problem import Problem, ProblemABC
63
from UQPyL.doe import LHS

0 commit comments

Comments
 (0)