• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python linear_assignment_.linear_assignment函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sklearn.utils.linear_assignment_.linear_assignment函数的典型用法代码示例。如果您正苦于以下问题:Python linear_assignment函数的具体用法?Python linear_assignment怎么用?Python linear_assignment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了linear_assignment函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_permute

def get_permute(W_r, H_r, W, H, coeff):
    T_0 = W_r.shape[1]
    T = W.shape[1]
    comp = zeros((T_0, T))
    for t in xrange(T):
        p = sqrt(W_r) - sqrt(tile(W[:, t], (T_0, 1))).T
        comp[:, t] = sum(p ** 2, 0)
    if T < T_0:
        t = array(linear_assignment(comp.T))[:, [1, 0]]
        # http://stackoverflow.com/questions/2828059/sorting-arrays-in-numpy-by-column
        return t[t[:, 0].argsort()]
    else:
        return array(linear_assignment(comp))
开发者ID:iv-ivan,项目名称:diplom,代码行数:13,代码来源:common.py


示例2: track

    def track(self, original_img, filtered_img, prev_data):
        n_objects = self.nObjectsSpinBox.value()
        distance_threshold = self.distanceThresholdSpinBox.value()

        if self.k_means is None:
            self.k_means = cluster.KMeans(n_clusters=n_objects)

        non_zero_pos = np.transpose(np.nonzero(filtered_img.T))
        try:
            center_pos = self.k_means.fit(non_zero_pos).cluster_centers_
        except:
            if self.ret_pos_old is None:
                return {'position': np.full((n_objects, 2), np.nan)}
            else:
                return {'position': self.ret_pos_old}

        if self.ret_pos_old is None:
            self.ret_pos_old = center_pos.copy()
            self.ret_pos = center_pos
        else:
            ret_pos_old_repeated = np.repeat(self.ret_pos_old, n_objects, axis=0)
            center_pos_tiled = np.tile(center_pos, (n_objects, 1))
            cost_mtx = np.linalg.norm(ret_pos_old_repeated - center_pos_tiled, axis=1)
            cost_mtx = cost_mtx.reshape((n_objects, n_objects))

            idx = linear_assignment(cost_mtx)
            idx = idx[cost_mtx[idx[:,0], idx[:,1]]<=distance_threshold]

            self.ret_pos[:] = self.ret_pos_old[:]
            self.ret_pos[idx[:, 0], :] = center_pos[idx[:, 1], :]

            self.ret_pos_old[:] = self.ret_pos[:].copy()

        return {'position': self.ret_pos}
开发者ID:UMATracker,项目名称:UMATracker-Tracker,代码行数:34,代码来源:k_means_widget.py


示例3: get_indexList

def get_indexList(coord, coord_prev, indexListPrev, totWorms, max_allow_dist = 10.0):
    #get the indexes of the next worms from their nearest neightbors using the hungarian algorithm
    
    if coord_prev.size!=0:
        costMatrix = cdist(coord_prev, coord);
        assigment = linear_assignment(costMatrix)
        
        indexList = np.zeros(coord.shape[0]);
        speed = np.zeros(coord.shape[0])

        for row, column in assigment: #ll = 1:numel(indexList)
            if costMatrix[row,column] < max_allow_dist:
                indexList[column] = indexListPrev[row];
                speed[column] = costMatrix[row][column];
            elif column < coord.shape[0]:
                totWorms = totWorms +1;
                indexList[column] = totWorms;
        
        for rep_ind in list_duplicates(indexList):
            totWorms = totWorms +1; #assign new worm_index to joined trajectories
            indexList[rep_ind] = totWorms;
        
    else:
        indexList = totWorms + np.arange(1,coord.shape[0]+1);
        totWorms = indexList[-1]
        speed = totWorms*[None]
        #print costMatrix[-1,-1]
    return (totWorms, indexList, speed)
开发者ID:KezhiLi,项目名称:Multiworm_Tracking,代码行数:28,代码来源:tracking_bgnd_MP.py


示例4: best_map

def best_map(l1, l2):
    """
    Permute labels of l2 to match l1 as much as possible
    """
    if len(l1) != len(l2):
        print "L1.shape must == L2.shape"
        exit(0)

    label1 = np.unique(l1)
    n_class1 = len(label1)

    label2 = np.unique(l2)
    n_class2 = len(label2)

    n_class = max(n_class1, n_class2)
    G = np.zeros((n_class, n_class))

    for i in range(0, n_class1):
        for j in range(0, n_class2):
            ss = l1 == label1[i]
            tt = l2 == label2[j]
            G[i, j] = np.count_nonzero(ss & tt)

    A = la.linear_assignment(-G)

    new_l2 = np.zeros(l2.shape)
    for i in range(0, n_class2):
        new_l2[l2 == label2[A[i][1]]] = label1[A[i][0]]
    return new_l2.astype(int)
