Esempio n. 1
0
    def argmin(c, lo, hi):
        mu = 0
        cut = None
        xl, xr = Num(), Num()
        yl, yr = Num(), 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:
                tmpx = Num.numXpect(xl, xr) * 1.0
                tmpy = Num.numXpect(yl, yr) * 1.0
                if tmpx < bestx and tmpy < besty:
                    (cut, bestx, besty) = i, tmpx, tmpy
        return cut,mu
Esempio n. 2
0
    def argmin(self, c, lo, hi):
        cut = None
        xl, xr = Num([]), Num([])
        yl, yr = Num([]), Num([])
        for i in range(lo, hi + 1):
            xr.numInc(float(self.rows[i][c]))
            yr.numInc(float(self.rows[i][self.goal]))
        bestx = xr.sd
        besty = yr.sd
        mu = yr.mu
        sd = yr.sd
        if hi - lo > self.enough * 2:
            for i in range(lo, hi + 1):
                x = float(self.rows[i][c])
                y = float(self.rows[i][self.goal])
                xl.numInc(x)
                xr.numDec(x)
                yl.numInc(y)
                yr.numDec(y)
                if xl.n >= self.enough and xr.n >= self.enough:
                    tmpx = Num.numXpect(xl, xr) * Vars.unsuper['margin']
                    tmpy = Num.numXpect(yl, yr) * Vars.unsuper['margin']
                    if type(tmpx) == "complex":
                        continue
                    if tmpx < bestx and tmpy < besty:
                        cut, bestx, besty = i, tmpx, tmpy

        return cut, mu, sd
Esempio n. 3
0
 def argmin(c, lo, hi):
     cut = None
     if (hi-lo > 2*enough):
         l = Num([])
         r = Num([])
         for i in range(lo,hi+1):
             r.num_inc(rows[i][c])
         best = r.sd
         for i in range(lo,hi+1):
             x = rows[i][c]
             l.num_inc(x)
             r.num_dec(x)
             if l.n >= enough and r.n >= enough:
                 tmp = Num.num_xpect(data, l, r) * param_margin
                 if tmp < best:
                     cut, best = i, tmp
     return cut
Esempio n. 4
0
File: oknum.py Progetto: se4ai/code
def _num1():
  n= Num([9,2,5,4,12,7,8,11,9,3,7,4,12,5,4,10,9,6,9,4])
  assert math.isclose(n.sd,3.0608,abs_tol=0.001)
  assert n.mu == 7
Esempio n. 5
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
Esempio n. 6
0
	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:
					if r.n >= enough:
						tmp = Num.numXpect(data, l, r) * y
						if tmp < best:
							cut = i
							best = tmp
		return cut
Esempio n. 7
0
def testNum():
    n = Num([
        4, 10, 15, 38, 54, 57, 62, 83, 100, 100, 174, 190, 215, 225, 233, 250,
        260, 270, 299, 300, 306, 333, 350, 375, 443, 475, 525, 583, 780, 1000
    ])
    assert n.mu == 270.3 and round(n.sd, 3) == 231.946