File blackbox.py changed (mode: 100644) (index b7128ae..550ac84) |
... |
... |
from scipy import spatial |
15 |
15 |
from . import plot |
from . import plot |
16 |
16 |
import pickle |
import pickle |
17 |
17 |
from . import IS_stat |
from . import IS_stat |
|
18 |
|
from .candybox import CandyBox |
18 |
19 |
from . import sball # for adaptive censoring |
from . import sball # for adaptive censoring |
19 |
20 |
from . import f_models # for adaptive censoring |
from . import f_models # for adaptive censoring |
20 |
21 |
from scipy import stats # for adaptive censoring |
from scipy import stats # for adaptive censoring |
|
... |
... |
class BlackBox: |
157 |
158 |
if attr == 'blackbox': |
if attr == 'blackbox': |
158 |
159 |
return bx |
return bx |
159 |
160 |
|
|
|
161 |
|
# branime sa rekurzii |
|
162 |
|
# defend against recursion |
|
163 |
|
# рекурсилы пезьдэт! |
|
164 |
|
if attr == 'sample_box': |
|
165 |
|
raise AttributeError |
|
166 |
|
|
160 |
167 |
# По всем вопросам обращайтесь |
# По всем вопросам обращайтесь |
161 |
168 |
# на нашу горячую линию |
# на нашу горячую линию |
162 |
169 |
else: |
else: |
|
... |
... |
class BlackBox: |
184 |
191 |
bx.sorted_plan_U[i] = np.insert(bx.sorted_plan_U[i], plan_index, input_sample.U[j,i]) |
bx.sorted_plan_U[i] = np.insert(bx.sorted_plan_U[i], plan_index, input_sample.U[j,i]) |
185 |
192 |
|
|
186 |
193 |
def regen(bx): |
def regen(bx): |
|
194 |
|
# шайтан регенираци лэзьиз |
|
195 |
|
bx._logger(msg='regeneration started') |
187 |
196 |
# pro LHS_like_correction |
# pro LHS_like_correction |
188 |
197 |
bx.sorted_plan_U = [i for i in range(bx.nvar)] # just create list |
bx.sorted_plan_U = [i for i in range(bx.nvar)] # just create list |
189 |
198 |
for i in range(bx.nvar): |
for i in range(bx.nvar): |
|
... |
... |
class Censoring(BlackBox): |
244 |
253 |
super().__init__(sample_object) |
super().__init__(sample_object) |
245 |
254 |
|
|
246 |
255 |
def __repr__(bx): |
def __repr__(bx): |
247 |
|
return "%s(%s, %s)"%('Censoring', repr(bx.sample_box), repr(bx.tri_space)) |
|
|
256 |
|
return "%s(%s, %s)"%(bx.__class__.__name__, repr(bx.sample_box), repr(bx.tri_space)) |
248 |
257 |
|
|
249 |
258 |
def __str__(bx): |
def __str__(bx): |
250 |
|
return str('Censoring') |
|
|
259 |
|
return str(bx.__class__.__name__) |
251 |
260 |
|
|
252 |
261 |
def increment(bx, input_sample): |
def increment(bx, input_sample): |
253 |
262 |
super().increment(input_sample) |
super().increment(input_sample) |
|
... |
... |
class Censoring(BlackBox): |
267 |
276 |
|
|
268 |
277 |
def regen(bx): |
def regen(bx): |
269 |
278 |
super().regen() |
super().regen() |
|
279 |
|
# chcu zachytit spadnuti QHull na začatku, kdy ještě není dostatek teček. |
|
280 |
|
# Jinak je třeba nechat QHull spadnout |
|
281 |
|
if bx.nsim > 2*bx.nvar + 3: |
|
282 |
|
# tady je to OK |
|
283 |
|
bx.tri = spatial.Delaunay(getattr(bx.sampled_plan, bx.tri_space), incremental=True) |
|
284 |
|
if len(bx.tri.coplanar): |
|
285 |
|
#print('triangulace v pořádku není') |
|
286 |
|
bx._logger(msg='triangulation is coplanar') |
|
287 |
|
else: |
|
288 |
|
#print('triangulace je v pořádku') |
|
289 |
|
bx._logger(msg='triangulation is OK') |
|
290 |
|
|
|
291 |
|
else: # lze přípustit chybu triangulace |
|
292 |
|
try: |
|
293 |
|
bx.tri = spatial.Delaunay(getattr(bx.sampled_plan, bx.tri_space), incremental=True) |
|
294 |
|
except: |
|
295 |
|
bx._logger(msg='triangulation failed') |
|
296 |
|
|
|
297 |
|
|
270 |
298 |
# pokud tecek nestaci na vytvareni aspon jedneho simplexu - pokrcim rameny |
# pokud tecek nestaci na vytvareni aspon jedneho simplexu - pokrcim rameny |
271 |
299 |
try: |
try: |
272 |
300 |
# tady je to OK |
# tady je to OK |
|
... |
... |
class AdaptiveCensoring(Censoring): |
704 |
732 |
|
|
705 |
733 |
|
|
706 |
734 |
|
|
707 |
|
class MinEnergyCensoredSampling(AdaptiveCensoring): |
|
|
735 |
|
class MinEnergyCensoredSampling(Censoring): |
708 |
736 |
# už mě to dědění nebaví |
# už mě to dědění nebaví |
709 |
737 |
# без поллитры не разберёшься, что этот слоёный пирог делает |
# без поллитры не разберёшься, что этот слоёный пирог делает |
710 |
738 |
def __init__(bx, sample_object, tri_space='Rn', tree_space=None, sampling_space=None, kechato_space='U', \ |
def __init__(bx, sample_object, tri_space='Rn', tree_space=None, sampling_space=None, kechato_space='U', \ |
711 |
|
potencial='ksee', p_norm=2, pf_lim=(1,0), budget=1000, simplex_budget=100): |
|
712 |
|
super().__init__(sample_object, tri_space, pf_lim) |
|
|
739 |
|
potencial='ksee', p_norm=2, budget=1000, simplex_budget=100): |
|
740 |
|
|
|
741 |
|
bx.sball = sball.Sball(sample_object.nvar) |
|
742 |
|
bx.base_r = bx.sball.get_r(0.5) |
713 |
743 |
|
|
714 |
744 |
if tree_space is None: |
if tree_space is None: |
715 |
745 |
bx.tree_space = tri_space |
bx.tree_space = tri_space |
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
720 |
750 |
bx.sampling_space = tri_space |
bx.sampling_space = tri_space |
721 |
751 |
else: |
else: |
722 |
752 |
bx.sampling_space = sampling_space |
bx.sampling_space = sampling_space |
723 |
|
|
|
724 |
|
bx.sampling_space = sampling_space |
|
|
753 |
|
|
|
754 |
|
bx.kechato_space = kechato_space |
725 |
755 |
# pro simplexy. Chcu ukladat jejich míry |
# pro simplexy. Chcu ukladat jejich míry |
726 |
|
bx.siss = IS_stat.ISSI() |
|
|
756 |
|
# viz. .regen() |
|
757 |
|
#bx.siss = IS_stat.ISSI() |
727 |
758 |
bx.budget = budget |
bx.budget = budget |
728 |
759 |
bx.simplex_budget = simplex_budget |
bx.simplex_budget = simplex_budget |
729 |
760 |
bx.p_norm = p_norm |
bx.p_norm = p_norm |
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
731 |
762 |
|
|
732 |
763 |
# for current candidates |
# for current candidates |
733 |
764 |
# kandidaty musí být 'judged' a 'assessed' |
# kandidaty musí být 'judged' a 'assessed' |
734 |
|
bx.candidates_index = dict() |
|
|
765 |
|
# viz. regen() |
|
766 |
|
#bx.candidates_index = dict() |
735 |
767 |
# krám, přece třidíme odpad! |
# krám, přece třidíme odpad! |
736 |
768 |
bx.former_candidates = [] |
bx.former_candidates = [] |
737 |
769 |
bx.unjudged_candidates = [] |
bx.unjudged_candidates = [] |
738 |
770 |
# user .candidates should be initializated in the base class |
# user .candidates should be initializated in the base class |
739 |
771 |
# but we need to set additional attributes to them |
# but we need to set additional attributes to them |
|
772 |
|
super().__init__(sample_object, tri_space) |
740 |
773 |
bx.candidates = CandyBox(bx.f()) |
bx.candidates = CandyBox(bx.f()) |
741 |
774 |
|
|
742 |
775 |
|
|
|
776 |
|
|
|
777 |
|
|
743 |
778 |
def regen(bx): |
def regen(bx): |
744 |
779 |
""" |
""" |
745 |
780 |
regen() recreates data structures of the box. |
regen() recreates data structures of the box. |
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
748 |
783 |
super().regen() |
super().regen() |
749 |
784 |
# zás mám vyhodit odhady? |
# zás mám vyhodit odhady? |
750 |
785 |
bx.siss = IS_stat.ISSI() |
bx.siss = IS_stat.ISSI() |
|
786 |
|
bx.candidates_index = dict() |
751 |
787 |
|
|
752 |
|
# chcu zachytit spadnuti QHull na začatku, kdy ještě není |
|
753 |
|
# dostatek teček. Je-li bx.tri fakticky existuje, tj. |
|
754 |
|
# triangulace jíž existovala - je třeba nechat QHull spadnout |
|
755 |
|
choose = bx.LHS_like_correction(bx.get_candidates(1)) |
|
756 |
|
if bx.nsim < bx.nvar + 1: # je to legální |
|
757 |
|
bx._log("we have no enough points to build the triangulation, so", str(choose), "is our recommendation") |
|
758 |
|
return choose |
|
|
788 |
|
if "tri" in dir(bx): |
|
789 |
|
# tri - Deloneho triangulace |
|
790 |
|
bx.simplex_events = bx.get_events() |
|
791 |
|
bx.estimate_outside() |
|
792 |
|
for simplex_id in range(bx.tri.nsimplex): |
|
793 |
|
# zde jen počítame |
|
794 |
|
bx.estimate_simplex(simplex_id) |
|
795 |
|
|
|
796 |
|
|
|
797 |
|
elif bx.nsim > 0: # požaduji, aby nějaké těčíčky byly vždy pritomné |
759 |
798 |
|
|
760 |
|
elif bx.nsim < 2*bx.nvar + 3: # to je ještě budiž |
|
761 |
|
bx._log("we have troubles with the triangulation, so we offer this random sample for now:", str(choose)) |
|
762 |
|
return choose |
|
763 |
|
else: # no to teda ne! |
|
764 |
|
raise ValueError("AdaptiveCensoring: s tou triangulací je fakt něco není v pořadku") |
|
|
799 |
|
candidates = IS_stat.IS(bx.f, bx.h, space_from_h='R', space_to_f=bx.sampling_space, Nsim=bx.budget) |
|
800 |
|
# nevím co tam bylo za h-ko, ale nechť IM zůstane 1 |
|
801 |
|
implicit_multiplicator = 1 |
|
802 |
|
|
|
803 |
|
# teoreticky lze |
|
804 |
|
#bx.siss.add_IS_serie(candidates.w, candidates.simplex, implicit_multiplicator) |
|
805 |
|
|
|
806 |
|
bx.assess_candidates(candidates) |
|
807 |
|
# uložíme |
|
808 |
|
bx.candidates_index[-1] = candidates |
|
809 |
|
|
|
810 |
|
|
|
811 |
|
|
|
812 |
|
|
|
813 |
|
|
|
814 |
|
|
|
815 |
|
def export_estimation(bx): |
|
816 |
|
simplices = np.array(tuple(bx.siss.estimations.keys())) |
|
817 |
|
probabilities = np.array(tuple(bx.siss.estimations.values())) |
|
818 |
|
|
|
819 |
|
estimation = dict() |
|
820 |
|
estimation[-1] = np.sum(probabilities[simplices == -1]) |
|
821 |
|
|
|
822 |
|
# jevy aj klidně in-place (nerobím kopiju) |
|
823 |
|
events = simplices[simplices != -1] |
|
824 |
|
probabilities = probabilities[simplices != -1] |
|
825 |
|
|
|
826 |
|
# zhruba - get_events() vrací pole s odpovidajícími čísly jevů pro každý simplex, počineje od nuly |
|
827 |
|
# tím slajsingem my jakoby vybirame ke každemu nalezenemu simplexovi ten správnej mu odpovídajicí jev |
|
828 |
|
events = bx.simplex_events[events] |
|
829 |
|
|
|
830 |
|
for i in range(3): # kvůli 0,1,2 robiť cyklus? |
|
831 |
|
estimation[i] = np.sum(probabilities[events == i]) |
|
832 |
|
|
|
833 |
|
bx.guessbox.guess('TRI_overall_estimations', bx.tri.npoints, estimation) |
765 |
834 |
|
|
766 |
835 |
|
|
767 |
836 |
def increment(bx, input_sample): |
def increment(bx, input_sample): |
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
775 |
844 |
|
|
776 |
845 |
|
|
777 |
846 |
|
|
778 |
|
# current estimations |
|
779 |
|
try: # to čo já vidím v kódu - ISSI slovníky se pokažde generujóu znovu, |
|
780 |
|
# není nutně je explicitně kopirovať |
|
781 |
|
# nsimky, Alexi, prosím, překopej |
|
782 |
|
bx.guessbox.guess('TRI_overall_estimations', bx.nsim-1, bx.oiss.estimations) |
|
783 |
|
bx.guessbox.guess('TRI_current_estimations', bx.nsim-1, bx.ciss.estimations) |
|
784 |
|
except AttributeError: |
|
785 |
|
bx.guessbox.guess('TRI_upper_pf', bx.nsim-1, 1) |
|
786 |
|
|
|
787 |
|
|
|
788 |
847 |
# fór je v tom, že tu triangulaci nemůžeme výtvořit hned na začátku |
# fór je v tom, že tu triangulaci nemůžeme výtvořit hned na začátku |
789 |
848 |
if "tri" in dir(bx): |
if "tri" in dir(bx): |
790 |
849 |
# tri - Deloneho triangulace |
# tri - Deloneho triangulace |
791 |
850 |
|
|
|
851 |
|
bx.export_estimation() |
|
852 |
|
|
|
853 |
|
# чыры-пыры |
|
854 |
|
# invalidujeme staré vzorky |
|
855 |
|
if -2 in bx.candidates_index: |
|
856 |
|
bx.former_candidates.append(bx.candidates_index.pop(-2)) |
|
857 |
|
|
|
858 |
|
|
792 |
859 |
former_simplices = bx.tri.simplices |
former_simplices = bx.tri.simplices |
|
860 |
|
mixed = bx.is_mixed() |
793 |
861 |
|
|
794 |
862 |
# sample je jíž převeden na f (v .add_sample()), takže je to bezpěčný |
# sample je jíž převeden na f (v .add_sample()), takže je to bezpěčný |
795 |
863 |
bx.tri.add_points(getattr(input_sample, bx.tri_space)) |
bx.tri.add_points(getattr(input_sample, bx.tri_space)) |
|
864 |
|
bx.simplex_events = bx.get_events() |
796 |
865 |
# print('increment se podaril') |
# print('increment se podaril') |
797 |
866 |
if len(bx.tri.coplanar): # pokud triangulace není v pořadku |
if len(bx.tri.coplanar): # pokud triangulace není v pořadku |
798 |
867 |
#print('triangulace v pořádku není') |
#print('triangulace v pořádku není') |
799 |
868 |
bx._logger(msg='triangulation has coplanar points') |
bx._logger(msg='triangulation has coplanar points') |
800 |
869 |
|
|
801 |
|
# invalidujeme staré |
|
802 |
|
if -2 in bx.candidates_index: |
|
803 |
|
pass |
|
804 |
|
#D.pop(k[,d]) |
|
805 |
870 |
|
|
806 |
|
# pokud není splněná podmínka, |
|
807 |
|
# tak nemáme jistotu, že se potenciály nezměni |
|
808 |
|
# ani u kandidatů, které se nacházejí v pojíštěných státem buňkách |
|
809 |
|
if (bx.tree_space != bx.tri_space) or (bx.p_norm != 2): |
|
810 |
|
for candidates in bx.candidates_index.values(): |
|
811 |
|
bx.assess_candidates(candidates) |
|
812 |
871 |
|
|
813 |
872 |
|
|
814 |
873 |
# zkontrolujeme co se změnilo |
# zkontrolujeme co se změnilo |
815 |
874 |
# předpokladám, že se počet simplexů přidaním bodů nezměnší |
# předpokladám, že se počet simplexů přidaním bodů nezměnší |
816 |
875 |
equal_mask = former_simplices == bx.tri.simplices[:len(former_simplices)] |
equal_mask = former_simplices == bx.tri.simplices[:len(former_simplices)] |
817 |
|
changed_simplices_ids = np.argwhere(~equal_mask) |
|
|
876 |
|
changed_simplices_ids = np.argwhere(~equal_mask.all(axis=1)).flatten() |
|
877 |
|
|
|
878 |
|
# invalidirujeme jejich odhady |
818 |
879 |
for simplex_id in changed_simplices_ids: |
for simplex_id in changed_simplices_ids: |
819 |
|
# invalidirujeme jejich odhady |
|
820 |
880 |
bx.siss.delete_event_data(simplex_id) |
bx.siss.delete_event_data(simplex_id) |
821 |
|
# a hned je znovu spočítame |
|
822 |
|
bx.simplex_estimation(simplex_id) |
|
|
881 |
|
|
|
882 |
|
# popajem pouze mixy, ty musel jsem spočítat před aktualizací |
|
883 |
|
for simplex_id in changed_simplices_ids[mixed[changed_simplices_ids]]: |
|
884 |
|
bx.former_candidates.append(bx.candidates_index.pop(simplex_id)) |
|
885 |
|
|
|
886 |
|
|
|
887 |
|
# pokud není splněná podmínka, |
|
888 |
|
# tak nemáme jistotu, že se potenciály nezměni |
|
889 |
|
# ani u kandidatů, které se nacházejí v pojíštěných státem buňkách |
|
890 |
|
if (bx.tree_space != bx.tri_space) or (bx.p_norm != 2): |
|
891 |
|
for candidates in bx.candidates_index.values(): |
|
892 |
|
bx.assess_candidates(candidates) |
|
893 |
|
|
|
894 |
|
# změněné simplexy přepočítáme |
|
895 |
|
for simplex_id in changed_simplices_ids: |
|
896 |
|
bx.estimate_simplex(simplex_id) |
|
897 |
|
|
823 |
898 |
|
|
824 |
899 |
|
|
825 |
900 |
# teď nové simplexy |
# teď nové simplexy |
826 |
901 |
# simplexy свежего разлива |
# simplexy свежего разлива |
827 |
|
for simplex_id in range(len(former_simplices), len(bx.tri.simplices)): |
|
|
902 |
|
for simplex_id in range(len(former_simplices), bx.tri.nsimplex): |
828 |
903 |
# zde jen počítame |
# zde jen počítame |
829 |
|
bx.simplex_estimation(simplex_id) |
|
|
904 |
|
bx.estimate_simplex(simplex_id) |
830 |
905 |
|
|
831 |
906 |
|
|
832 |
907 |
|
|
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
836 |
911 |
test = input_sample.simplex > -1 |
test = input_sample.simplex > -1 |
837 |
912 |
# эскером |
# эскером |
838 |
913 |
if not test.all(): |
if not test.all(): |
839 |
|
bx.outside_estimation() |
|
|
914 |
|
bx.former_candidates.append(bx.candidates_index.pop(-1)) |
|
915 |
|
bx.siss.delete_event_data(-1) |
|
916 |
|
bx.estimate_outside() |
840 |
917 |
except BaseException as e: |
except BaseException as e: |
841 |
918 |
msg = "input sample didn't provide correct 'simplex' attribute " |
msg = "input sample didn't provide correct 'simplex' attribute " |
842 |
919 |
error_msg = bx.__class__.__name__ + ": " + msg + repr(e) |
error_msg = bx.__class__.__name__ + ": " + msg + repr(e) |
843 |
920 |
bx._logger(msg=error_msg) |
bx._logger(msg=error_msg) |
844 |
|
bx.outside_estimation() |
|
|
921 |
|
bx.former_candidates.append(bx.candidates_index.pop(-1)) |
|
922 |
|
bx.siss.delete_event_data(-1) |
|
923 |
|
bx.estimate_outside() |
845 |
924 |
|
|
846 |
925 |
|
|
847 |
926 |
|
|
848 |
|
for i in range(len(bx.tri.simplices)): |
|
849 |
|
len(np.setdiff1d(simplex, bx.failure_points)) |
|
850 |
927 |
|
|
851 |
|
# drop indexes |
|
852 |
|
bx.simplex_index = {'failure':[], 'success':[], 'mix':[]} |
|
853 |
|
|
|
854 |
|
# a znovu začneme počítat |
|
855 |
|
# -1 = 'out', 0=success, 1=failure, 2=mix |
|
856 |
|
bx.ciss = IS_stat.ISSI([-1,0,1,2]) |
|
857 |
|
|
|
858 |
|
elif bx.nsim > bx.nvar: |
|
|
928 |
|
else: |
859 |
929 |
bx._logger('Triangulace (zatím?) neexistuje') |
bx._logger('Triangulace (zatím?) neexistuje') |
860 |
930 |
bx.regen() |
bx.regen() |
861 |
931 |
|
|
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
881 |
951 |
bx._logger(msg="median first!") |
bx._logger(msg="median first!") |
882 |
952 |
return bx.LHS_like_correction(bx.h(1)) |
return bx.LHS_like_correction(bx.h(1)) |
883 |
953 |
else: |
else: |
|
954 |
|
selected = bx.select_candidate() |
884 |
955 |
# hrubě ošidíme s takovejhlema usilima námi pěčlivě vybraný vzorečiček |
# hrubě ošidíme s takovejhlema usilima námi pěčlivě vybraný vzorečiček |
885 |
|
return bx.LHS_like_correction(bx.select_candidate()) |
|
|
956 |
|
selected.sampling_plan = bx.LHS_like_correction(selected) |
|
957 |
|
return selected |
886 |
958 |
|
|
887 |
959 |
|
|
888 |
960 |
|
|
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
917 |
989 |
# -1 = 'out', 0=success, 1=failure, 2=mix |
# -1 = 'out', 0=success, 1=failure, 2=mix |
918 |
990 |
candidates = candidates[candidates.event != 0] |
candidates = candidates[candidates.event != 0] |
919 |
991 |
candidates = candidates[candidates.event != 1] |
candidates = candidates[candidates.event != 1] |
920 |
|
if len(candidates) > 0: |
|
921 |
|
# uvalíme pokutu |
|
922 |
|
bx.assess_candidates(candidates) |
|
923 |
|
# uložíme |
|
924 |
|
bx.candidates_index[-1].add_sample(candidates[candidates.event == -1] ) |
|
|
992 |
|
# uvalíme pokutu |
|
993 |
|
bx.assess_candidates(candidates) |
|
994 |
|
# uložíme |
|
995 |
|
bx.candidates_index[-1].add_sample(candidates[candidates.event == -1] ) |
|
996 |
|
if len(candidates[candidates.event == 2]) > 0: |
925 |
997 |
# -2 je určen pro zbytky, кылем-мылем |
# -2 je určen pro zbytky, кылем-мылем |
926 |
998 |
bx.candidates_index[-2] = candidates[candidates.event == 2] |
bx.candidates_index[-2] = candidates[candidates.event == 2] |
927 |
999 |
|
|
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
933 |
1005 |
highest_bid = 0 |
highest_bid = 0 |
934 |
1006 |
for candidates in bx.candidates_index.values(): |
for candidates in bx.candidates_index.values(): |
935 |
1007 |
bids = getattr(candidates, bx.potencial) |
bids = getattr(candidates, bx.potencial) |
936 |
|
bid = max(bids) |
|
|
1008 |
|
bid = np.max(bids) |
937 |
1009 |
# side effect |
# side effect |
938 |
1010 |
if bid > highest_bid: |
if bid > highest_bid: |
939 |
1011 |
bidder = candidates[np.argmax(bids)] |
bidder = candidates[np.argmax(bids)] |
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
1010 |
1082 |
# -1 = 'out', 0=success, 1=failure, 2=mix |
# -1 = 'out', 0=success, 1=failure, 2=mix |
1011 |
1083 |
candidates = candidates[candidates.event != 0] |
candidates = candidates[candidates.event != 0] |
1012 |
1084 |
candidates = candidates[candidates.event != 1] |
candidates = candidates[candidates.event != 1] |
1013 |
|
if len(candidates) > 0: |
|
1014 |
|
# uvalíme pokutu |
|
1015 |
|
bx.assess_candidates(candidates) |
|
1016 |
|
# uložíme |
|
1017 |
|
bx.candidates_index[-1] = candidates[candidates.event == -1] |
|
|
1085 |
|
# uvalíme pokutu |
|
1086 |
|
bx.assess_candidates(candidates) |
|
1087 |
|
# uložíme |
|
1088 |
|
bx.candidates_index[-1] = candidates[candidates.event == -1] |
|
1089 |
|
if len(candidates[candidates.event == 2]) > 0: |
1018 |
1090 |
# -2 je určen pro zbytky, кылем-мылем |
# -2 je určen pro zbytky, кылем-мылем |
1019 |
1091 |
bx.candidates_index[-2] = candidates[candidates.event == 2] |
bx.candidates_index[-2] = candidates[candidates.event == 2] |
1020 |
1092 |
|
|
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
1036 |
1108 |
# multiply by simplex_volume, but it looks like it shouldn't be here |
# multiply by simplex_volume, but it looks like it shouldn't be here |
1037 |
1109 |
# for simplex: d = nvar+2 |
# for simplex: d = nvar+2 |
1038 |
1110 |
# sice to má nazev h_plan, ale nese rozdělení a hustoty v f-ku |
# sice to má nazev h_plan, ale nese rozdělení a hustoty v f-ku |
1039 |
|
h_plan = IS_like(vertices, sampling_space=bx.sampling_space, nis=bx.simplex_budget, d=bx.nvar+2) |
|
|
1111 |
|
h_plan = IS_stat.IS_like(vertices, sampling_space=bx.sampling_space, nis=bx.simplex_budget, d=bx.nvar+2) |
1040 |
1112 |
|
|
1041 |
1113 |
# nejdřív vyfiltrujeme vzorky, pak budeme řešit hustoty |
# nejdřív vyfiltrujeme vzorky, pak budeme řešit hustoty |
1042 |
1114 |
# |
# |
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
1063 |
1135 |
|
|
1064 |
1136 |
# fp like a failure points. Number of failure points |
# fp like a failure points. Number of failure points |
1065 |
1137 |
# intersect 2 times faster than setdiff (in my tests) |
# intersect 2 times faster than setdiff (in my tests) |
1066 |
|
fp = len(np.intersect1d(simplex, sample_box.failure_points, assume_unique=True)) |
|
|
1138 |
|
fp = len(np.intersect1d(simplex, bx.sample_box.failure_points, assume_unique=True)) |
1067 |
1139 |
# -1 = 'out', 0=success, 1=failure, 2=mix |
# -1 = 'out', 0=success, 1=failure, 2=mix |
1068 |
|
if fp == nvar + 1: |
|
|
1140 |
|
if fp == bx.nvar + 1: |
1069 |
1141 |
pass |
pass |
1070 |
1142 |
#event = 'failure' |
#event = 'failure' |
1071 |
1143 |
#event_id = 0 |
#event_id = 0 |
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
1123 |
1195 |
ksee = np.empty(len(candidates)) |
ksee = np.empty(len(candidates)) |
1124 |
1196 |
for i in np.unique(ii): |
for i in np.unique(ii): |
1125 |
1197 |
# doufám, že je to legální |
# doufám, že je to legální |
1126 |
|
ksee[i==ii] = lk.kechato_potential(bx.f_model[i], candidates, kechato_space=bx.kechato_space) |
|
|
1198 |
|
ksee[i==ii] = lk.kechato_potential(bx.f_model[i], candidates[i==ii], kechato_space=bx.kechato_space) |
1127 |
1199 |
candidates.ksee = ksee |
candidates.ksee = ksee |
1128 |
1200 |
|
|
1129 |
1201 |
|
|
|
... |
... |
class MinEnergyCensoredSampling(AdaptiveCensoring): |
1142 |
1214 |
|
|
1143 |
1215 |
candidates.simplex = found_simplices |
candidates.simplex = found_simplices |
1144 |
1216 |
events = found_simplices.copy() |
events = found_simplices.copy() |
1145 |
|
events[found_simplices >= 0] = bx.get_events()[found_simplices[found_simplices >= 0]] |
|
|
1217 |
|
# black magic |
|
1218 |
|
# zhruba - get_events() vrací pole s odpovidajícími čísly jevů pro každý simplex, počineje od nuly |
|
1219 |
|
# tím slajsingem my jakoby vybirame ke každemu nalezenemu simplexovi ten správnej mu odpovídajicí jev |
|
1220 |
|
events[found_simplices >= 0] = bx.simplex_events[found_simplices[found_simplices >= 0]] |
1146 |
1221 |
candidates.event = events |
candidates.event = events |
1147 |
1222 |
|
|
1148 |
1223 |
|
|