/misc.py (8aac057ad91bea3300c87b1ae30e717aab7e6002) (3164 bytes) (mode 100644) (type blob)
#!/usr/bin/env python
# coding: utf-8
import numpy as np
from scipy import interpolate
from . import sball # for Isocurves
from . import IS_stat
class RBF_surrogate:
def __init__(self, sample_box, space='R'):
self.sample_box = sample_box
self.space = space
self._nsim = -100500
self.update()
def __call__(self, *args):
self.update()
self.rbf(*args)
def update(self):
if self.sample_box.nsim > self._nsim:
sample_space = getattr(self.sample_box, self.space)
self.rbf = interpolate.Rbf(*sample_space.T, self.sample_box.g_values, function='gaussian')
self._nsim = self.sample_box.nsim
def get_pf_estimation(self, nis=100000):
self.update()
nodes = IS_stat.IS_norm(self.sample_box.f_model, mean=0, std=2.5, sampling_space='G', nis=nis, design=None)
gi = self.rbf(*getattr(nodes, self.space).T)
return np.sum(nodes.w[gi<0])/nis
def get_isodistances(f_model, r, nrod=200):
phi = np.linspace(0, 6.283185307, nrod, endpoint=True)
cos_phi = np.cos(phi)
sin_phi = np.sin(phi)
sample_G = np.array((cos_phi, sin_phi)).T * r
return f_model.new_sample(sample_G, space='G', extend=True)
def isolevels_2d(pdf, weighting_pdf_const, r_levels, from_top=None):
"""
weighting_pdf_const = 1 / (xmax - xmin) / (ymax - ymin)
"""
s_ball = sball.Sball(2) # nvar=2
p_levels = []
for r in r_levels:
p_levels.append(1 - s_ball.get_pf(r))
return isolevels(pdf, weighting_pdf_const, p_levels, from_top)
def isolevels(pdf, weighting_pdf_const, p_levels, from_top=None):
"""
weighting_pdf_const = 1 / (xmax - xmin) / (ymax - ymin)
"""
#č třeba P prostor doopravdy zlobí, takže zkusím nějak tak
if from_top is None:
weights = pdf / weighting_pdf_const
p_all = np.sum(weights) / len(pdf)
#č prečo víme, že celková pravděpodobnost může bejt nekoněčně velká
if p_all <= 1:
from_top = True
else:
from_top = False
max_pdf = np.max(pdf)
pdf_levels = []
if from_top:
# descending
sorted_pdf = np.flip(np.sort(pdf))
p_cumsum = np.cumsum(sorted_pdf) / weighting_pdf_const / len(pdf)
for p in p_levels:
# little bit tricky, didn't find numpy method for this
mask = p_cumsum <= p
level_down_bound = np.max(sorted_pdf[~mask], initial=0)
level_up_bound = np.min(sorted_pdf[mask], initial=max_pdf)
pdf_levels.append((level_down_bound + level_up_bound) / 2)
else: # from bottom
sorted_pdf = np.sort(pdf)
p_cumsum = np.cumsum(sorted_pdf) / weighting_pdf_const / len(pdf)
for p in p_levels:
# little bit tricky, didn't find numpy method for this
mask = p_cumsum <= 1-p
level_down_bound = np.max(sorted_pdf[mask], initial=0)
level_up_bound = np.min(sorted_pdf[~mask], initial=max_pdf)
pdf_levels.append((level_down_bound + level_up_bound) / 2)
return pdf_levels
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
28117 |
0907e38499eeca10471c7d104d4b4db30b8b7084 |
IS_stat.py |
100644 |
blob |
6 |
0916b75b752887809bac2330f3de246c42c245cd |
__init__.py |
100644 |
blob |
72 |
458b7e2ca46acd9ec0d2caf3cc4d72e515bb73dc |
__main__.py |
100644 |
blob |
73368 |
3d245b8568158ac63c80fa0847631776a140db0f |
blackbox.py |
100644 |
blob |
11243 |
10c424c2ce5e8cdd0da97a5aba74c54d1ca71e0d |
candybox.py |
100644 |
blob |
60254 |
5e8651af086bf76d45b18fc711fe2ccd015c264a |
closedbox.py |
100644 |
blob |
29927 |
066a2d10ea1d21daa6feb79fa067e87941299ec4 |
convex_hull.py |
100644 |
blob |
101505 |
750fd8843bcd4bb2cb4e13fc4de9b92fcf16f409 |
dicebox.py |
100644 |
blob |
36886 |
d27b8a79485ea48402937e44102a2c44fcef4dc5 |
estimation.py |
100644 |
blob |
34394 |
3f0ab9294a9352a071de18553aa687c2a9e6917a |
f_models.py |
100644 |
blob |
35721 |
3daee87ec0bc670207356490e16f200fed0d4fc4 |
g_models.py |
100644 |
blob |
21043 |
ca09c8a3fdcda14efa46d4a98fc55855773dcbca |
ghull.py |
100644 |
blob |
2718 |
5d721d117448dbb96c554ea8f0e4651ffe9ac457 |
gp_plot.py |
100644 |
blob |
29393 |
96162a5d181b8307507ba2f44bafe984aa939163 |
lukiskon.py |
100644 |
blob |
3164 |
8aac057ad91bea3300c87b1ae30e717aab7e6002 |
misc.py |
040000 |
tree |
- |
ea76ee9256f0f148427487c733a2dc4c00c9fc1a |
mplot |
100644 |
blob |
1462 |
437b0d372b6544c74fea0d2c480bb9fd218e1854 |
plot.py |
100644 |
blob |
2807 |
1feb1d43e90e027f35bbd0a6730ab18501cef63a |
plotly_plot.py |
040000 |
tree |
- |
195fa1f8abb1e3ea0913a85b10e7c51613b705ea |
qt_gui |
100644 |
blob |
8566 |
5c8f8cc2a34798a0f25cb9bf50b5da8e86becf64 |
reader.py |
100644 |
blob |
4284 |
a0e0b4e593204ff6254f23a67652804db07800a6 |
samplebox.py |
100644 |
blob |
6558 |
df0e88ea13c95cd1463a8ba1391e27766b95c3a5 |
sball.py |
100644 |
blob |
6739 |
0b6f1878277910356c460674c04d35abd80acf13 |
schemes.py |
100644 |
blob |
76 |
11b2fde4aa744a1bc9fa1b419bdfd29a25c4d3e8 |
shapeshare.py |
100644 |
blob |
54884 |
fbe116dab4fc19bb7568102de21f53f15a8fc6bf |
simplex.py |
100644 |
blob |
13090 |
2b9681eed730ecfadc6c61b234d2fb19db95d87d |
spring.py |
100644 |
blob |
10953 |
da8a8aaa8cac328ec0d1320e83cb802b562864e2 |
stm_df.py |
040000 |
tree |
- |
4cad9136391e4dd71294c2b0486ab93c31317313 |
testcases |
100644 |
blob |
2465 |
d829bff1dd721bdb8bbbed9a53db73efac471dac |
welford.py |
100644 |
blob |
25318 |
fcdabd880bf7199783cdb9c0c0ec88c9813a5b18 |
whitebox.py |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/iam-git/WellMet
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/iam-git/WellMet
Clone this repository using git:
git clone git://git.rocketgit.com/user/iam-git/WellMet
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main