File blackbox.py changed (mode: 100644) (index 5697200..b7128ae) |
... |
... |
import inspect # for ._log() function |
24 |
24 |
from .samplebox import SampleBox # for candidates packing |
from .samplebox import SampleBox # for candidates packing |
25 |
25 |
from . import lukiskon as lk |
from . import lukiskon as lk |
26 |
26 |
|
|
|
27 |
|
from . import estimation as stm # for KechatoLukiskon |
27 |
28 |
|
|
28 |
29 |
|
|
29 |
30 |
|
|
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
799 |
800 |
|
|
800 |
801 |
# invalidujeme staré |
# invalidujeme staré |
801 |
802 |
if -2 in bx.candidates_index: |
if -2 in bx.candidates_index: |
802 |
|
pass |
|
|
803 |
|
pass |
803 |
804 |
#D.pop(k[,d]) |
#D.pop(k[,d]) |
804 |
805 |
|
|
805 |
806 |
# pokud není splněná podmínka, |
# pokud není splněná podmínka, |
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
887 |
888 |
|
|
888 |
889 |
def select_candidate(bx): |
def select_candidate(bx): |
889 |
890 |
|
|
890 |
|
|
|
891 |
891 |
# krám, přece třidíme odpad! |
# krám, přece třidíme odpad! |
892 |
892 |
# pokud v tohlenstom krámu najdeme něco slíbného, |
# pokud v tohlenstom krámu najdeme něco slíbného, |
893 |
893 |
# tak tu celou skladku прошерстиме - prohrabáme |
# tak tu celou skladku прошерстиме - prohrabáme |
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
1145 |
1145 |
events[found_simplices >= 0] = bx.get_events()[found_simplices[found_simplices >= 0]] |
events[found_simplices >= 0] = bx.get_events()[found_simplices[found_simplices >= 0]] |
1146 |
1146 |
candidates.event = events |
candidates.event = events |
1147 |
1147 |
|
|
|
1148 |
|
|
|
1149 |
|
|
|
1150 |
|
|
|
1151 |
|
|
|
1152 |
|
|
|
1153 |
|
class KechatoLukiskon(BlackBox): |
|
1154 |
|
def __init__(kl, sample_object, model_space='Rn', sampling_space=None, kechato_space='Rn', p_norm=1, gradient=None, budget=20000): |
|
1155 |
|
kl.model_space = model_space |
|
1156 |
|
kl.sampling_space = sampling_space |
|
1157 |
|
kl.kechato_space = kechato_space |
|
1158 |
|
kl.p_norm = p_norm |
|
1159 |
|
kl.gradient = gradient |
|
1160 |
|
kl.budget = budget |
|
1161 |
|
|
|
1162 |
|
super().__init__(sample_object) |
|
1163 |
|
|
|
1164 |
|
|
|
1165 |
|
def __call__(kl): |
|
1166 |
|
kl._logger(msg="умой! Умойлэсь но умой сэмпл шедьтоно") |
|
1167 |
|
|
|
1168 |
|
if (len(kl.failure_points) < 1) or (len(kl.success_points) < 1): |
|
1169 |
|
kl._logger(msg="Умоез сэмпл шедьтыны уг быгаты :( ") |
|
1170 |
|
return kl.LHS_like_correction(kl.h(1)) |
|
1171 |
|
|
|
1172 |
|
else: |
|
1173 |
|
|
|
1174 |
|
kl.ivortodon = 0 |
|
1175 |
|
kl.to_sample = None |
|
1176 |
|
|
|
1177 |
|
# ty brdo, stm nedává číslo tečky. Nemusí, no... |
|
1178 |
|
kl.i = 0 |
|
1179 |
|
stm.Voronoi_2_point_estimation(kl, model_space=kl.model_space, sampling_space=kl.sampling_space,\ |
|
1180 |
|
p_norm=kl.p_norm, gradient=kl.gradient, budget=kl.budget, callback=kl.callback) |
|
1181 |
|
|
|
1182 |
|
if kl.to_sample is not None: |
|
1183 |
|
# hrubě ošidíme s takovejhlema usilima námi pěčlivě vybraný vzorečiček |
|
1184 |
|
return kl.LHS_like_correction(kl.to_sample) |
|
1185 |
|
else: |
|
1186 |
|
kl._logger(msg="Умоез сэмпл шедьтыны ӧй быгаты :( ") |
|
1187 |
|
return kl.LHS_like_correction(kl.h(1)) |
|
1188 |
|
|
|
1189 |
|
|
|
1190 |
|
def callback(kl, *args, **kwargs): |
|
1191 |
|
# spoléhám na to, že stm vrácí tečky v f-ku |
|
1192 |
|
nodes = kwargs['nodes'] |
|
1193 |
|
node_pf = nodes.node_pf_estimations |
|
1194 |
|
|
|
1195 |
|
mask = (node_pf > 0) * (node_pf < 1) |
|
1196 |
|
nodes = nodes[mask] |
|
1197 |
|
if len(nodes) > 0: |
|
1198 |
|
node_pf = node_pf[mask] |
|
1199 |
|
|
|
1200 |
|
# !!!! ENTROPY !!! |
|
1201 |
|
nodes.entropy = -node_pf*np.log(node_pf) - (1-node_pf)*np.log(1-node_pf) |
|
1202 |
|
|
|
1203 |
|
nodes.ksee = lk.kechato_potential(kl.f_model[kl.i], nodes, kechato_space=kl.kechato_space) |
|
1204 |
|
|
|
1205 |
|
nodes.ivortodon = nodes.entropy * nodes.ksee |
|
1206 |
|
|
|
1207 |
|
if np.max(nodes.ivortodon) > kl.ivortodon: |
|
1208 |
|
# side effects |
|
1209 |
|
kl.ivortodon = np.max(nodes.ivortodon) |
|
1210 |
|
kl.to_sample = nodes[np.argmax(nodes.ivortodon)] |
|
1211 |
|
|
|
1212 |
|
# side effect |
|
1213 |
|
kl.i += 1 |
|
1214 |
|
|
|
1215 |
|
|
|
1216 |
|
|
|
1217 |
|
|
|
1218 |
|
|
File candybox.py changed (mode: 100644) (index dfa1372..e5ef3df) |
... |
... |
class CandyBox: |
95 |
95 |
df = pd.DataFrame(df).T |
df = pd.DataFrame(df).T |
96 |
96 |
|
|
97 |
97 |
# chcem jednoduché numpy-like chovaní |
# chcem jednoduché numpy-like chovaní |
98 |
|
df.reset_index(inplace=True) |
|
|
98 |
|
# dělá problémy |
|
99 |
|
#df.reset_index(inplace=True) |
99 |
100 |
return CandyBox(cb.sampling_plan[slice], df=df) |
return CandyBox(cb.sampling_plan[slice], df=df) |
100 |
101 |
# if not |
# if not |
101 |
102 |
else: |
else: |
|
... |
... |
class CandyBox: |
237 |
238 |
# we'll see, if .new_sample will be needed |
# we'll see, if .new_sample will be needed |
238 |
239 |
# year, we need it |
# year, we need it |
239 |
240 |
# мыным выль сэмпл кулэ! |
# мыным выль сэмпл кулэ! |
240 |
|
def new_sample(cb, input): |
|
|
241 |
|
def new_sample(cb, input=None, space='R'): |
241 |
242 |
# čo to je za vstup? |
# čo to je za vstup? |
242 |
243 |
if hasattr(input, 'sampling_plan'): #sweety_input: |
if hasattr(input, 'sampling_plan'): #sweety_input: |
243 |
244 |
# if pandas |
# if pandas |
244 |
245 |
if hasattr(input, 'df'): |
if hasattr(input, 'df'): |
245 |
|
return CandyBox(cb.sampling_plan.new_sample(input.sampling_plan), df=input.df) |
|
|
246 |
|
return CandyBox(cb.sampling_plan.new_sample(input.sampling_plan, space=space), df=input.df) |
246 |
247 |
|
|
247 |
248 |
# if there is no pandas DataFrame |
# if there is no pandas DataFrame |
248 |
249 |
# we suppose there is dictionary in input.kwargs |
# we suppose there is dictionary in input.kwargs |
249 |
250 |
else: |
else: |
250 |
|
return CandyBox(cb.sampling_plan.new_sample(input.sampling_plan), **input.kwargs) |
|
|
251 |
|
return CandyBox(cb.sampling_plan.new_sample(input.sampling_plan, space=space), **input.kwargs) |
251 |
252 |
|
|
252 |
253 |
# nesladký vstup |
# nesladký vstup |
253 |
254 |
else: |
else: |
254 |
|
return cb.sampling_plan.new_sample(input) |
|
|
255 |
|
return cb.sampling_plan.new_sample(input, space) |
255 |
256 |
|
|
256 |
257 |
|
|
257 |
258 |
|
|