def centroid(s, t): pmap = s._pmap(t) centx, centy = 0., 0. for x in range(PMAP_GRID_DIM): for y in range(PMAP_GRID_DIM): centx += pmap[x][y] * x centy += pmap[x][y] * y centx *= PMAP_GRID_SCALE centy *= PMAP_GRID_SCALE return (centx, centy)
def centroiderr(s, t): pmap = s._pmap(t) centx, centy = 0., 0. for x in range(PMAP_GRID_DIM): for y in range(PMAP_GRID_DIM): centx += pmap[x][y] * x centy += pmap[x][y] * y centx *= PMAP_GRID_SCALE centy *= PMAP_GRID_SCALE spts = sorted([(x, y, mag((centx - x, centy - y))) for x in range(PMAP_GRID_DIM) for y in range(PMAP_GRID_DIM)], key=lambda t:t[2]) psum = 0. i = -1 while psum < SIGMA: i += 1 psum += pmap[spts[i][0]][spts[i][1]] return ((centx, centy), spts[i][2])
def centroiderr(s, t): pmap = s._pmap(t) centx, centy = 0., 0. for x in range(PMAP_GRID_DIM): for y in range(PMAP_GRID_DIM): centx += pmap[x][y] * x centy += pmap[x][y] * y centx *= PMAP_GRID_SCALE centy *= PMAP_GRID_SCALE spts = sorted([(x, y, mag((centx - x, centy - y))) for x in range(PMAP_GRID_DIM) for y in range(PMAP_GRID_DIM)], key=lambda t: t[2]) psum = 0. i = -1 while psum < SIGMA: i += 1 psum += pmap[spts[i][0]][spts[i][1]] return ((centx, centy), spts[i][2])