Ejemplo n.º 1
0
 def test_basic_no_gsl(self):
     import sys
     sys.modules['gsl'] = None
     import kvxopt
     kvxopt.normal(4, 8)
     kvxopt.uniform(4, 8)
Ejemplo n.º 2
0
        step = 1.0
        while 1-step*max(y) < 0: step *= BETA 
        while True:
            if -sum(log(1-step*y)) < ALPHA*step*lam: break
            step *= BETA
        x += step*v


# Generate an analytic centering problem  
#
#    -b1 <=  Ar*x <= b2 
#
# with random mxn Ar and random b1, b2.

m, n  = 500, 500
Ar = normal(m,n);
A = matrix([Ar, -Ar])
b = uniform(2*m,1)

x, ntdecrs = acent(A, b)  
try: 
    import pylab
except ImportError: 
    pass
else:
    pylab.semilogy(range(len(ntdecrs)), ntdecrs, 'o', 
             range(len(ntdecrs)), ntdecrs, '-')
    pylab.xlabel('Iteration number')
    pylab.ylabel('Newton decrement')
    pylab.show()
Ejemplo n.º 3
0
# The robust LP example of section 10.5 (Examples).

from kvxopt import normal, uniform
from kvxopt.modeling import variable, dot, op, sum
from kvxopt.blas import nrm2

m, n = 500, 100
A = normal(m, n)
b = uniform(m)
c = normal(n)

x = variable(n)
op(dot(c, x), A * x + sum(abs(x)) <= b).solve()

x2 = variable(n)
y = variable(n)
op(dot(c, x2), [A * x2 + sum(y) <= b, -y <= x2, x2 <= y]).solve()

print("\nDifference between two solutions %e" % nrm2(x.value - x2.value))
Ejemplo n.º 4
0
    S = matrix(0.0, (m, m))
    v = matrix(0.0, (m, 1))

    def Fkkt(x, z, W):
        ds = (2.0 * div(1 + x**2, (1 - x**2)**2))**-0.5
        Asc = A * spdiag(ds)
        blas.syrk(Asc, S)
        S[::m + 1] += 1.0
        lapack.potrf(S)
        a = z[0]

        def g(x, y, z):
            x[:] = mul(x, ds) / a
            blas.gemv(Asc, x, v)
            lapack.potrs(S, v)
            blas.gemv(Asc, v, x, alpha=-1.0, beta=1.0, trans='T')
            x[:] = mul(x, ds)

        return g

    return solvers.cp(F, kktsolver=Fkkt)['x']


m, n = 200, 2000
setseed()
A = normal(m, n)
x = uniform(n, 1)
b = A * x
x = l2ac(A, b)