Example #1
0
    def argmin(c, lo, hi):
        # Function is use to find the best cut by creating two counters on left and right
        xl = Num([])
        xr = Num([])
        yl = Num([])
        yr = Num([])
        cut = None
        for i in range(lo, hi + 1):
            xr.numInc(rows[i][c])
            yr.numInc(rows[i][goal])
        bestx = xr.sd
        besty = yr.sd
        mu = yr.mu
        n = yr.n
        if (hi - lo) > 2 * enough:
            for i in range(lo, hi + 1):
                xl.numInc(rows[i][c])
                xr.numDec(rows[i][c])
                yl.numInc(rows[i][goal])
                yr.numDec(rows[i][goal])

                if xl.n >= enough and xr.n >= enough:
                    tmpx = Num.numXpect(data, xl, xr) * super_margin
                    tmpy = Num.numXpect(data, yl, yr) * super_margin
                    if tmpx < bestx:
                        if tmpy < besty:
                            cut, bestx, besty = i, tmpx, tmpy
        return (cut, mu, n, besty)
Example #2
0
 def argmin(c, lo, hi):
     cut = None
     xl = Num()
     xr = Num()
     yl = Num()
     yr = Num()
     for i in range(lo, hi + 1):
         xr.numInc(rows[i][c])
         yr.numInc(rows[i][goal])
     bestx = xr.sd
     besty = yr.sd
     mu = yr.mu
     n = yr.n
     if (hi - lo > 2 * enough):
         for i in range(lo, hi + 1):
             x = rows[i][c]
             y = rows[i][goal]
             xl.numInc(x)
             xr.numDec(x)
             yl.numInc(y)
             yr.numDec(y)
             if xl.n >= enough and xr.n >= enough:
                 tmpx = Num.numXpect(xl, xr) * 1.05
                 tmpy = Num.numXpect(yl, yr) * 1.05
                 if tmpx < bestx and tmpy < besty:
                     cut, bestx, besty = i, tmpx, tmpy
     return cut, mu, n, besty
Example #3
0
 def argmin(c, lo, hi):
     """
     finds the cut index for the min sd returns that. If cut is not found, returns None
     
     Param:
         int c for index of rows
         int lo for the lowest cut
         int hi for the highest cut
     
     Return:
         int cut index or None
     """
     cut = None
     if(hi - lo > 2 * enough):
         l = Num()
         r = Num()
         
         for i in range(lo,hi+1):
             r.numInc(rows[i][c])
         
         best = r.sd
         
         for i in range(lo,hi+1):
             x = rows[i][c]
             l.numInc(x)
             r.numDec(x)
             
             if (l.n >= enough and r.n >= enough):
                 temp = Num.numXpect(l, r)
                 if(isinstance(temp, complex)):
                     temp = temp.real
                 if(temp < best):
                     cut = i
                     best = temp
     return cut
Example #4
0
    def argmin(c, lo, hi):
        """
        finds the cut index for the min sd returns that. If cut is not found, returns None

        Param:
            int c for index of rows
            int lo for the lowest cut
            int hi for the highest cut

        Return:
            int cut index or None
        """

        mu = 0
        cut = None
        if (hi - lo > 2 * enough):

            xl = Num()
            xr = Num()
            yl = Num()
            yr = Num()


            for i in range(lo, hi + 1):
                xr.numInc(rows[i][c])
                yr.numInc(rows[i][goal])

            bestx = xr.sd
            besty = yr.sd
            mu = yr.mu

            for i in range(lo, hi + 1):
                x = rows[i][c]
                y = rows[i][goal]

                xl.numInc(x)
                xr.numDec(x)
                yl.numInc(y)
                yr.numDec(y)

                if (xl.n >= enough and xr.n >= enough):
                    tempx = Num.numXpect(xl, xr) * Config().superMargin
                    tempy = Num.numXpect(yl, yr) * Config().superMargin
                    if (tempx < bestx) and (tempy < besty):
                        cut = i
                        bestx = tempx
                        besty = tempy
        return cut, mu
    def argmin(c, lo, hi):
        cut = None
        if ((hi - lo) > 2 * enough):
            l = Num([])
            r = Num([])
            for i in range(lo, hi + 1):
                r.numInc(rows[i][c])
            best = r.sd
            for i in range(lo, hi + 1):
                x = rows[i][c]
                l.numInc(x)
                r.numDec(x)

                if l.n >= enough and r.n >= enough:
                    tmp = Num.numXpect(data, l, r) * 1.05
                    if tmp < best:
                        cut = i
                        best = tmp
        return cut