File wellmet/dicebox/circumtri.py changed (mode: 100644) (index f047642..d69f288) |
... |
... |
class CircumTri(_Exploration): |
315 |
315 |
else: |
else: |
316 |
316 |
bx._regen_inside() |
bx._regen_inside() |
317 |
317 |
|
|
318 |
|
|
|
319 |
|
if np.any(bx.convex_hull.is_outside(input_sample)): |
|
|
318 |
|
R2 = np.sum(input_sample.G**2, axis=1) |
|
319 |
|
if bx._nsim > 1 and np.any(R2 > bx.shell_stats.R**2): |
320 |
320 |
bx.to_explore = 0 |
bx.to_explore = 0 |
321 |
321 |
bx.convex_hull.update() |
bx.convex_hull.update() |
322 |
322 |
bx.estimate_outside() |
bx.estimate_outside() |
|
323 |
|
elif np.any(bx.convex_hull.is_outside(input_sample)): |
|
324 |
|
bx.to_refine = 0 |
|
325 |
|
bx.convex_hull.update() |
|
326 |
|
bx.estimate_outside() |
323 |
327 |
else: |
else: |
324 |
328 |
bx.to_refine = 0 |
bx.to_refine = 0 |
325 |
329 |
|
|
|
... |
... |
class CircumTri(_Exploration): |
328 |
332 |
|
|
329 |
333 |
|
|
330 |
334 |
|
|
|
335 |
|
def is_mixed(bx, simplices=None): |
331 |
336 |
|
|
|
337 |
|
if simplices is None: |
|
338 |
|
simplices = bx.tri.simplices |
|
339 |
|
|
|
340 |
|
in_failure = np.isin(simplices, bx.failure_points) |
|
341 |
|
has_failure = in_failure.any(axis=1) |
|
342 |
|
all_failure = in_failure.all(axis=1) |
|
343 |
|
return np.logical_xor(has_failure, all_failure) |
332 |
344 |
|
|
333 |
345 |
|
|
334 |
|
# def _rate_outside_nodes(bx, outside_nodes, d): |
|
335 |
|
# #č sice získáme filtrovaný outside, |
|
336 |
|
# node_potentials = outside_nodes.pdf(bx.tri_space)**(1 / bx.nvar) * d |
|
337 |
|
# |
|
338 |
|
# max_node = np.nanargmax(node_potentials) |
|
339 |
|
# max_node_potential = node_potentials[max_node] |
|
340 |
|
# |
|
341 |
|
# |
|
342 |
|
# if max_node_potential > bx.potential_index[-1]: |
|
343 |
|
# node_rating = 0 #max_node_potential * max_entropy |
|
344 |
|
# if bx.store_candidates_metainformation: |
|
345 |
|
# outside_node = CandyNodes(outside_nodes[max_node]) |
|
346 |
|
# outside_node.potential = max_node_potential |
|
347 |
|
# outside_node.rating = node_rating |
|
348 |
|
# else: |
|
349 |
|
# outside_node = outside_nodes[max_node] |
|
350 |
|
# |
|
351 |
|
# bx.candidates_index[-1] = outside_node |
|
352 |
|
# bx.potential_index.pop(-1) |
|
353 |
|
# bx.potential_index[-1] = max_node_potential |
|
354 |
|
# bx.rating_index.pop(-1, None) |
|
355 |
|
# bx.rating_index[-1] = node_rating |
|
|
346 |
|
def _rate_outside_nodes(bx, outside_nodes, d, i): |
|
347 |
|
failsi = bx.failsi |
|
348 |
|
if np.all(failsi) or not np.any(failsi): |
|
349 |
|
return |
|
350 |
|
|
|
351 |
|
try: |
|
352 |
|
mask = bx.is_mixed(bx.convex_hull.simplices[i]) |
|
353 |
|
if not np.any(mask): |
|
354 |
|
return |
|
355 |
|
outside_nodes = outside_nodes[mask] |
|
356 |
|
d = d[mask] |
|
357 |
|
|
|
358 |
|
except: |
|
359 |
|
pass |
|
360 |
|
|
|
361 |
|
#č konkretně tato třída je pevně napojena na G prostor |
|
362 |
|
#č ale bacha, kbyby se to změnilo... |
|
363 |
|
_d1, i1 = bx.tree.query(outside_nodes.G, k=1) |
|
364 |
|
|
|
365 |
|
PDF = bx.pdf(bx.tri_space) |
|
366 |
|
|
|
367 |
|
nodes_pdf = outside_nodes.pdf(bx.tri_space) |
|
368 |
|
node_potentials = d**bx.nvar * nodes_pdf**bx.psi_q * PDF[i1]**(1-bx.psi_q) |
|
369 |
|
|
|
370 |
|
max_node = np.argmax(node_potentials) |
|
371 |
|
max_node_potential = node_potentials[max_node] |
|
372 |
|
|
|
373 |
|
|
|
374 |
|
if max_node_potential > bx.potential_index[-1]: |
|
375 |
|
if bx.store_candidates_metainformation: |
|
376 |
|
outside_node = CandyNodes(outside_nodes[max_node]) |
|
377 |
|
outside_node.potential = max_node_potential |
|
378 |
|
else: |
|
379 |
|
outside_node = outside_nodes[max_node] |
|
380 |
|
|
|
381 |
|
bx.candidates_index[-1] = outside_node |
|
382 |
|
bx.potential_index.pop(-1) |
|
383 |
|
bx.potential_index[-1] = max_node_potential |
356 |
384 |
|
|
357 |
385 |
|
|
358 |
386 |
|
|
|
... |
... |
class CircumTri(_Exploration): |
364 |
392 |
#č Máme 2 úkoly: |
#č Máme 2 úkoly: |
365 |
393 |
#č 1. Získat odhady a uložit je, abychom nemuseli opakovaně integrovat, |
#č 1. Získat odhady a uložit je, abychom nemuseli opakovaně integrovat, |
366 |
394 |
#č dokud se neobjeví nějaký nový vzorek zvenku. |
#č dokud se neobjeví nějaký nový vzorek zvenku. |
367 |
|
# #č 2. Získat kandidaty. |
|
368 |
|
# #č a. z mezíkruží (-12) |
|
369 |
|
# |
|
370 |
|
# #č prace s tečkami v mezikruži se změnila |
|
371 |
|
# #č teď tečky dostávám přes kolbek po částech |
|
372 |
|
# #č a není předem známo, kolik těch částí bude. |
|
373 |
|
# bx.candidates_index.pop(-1, None) |
|
374 |
|
# #č těch kastomných slovníků se bojím... |
|
375 |
|
# bx.potential_index.pop(-1, None) |
|
376 |
|
# #bx.rating_index.pop(-1, None) |
|
377 |
|
# bx.potential_index[-1] = 0 #č pro callback |
|
|
395 |
|
#č 2. Získat kandidaty. |
|
396 |
|
#č a. z mezíkruží (-12) |
|
397 |
|
|
|
398 |
|
#č prace s tečkami v mezikruži se změnila |
|
399 |
|
#č teď tečky dostávám přes kolbek po částech |
|
400 |
|
#č a není předem známo, kolik těch částí bude. |
|
401 |
|
bx.candidates_index.pop(-1, None) |
|
402 |
|
#č těch kastomných slovníků se bojím... |
|
403 |
|
bx.potential_index.pop(-1, None) |
|
404 |
|
#bx.rating_index.pop(-1, None) |
|
405 |
|
bx.potential_index[-1] = 0 #č pro callback |
378 |
406 |
|
|
379 |
407 |
bx.shell_stats = bx.ghull.get_shell_estimation() |
bx.shell_stats = bx.ghull.get_shell_estimation() |
380 |
408 |
|
|
|
409 |
|
bx.tree = KDTree(bx.G, compact_nodes=True, balanced_tree=False) |
|
410 |
|
|
381 |
411 |
# get candidates! |
# get candidates! |
382 |
412 |
#č explicitně (pokažde) počtem teček zadavám přesnost integrace |
#č explicitně (pokažde) počtem teček zadavám přesnost integrace |
383 |
413 |
#č takže změny bx.shell_budget budou při dálším spuštění aplikovány |
#č takže změny bx.shell_budget budou při dálším spuštění aplikovány |
384 |
|
bx.shell_estimation = bx.ghull.integrate(bx.shell_budget) |
|
385 |
|
#callback_outside=bx._rate_outside_nodes) |
|
|
414 |
|
bx.shell_estimation = bx.ghull.integrate(bx.shell_budget, |
|
415 |
|
callback_outside=bx._rate_outside_nodes) |
386 |
416 |
|
|
387 |
417 |
|
|
388 |
418 |
|
|