开发者ID:Bekterra,项目名称:scikit-feature,代码行数:29,代码来源:unsupervised_evaluation.py


示例5: assignment

def assignment(costMatrix, costOfNonAssignment=140):
    Assignment = namedtuple('Assignment', 'trackIndex detectionIndex')
    assignments = []
    unmatchedTracks = []
    unmatchedDetections = []

    # print(costMatrix)

    # If matrix is rectangular, then pad
    rows, cols = costMatrix.shape
    diff = rows - cols
    if diff != 0:
        padValue = costOfNonAssignment + 1
        if diff < 0:
            pad_width = [(0, np.abs(diff)), (0, 0)]
        if diff > 0:
            pad_width = [(0, 0), (0, diff)]
        costMatrix = np.pad(costMatrix, pad_width, mode='constant',
            constant_values=(padValue, padValue))
    # Compute the optimal assignment
    assign = linear_assignment(costMatrix)

    # Throw out any assignments that cost more than the costOfNonAssingment
    for row in assign:
        trackIndex = row[0]
        detectionIndex =  row[1]
        if costMatrix[trackIndex, detectionIndex] > costOfNonAssignment:
            if trackIndex < rows:
                unmatchedTracks.append(trackIndex)
            if detectionIndex < cols:
                unmatchedDetections.append(detectionIndex)
        else:
            assignments.append(Assignment(trackIndex, detectionIndex))

    return assignments, unmatchedTracks, unmatchedDetections
开发者ID:verbetam,项目名称:bee_video,代码行数:35,代码来源:tools.py


示例6: syntax_similarity_conversation

 def syntax_similarity_conversation(self, documents1, average=False): #syntax similarity of each document with its before and after document
     global numnodes
     documents1parsed = []
     for d1 in range(len(documents1)):
         sys.stderr.write(str(d1)+"\n")
         # print documents1[d1]
         tempsents = (self.sent_detector.tokenize(documents1[d1].strip()))
         for s in tempsents:
             if len(s.split())>100:
                 documents1parsed.append("NA")
                 break
         else:
             temp = list(self.parser.raw_parse_sents((tempsents)))
             for i in range(len(temp)):
                 temp[i] = list(temp[i])[0]
                 temp[i] = ParentedTree.convert(temp[i])
             documents1parsed.append(list(temp))
     results = OrderedDict()
     for d1 in range(len(documents1parsed)):
         d2 = d1+1
         if d2 == len(documents1parsed):
             break
         if documents1parsed[d1] == "NA" or documents1parsed[d2]=="NA":
             continue
         costMatrix = []
         for i in range(len(documents1parsed[d1])):
             numnodes = 0
             tempnode = Node(documents1parsed[d1][i].root().label())
             new_sentencedoc1 = self.convert_mytree(documents1parsed[d1][i],tempnode)
             temp_costMatrix = []
             sen1nodes = numnodes
             for j in range(len(documents1parsed[d2])):
                 numnodes=0.0
                 tempnode = Node(documents1parsed[d2][j].root().label())
                 new_sentencedoc2 = self.convert_mytree(documents1parsed[d2][j],tempnode)
                 ED = simple_distance(new_sentencedoc1, new_sentencedoc2)
                 ED = ED / (numnodes + sen1nodes)
                 temp_costMatrix.append(ED)
             costMatrix.append(temp_costMatrix)
         costMatrix = np.array(costMatrix)
         if average==True:
             return 1-np.mean(costMatrix)
         else:
             indexes = su.linear_assignment(costMatrix)
             total = 0
             rowMarked = [0] * len(documents1parsed[d1])
             colMarked = [0] * len(documents1parsed[d2])
             for row, column in indexes:
                 total += costMatrix[row][column]
                 rowMarked[row] = 1
                 colMarked [column] = 1
             for k in range(len(rowMarked)):
                 if rowMarked[k]==0:
                     total+= np.min(costMatrix[k])
             for c in range(len(colMarked)):
                 if colMarked[c]==0:
                     total+= np.min(costMatrix[:,c])
             maxlengraph = max(len(documents1parsed[d1]),len(documents1parsed[d2]))
             results[(d1,d2)] = 1-total/maxlengraph#, minWeight/minlengraph, randtotal/lengraph
     return results
开发者ID:USC-CSSL,项目名称:CASSIM,代码行数:60,代码来源:Cassim.py


