Пример #1
0
# set the bounds
lb = zeros(nx)
ub = 1 * ones(nx)
_b = .1 * ones(nx)  # good starting value if most solved xi should be zero

# build the constraints operator
from mystic.symbolic import linear_symbolic, solve, simplify, \
     generate_solvers as solvers, generate_constraint as constraint
constrain = linear_symbolic(Aeq, Beq)
#NOTE: HACK assumes a single equation of the form: '1.0*x0 + ... = 0.0\n'
x0, rhs = constrain.strip().split(' = ')
x0, xN = x0.split(' + ', 1)
N, x0 = x0.split("*")
constrain = "{x0} = ({rhs} - ({xN}))/{N}".format(x0=x0, xN=xN, N=N, rhs=rhs)
#NOTE: end HACK (as mystic.symbolic.solve takes __forever__)
constrain = constraint(solvers(constrain))
#constrain = constraint(solvers(solve(constrain)))

from mystic import suppressed


@suppressed(1e-2)
def conserve(x):
    return constrain(x)


from mystic.monitors import VerboseMonitor
mon = VerboseMonitor(10)

# solve the dual for alpha
from mystic.solvers import DifferentialEvolutionSolver as DESolver
Пример #2
0
Q = KernelMatrix(XX)  # Q_ij = K(x_i, x_j)
b = -ones(nx)  # b_i = 1  (in dual)

# build the constraints (y.T * x = 0.0)
# 1.0*x0 + 1.0*x1 + ... - 1.0*xN = 0.0
Aeq = y
Beq = array([0.])
# set the bounds
lb = zeros(nx)
ub = 99999 * ones(nx)

# build the constraints operator
from mystic.symbolic import linear_symbolic, solve, \
     generate_solvers as solvers, generate_constraint as constraint
constrain = linear_symbolic(Aeq, Beq)
constrain = constraint(solvers(solve(constrain, target=['x0'])))

from mystic import suppressed


@suppressed(1e-5)
def conserve(x):
    return constrain(x)


#from mystic.monitors import VerboseMonitor
#mon = VerboseMonitor(10)

# solve the dual for alpha
from mystic.solvers import diffev
alpha = diffev(objective, list(zip(lb,ub)), args=(Q,b), npop=nx*3, gtol=200, \
Пример #3
0
svr_epsilon = 4
b = Y + svr_epsilon * ones(Y.size)

# build the constraints (y.T * x = 0.0)
# 1.0*x0 + 1.0*x1 + ... - 1.0*xN = 0.0
Aeq = concatenate([ones(nx), -ones(nx)]).reshape(1, N)
Beq = array([0.0])
# set the bounds
lb = zeros(N)
ub = zeros(N) + 0.5

# build the constraints operator
from mystic.symbolic import linear_symbolic, solve, generate_solvers as solvers, generate_constraint as constraint

constrain = linear_symbolic(Aeq, Beq)
constrain = constraint(solvers(solve(constrain, target=["x0"])))

from mystic import suppressed


@suppressed(1e-5)
def conserve(x):
    return constrain(x)


from mystic.monitors import VerboseMonitor

mon = VerboseMonitor(10)

# solve for alpha
from mystic.solvers import diffev
Пример #4
0
svr_epsilon = 3
b = Y + svr_epsilon * ones(Y.size)

# build the constraints (y.T * x = 0.0)
# 1.0*x0 + 1.0*x1 + ... - 1.0*xN = 0.0
Aeq = concatenate([ones(nx), -ones(nx)]).reshape(1,N)
Beq = array([0.])
# set the bounds
lb = zeros(N)
ub = zeros(N) + 0.5

# build the constraints operator
from mystic.symbolic import linear_symbolic, solve, \
     generate_solvers as solvers, generate_constraint as constraint
constrain = linear_symbolic(Aeq,Beq)
constrain = constraint(solvers(solve(constrain,target=['x0'])))

from mystic import suppressed
@suppressed(1e-5)
def conserve(x):
    return constrain(x)

from mystic.monitors import VerboseMonitor
mon = VerboseMonitor(10)

# solve for alpha
from mystic.solvers import diffev
alpha = diffev(objective, list(zip(lb,.1*ub)), args=(Q,b), npop=N*3, gtol=200, \
               itermon=mon, \
               ftol=1e-5, bounds=list(zip(lb,ub)), constraints=conserve, disp=1)
Пример #5
0
# set the bounds
lb = zeros(nx)
ub = 1 * ones(nx)
_b = .1 * ones(nx) # good starting value if most solved xi should be zero

# build the constraints operator
from mystic.symbolic import linear_symbolic, solve, simplify, \
     generate_solvers as solvers, generate_constraint as constraint
constrain = linear_symbolic(Aeq,Beq)
#NOTE: HACK assumes a single equation of the form: '1.0*x0 + ... = 0.0\n'
x0,rhs = constrain.strip().split(' = ')
x0,xN = x0.split(' + ', 1) 
N,x0 = x0.split("*")
constrain = "{x0} = ({rhs} - ({xN}))/{N}".format(x0=x0, xN=xN, N=N, rhs=rhs)
#NOTE: end HACK (as mystic.symbolic.solve takes __forever__)
constrain = constraint(solvers(constrain))
#constrain = constraint(solvers(solve(constrain)))

from mystic import suppressed
@suppressed(5e-2)
def conserve(x):
    return constrain(x)

from mystic.monitors import VerboseMonitor
mon = VerboseMonitor(10)

# solve the dual for alpha
from mystic.solvers import diffev
alpha = diffev(objective, list(zip(lb,_b)), args=(Q,b), npop=nx*3, gtol=200,\
               itermon=mon, \
               ftol=1e-8, bounds=list(zip(lb,ub)), constraints=conserve, disp=1)