File blackbox.py changed (mode: 100644) (index 2f67a3e..4a921c5) |
... |
... |
class OptimizedCensoredSampling(MinEnergyCensoredSampling): |
1337 |
1337 |
|
|
1338 |
1338 |
|
|
1339 |
1339 |
|
|
1340 |
|
|
|
1341 |
|
if len(bx.unjudged_candidates) > 0: |
|
1342 |
|
#č prohrabeme odpad |
|
1343 |
|
candidates = bx.unjudged_candidates.pop() |
|
1344 |
|
for i in range(len(bx.former_candidates)): |
|
1345 |
|
candidates.add_sample(bx.former_candidates.pop()) |
|
1346 |
|
for i in range(len(bx.unjudged_candidates)): |
|
1347 |
|
candidates.add_sample(bx.unjudged_candidates.pop()) |
|
|
1340 |
|
#č prohrabeme odpad |
|
1341 |
|
bx._judge_unjudged(bx.unjudged_candidates) |
|
1342 |
|
bx._judge_unjudged(bx.former_candidates) |
1348 |
1343 |
|
|
1349 |
1344 |
|
|
1350 |
|
mask = bx.is_outside(candidates) |
|
1351 |
|
candidates = candidates[mask] |
|
1352 |
1345 |
|
|
1353 |
1346 |
|
|
|
1347 |
|
else: |
|
1348 |
|
bx._logger('Triangulace (zatím?) neexistuje') |
|
1349 |
|
bx.regen() |
|
1350 |
|
|
|
1351 |
|
|
|
1352 |
|
|
|
1353 |
|
def _judge_unjudged(bx, list): |
|
1354 |
|
for i in range(len(list)): |
|
1355 |
|
candidates = list.pop() |
|
1356 |
|
bx.is_outside(candidates) |
|
1357 |
|
|
|
1358 |
|
mask = candidates.is_outside |
|
1359 |
|
if np.any(mask): #č pokud aspoň jeden bydlí mimo Brno |
|
1360 |
|
candidates = candidates[mask] |
1354 |
1361 |
candidates.simplex = candidates.event = np.full(len(candidates), -1, dtype=np.int8) |
candidates.simplex = candidates.event = np.full(len(candidates), -1, dtype=np.int8) |
1355 |
|
|
|
1356 |
|
|
|
1357 |
1362 |
#č vyhodnotíme |
#č vyhodnotíme |
1358 |
1363 |
bx.assess_candidates(candidates) |
bx.assess_candidates(candidates) |
1359 |
1364 |
#č vzorky je třeba přidát ke kandidatům |
#č vzorky je třeba přidát ke kandidatům |
1360 |
1365 |
# jako, nic nepokazí, ale čo tam připadně bylo - přepíše |
# jako, nic nepokazí, ale čo tam připadně bylo - přepíše |
1361 |
1366 |
bx.candidates_index[-1].add_sample(candidates) |
bx.candidates_index[-1].add_sample(candidates) |
1362 |
|
|
|
1363 |
|
|
|
1364 |
|
|
|
1365 |
|
|
|
1366 |
|
else: |
|
1367 |
|
bx._logger('Triangulace (zatím?) neexistuje') |
|
1368 |
|
bx.regen() |
|
1369 |
|
|
|
1370 |
1367 |
|
|
1371 |
1368 |
|
|
1372 |
1369 |
|
|
1373 |
1370 |
def estimate_outside(bx): |
def estimate_outside(bx): |
1374 |
1371 |
# předpokládám, že triangulece jíž existuje |
# předpokládám, že triangulece jíž existuje |
1375 |
|
|
|
|
1372 |
|
|
1376 |
1373 |
# -1 = 'out', 0=success, 1=failure, 2=mix |
# -1 = 'out', 0=success, 1=failure, 2=mix |
1377 |
1374 |
#current outside probability estimation |
#current outside probability estimation |
1378 |
1375 |
try: |
try: |
|
... |
... |
class OptimizedCensoredSampling(MinEnergyCensoredSampling): |
1384 |
1381 |
if p_out == 0: |
if p_out == 0: |
1385 |
1382 |
p_out = 1/(bx.nsim + 1) |
p_out = 1/(bx.nsim + 1) |
1386 |
1383 |
bx._logger(msg="suppose p_out=1/(bx.nsim + 1)="+str(p_out)) |
bx._logger(msg="suppose p_out=1/(bx.nsim + 1)="+str(p_out)) |
1387 |
|
|
|
|
1384 |
|
|
|
1385 |
|
# |
|
1386 |
|
# get candidates! |
|
1387 |
|
# |
1388 |
1388 |
if p_out > 0.5: |
if p_out > 0.5: |
1389 |
1389 |
# zužovat nechceme |
# zužovat nechceme |
1390 |
1390 |
# trapit sa generacema taky ne |
# trapit sa generacema taky ne |
1391 |
1391 |
candidates = IS_stat.IS(bx.f, bx.h, space_from_h='R', space_to_f=bx.sampling_space, Nsim=bx.budget) |
candidates = IS_stat.IS(bx.f, bx.h, space_from_h='R', space_to_f=bx.sampling_space, Nsim=bx.budget) |
1392 |
1392 |
|
|
1393 |
1393 |
# nevím co tam bylo za h-ko, ale nechť IM zůstane 1 |
# nevím co tam bylo za h-ko, ale nechť IM zůstane 1 |
1394 |
|
implicit_multiplicator = 1 |
|
|
1394 |
|
#implicit_multiplicator = 1 |
1395 |
1395 |
|
|
1396 |
|
else: # tak deme... trapit sa generacema |
|
|
1396 |
|
else: # tak jdeme... trapit sa generacema |
1397 |
1397 |
|
|
1398 |
1398 |
sampling_r, __ = bx.sball.get_r_iteration(p_out) |
sampling_r, __ = bx.sball.get_r_iteration(p_out) |
1399 |
1399 |
# asi tam bylo sampling_r/bx.base_r, že? |
# asi tam bylo sampling_r/bx.base_r, že? |
1400 |
1400 |
# u stats.norm zadáváme směrodatnou odchylku, je to asi správné |
# u stats.norm zadáváme směrodatnou odchylku, je to asi správné |
1401 |
1401 |
h = f_models.UnCorD([stats.norm(0, sampling_r/bx.base_r) for i in range(bx.nvar)]) |
h = f_models.UnCorD([stats.norm(0, sampling_r/bx.base_r) for i in range(bx.nvar)]) |
1402 |
|
|
|
1403 |
|
# for IS_stats |
|
1404 |
|
#svar = (sampling_r/bx.base_r)**2 # svar like sampling_variance |
|
1405 |
|
# něco takovýho bych nahrubo placnul |
|
1406 |
|
#implicit_multiplicator = svar**bx.nvar * np.exp(bx.nvar/svar - bx.nvar) |
|
1407 |
|
|
|
1408 |
1402 |
candidates = IS_stat.IS(bx.f, h, space_from_h='R', space_to_f=bx.sampling_space, Nsim=bx.budget) |
candidates = IS_stat.IS(bx.f, h, space_from_h='R', space_to_f=bx.sampling_space, Nsim=bx.budget) |
1409 |
1403 |
|
|
1410 |
|
|
|
|
1404 |
|
bx.is_outside(candidates) |
|
1405 |
|
candidates = candidates[candidates.is_outside] |
|
1406 |
|
|
|
1407 |
|
|
|
1408 |
|
#č řeším problém, že při načítaní ze souboru |
|
1409 |
|
#č blackbox nemá adekvatní odhad Brno-venkova |
|
1410 |
|
while len(candidates) < 2: |
|
1411 |
|
p_out = p_out/2 |
|
1412 |
|
bx._logger(msg="suppose p_out="+str(p_out)) |
|
1413 |
|
|
|
1414 |
|
sampling_r, __ = bx.sball.get_r_iteration(p_out) |
|
1415 |
|
# asi tam bylo sampling_r/bx.base_r, že? |
|
1416 |
|
# u stats.norm zadáváme směrodatnou odchylku, je to asi správné |
|
1417 |
|
h = f_models.UnCorD([stats.norm(0, sampling_r/bx.base_r) for i in range(bx.nvar)]) |
|
1418 |
|
candidates = IS_stat.IS(bx.f, h, space_from_h='R', space_to_f=bx.sampling_space, Nsim=bx.budget) |
|
1419 |
|
|
|
1420 |
|
bx.is_outside(candidates) |
|
1421 |
|
candidates = candidates[candidates.is_outside] |
|
1422 |
|
|
1411 |
1423 |
|
|
1412 |
|
mask = bx.is_outside(candidates) |
|
1413 |
|
candidates = candidates[mask] |
|
1414 |
1424 |
|
|
1415 |
1425 |
#č necháme ISSI trapit sa pravděpodobnostma |
#č necháme ISSI trapit sa pravděpodobnostma |
1416 |
1426 |
bx.siss.add_single_event_data(candidates.w, event=-1, nis=bx.budget) |
bx.siss.add_single_event_data(candidates.w, event=-1, nis=bx.budget) |
|
... |
... |
class OptimizedCensoredSampling(MinEnergyCensoredSampling): |
1438 |
1448 |
# N=nsim |
# N=nsim |
1439 |
1449 |
NxN = A @ x.T + np.atleast_2d(b).T |
NxN = A @ x.T + np.atleast_2d(b).T |
1440 |
1450 |
mask = np.any(NxN > 0, axis=0) |
mask = np.any(NxN > 0, axis=0) |
1441 |
|
return mask |
|
|
1451 |
|
candidates.is_outside = mask |
1442 |
1452 |
|
|
1443 |
1453 |
|
|
1444 |
1454 |
|
|