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

# solve the dual for alpha
from mystic.solvers import DifferentialEvolutionSolver as DESolver
from mystic.termination import Or, ChangeOverGeneration, CollapseAt
ndim = len(lb)
npop = nx * 3
stop = Or(ChangeOverGeneration(1e-8, 200), CollapseAt(0.0))
solver = DESolver(ndim, npop)
solver.SetRandomInitialPoints(min=lb, max=_b)
solver.SetStrictRanges(min=lb, max=ub)
solver.SetGenerationMonitor(mon)
solver.SetConstraints(conserve)
solver.SetTermination(stop)
solver.Solve(objective, ExtraArgs=(Q, b), disp=1)
alpha = solver.bestSolution

print 'solved x: ', alpha
print "constraint A*x == 0: ", inner(Aeq, alpha)
print "minimum 0.5*x'Qx + b'*x: ", solver.bestEnergy

# calculate weight vectors, support vectors, and bias
wv = WeightVector(alpha, X, y)
sv1, sv2 = SupportVectors(alpha, y, eps=1e-6)
bias = Bias(alpha, X, y)

ym = (y.flatten() < 0).nonzero()[0]
yp = (y.flatten() > 0).nonzero()[0]
ii = inner(wv, X)
Beispiel #2
0
target = 0.0
n = 10

#term = Or((COG(generations=300), CollapseAt(None, generations=100), CollapseAs(generations=100)))
term = Or((COG(generations=500), CollapseAt(target, generations=100)))
#term = COG(generations=500)

from mystic.solvers import DifferentialEvolutionSolver as TheSolver
#from mystic.solvers import PowellDirectionalSolver as TheSolver
from mystic.solvers import BuckshotSolver
#solver = BuckshotSolver(n, 10)
solver = TheSolver(n)
solver.SetRandomInitialPoints()
solver.SetStrictRanges(min=[0] * n, max=[5] * n)
solver.SetEvaluationLimits(evaluations=320000, generations=1000)
solver.SetTermination(term)

#from mystic.termination import state
#print state(solver._termination).keys()
solver.Solve(model, disp=verbose)

# while collapse and solver.Collapse(verbose):
#   solver.Solve(model)

# we are done; get result
print solver.Terminated(info=True)
print solver.bestEnergy, "@"
print solver.bestSolution

# EOF