Пример #1
0
    print("Powell's Method")
    print("===============")

    # dimensional information
    from mystic.tools import random_seed
    random_seed(12)
    ndim = len(pointvec)
    nbins = 1 #[2,1,2,1,2,1,2,1,1]


    # configure monitor
    stepmon = VerboseMonitor(1)

    # use lattice-Powell to solve 8th-order Chebyshev coefficients
    solver = LatticeSolver(ndim, nbins)
    solver.SetNestedSolver(PowellDirectionalSolver)
    solver.SetMapper(Pool().map)
    solver.SetGenerationMonitor(stepmon)
    solver.SetStrictRanges(min=[0]*ndim, max=[1]*ndim)
    solver.SetConstraints(constraintfunc)
    solver.Solve(test_obj, NCOG(1e+2), disp=1)
    solution = solver.Solution()

    # use pretty print for polynomials
    print(solution)

for i in list(range(0,len(pointvec))):
    if round(solution[i])==1:
        print(namevec[i])
print(team_c(solution))
Пример #2
0
    print("===============")

    # dimensional information
    from mystic.tools import random_seed
    random_seed(123)
    ndim = 9
    nbins = 8  #[2,1,2,1,2,1,2,1,1]

    # draw frame and exact coefficients
    plot_exact()

    # configure monitor
    stepmon = VerboseMonitor(1)

    # use lattice-Powell to solve 8th-order Chebyshev coefficients
    solver = LatticeSolver(ndim, nbins)
    solver.SetNestedSolver(PowellDirectionalSolver)
    solver.SetMapper(Pool().map)
    solver.SetGenerationMonitor(stepmon)
    solver.SetStrictRanges(min=[-300] * ndim, max=[300] * ndim)
    solver.Solve(chebyshev8cost, NCOG(1e-4), disp=1)
    solution = solver.Solution()

    # use pretty print for polynomials
    print(poly1d(solution))

    # compare solution with actual 8th-order Chebyshev coefficients
    print("\nActual Coefficients:\n %s\n" % poly1d(chebyshev8coeffs))

    # plot solution versus exact coefficients
    plot_solution(solution)
if ide < 55:
    g = proc.processDataForOptimizing
elif ide > 54 and ide < 109:
    g = proc.processDataForOptimizingUpdate1
else:
    g = proc.processDataForOptimizingBL

my_solver = PowellDirectionalSolver(
    dim
)  # initializes the PowellDirectionalSolver with the number of parameters
my_solver.SetStrictRanges(
    lb, ub
)  # sets the range that the solutions must be within for PowellDirectionalSolver
start = time.time()
solver = LatticeSolver(
    dim, nbins=2
)  # initalizes the LatticeSolver with the number of parameters and the number of bins for starting points
solver.SetStrictRanges(
    lb, ub
)  # sets the range that the solutions must be within for the LatticeSolver
solver.SetNestedSolver(
    my_solver)  # nests the PowellDirectionalSolver within the LatticeSolver
solver.SetMapper(Pool(nodes=100).map)
solver.Solve(g)  # LatticeSolver optimizes on the function g
sol = solver.Solution(
)  # sets sol to the list of values that each parameter is optimized to
stop = time.time()
lst = []
for j in range(len(sol)):
    lst.append(
        params[j] + "->" + str(sol[j])