File wellmet/dicebox/circumtri.py changed (mode: 100644) (index c585d15..f5e6a96) |
4 |
4 |
|
|
5 |
5 |
import numpy as np |
import numpy as np |
6 |
6 |
from scipy.spatial import distance |
from scipy.spatial import distance |
|
7 |
|
from scipy.spatial import KDTree |
7 |
8 |
|
|
8 |
9 |
import quadpy |
import quadpy |
9 |
10 |
|
|
|
... |
... |
class CircumTri(_Exploration): |
205 |
206 |
|
|
206 |
207 |
|
|
207 |
208 |
#č teď je to kolbek, který volá Triangulation |
#č teď je to kolbek, který volá Triangulation |
208 |
|
def _on_mixed_added(bx, simplex, indices, vertices_model, _nodes, _vol, fr, wfr, _mfpdf): |
|
|
209 |
|
def _on_mixed_added(bx, simplex, indices, vertices_model, nodes, _vol, fr, wfr, _mfpdf): |
209 |
210 |
|
|
210 |
211 |
circum_center = bx.CC.get_circumcenter(vertices_model) |
circum_center = bx.CC.get_circumcenter(vertices_model) |
211 |
212 |
r = distance.euclidean(circum_center, vertices_model[0]) |
r = distance.euclidean(circum_center, vertices_model[0]) |
|
... |
... |
class CircumTri(_Exploration): |
215 |
216 |
circum_pdf = float(circum_node.pdf(bx.tri_space)) |
circum_pdf = float(circum_node.pdf(bx.tri_space)) |
216 |
217 |
circum_potential = r * circum_pdf**(1/bx.nvar) |
circum_potential = r * circum_pdf**(1/bx.nvar) |
217 |
218 |
|
|
218 |
|
# circum rating |
|
219 |
|
if bx.weighted_entropy: |
|
220 |
|
entropy = get_entropy(wfr) |
|
|
219 |
|
failsi = bx.Tri.failsi[indices] |
|
220 |
|
|
|
221 |
|
|
|
222 |
|
tree = KDTree(vertices_model, compact_nodes=False, balanced_tree=False) |
|
223 |
|
|
|
224 |
|
#č konkretně tato třída je pevně napojena na G prostor |
|
225 |
|
#č ale bacha, kbyby se to změnilo... |
|
226 |
|
dd, ii = tree.query(nodes.G, k=2) |
|
227 |
|
|
|
228 |
|
failsi_pair = failsi[ii] |
|
229 |
|
mask = np.logical_xor(failsi_pair[:,0], failsi_pair[:,1]) |
|
230 |
|
#mask = np.sum(failsi[ii], axis=1) == 1 |
|
231 |
|
if np.any(mask): |
|
232 |
|
nodes = nodes[mask] |
|
233 |
|
|
|
234 |
|
dr = distance.cdist(nodes.G, [circum_center]).flatten() |
|
235 |
|
nodes_pdf = nodes.pdf('G') |
|
236 |
|
node_potentials = (r - dr) * nodes_pdf**(1/bx.nvar) |
|
237 |
|
|
|
238 |
|
|
|
239 |
|
max_node = np.nanargmax(node_potentials) |
|
240 |
|
max_node_potential = node_potentials[max_node] |
221 |
241 |
else: |
else: |
222 |
|
entropy = get_entropy(fr) |
|
223 |
|
circum_rating = circum_potential * entropy |
|
|
242 |
|
max_node_potential = -np.inf |
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
|
if max_node_potential > circum_potential: |
|
247 |
|
result_node = nodes[max_node] |
|
248 |
|
result_potential = max_node_potential |
|
249 |
|
|
|
250 |
|
d1, d2 = dd[mask][max_node] |
|
251 |
|
if bx.weighted_entropy: |
|
252 |
|
ii = ii[mask][max_node] |
|
253 |
|
pdf1, pdf2 = bx.Tri.PDF[indices][ii] |
|
254 |
|
entropy = get_entropy(pdf1 * d2 / (pdf1 * d2 + pdf2 * d1)) |
|
255 |
|
else: |
|
256 |
|
entropy = get_entropy(d1 / (d1 + d2)) |
|
257 |
|
result_rating = max_node_potential * entropy |
|
258 |
|
else: |
|
259 |
|
result_node = circum_node |
|
260 |
|
result_potential = circum_potential |
|
261 |
|
# circum rating |
|
262 |
|
if bx.weighted_entropy: |
|
263 |
|
entropy = get_entropy(wfr) |
|
264 |
|
else: |
|
265 |
|
entropy = get_entropy(fr) |
|
266 |
|
result_rating = circum_potential * entropy |
224 |
267 |
|
|
225 |
268 |
|
|
226 |
269 |
#č nodes příjdou zabalené do CandyNodes. Ty mají .attrs a .kwargs |
#č nodes příjdou zabalené do CandyNodes. Ty mají .attrs a .kwargs |
227 |
270 |
if bx.store_candidates_metainformation: |
if bx.store_candidates_metainformation: |
228 |
|
circum_node = CandyNodes(circum_node) |
|
229 |
|
circum_node.potential = circum_potential |
|
230 |
|
circum_node.rating = circum_rating |
|
231 |
|
bx.candidates_index[simplex] = circum_node |
|
232 |
|
bx.potential_index[simplex] = circum_potential |
|
233 |
|
bx.rating_index[simplex] = circum_rating |
|
|
271 |
|
result_node = CandyNodes(result_node) |
|
272 |
|
result_node.potential = result_potential |
|
273 |
|
result_node.rating = result_rating |
|
274 |
|
|
|
275 |
|
bx.candidates_index[simplex] = result_node |
|
276 |
|
bx.potential_index[simplex] = result_potential |
|
277 |
|
bx.rating_index[simplex] = result_rating |
234 |
278 |
|
|
235 |
279 |
|
|
236 |
280 |
|
|