def distVarCost(a, b, c):
    #np.seterr(all='warn')
    '''prefers lines with less variance in their spacing'''
    abDist = cluster_util.findDistance(a, b)
    bcDist = cluster_util.findDistance(b, c)
    if bcDist == 0:
        #shouldn't ever occur, but prevents undefined data while debugging
        return 0
    return np.abs(np.log2((1 / abDist) * bcDist))
Beispiel #2
0
def distVarCost(a, b, c):
    #np.seterr(all='warn')
    '''prefers lines with less variance in their spacing'''
    abDist = cluster_util.findDistance(a, b)
    bcDist = cluster_util.findDistance(b, c)
    if bcDist==0:
        #shouldn't ever occur, but prevents undefined data while debugging
        return 0
    return np.abs(np.log2((1/abDist)*bcDist))
Beispiel #3
0
def findChains(inputObjectSet, params ):
    '''finds all the chains, then returns the ones that satisfy constraints, sorted from best to worst.'''
  
    bestlines = []
    explored = set()
    pairwise = cluster_util.find_pairs(inputObjectSet)
    pairwise.sort(key=lambda p: cluster_util.findDistance(p[0].position, p[1].position),reverse=False)
    for pair in pairwise:
        start,finish = pair[0],pair[1]
        if frozenset([start.id,finish.id]) not in explored:
            result = chainSearch(start, finish, inputObjectSet,params)
            if result != None: 
                bestlines.append(result)
                s = map(frozenset,cluster_util.find_pairs(result[0:len(result)-1]))
                
                map(explored.add,s)

               
    verybest = []
    costSum = 0
    for line in bestlines:
        if len(line)>params.min_line_length:
            verybest.append(line)
    verybest.sort(key=lambda l: len(l),reverse=True)
    costs = map(lambda l: l.pop()+2,verybest)
    listOfTheWordLine = ["line"]*len(costs)
    data = np.array(map(lambda x: (x.position,x.id),inputObjectSet))

    return zip(costs,verybest,listOfTheWordLine)
def findChains(inputObjectSet, params, distanceMatrix=-1):
    '''finds all the chains, then returns the ones that satisfy constraints, sorted from best to worst.'''

    if distanceMatrix == -1:
        distanceMatrix = cluster_util.create_distance_matrix(inputObjectSet)

    bestlines = []
    explored = set()
    pairwise = cluster_util.find_pairs(inputObjectSet)
    pairwise.sort(
        key=lambda p: cluster_util.findDistance(p[0].position, p[1].position),
        reverse=False)
    for pair in pairwise:
        start, finish = pair[0], pair[1]
        if frozenset([start.id, finish.id]) not in explored:
            result = chainSearch(start, finish, inputObjectSet, params,
                                 distanceMatrix)
            if result != None:
                bestlines.append(result)
                s = map(frozenset,
                        cluster_util.find_pairs(result[0:len(result) - 1]))

                map(explored.add, s)

    verybest = []
    costSum = 0
    for line in bestlines:
        if len(line) > params.min_line_length:
            verybest.append(line)
    verybest.sort(key=lambda l: len(l), reverse=True)
    costs = map(lambda l: l.pop() + 2, verybest)
    data = np.array(map(lambda x: (x.position, x.id), inputObjectSet))
    output = []
    for i in zip(costs, verybest):
        output.append(cluster_util.LineBundle(i[1], i[0]))
    return output
def distCost(current, step, start, goal):
    '''prefers dense lines to sparse ones'''
    stepdist = cluster_util.findDistance(current, step)
    totaldist = cluster_util.findDistance(start, goal)
    return stepdist**2 / totaldist**2
Beispiel #6
0
def distCost(current,step,start,goal):
    '''prefers dense lines to sparse ones'''
    stepdist = cluster_util.findDistance(current, step)
    totaldist= cluster_util.findDistance(start, goal)
    return stepdist**2/totaldist**2