|
1 | | -import sys |
2 | | -sys.path.insert(0, '.') |
3 | 1 | import numpy as np |
4 | 2 | import xarray as xr |
5 | 3 |
|
@@ -33,43 +31,47 @@ def objFunc(X): |
33 | 31 |
|
34 | 32 | gauss = Problem(nInput = 2, nOutput = 1, objFunc = objFunc, ub = 10, lb = -10) |
35 | 33 |
|
36 | | - |
37 | 34 | # ------------------------------- # |
38 | 35 | # Gaussian Mixture 4D # |
39 | 36 | # ------------------------------- # |
40 | 37 |
|
41 | | -def objFunc(X): |
| 38 | +# def objFunc(X): |
42 | 39 |
|
43 | | - X = np.atleast_2d(X) |
44 | | - _, D = X.shape |
| 40 | +# X = np.atleast_2d(X) |
| 41 | +# _, D = X.shape |
45 | 42 |
|
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]) |
48 | 45 |
|
49 | | - Sigma1 = np.eye(D) |
50 | | - Sigma2 = np.eye(D) |
| 46 | +# Sigma1 = np.eye(D) |
| 47 | +# Sigma2 = np.eye(D) |
51 | 48 |
|
52 | | - inv1 = np.linalg.inv(Sigma1) |
53 | | - inv2 = np.linalg.inv(Sigma2) |
| 49 | +# inv1 = np.linalg.inv(Sigma1) |
| 50 | +# inv2 = np.linalg.inv(Sigma2) |
54 | 51 |
|
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) |
57 | 54 |
|
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)) |
59 | 56 |
|
60 | | - return f[:, np.newaxis] |
| 57 | +# return f[:, np.newaxis] |
61 | 58 |
|
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") |
63 | 60 |
|
64 | 61 | # ------------------------------------------- # |
65 | 62 | # Metropolis-Hastings # |
66 | 63 | # ------------------------------------------- # |
67 | 64 |
|
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) |
69 | 69 |
|
70 | | -mh = MH(nChains = 10, warmUp = 10, maxIters = 1000, propDist = 'gauss', verboseFlag = True, verboseFreq = 1) |
| 70 | +# res = mh.run(problem = gauss) |
71 | 71 |
|
72 | | -res = mh.run(problem = gauss4) |
| 72 | +# print(res['posterior'].info) |
| 73 | +# print(res['stats'].info) |
| 74 | +# print(res['optimization'].info) |
73 | 75 |
|
74 | 76 | # ------------------------------------------- # |
75 | 77 | # MH-Gibbs # |
|
0 commit comments