File dicebox.py changed (mode: 100644) (index a800509..c99ff6d) |
... |
... |
class Erjee(Chrt): |
919 |
919 |
|
|
920 |
920 |
|
|
921 |
921 |
|
|
|
922 |
|
|
|
923 |
|
|
|
924 |
|
|
|
925 |
|
|
|
926 |
|
|
|
927 |
|
|
|
928 |
|
# MinEnergyCensoredSampling |
|
929 |
|
class Razitko(Erjee): |
|
930 |
|
#č už mě to dědění nebaví |
|
931 |
|
#ё без поллитры было не разобраться, что этот слоёный пирог делал |
|
932 |
|
def __init__(bx, sample_object, scheme, tri_space='Rn', tree_space=None,\ |
|
933 |
|
sampling_space=None, kechato_space='U', potencial='psee',\ |
|
934 |
|
p_norm=2, budget=1000, \ |
|
935 |
|
LHS_correction=False, design=None): |
|
936 |
|
|
|
937 |
|
bx.scheme = scheme |
|
938 |
|
bx.tri_space = tri_space |
|
939 |
|
if tree_space is None: |
|
940 |
|
bx.tree_space = tri_space |
|
941 |
|
else: |
|
942 |
|
bx.tree_space = tree_space |
|
943 |
|
|
|
944 |
|
if sampling_space is None: |
|
945 |
|
bx.sampling_space = tri_space |
|
946 |
|
else: |
|
947 |
|
bx.sampling_space = sampling_space |
|
948 |
|
|
|
949 |
|
|
|
950 |
|
bx.kechato_space = kechato_space |
|
951 |
|
bx.budget = budget |
|
952 |
|
bx.p_norm = p_norm |
|
953 |
|
bx.potencial = potencial |
|
954 |
|
bx.LHS_correction = LHS_correction |
|
955 |
|
bx.design = design |
|
956 |
|
|
|
957 |
|
# for current candidates |
|
958 |
|
# kandidaty musí být 'judged' a 'assessed' |
|
959 |
|
# viz. regen() |
|
960 |
|
#bx.candidates_index = dict() |
|
961 |
|
# krám, přece třidíme odpad! |
|
962 |
|
bx.former_candidates = [] |
|
963 |
|
bx.unjudged_candidates = [] |
|
964 |
|
|
|
965 |
|
super().__init__(sample_object) |
|
966 |
|
|
|
967 |
|
# přidávání vzorků musí bejt explicitní! |
|
968 |
|
# def add_sample(bx, input_sample): |
|
969 |
|
# bx._logger(msg="we have got new data:", data=input_sample) |
|
970 |
|
# bx.sample_box.add_sample(input_sample) |
|
971 |
|
# # tohle musí převest rozdělení vstupního vzorku na vlastní rozdělení skříňky |
|
972 |
|
# #inner_sample = bx.sample_box.new_sample(input_sample) |
|
973 |
|
# #bx.increment(inner_sample) |
|
974 |
|
|
|
975 |
|
def init_parameters(bx): |
|
976 |
|
""" |
|
977 |
|
Returns dictionary of parameters the DiceBox was initialized with |
|
978 |
|
""" |
|
979 |
|
return {'sample_object':bx.sample_box, 'scheme':bx.scheme.name,\ |
|
980 |
|
'tri_space':bx.tri_space, 'tree_space':bx.tree_space,\ |
|
981 |
|
'sampling_space':bx.sampling_space, 'kechato_space':bx.kechato_space,\ |
|
982 |
|
'potencial':bx.potencial, 'p_norm':bx.p_norm, 'budget':bx.budget,\ |
|
983 |
|
'LHS_correction':bx.LHS_correction, 'design':str(bx.design)} |
|
984 |
|
|
|
985 |
|
def _regen_inside(bx): |
|
986 |
|
failsi = bx.failsi |
|
987 |
|
if np.any(failsi) and not np.all(failsi): |
|
988 |
|
#bx._logger(msg="triangulation started") |
|
989 |
|
bx.__regen_inside() |
|
990 |
|
else: |
|
991 |
|
#č jíž není nutný |
|
992 |
|
#bx.simplex_stats = dict() # for .get_pf_estimation() |
|
993 |
|
bx._logger(msg="triangulation skipped") |
|
994 |
|
|
|
995 |
|
def __regen_inside(bx): |
|
996 |
|
# create .tri triangulation |
|
997 |
|
if bx.nsim > bx.nvar + 1: # incremental triangulation require one more point |
|
998 |
|
try: |
|
999 |
|
# I'll use tri_space as a weigthing space |
|
1000 |
|
# It could be separeted, but I am a little bit tired |
|
1001 |
|
# from so much different spaces over there |
|
1002 |
|
bx.Tri = sx.FastCubatureTriangulation(bx.samplebox, bx.scheme,\ |
|
1003 |
|
tri_space=bx.tri_space, issi=bx.siss, \ |
|
1004 |
|
weighting_space=bx.tri_space, incremental=True,\ |
|
1005 |
|
on_add_simplex=bx._on_add_simplex,\ |
|
1006 |
|
on_delete_simplex=bx._invalidate_simplex) |
|
1007 |
|
|
|
1008 |
|
bx.Tri.integrate() |
|
1009 |
|
#č tri - Deloneho triangulace |
|
1010 |
|
bx.tri = bx.Tri.tri #č všichní tam očekávajou QHull |
|
1011 |
|
|
|
1012 |
|
except BaseException as e: |
|
1013 |
|
#č chcu zachytit spadnuti QHull na začatku, |
|
1014 |
|
#č kdy ještě není dostatek teček. |
|
1015 |
|
#č Jinak je třeba nechat QHull spadnout |
|
1016 |
|
if bx.nsim > 2*bx.nvar + 3: |
|
1017 |
|
#č no to teda ne! |
|
1018 |
|
raise |
|
1019 |
|
else: |
|
1020 |
|
#č lze přípustit chybu triangulace |
|
1021 |
|
bx._logger(msg='triangulation failed') |
|
1022 |
|
|
|
1023 |
|
|
|
1024 |
|
#č tato funkce běží 91% času |
|
1025 |
|
# bottleneck function |
|
1026 |
|
def _handle_changed_triangulation(bx, input_sample): |
|
1027 |
|
""" |
|
1028 |
|
Triangulace zajistěně existuje |
|
1029 |
|
""" |
|
1030 |
|
bx.Tri.update() |
|
1031 |
|
|
|
1032 |
|
|
|
1033 |
|
def get_pf_estimation(bx): |
|
1034 |
|
#č dle toho, čo vidím v kódu (spouští nás .increment()) |
|
1035 |
|
#č přinejmenším konvexní obálka |
|
1036 |
|
#č zajištěně existuje |
|
1037 |
|
if 'tri' in dir(bx): |
|
1038 |
|
return bx.Tri.get_pf_estimation() |
|
1039 |
|
|
|
1040 |
|
#оӵ триангуляци ӧвӧл, иськем... |
|
1041 |
|
#č dostaneme vyrovnané odhady Brna-města (-2) a Brna-venkova (-1) |
|
1042 |
|
pf_inside = bx.siss.estimations[-2] |
|
1043 |
|
pf_outside = bx.siss.estimations[-1] |
|
1044 |
|
|
|
1045 |
|
if np.all(bx.failsi): |
|
1046 |
|
#č veškerej vnitršek je v poruše |
|
1047 |
|
# -1=outside, 0=success, 1=failure, 2=mix |
|
1048 |
|
return {'TRI_estimation': {-1:pf_outside, 0:0, 1:pf_inside, 2:0}, \ |
|
1049 |
|
'vertex_estimation' : pf_inside, \ |
|
1050 |
|
'weighted_vertex_estimation' : pf_inside} |
|
1051 |
|
|
|
1052 |
|
else: |
|
1053 |
|
#č vnitršek je asi v pořadku |
|
1054 |
|
# -1=outside, 0=success, 1=failure, 2=mix |
|
1055 |
|
return {'TRI_estimation': {-1:pf_outside, 0:pf_inside, 1:0, 2:0}, \ |
|
1056 |
|
'vertex_estimation' : 0, \ |
|
1057 |
|
'weighted_vertex_estimation' : 0} |
|
1058 |
|
|
|
1059 |
|
|
|
1060 |
|
#č bejvalej .estimate_simplex() |
|
1061 |
|
#č teď je to kolbek, který volá Triangulation |
|
1062 |
|
def _on_add_simplex(bx, box=None, indices=None, simplex=None, nodes=None, cell_stats=None): |
|
1063 |
|
if cell_stats['event'] == 'mix': |
|
1064 |
|
candidates = CandyBox(nodes, event_id=np.full(len(nodes), 2, dtype=np.int8)) |
|
1065 |
|
|
|
1066 |
|
#č vyhodnotíme je |
|
1067 |
|
bx.assess_candidates(candidates) |
|
1068 |
|
|
|
1069 |
|
#č vzorky je třeba přidát ke kandidatům |
|
1070 |
|
#č jako, nic nepokazí, ale čo tam připadně bylo - přepíše |
|
1071 |
|
bx.candidates_index[tuple(indices)] = candidates |
|
1072 |
|
|
|
1073 |
|
# callback |
|
1074 |
|
#č sx.on_delete_simplex(indices=indices) |
|
1075 |
|
def _invalidate_simplex(bx, indices): |
|
1076 |
|
simplex = tuple(indices) |
|
1077 |
|
|
|
1078 |
|
if simplex in bx.candidates_index: |
|
1079 |
|
bx.candidates_index.pop(simplex) |
|
1080 |
|
|
|
1081 |
|
|
|
1082 |
|
|
|
1083 |
|
|
|
1084 |
|
|
|
1085 |
|
|
|
1086 |
|
|
|
1087 |
|
|
|
1088 |
|
|
|
1089 |
|
|
|
1090 |
|
|
|
1091 |
|
|
|
1092 |
|
|
|
1093 |
|
|
|
1094 |
|
|
|
1095 |
|
|
|
1096 |
|
|
|
1097 |
|
|
|
1098 |
|
|
|
1099 |
|
|
922 |
1100 |
class FullSimpleX: |
class FullSimpleX: |
923 |
1101 |
def export_estimation(bx): |
def export_estimation(bx): |
924 |
1102 |
bx.siss.get_estimations() |
bx.siss.get_estimations() |