File testcases/gaussian_2D.py added (mode: 100644) (index 0000000..248a233) |
|
1 |
|
#!/usr/bin/env python |
|
2 |
|
# coding: utf-8 |
|
3 |
|
|
|
4 |
|
""" |
|
5 |
|
We will prepare here WhiteBox instances |
|
6 |
|
of different Gaussian 2D problems |
|
7 |
|
""" |
|
8 |
|
|
|
9 |
|
import numpy as np |
|
10 |
|
from .. import g_models as gm |
|
11 |
|
from .. import f_models |
|
12 |
|
from ..whitebox import WhiteBox |
|
13 |
|
|
|
14 |
|
__all__ = [] |
|
15 |
|
|
|
16 |
|
#č zde ten __all__ těžko dohlídáme |
|
17 |
|
#č budeme přidávat do seznamu postupně |
|
18 |
|
def add(str): __all__.append(str) |
|
19 |
|
|
|
20 |
|
f = f_models.SNorm(2) |
|
21 |
|
|
|
22 |
|
|
|
23 |
|
""" FourBranch2D |
|
24 |
|
g1 = k1 + 0.1*(x1 - x2)**2 - (x1 + x2)/np.sqrt(2) |
|
25 |
|
g2 = k1 + 0.1*(x1 - x2)**2 + (x1 + x2)/np.sqrt(2) |
|
26 |
|
g3 = (x1 - x2) + k2/np.sqrt(2) |
|
27 |
|
g4 = (x2 - x1) + k2/np.sqrt(2) #č byl tu překlep v jednom članku |
|
28 |
|
g = np.min((g1, g2, g3, g4), axis=0)""" |
|
29 |
|
#whitebox.WhiteBox(f, gm.FourBranch2D(k1=3, k2=7)) |
|
30 |
|
# |
|
31 |
|
# Four branch system |
|
32 |
|
add('four_branch') |
|
33 |
|
def four_branch(): |
|
34 |
|
wt = WhiteBox(f, gm.FourBranch2D(k1=3, k2=7)) |
|
35 |
|
wt.pf_exact = 2.34e-03 |
|
36 |
|
wt.pf_exact_method = 'known value' #"some guys said me that" |
|
37 |
|
wt.description = "Four branch system. Structural Safety 62 (2016) 66-75" |
|
38 |
|
return wt |
|
39 |
|
|
|
40 |
|
|
|
41 |
|
add('four_branch_2') |
|
42 |
|
def four_branch_2(): |
|
43 |
|
wt = WhiteBox(f, gm.FourBranch2D(k1=5.5, k2=11)) |
|
44 |
|
# TODO calculate |
|
45 |
|
#wt.pf_exact = 0.257 |
|
46 |
|
#wt.pf_exact_method = 'known value' #"some guys said me that" it's 0.256 |
|
47 |
|
wt.description = "Four branch system from another paper" |
|
48 |
|
return wt |
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
# Breitung |
|
55 |
|
# Piecewise linear function |
|
56 |
|
add('piecewise_linear') |
|
57 |
|
def piecewise_linear(): |
|
58 |
|
wt = WhiteBox(f, gm.piecewise_2D_linear) |
|
59 |
|
wt.description = "Breitung. Piecewise linear function" |
|
60 |
|
return wt |
|
61 |
|
|
|
62 |
|
|
|
63 |
|
""" Logistic2D |
|
64 |
|
# sebemenší parametrizace |
|
65 |
|
y1 = self._c1 - x1 |
|
66 |
|
y2 = self._c2 + x2 |
|
67 |
|
y3 = 1.0/(1+np.exp(-2.0*y2)) - 0.5 |
|
68 |
|
|
|
69 |
|
if self.easy_version: |
|
70 |
|
g = np.minimum(y1,y2) # easy version for SuS |
|
71 |
|
else: |
|
72 |
|
g = np.minimum(y1,y3) # difficult version for SuS""" |
|
73 |
|
#whitebox.WhiteBox(f, gm.Logistic2D(c1=5, c2=4, easy_version=True)) |
|
74 |
|
# Logistic 2D function |
|
75 |
|
add('min_linear') |
|
76 |
|
def min_linear(): |
|
77 |
|
wt = WhiteBox(f, gm.Logistic2D()) |
|
78 |
|
wt.description = "Breitung. 2D linear (easy version for SuS)" |
|
79 |
|
return wt |
|
80 |
|
|
|
81 |
|
add('min_logistic') |
|
82 |
|
def min_logistic(): |
|
83 |
|
wt = WhiteBox(f, gm.Logistic2D(easy_version=False)) |
|
84 |
|
wt.description = "Breitung. Logistic 2D function (hard version for SuS)" |
|
85 |
|
return wt |
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
# soucin velicin plus nějaká konstanta |
|
90 |
|
# g= X1 * X2 * X3 * X4 + c |
|
91 |
|
add('prod_1') |
|
92 |
|
add('prod_5') |
|
93 |
|
def prod_1(): |
|
94 |
|
return WhiteBox(f, gm.Z_prod(const=1)) |
|
95 |
|
def prod_5(): |
|
96 |
|
return WhiteBox(f, gm.Z_prod(const=5)) |
|
97 |
|
|
|
98 |
|
gm_z_prod = gm.Z_prod(const=5) |
|
99 |
|
|
|
100 |
|
def proxy_prod(input_sample): |
|
101 |
|
# očekávam, že get_R_coordinates mně vrátí 2D pole |
|
102 |
|
sample = gm.get_R_coordinates(input_sample, 2) |
|
103 |
|
x, y = sample.T |
|
104 |
|
|
|
105 |
|
# osudná podmínka |
|
106 |
|
mask = np.atleast_1d(np.sign(x)==np.sign(y)).astype(bool) |
|
107 |
|
#č mrdáme na kontrolu. současný startup candybox vytvoří vždycky |
|
108 |
|
input_sample.candybox.proxy = mask |
|
109 |
|
sweet_sample = input_sample |
|
110 |
|
#sweet_sample = CandyBox(input_sample, proxy=mask) |
|
111 |
|
|
|
112 |
|
# zatím, pro jednoduchost, předpokladáme, |
|
113 |
|
# že dostaváme vzorky po jednom |
|
114 |
|
if np.all(mask): |
|
115 |
|
# nevíme vůbec, co to je za funkci |
|
116 |
|
# ale veříme, že víme co tam bude |
|
117 |
|
g = np.full(len(sweet_sample), 1) |
|
118 |
|
# s praznejm podpísem odmítá |
|
119 |
|
return samplebox.SampleBox(sweet_sample, g, 'proxy_prod') |
|
120 |
|
|
|
121 |
|
else: # deme počítat, bez b |
|
122 |
|
true_sample = gm_z_prod(sweet_sample) |
|
123 |
|
# padelame pospís |
|
124 |
|
true_sample.gm_signature = 'proxy_prod' |
|
125 |
|
return true_sample |
|
126 |
|
|
|
127 |
|
# wrap |
|
128 |
|
proxy_prod.get_2D_R_boundary = gm_z_prod.get_2D_R_boundary |
|
129 |
|
|
|
130 |
|
add('proxy_prod_5') |
|
131 |
|
def proxy_prod_5(): |
|
132 |
|
return WhiteBox(f, proxy_prod) |
|
133 |
|
|
|
134 |
|
|
|
135 |
|
""" |
|
136 |
|
c = 0.5 # wave amplitude in Gaussian space |
|
137 |
|
d = 3.0 # average of sine fiunction in Gaussian space |
|
138 |
|
k = 6 # number of sine waves (design points) |
|
139 |
|
""" |
|
140 |
|
add('sinball') |
|
141 |
|
def sinball(): |
|
142 |
|
return WhiteBox(f, gm.S_ballSin2D(c=0.5, d=3.0, k=6)) |
|
143 |
|
|
|
144 |
|
|
|
145 |
|
# Fajvka |
|
146 |
|
# člověk se tu bez půllitry nevýzná |
|
147 |
|
# viz. conic_section_boundaries_test.py pro inspiraciju |
|
148 |
|
add('five') |
|
149 |
|
def five(): |
|
150 |
|
return WhiteBox(f, gm.ConicSection(l=.1, e=1.1, teta=-np.pi/4, c=(-3,1), sign=1)) |
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
# Sin2D |
|
156 |
|
# g = self._kx * x + self._ky * y + np.sin(self._kxsin*x) + self._const |
|
157 |
|
#add('sin') |
|
158 |
|
#def sin(): |
|
159 |
|
# return whitebox.WhiteBox(f, gm.Sin2D(kx=-1/4., ky=-1, kxsin=5, const=5)) |
|
160 |
|
add('sin_shields') |
|
161 |
|
def sin_shields(): |
|
162 |
|
return WhiteBox(f, gm.Sin2D(kx=-1/4., ky=-1, kxsin=5, const=4)) |
|
163 |
|
|
|
164 |
|
|
|
165 |
|
# Prod_FourBetas |
|
166 |
|
# g = beta^2/2 - |x1 * x2| |
|
167 |
|
#č Breitung má |
|
168 |
|
# g = 15 - |x1 * x2| |
|
169 |
|
# beta^2/2 == 15 |
|
170 |
|
# beta == sqrt(30) |
|
171 |
|
add('prod_four_betas') |
|
172 |
|
def prod_four_betas(): |
|
173 |
|
return WhiteBox(f, gm.Prod_FourBetas(beta=np.sqrt(30))) |
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
""" BlackSwan2D |
|
178 |
|
a = 2.0 # boundary for x1 |
|
179 |
|
b = 5.0 # boundary for x2 |
|
180 |
|
y = np.where(sim[:,0] <= a, sim[:,0], sim[:,1]) |
|
181 |
|
# pro x1 <= a y = x1 |
|
182 |
|
# pro x1 > a y = x2 |
|
183 |
|
g = b - y # failure for b<y""" |
|
184 |
|
#whitebox.WhiteBox(f, gm.BlackSwan2D(a=2.0, b=5.0)) |
|
185 |
|
add('black_swan') |
|
186 |
|
def black_swan(): |
|
187 |
|
return WhiteBox(f, gm.BlackSwan2D(a=2.0, b=5.0)) |
|
188 |
|
|
|
189 |
|
|
|
190 |
|
""" Metaballs2D |
|
191 |
|
# sebemenší parametrizace |
|
192 |
|
y1 = 4/9*(x1 + 2 )**2 + 1/25 * (x2 )**2 |
|
193 |
|
y2 = 1/4*(x1 - 2.5)**2 + 1/25 * (x2-0.5)**2 |
|
194 |
|
g = 30.0/( y1**2 + 1.0 ) + 20.0/( y2**2 + 1.0 ) - self._const""" |
|
195 |
|
#whitebox.WhiteBox(f, gm.Metaballs2D(const=5)) |
|
196 |
|
#ё проклял уж всех богов с этой "себеменьшей параметризацией", блин |
|
197 |
|
#č u Breitung'a doopravdy vidím const=5 |
|
198 |
|
add('metaball') |
|
199 |
|
def metaball(): |
|
200 |
|
return WhiteBox(f, gm.Metaballs2D(const=5)) |
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
""" CosExp2D |
|
205 |
|
# sebemenší parametrizace |
|
206 |
|
s = self._s |
|
207 |
|
# g = cos((np.exp(-xm-s ))*xm) * np.exp(-(x +s )/3) |
|
208 |
|
g = np.cos( ( np.exp(-sample[:,0] - s ) )*sample[:,0]) * np.exp( -(sample[:,0] + s )/3 ) """ |
|
209 |
|
#whitebox.WhiteBox(f, gm.CosExp2D(s=5)) |
|
210 |
|
add('cos_exp') |
|
211 |
|
def cos_exp(): |
|
212 |
|
return WhiteBox(f, gm.CosExp2D(s=5)) |
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|