示例7: syntax_similarity_two_documents

 def syntax_similarity_two_documents(self, doc1, doc2, average=False): #syntax similarity of two single documents
     global numnodes
     doc1sents = self.sent_detector.tokenize(doc1.strip())
     doc2sents = self.sent_detector.tokenize(doc2.strip())
     for s in doc1sents: # to handle unusual long sentences.
         if len(s.split())>100:
             return "NA"
     for s in doc2sents:
         if len(s.split())>100:
             return "NA"
     try: #to handle parse errors. Parser errors might happen in cases where there is an unsuall long word in the sentence.
         doc1parsed = self.parser.raw_parse_sents((doc1sents))
         doc2parsed = self.parser.raw_parse_sents((doc2sents))
     except Exception as e:
         sys.stderr.write(str(e))
         return "NA"
     costMatrix = []
     doc1parsed = list(doc1parsed)
     for i in range(len(doc1parsed)):
         doc1parsed[i] = list(doc1parsed[i])[0]
     doc2parsed = list(doc2parsed)
     for i in range(len(doc2parsed)):
         doc2parsed[i] = list(doc2parsed[i])[0]
     for i in range(len(doc1parsed)):
         numnodes = 0
         sentencedoc1 = ParentedTree.convert(doc1parsed[i])
         tempnode = Node(sentencedoc1.root().label())
         new_sentencedoc1 = self.convert_mytree(sentencedoc1,tempnode)
         temp_costMatrix = []
         sen1nodes = numnodes
         for j in range(len(doc2parsed)):
             numnodes=0.0
             sentencedoc2 = ParentedTree.convert(doc2parsed[j])
             tempnode = Node(sentencedoc2.root().label())
             new_sentencedoc2 = self.convert_mytree(sentencedoc2,tempnode)
             ED = simple_distance(new_sentencedoc1, new_sentencedoc2)
             ED = ED / (numnodes + sen1nodes)
             temp_costMatrix.append(ED)
         costMatrix.append(temp_costMatrix)
     costMatrix = np.array(costMatrix)
     if average==True:
         return 1-np.mean(costMatrix)
     else:
         indexes = su.linear_assignment(costMatrix)
         total = 0
         rowMarked = [0] * len(doc1parsed)
         colMarked = [0] * len(doc2parsed)
         for row, column in indexes:
             total += costMatrix[row][column]
             rowMarked[row] = 1
             colMarked [column] = 1
         for k in range(len(rowMarked)):
             if rowMarked[k]==0:
                 total+= np.min(costMatrix[k])
         for c in range(len(colMarked)):
             if colMarked[c]==0:
                 total+= np.min(costMatrix[:,c])
         maxlengraph = max(len(doc1parsed),len(doc2parsed))
         return 1-(total/maxlengraph)
开发者ID:USC-CSSL,项目名称:CASSIM,代码行数:59,代码来源:Cassim.py


示例8: accuracy

def accuracy(l,lg):
    profitMatrix = confusion_matrix(lg, l)
    costMatrix = lg.shape[0] - profitMatrix
    ind = linear_assignment(costMatrix)
    total = 0.0
    for i in ind:
        total += profitMatrix[i[0],i[1]]
    return total / lg.shape[0]
开发者ID:Joaggi,项目名称:Machine-Learning,代码行数:8,代码来源:accuracy.py


示例9: get_deci_map

 def get_deci_map(self, state_map, w, dnum, tnum):
     score_mat = state_map.dot(w)
     match_idxs = linear_assignment(-score_mat)
     deci_map = np.zeros_like(score_mat)
     for m in match_idxs:
         if m[0]<dnum or m[1]<tnum:
             deci_map[m[0],m[1]] = 1
     return match_idxs, deci_map
开发者ID:tyhu,项目名称:PyAI,代码行数:8,代码来源:mot_tracker.py


示例10: accuracy

def accuracy(l,lg):
    profitMatrix = confusion_matrix(lg,l)
    costMatrix = np.iinfo(np.int64).max - profitMatrix
    ind = linear_assignment(costMatrix)
    total = 0.0
    for i in ind:
        total += profitMatrix[tuple(i)]
    return total / lg.shape[0]
开发者ID:ejake,项目名称:tensor-factorization,代码行数:8,代码来源:accuracy.py


示例11: calcAssignMtx

    def calcAssignMtx(self):
        idx = linear_assignment(self.costMtx)

        if self.assignMtx is None:
            self.assignMtx = np.zeros((self.N, self.M))
        else:
            self.assignMtx[:] = 0
        self.assignMtx[idx[:, 0], idx[:,1]] = 1
