Tuesday, June 4, 2013

recoding peeker2

diabetes (probability of positive for diabetes)


housing (normalized resale value 0..1, min..max)


poi -1.5*log(p(defects)

Such sweet code:

def Abcx(row,c,left,right):
  a = dist(row,left)
  b = dist(row,right)
  x = (a**2 + c**2 - b**2)* 1.0 / (2*c + 1.0/The.inf)
  y = (a**2 - x**2)**0.5
  return Thing(x=x,y=y,row=row,a=a,b=b)

def quadrants(t,demo=False):
  z     = one(t.rows)
  left  = furthest(z)
  right = furthest(left)
  out = []
  quad1(t,left,right,out,demo)
  return out

def quad1(t,l,r,out,demo):
  t.left  = l
  t.right = r
  c = t.c = dist(l,r)
  x,y     = [],[]
  for row in t.rows:
    xy = Abcx(row,c,l,r)
    if   xy.a > t.c : return quad1(t,l,row,out,demo)
    elif xy.b > t.c : return quad1(t,row,r,out,demo)
    else:
      x += [xy]
      y += [xy]
  x = sorted(x,key=lambda z:z.x)
  y = sorted(x,key=lambda z:z.y)
  hi   = len(x) 
  stop = The.enough(hi)
  print "stop>",stop
  tile(x,y,0,hi,0,hi,out,stop,demo,2) 

def tile(x,y,x0,x2,y0,y2,out,stop,demo,depth=0):
  def tile1(x0,x2,y0,y2,out):
    tmp = []
    for one in x[x0:x2]:
      for two in y[y0:y2]:
        if one.row.row == two.row.row:
          tmp += [one]
    if demo:
      print '--|'*depth,len(tmp)
    if len(tmp) > stop: 
      tile(x,y,x0,x2,y0,y2,out,stop,demo,depth+1)
    else: 
      out += [tmp] 
   
  x1 = x0 + (x2 - x0)/2
  y1 = y0 + (y2 - y0)/2
  tile1( x0,x1, y0,y1 ,out)
  tile1( x0,x1, y1,y2 ,out) 
  tile1( x1,x2, y0,y1 ,out)
  tile1( x1,x2, y1,y2 ,out)

No comments:

Post a Comment