-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex2-intersetion-of-Nsphere-and-3product.jl
81 lines (66 loc) · 2.01 KB
/
ex2-intersetion-of-Nsphere-and-3product.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# ************************************
# This file specifies the model.
# ************************************
# the reaction coordniate map \xi: \mathbb{R}^d -> \mathbb{R}^k
d = 10
k = 2
beta = 1.0
# parameters of the ellipse
R = 3.0
c= 2.0
# how many different quantities of interest (QoI) will be recorded
num_qoi = 5
# for each quantity of interest, it contains number of bins, lower and upper ranges of the histgram.
qoi_hist_info = [[4, -0.5, 3.5], [300, -3.0, 3.0], [300, -3.0, 3.0], [300, -3.0, 3.0], [300, -3.0, 3.0]]
# initial state
x0 = ones(d)
x0[1] = 2.0
# user-defined prob. distribution
pj_vec = [[1.0], [0.4, 0.6], [0.2, 0.4, 0.4], [0.2, 0.3, 0.3, 0.2]]
# potential in the target distribution
function V(x)
return 0.5 * (x[1]-0.6)^2
end
# gradient of potential V
function grad_V(x)
tmp = zeros(d)
tmp[1] = x[1] - 0.6
return tmp
end
# quantity of interest
function QoI(x)
idx = 1 * (x[1] > 0) + 2 * (x[2] > 0) + 3 * (x[3] > 0)
if idx == 6
idx = 0
end
return [idx, x[1], x[2], x[3], x[4]]
end
# the ith component \xi_i of the map \xi.
# In this example, k=2, therefore, i=1 or 2.
function xi_i(x, idx)
if idx == 1
return prod(x[1:3]) - c
else
return 0.5 * (sum(x .^ 2) - R^2)
end
end
# gradient of the ith component \xi_i of the map \xi
function grad_xi_i(x, idx)
if idx == 1
tmp_vec = zeros(d)
tot_prod = prod(x[1:3])
tmp_vec[1:3] = [tot_prod/x[i] for i in 1:3]
return tmp_vec
else
return x
end
end
if solve_multiple_solutions_frequency > 0
# initialize constraint equation for HomotopyContinuation
@polyvar lam[1:k] p[1:((1+k)*d)]
# equations of the Lagrange multipliers, p contains parameters, lam is the unknown multipliers
#
# The general form is \xi_i(x + \nabla\xi \lam) = 0,
# where \lam is the unknown multipliers, x is given by p[1:d], and \nabla\xi is given by p[(d+1):((k+1)*d)]
F = [prod([(p[i] + p[d+i]*lam[1] + p[2*d+i]*lam[2]) for i in 1:3]) - c, 0.5 * (sum([(p[i] + p[d+i]*lam[1] + p[2*d+i]*lam[2])^2 for i in 1:d]) - R^2) ]
end