Пример #1
0
    def choose_thresh(infr):
        #prob_annots /= prob_annots.sum(axis=1)[:, None]
        # Find connected components
        #thresh = .25
        #thresh = 1 / (1.2 * np.sqrt(prob_names.shape[1]))
        unique_nids, prob_names = infr.make_prob_names()

        if len(unique_nids) <= 2:
            return .5

        nscores = np.sort(prob_names.flatten())
        # x = np.gradient(nscores).argmax()
        # x = (np.gradient(np.gradient(nscores)) ** 2).argmax()
        # thresh = nscores[x]

        curve = nscores
        idx1 = vt.find_elbow_point(curve)
        idx2 = vt.find_elbow_point(curve[idx1:]) + idx1
        if False:
            import plottool as pt
            idx3 = vt.find_elbow_point(curve[idx1:idx2 + 1]) + idx1
            pt.plot(curve)
            pt.plot(idx1, curve[idx1], 'bo')
            pt.plot(idx2, curve[idx2], 'ro')
            pt.plot(idx3, curve[idx3], 'go')
        thresh = nscores[idx2]
        #print('thresh = %r' % (thresh,))
        #thresh = .999
        #thresh = .1
        return thresh
Пример #2
0
    def choose_thresh(infr):
        #prob_annots /= prob_annots.sum(axis=1)[:, None]
        # Find connected components
        #thresh = .25
        #thresh = 1 / (1.2 * np.sqrt(prob_names.shape[1]))
        unique_nids, prob_names = infr.make_prob_names()

        if len(unique_nids) <= 2:
            return .5

        nscores = np.sort(prob_names.flatten())
        # x = np.gradient(nscores).argmax()
        # x = (np.gradient(np.gradient(nscores)) ** 2).argmax()
        # thresh = nscores[x]

        curve = nscores
        idx1 = vt.find_elbow_point(curve)
        idx2 = vt.find_elbow_point(curve[idx1:]) + idx1
        if False:
            import plottool as pt
            idx3 = vt.find_elbow_point(curve[idx1:idx2 + 1]) + idx1
            pt.plot(curve)
            pt.plot(idx1, curve[idx1], 'bo')
            pt.plot(idx2, curve[idx2], 'ro')
            pt.plot(idx3, curve[idx3], 'go')
        thresh = nscores[idx2]
        #print('thresh = %r' % (thresh,))
        #thresh = .999
        #thresh = .1
        return thresh
Пример #3
0
 def estimate_threshold(model, method=None):
     """
         import plottool as pt
         idx3 = vt.find_elbow_point(curve[idx1:idx2 + 1]) + idx1
         pt.plot(curve)
         pt.plot(idx1, curve[idx1], 'bo')
         pt.plot(idx2, curve[idx2], 'ro')
         pt.plot(idx3, curve[idx3], 'go')
     """
     if method is None:
         method = 'mean'
     curve = sorted(model.edge_weights)
     if method == 'mean':
         thresh = np.mean(curve)
     elif method == 'elbow':
         idx1 = vt.find_elbow_point(curve)
         idx2 = vt.find_elbow_point(curve[idx1:]) + idx1
         thresh = curve[idx2]
     else:
         raise ValueError('method = %r' % (method, ))
     return thresh
Пример #4
0
 def estimate_threshold(model, method=None):
     """
         import plottool as pt
         idx3 = vt.find_elbow_point(curve[idx1:idx2 + 1]) + idx1
         pt.plot(curve)
         pt.plot(idx1, curve[idx1], 'bo')
         pt.plot(idx2, curve[idx2], 'ro')
         pt.plot(idx3, curve[idx3], 'go')
     """
     if method is None:
         method = 'mean'
     curve = sorted(model.edge_weights)
     if method == 'mean':
         thresh = np.mean(curve)
     elif method == 'elbow':
         idx1 = vt.find_elbow_point(curve)
         idx2 = vt.find_elbow_point(curve[idx1:]) + idx1
         thresh = curve[idx2]
     else:
         raise ValueError('method = %r' % (method,))
     return thresh