开发者ID:UMATracker,项目名称:UMATracker-Tracker,代码行数:8,代码来源:rmot.py


示例12: ceafe

def ceafe(clusters, gold_clusters):
    clusters = [c for c in clusters if len(c) != 1]
    scores = np.zeros((len(gold_clusters), len(clusters)))
    for i in range(len(gold_clusters)):
        for j in range(len(clusters)):
            scores[i, j] = phi4(gold_clusters[i], clusters[j])
    matching = linear_assignment(-scores)
    similarity = sum(scores[matching[:, 0], matching[:, 1]])
    return similarity, len(clusters), similarity, len(gold_clusters)
开发者ID:clarkkev,项目名称:deep-coref,代码行数:9,代码来源:evaluation.py


示例13: cluster_acc

def cluster_acc(Y_pred, Y):
  from sklearn.utils.linear_assignment_ import linear_assignment
  assert Y_pred.size == Y.size
  D = max(Y_pred.max(), Y.max())+1
  w = np.zeros((D,D), dtype=np.int64)
  for i in range(Y_pred.size):
    w[Y_pred[i], Y[i]] += 1
  ind = linear_assignment(w.max() - w)
  return sum([w[i,j] for i,j in ind])*1.0/Y_pred.size, w
开发者ID:309972460,项目名称:mxnet,代码行数:9,代码来源:dec.py


示例14: match_detections

 def match_detections(self, old_dets, new_dets, iou_threshold):
     if len(old_dets) == 0 or len(new_dets) == 0:
         return []
     iou_cost = np.array(
         [[iou(old, new) for new in new_dets] for old in old_dets],
         'float32'
     )
     match_pairs = linear_assignment(-iou_cost)
     return match_pairs
开发者ID:hewr1993,项目名称:graduate_thesis,代码行数:9,代码来源:track.py


示例15: linear_assignment

def linear_assignment(df):
    """Wrapper of sklearn linear assignment algorithm for DataFrame cost matrix. Returns
    DataFrame with columns for matched labels. Minimizes cost.
    """
    from sklearn.utils.linear_assignment_ import linear_assignment

    x = linear_assignment(df.as_matrix())
    y = zip(df.index[x[:, 0]], df.columns[x[:, 1]])
    df_out = pd.DataFrame(y, columns=[df.index.name, df.columns.name])
    return df_out
开发者ID:feldman4,项目名称:lasagna,代码行数:10,代码来源:utils.py


示例16: solve_matching

def solve_matching(num_cluster, old_cluster, new_cluster):
  """Solves the hungarian matching based on the non-overlapping words."""
  cost_matrix = np.array([[.0]*num_cluster]*num_cluster)
  # cost_matrix = cost_matrix.astype(np.float32)
  for i in old_cluster:
    for j in new_cluster:
      cost_matrix[i][j] = count_non_overlapping(old_cluster[i], new_cluster[j])
  # import ipdb; ipdb.set_trace()
  assignments = hungarian.linear_assignment(cost_matrix)
  mapping = {}
  for i in xrange(assignments.shape[0]):
    # mapping[i] = assignments[i, 1]
    mapping[assignments[i, 1]] = i
  return mapping
开发者ID:intuinno,项目名称:conceptvector,代码行数:14,代码来源:matching.py


示例17: associate_detections_to_trackers

def associate_detections_to_trackers(detections, trackers, iou_threshold=0.3):
    """
    Assigns detections to tracked object (both represented as bounding boxes)
    Returns 3 lists of matches, unmatched_detections and unmatched_trackers
    """
    if (len(trackers) == 0):
        return np.empty((0, 2), dtype=int), np.arange(len(detections)), \
               np.empty((0, 5), dtype=int)
    iou_matrix = np.zeros((len(detections), len(trackers)), dtype=np.float32)

    for d, det in enumerate(detections):
        for t, trk in enumerate(trackers):
            iou_matrix[d, t] = iou(det, trk)
    matched_indices = linear_assignment(-iou_matrix)

    unmatched_detections = []
    for d, det in enumerate(detections):
        if (d not in matched_indices[:, 0]):
            unmatched_detections.append(d)
    unmatched_trackers = []
    for t, trk in enumerate(trackers):
        if (t not in matched_indices[:, 1]):
            unmatched_trackers.append(t)

    # filter out matched with low IOU
    matches = []
    for m in matched_indices:
        is_matched = (iou_matrix[m[0], m[1]] < iou_threshold)

        # @mhsung
        if (detections.shape[1] >= 6 and trackers.shape[1] >= 6):
            # det: [x0, y0, x1, y2, score, class_index, ...]
            # If class indices are given, bboxes with the same class index are
            # only matched.
            det_cls = detections[m[0], 5]
            trk_cls = trackers[m[0], 5]
            is_matched = is_matched and (det_cls == trk_cls)

        if is_matched:
            unmatched_detections.append(m[0])
            unmatched_trackers.append(m[1])
        else:
            matches.append(m.reshape(1, 2))
    if (len(matches) == 0):
        matches = np.empty((0, 2), dtype=int)
    else:
        matches = np.concatenate(matches, axis=0)

    return matches, np.array(unmatched_detections), np.array(unmatched_trackers)
