コード例 #1
0
ファイル: test_svr2.py プロジェクト: agamdua/mystic
    return (1+a1*a2)*(1+a1*a2)
Q = KernelMatrix(X, pk)

# the linear term for the QP
Y = concatenate([y,-y])
svr_epsilon = 4;
b = Y + svr_epsilon * ones(Y.size)

H = Q
f = b
Aeq = concatenate([ones(l), -ones(l)]).reshape(1,N)
Beq = array([0])
lb = zeros(N)
ub = zeros(N) + 0.5

alpha = qld.quadprog2(H, f, None, None, Aeq, Beq, lb, ub)
#alpha = 2*alpha

sv1 = SupportVectors(alpha[:l])
sv2 = SupportVectors(alpha[l:])

R = RegressionFunction(x, y, alpha, svr_epsilon, pk)

xx = arange(min(x),max(x),0.1)
pylab.plot(xx,R(xx))
pylab.plot(xx,R(xx)+svr_epsilon, 'k--')
pylab.plot(xx,R(xx)-svr_epsilon, 'k--')
pylab.plot(x[sv1],y[sv1],'ro')
pylab.plot(x[sv2],y[sv2],'go')

print alpha
コード例 #2
0
ファイル: qld_circle_dual.py プロジェクト: rowhit/mystic

if __name__ == '__main__':
    npt = 20
    from test_circle import xy
    npt1 = xy.shape[0]
    if npt is not npt1:
        xy = getpoints((x0, y0, R0), npt)
    else:
        pass
    Q = dot(xy, transpose(xy))
    f = -diag(Q) + 10
    H = Q * 2
    A = ones((1, npt))
    b = ones(1)
    x = qld.quadprog2(H, f, None, None, A, b, zeros(npt), ones(npt))

    center = dot(x, xy)
    print("center: %s" % center)
    # find support vectors (find numpy way please)

    sv = []
    for i, v in enumerate(x):
        if v > 0.001: sv.append(i)
    sv0 = sv[0]

    print(sv)
    R = linalg.norm(xy[sv0, :] - center)

    plot(xy, sv, x0, y0, R0, center, R)
コード例 #3
0
ファイル: qld_circle_dual.py プロジェクト: agamdua/mystic

if __name__ == '__main__':
    npt = 20
    from test_circle import xy
    npt1 = xy.shape[0]
    if npt is not npt1:
        xy = getpoints((x0,y0,R0),npt)
    else:
        pass
    Q = dot(xy, transpose(xy))
    f = -diag(Q)+10
    H = Q*2
    A = ones((1,npt))
    b = ones(1)
    x = qld.quadprog2(H, f, None, None, A, b, zeros(npt), ones(npt))

    center = dot(x,xy)
    print "center: " , center
    # find support vectors (find numpy way please)
    
    sv = []
    for i,v in enumerate(x):
       if v > 0.001: sv.append(i)
    sv0 = sv[0]
    
    print sv
    R = linalg.norm(xy[sv0,:]-center)

    plot(xy, sv, x0, y0, R0, center, R)