def test_pieri(): """ Does a test on the Pieri homotopies. """ (mdim, pdim, qdeg) = prompt_for_dimensions() pieri_root_count(mdim, pdim, qdeg) dim = mdim*pdim + qdeg*(mdim+pdim) planes = [random_complex_matrix(mdim+pdim, mdim) for k in range(0, dim)] # print '%d random %d-planes :' % (dim, m) # for A in planes: # for row in A: print row # print '' if(qdeg > 0): points = random_complex_matrix(dim, 1) print('interpolation points :') for point in points: print(point) (system, sols) = run_pieri_homotopies(mdim, pdim, qdeg, planes, points) else: (system, sols) = run_pieri_homotopies(mdim, pdim, qdeg, planes) print('evaluation of the solutions :') verify(system, sols) from phcpy.solver import newton_step print('verification with one Newton step :') newton_step(system, sols) # cheater(m, p, qdeg, system, sols) if(qdeg == 0): osculating_input(mdim, pdim, qdeg, system, sols)
def test_track(silent=True, precision="d", decimals=80): """ Tests the path tracking on a small random system. Two random trinomials are generated and random constants are added to ensure there are no singular solutions so we can use this generated system as a start system. The target system has the same monomial structure as the start system, but with random real coefficients. Because all coefficients are random, the number of paths tracked equals the mixed volume of the system. """ from phcpy.solver import random_trinomials, real_random_trinomials from phcpy.solver import solve, mixed_volume, newton_step pols = random_trinomials() real_pols = real_random_trinomials(pols) from random import uniform as u qone = pols[0][:-1] + ("%+.17f" % u(-1, +1)) + ";" qtwo = pols[1][:-1] + ("%+.17f" % u(-1, +1)) + ";" rone = real_pols[0][:-1] + ("%+.17f" % u(-1, +1)) + ";" rtwo = real_pols[1][:-1] + ("%+.17f" % u(-1, +1)) + ";" start = [qone, qtwo] target = [rone, rtwo] start_sols = solve(start, silent) sols = track(target, start, start_sols, precision, decimals) mixvol = mixed_volume(target) print "mixed volume of the target is", mixvol print "number of solutions found :", len(sols) newton_step(target, sols, precision, decimals)
def test_monitored_track(): """ Often the number of paths to track can be huge and waiting on the outcome of track() without knowing how many paths that have been tracked so far can be annoying. This script illustrates how one can monitor the progress of the path tracking. We must use the same gamma constant with each call of track. """ from random import uniform from cmath import pi, exp angle = uniform(0, 2 * pi) ourgamma = exp(complex(0, 1) * angle) from phcpy.solver import total_degree_start_system, newton_step quadrics = ["x**2 + 4*y**2 - 4;", "2*y**2 - x;"] (startsys, startsols) = total_degree_start_system(quadrics) targetsols = [] for ind in range(0, len(startsols)): print "tracking path", ind + 1, "...", endsol = track(quadrics, startsys, [startsols[ind]], gamma=ourgamma) print "found solution\n", endsol[0] targetsols.append(endsol[0]) print "tracked", len(targetsols), "paths, running newton_step..." newton_step(quadrics, targetsols)
def test_track(silent=True, precision='d', decimals=80): """ Tests the path tracking on a small random system. Two random trinomials are generated and random constants are added to ensure there are no singular solutions so we can use this generated system as a start system. The target system has the same monomial structure as the start system, but with random real coefficients. Because all coefficients are random, the number of paths tracked equals the mixed volume of the system. """ from phcpy.solver import random_trinomials, real_random_trinomials from phcpy.solver import solve, mixed_volume, newton_step pols = random_trinomials() real_pols = real_random_trinomials(pols) from random import uniform as u qone = pols[0][:-1] + ('%+.17f' % u(-1, +1)) + ';' qtwo = pols[1][:-1] + ('%+.17f' % u(-1, +1)) + ';' rone = real_pols[0][:-1] + ('%+.17f' % u(-1, +1)) + ';' rtwo = real_pols[1][:-1] + ('%+.17f' % u(-1, +1)) + ';' start = [qone, qtwo] target = [rone, rtwo] start_sols = solve(start, silent) sols = track(target, start, start_sols, precision, decimals) mixvol = mixed_volume(target) print 'mixed volume of the target is', mixvol print 'number of solutions found :', len(sols) newton_step(target, sols, precision, decimals)
def test_pieri(): """ Does a test on the Pieri homotopies. """ (mdim, pdim, qdeg) = prompt_for_dimensions() pieri_root_count(mdim, pdim, qdeg) dim = mdim * pdim + qdeg * (mdim + pdim) planes = [random_complex_matrix(mdim + pdim, mdim) for k in range(0, dim)] # print '%d random %d-planes :' % (dim, m) # for A in planes: # for row in A: print row # print '' if (qdeg > 0): points = random_complex_matrix(dim, 1) print('interpolation points :') for point in points: print(point) (system, sols) = run_pieri_homotopies(mdim, pdim, qdeg, planes, points) else: (system, sols) = run_pieri_homotopies(mdim, pdim, qdeg, planes) print('evaluation of the solutions :') verify(system, sols) from phcpy.solver import newton_step print('verification with one Newton step :') newton_step(system, sols) # cheater(m, p, qdeg, system, sols) if (qdeg == 0): osculating_input(mdim, pdim, qdeg, system, sols)
def test_monitored_track(): """ Often the number of paths to track can be huge and waiting on the outcome of track() without knowing how many paths that have been tracked so far can be annoying. This script illustrates how one can monitor the progress of the path tracking. We must use the same gamma constant with each call of track. """ from random import uniform from cmath import pi, exp angle = uniform(0, 2*pi) ourgamma = exp(complex(0, 1)*angle) from phcpy.solver import total_degree_start_system, newton_step quadrics = ['x**2 + 4*y**2 - 4;', '2*y**2 - x;'] (startsys, startsols) = total_degree_start_system(quadrics) targetsols = [] for ind in range(0, len(startsols)): print 'tracking path', ind+1, '...', endsol = track(quadrics, startsys, [startsols[ind]], gamma=ourgamma) print 'found solution\n', endsol[0] targetsols.append(endsol[0]) print 'tracked', len(targetsols), 'paths, running newton_step...' newton_step(quadrics, targetsols)
""" We illustrate deflation on the example of Griewank and Osborne. The point (0, 0) is an irregular singularity and Newton fails to converge even if we start already quite close to (0, 0). Deflation solves this problem. """ p = ['(29/16)*x^3 - 2*x*y;', 'x^2 - y;'] from phcpy.solutions import make_solution sol = make_solution(['x', 'y'],[1.0e-6, 1.0e-6]) print 'the initial solution :' print sol from phcpy.solver import newton_step from phcpy.solutions import diagnostics sols = [sol] for k in range(5): sols = newton_step(p, sols) (err, rco, res) = diagnostics(sols[0]) print 'forward error :', err print 'estimate for inverse condition :', rco print 'backward error :', res print 'the solution after five Newton steps :' print sols[0] from phcpy.solver import standard_deflate sols = standard_deflate(p, sols) print 'after deflation :' print sols[0]
Illustration of a mixed volume computation, polyhedral homotopies and the path tracking in double precision. First we construct a random coefficient start system, computing the mixed volume and running polyhedral homotopies. Then we use the constructed start system g and corresponding start solutions sols to solve the original system f. Finally, we verify the solutions with one Newton step on each computed solution, in double double precision. """ f = ['x^3*y + x*y^2 - 8;', 'x*y - 3;'] print 'the polynomials in the target system :' for pol in f: print pol from phcpy.solver import mixed_volume as mv from phcpy.solver import random_coefficient_system as rcs print 'the mixed volume :', mv(f) (g, gsols) = rcs() print 'the polynomials in the start system :' for pol in g: print pol print 'number of start solutions :', len(gsols) from phcpy.trackers import standard_double_track as track fsols = track(f, g, gsols) from phcpy.solver import newton_step for sol in fsols: print sol print 'one Newton step in double double precision...' nsols = newton_step(f, fsols, precision='dd') for sol in nsols: print sol