开发者ID:mhsung,项目名称:TheiaSfM,代码行数:49,代码来源:sort.py


示例18: associate_detections_to_trackers

def associate_detections_to_trackers(
        detections, trackers, distance_threshold=0.3):
    """
    Assigns detections to tracked object (both represented as bounding boxes)

    Returns 3 lists of matches, unmatched_detections and unmatched_trackers
    """
    if(len(trackers) == 0):
        return np.empty((0, 2), dtype=int), np.arange(
            len(detections)), np.empty((0, 6), dtype=int)
    distance_matrix = np.zeros(
        (len(detections), len(trackers)), dtype=np.float32)

    for d, det in enumerate(detections):
        for t, trk in enumerate(trackers):
            distance_matrix[d, t] = distance(det, trk)
            print('distance of new det:{} to tracker {} = {}'.format(
                d, t, distance_matrix[d, t]))

    # warnings.warn(str(distance_matrix))
    # warnings.warn('tracking')

    matched_indices = linear_assignment(-distance_matrix)

    unmatched_detections = []
    for d, det in enumerate(detections):
        if(d not in matched_indices[:, 0]):
            unmatched_detections.append(d)
    unmatched_trackers = []
    for t, trk in enumerate(trackers):
        if(t not in matched_indices[:, 1]):
            unmatched_trackers.append(t)

    # filter out matched with low distance
    matches = []
    for m in matched_indices:
        if(distance_matrix[m[0], m[1]] < distance_threshold):
            unmatched_detections.append(m[0])
            unmatched_trackers.append(m[1])
        else:
            matches.append(m.reshape(1, 2))
    if(len(matches) == 0):
        matches = np.empty((0, 2), dtype=int)
    else:
        matches = np.concatenate(matches, axis=0)

    return matches, np.array(
        unmatched_detections), np.array(unmatched_trackers)
开发者ID:Bruslan,项目名称:MV3D-1,代码行数:48,代码来源:multi_object_tracker.py


示例19: ceafe

    def ceafe(clusters, gold_clusters):
        """
        Computes the  Constrained EntityAlignment F-Measure (CEAF) for evaluating coreference.
        Gold and predicted mentions are aligned into clusterings which maximise a metric - in
        this case, the F measure between gold and predicted clusters.

        <https://www.semanticscholar.org/paper/On-Coreference-Resolution-Performance-Metrics-Luo/de133c1f22d0dfe12539e25dda70f28672459b99>
        """
        clusters = [cluster for cluster in clusters if len(cluster) != 1]
        scores = np.zeros((len(gold_clusters), len(clusters)))
        for i, gold_cluster in enumerate(gold_clusters):
            for j, cluster in enumerate(clusters):
                scores[i, j] = Scorer.phi4(gold_cluster, cluster)
        matching = linear_assignment(-scores)
        similarity = sum(scores[matching[:, 0], matching[:, 1]])
        return similarity, len(clusters), similarity, len(gold_clusters)
开发者ID:Jordan-Sauchuk,项目名称:allennlp,代码行数:16,代码来源:conll_coref_scores.py


示例20: __init__

    def __init__(self, boxes1, boxes2, labels1=None, labels2=None):
        self._boxes1 = boxes1
        self._boxes2 = boxes2

        if len(boxes1) == 0 or len(boxes2) == 0:
            pass
        else:
            
            if labels1 is None or labels2 is None:
                self._iou_matrix = self._calc(boxes1,
                                              boxes2,
                                              np.ones((len(boxes1),)),
                                              np.ones((len(boxes2),)))
            else:
                self._iou_matrix = self._calc(boxes1, boxes2, labels1, labels2)
            self._match_pairs = linear_assignment(-1*self._iou_matrix)
开发者ID:wyw636,项目名称:Yolo-digit-detector,代码行数:16,代码来源:_box_match.py



注:本文中的sklearn.utils.linear_assignment_.linear_assignment函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python multiclass.type_of_target函数代码示例发布时间:2022-05-27
下一篇:
Python fixes.unique函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap