Ejemplo n.º 1
0
 def __init__(i, all, my, branch, branches, stop=None, level=0):
     i.my = my
     stop = stop or 2 * len(all.rows)**my.bins
     best, rest = sorted([all.clone(rows) for rows in all.polarize()])
     bins = [
         bin for xbest, xrest in zip(best.x, rest.x)
         for bin in xbest.discretize(xrest, my)
     ]
     bestIdea = i.values("plan", bins)[-1][1]
     worstIdea = i.values("monitor", bins)[-1][1]
     pre = "|.. " * level
     for yes, no, idea in [(1, 0, bestIdea), (0, 1, worstIdea)]:
         leaf, tree = all.clone(), all.clone()
         for row in all.rows:
             (leaf if i.match(idea, row) else tree).add(row)
         branch1 = kopy(branch)
         branch1 += [
             o(at=idea.at,
               lo=idea.lo,
               hi=idea.hi,
               type=yes,
               txt="if " + i.show(idea) + " then",
               then=leaf.ys(),
               n=len(leaf.rows))
         ]
         if len(tree.rows) <= stop:
             branch1 += [
                 o(type=no, txt="  ", then=tree.ys(), n=len(tree.rows))
             ]
             branches += [branch1]
         else:
             Fft(tree, my, branch1, branches, stop=stop, level=level + 1)
Ejemplo n.º 2
0
Archivo: sk.py Proyecto: timm/keys
 def divide(lo,hi,b4,rank):
   cut = left=right=None
   best = 0
   for j in range(lo+1,hi):
       left0  = Rx.sum( rxs[lo:j] )
       right0 = Rx.sum( rxs[j:hi] )
       now    = left0.xpect(right0, b4)
       if now > best:
           if left0 != right0:
               best, cut,left,right = now,j,kopy(left0),kopy(right0)
   if cut:
     rank = divide(lo, cut, left, rank) + 1
     rank = divide(cut ,hi, right,rank)
   else:
     for rx in rxs[lo:hi]:
       rx.rank = rank
   return rank
    def __divide(i, lo, hi, xr, yr, rank):
        "Find a split between lo and hi, then recurse on each split."
        xb4 = kopy(xr)
        xb4.stats = kopy(yr)
        xl = i.xis(key=i.x)
        yl = i.yis(key=i.y)
        best = yr.variety()
        cut = None
        # print("xl: ", xl)
        # print("yl: ", yl)
        for j in range(lo, hi):
            xl + i._lst[j]
            yl + i._lst[j]
            xr - i._lst[j]
            yr - i._lst[j]
            if xl.n >= i.step:
                if xr.n >= i.step:
                    # if j == 391:
                    # print("list: ", i._lst[j])

                    now = i.x(i._lst[j])
                    if j + 1 < len(i._lst):
                        after = i.x(i._lst[j + 1])
                    else:
                        # print("HERE: ",  i._lst[j])
                        after = i.x(i._lst[j])
                    if now == after: continue
                    if abs(xr.mu - xl.mu) >= i.epsilon:
                        if after - i.start >= i.epsilon:
                            if i.stop - now >= i.epsilon:
                                xpect = yl.xpect(yr)
                                if xpect * THE.div.trivial < best:
                                    best, cut = xpect, j
        if cut:
            ls, rs = i._lst[lo:cut], i._lst[cut:hi]
            i.finalcut = cut
            i.finallow = lo
            rank = i.__divide(lo, cut, i.xis(ls, key=i.x), i.yis(ls, key=i.y),
                              rank) + 1
            rank = i.__divide(cut, hi, i.xis(rs, key=i.x), i.yis(rs, key=i.y),
                              rank)
        else:
            xb4.rank = rank
            i.ranges += [xb4]
        return rank
Ejemplo n.º 4
0
 def run():
     """(1) Update the config using any command-line settings.
    (2) Maybe, update `todo` from the  command line."""
     my = o(**Eg.cli("python3.9 eg.py [OPTIONS]", CONFIG))
     if my.Todo:
         return [
             print(f"{name:>15} : {f.__doc__ or ''}")
             for name, f in Eg.all.items()
         ]
     if my.todo == "all":
         for _, f in Eg.all.items():
             my = kopy(my)
             Eg.run1(my, f)
         print("Errors:", Eg.crash)
         sys.exit(Eg.crash)
     else:
         if my.todo:
             Eg.run1(my, Eg.all[my.todo])
Ejemplo n.º 5
0
 def __init__(i, listofdicts=[]):
     i.x, i.y, dd = o(), o(), kopy(Cocomo.defaults)
     # set up the defaults
     for d in dd:
         for k in dd[d]:
             i.x[k] = dd[d][k]  # can't +=: no background info
     # apply any other constraints
     for dict1 in listofdicts:
         for k in dict1:
             try:
                 i.x[k] += dict1[k]  # now you can +=
             except Exception as e:
                 print(k, e)
     # ----------------------------------------------------------
     for k in dd.misc:
         i.y[k] = i.x[k]()
     for k in dd.pos:
         i.y[k] = F(.073, .21)() * (i.x[k]() - 3) + 1
     for k in dd.neg:
         i.y[k] = F(-.178, -.078)() * (i.x[k]() - 3) + 1
     for k in dd.sf:
         i.y[k] = F(-1.56, -1.014)() * (i.x[k]() - 6)