cone.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:learning-to-prune 作者: timvieira 项目源码 文件源码
def lambda_cone(accuracy, runtime, ax, c, conesize, lines=1, aspect_equal=1):
    #ax.scatter(runtime, accuracy, c=tradeoff, lw=0)

    P = zip(runtime, accuracy)
    #P.extend([(0,0), (runtime.max()+0.5e7, accuracy.max())])
    P.extend([(runtime.min()-.1*runtime.ptp(), 0),
              (runtime.max()+.1*runtime.ptp(), accuracy.max())])

#    tradeoff = np.array(list(tradeoff) + [np.inf, 0.0])

    hull = ConvexHull(P)
    v = hull.points[hull.vertices]

    ddd = []

    V = len(hull.vertices)
    for i in range(V):
        x1,y1 = v[(i-1) % V]
        x,y = v[i]
        x3,y3 = v[(i+1) % V]

        # slopes give a range for lambda values to try.
        m12 = (y-y1)/(x-x1)
        m23 = (y3-y)/(x3-x)

        # Note: This filter skips cases where the convex hull contains a
        # segments (edge) that is beneath the fronter (we know this because of
        # the orientation of the edge)..
        if m12 >= m23:
            continue

        ddd.append([m12, m23, x, y])

        ax.add_artist(Polygon([[x,y],
                               point(x, y, m12, -conesize),
                               point(x, y, m23, -conesize),
                               [x,y]],
                              linewidth=0,
                              alpha=0.5,
                              color=c,
                          ))

        if lines:
            ax.plot([x1,x,x3], [y1,y,y3], c=c, alpha=0.5)

    if aspect_equal:
        ax.set_aspect('equal')
    ax.grid(True)
    return ddd
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号