Commit fb56193f authored by Kirill Smelkov's avatar Kirill Smelkov

X fix metric to keep Z <- N order stable over key^

with just sum of abs, it was reverting the order for e.g.

	[2,3) [3,∞)  wrt  [-∞,1) [1,2)

where cost matrix was

	⎡∞ + 4  2⋅∞ + 2⎤
	⎢              ⎥
	⎣  2       ∞   ⎦

and 0-0 + 1-1 is the same as 0-1 + 1-0

with squares 2 in (2⋅∞)² becomes 4 and wins ∞²+∞².

This assert in T2/T1-T3/B0-B1-T-T/B2-B3 -> T2/T1-T/T-T-B2,3/B0-B1.
parent ef6fb8db
......@@ -262,7 +262,8 @@ def Restructure(ztree, newStructure):
# - find solution to linear assignment problem A <- B with the cost given by D
# https://en.wikipedia.org/wiki/Assignment_problem
#
# D(A,B) = |A.lo - B.lo| + |A.hi - B.hi|
# 2 2
# D(A,B) = (A.lo - B.lo) + (A.hi - B.hi)
# we will modify nodes from new set:
# - node.Z will point to associated znode
......@@ -292,16 +293,19 @@ def Restructure(ztree, newStructure):
if v == -inf: return -1E4
assert abs(v) < 1E3
return v
def d(x,y):
return abs(fin(x)-fin(y))
return d(a.range.klo, b.range.klo) + \
d(a.range.khi, b.range.khi)
def d2(x,y):
#return abs(fin(x)-fin(y))
return (fin(x)-fin(y))**2
return d2(a.range.klo, b.range.klo) + \
d2(a.range.khi, b.range.khi)
# cost matrix
C = np.zeros((len(RNv), len(RZv)))
for j in range(len(RNv)): # "workers"
for i in range(len(RZv)): # "jobs"
C[j,i] = D(RZv[i], RNv[j])
#print('\nCOST:')
#print(C)
# find the assignments.
# TODO try to avoid scipy dependency; we could also probably make
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment