Add files
This commit is contained in:
7
python/examples/eigen_in_python.py
Normal file
7
python/examples/eigen_in_python.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import pybertini as pb
|
||||
import numpy as np
|
||||
|
||||
mpfr_complex = pb.multiprec.Complex
|
||||
|
||||
|
||||
np.empty(dtype=mpfr_complex, shape=(3,))
|
||||
141
python/examples/endgame.py
Normal file
141
python/examples/endgame.py
Normal file
@@ -0,0 +1,141 @@
|
||||
import pybertini as pb
|
||||
|
||||
from pybertini import Variable, VariableGroup, System
|
||||
import pybertini.system.start_system as ss
|
||||
|
||||
from pybertini.function_tree.symbol import Rational
|
||||
|
||||
from pybertini.endgame import *
|
||||
from pybertini.endgame.config import *
|
||||
|
||||
from pybertini.tracking import *
|
||||
from pybertini.tracking.config import *
|
||||
|
||||
from pybertini.multiprec import Float as mpfr_float
|
||||
from pybertini.multiprec import Complex as mpfr_complex
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
|
||||
ambient_precision = 50;
|
||||
|
||||
|
||||
|
||||
x = Variable("x");
|
||||
y = Variable("y");
|
||||
t = Variable("t");
|
||||
#
|
||||
sys = System();
|
||||
#
|
||||
var_grp = VariableGroup();
|
||||
var_grp.append(x);
|
||||
var_grp.append(y);
|
||||
|
||||
sys.add_variable_group(var_grp);
|
||||
|
||||
sys.add_function((x-1)**3)
|
||||
sys.add_function((y-1)**2)
|
||||
|
||||
sys.homogenize();
|
||||
sys.auto_patch();
|
||||
|
||||
assert (sys.is_patched() == 1)
|
||||
assert (sys.is_homogeneous() == 1)
|
||||
|
||||
td = ss.TotalDegree(sys);
|
||||
|
||||
assert (td.is_patched() == 1)
|
||||
assert (td.is_homogeneous() == 1)
|
||||
|
||||
gamma = Rational.rand();
|
||||
|
||||
|
||||
final_system = (1-t)*sys + gamma*t*td;
|
||||
final_system.add_path_variable(t);
|
||||
|
||||
print(final_system)
|
||||
prec_config = AMPConfig(final_system);
|
||||
|
||||
stepping_pref = SteppingConfig();
|
||||
newton_pref = NewtonConfig();
|
||||
|
||||
|
||||
|
||||
tracker = AMPTracker(final_system);
|
||||
|
||||
tracker.setup(Predictor.RK4, 1e-5, 1e5, stepping_pref, newton_pref);
|
||||
tracker.precision_setup(prec_config);
|
||||
|
||||
num_paths_to_track = td.num_start_points();
|
||||
n = int(str(num_paths_to_track));
|
||||
|
||||
t_start = mpfr_complex(1);
|
||||
t_endgame_boundary = mpfr_complex("0.1");
|
||||
t_final = mpfr_complex(0);
|
||||
|
||||
|
||||
print('tracking to the endgame boundary')
|
||||
|
||||
|
||||
bdry_points = [np.empty(dtype=mpfr_complex, shape=(3,)) for i in range(n)]
|
||||
|
||||
for i in range(n):
|
||||
|
||||
pb.default_precision(ambient_precision);
|
||||
final_system.precision(ambient_precision);
|
||||
|
||||
print('here')
|
||||
|
||||
td.precision(ambient_precision)
|
||||
start_point = td.start_point_mp(i);
|
||||
|
||||
print('there')
|
||||
print(pb.multiprec.precision(start_point))
|
||||
|
||||
|
||||
bdry_pt = np.zeros(dtype=mpfr_complex, shape=(3));
|
||||
track_success_code = tracker.track_path(bdry_pt,t_start, t_endgame_boundary, start_point);
|
||||
print(bdry_pt.flags)
|
||||
bdry_points[i] = bdry_pt;
|
||||
|
||||
assert (track_success_code == SuccessCode.Success)
|
||||
|
||||
|
||||
|
||||
tracker.setup(Predictor.HeunEuler, 1e-6, 1e5, stepping_pref, newton_pref);
|
||||
my_endgame = AMPCauchyEG(tracker);
|
||||
|
||||
|
||||
print('running the endgame')
|
||||
|
||||
final_homogenized_solutions = [np.empty(dtype=mpfr_complex, shape=(3,)) for i in range(n)]
|
||||
for i in range(n):
|
||||
p = bdry_points[i]
|
||||
|
||||
print("RIGHT HERE V")
|
||||
|
||||
print(p[0].precision())
|
||||
|
||||
|
||||
print('moving to precision {} to match precision of boundary point'.format(pb.multiprec.precision(p)))
|
||||
|
||||
|
||||
pb.default_precision(p[0].precision());
|
||||
final_system.precision(p[0].precision());
|
||||
|
||||
print(p.flags)
|
||||
|
||||
t = mpfr_complex(0)
|
||||
t = t_endgame_boundary
|
||||
t.precision(p[0].precision())
|
||||
|
||||
q = np.zeros(dtype=mpfr_complex, shape=(3));
|
||||
print(p.flags)
|
||||
track_success_code = my_endgame.run(t,p);
|
||||
print(track_success_code)
|
||||
|
||||
|
||||
final_homogenized_solutions[i] = my_endgame.final_approximation();
|
||||
print(final_system.dehomogenize_point(final_homogenized_solutions[i]));
|
||||
assert (track_success_code == SuccessCode.Success)
|
||||
28
python/examples/evaluate_system.py
Normal file
28
python/examples/evaluate_system.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import pybertini as pb
|
||||
import numpy as np
|
||||
|
||||
pb.default_precision(500)
|
||||
|
||||
x = pb.Variable('x')
|
||||
y = pb.Variable('y')
|
||||
z = pb.Variable('z')
|
||||
|
||||
vg = pb.VariableGroup([x,y,z])
|
||||
|
||||
sys = pb.System()
|
||||
|
||||
sys.add_function(x-y)
|
||||
sys.add_function(x**2 + y**2 - 1)
|
||||
sys.add_function(5*x**3 + 16*x*y**4 - 17*x*y*z - z**3)
|
||||
|
||||
sys.add_variable_group(vg)
|
||||
|
||||
random_complex = lambda : pb.random.complex_in_minus_one_to_one()
|
||||
|
||||
n_iterations = 10000
|
||||
print(f'evaluating system at random complex point {n_iterations} times at precision {pb.default_precision()}')
|
||||
for ii in range(n_iterations):
|
||||
variable_values = np.array([random_complex(), random_complex(), random_complex()])
|
||||
result = sys.eval(variable_values)
|
||||
|
||||
|
||||
22
python/examples/finding_issue.py
Normal file
22
python/examples/finding_issue.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# finding issue
|
||||
|
||||
import pybertini as pb
|
||||
|
||||
x = pb.Variable('x')
|
||||
y = pb.Variable('y')
|
||||
|
||||
f = pb.function_tree.root.Function(x)
|
||||
f.name = 'f'
|
||||
x.set_current_value(1)
|
||||
|
||||
print(f.eval_d())
|
||||
|
||||
vg = pb.VariableGroup([x,y])
|
||||
|
||||
sys = pb.System()
|
||||
sys.add_function(f)
|
||||
|
||||
print(sys)
|
||||
# sys.add_function(x**2 + y**2 - 1)
|
||||
|
||||
sys.add_variable_group(vg)
|
||||
6
python/examples/make_and_print.py
Normal file
6
python/examples/make_and_print.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import numpy as np
|
||||
import pybertini as pb
|
||||
|
||||
v = np.zeros(shape=(3,), dtype=pb.multiprec.Complex)
|
||||
|
||||
print(v[0])
|
||||
33
python/examples/solve_system.py
Normal file
33
python/examples/solve_system.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import pybertini as pb
|
||||
import numpy as np
|
||||
|
||||
x = pb.Variable('x')
|
||||
y = pb.Variable('y')
|
||||
|
||||
vg = pb.VariableGroup([x,y])
|
||||
|
||||
sys = pb.System()
|
||||
|
||||
sys.add_function(x-y)
|
||||
sys.add_function(x**2 + y**2 - 1)
|
||||
|
||||
sys.add_variable_group(vg)
|
||||
|
||||
C = pb.multiprec.Complex
|
||||
|
||||
variable_values = np.array([C(0), C(0)])
|
||||
|
||||
result = sys.eval(variable_values)
|
||||
print(result)
|
||||
|
||||
sys.homogenize()
|
||||
sys.auto_patch()
|
||||
|
||||
|
||||
solver = pb.nag_algorithm.ZeroDimCauchyAdaptivePrecisionTotalDegree(sys)
|
||||
|
||||
solver.solve()
|
||||
|
||||
for soln in solver.solutions():
|
||||
|
||||
print(sys.dehomogenize_point(soln))
|
||||
46
python/examples/track_path_constructed_homotopy.py
Normal file
46
python/examples/track_path_constructed_homotopy.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import pybertini as pb
|
||||
|
||||
pb.logging.init()
|
||||
# pb.logging.add_file('asdf.txt')
|
||||
|
||||
import numpy as np
|
||||
|
||||
x = pb.Variable('x')
|
||||
y = pb.Variable('y')
|
||||
z = pb.Variable('z')
|
||||
|
||||
t = pb.Variable('t')
|
||||
|
||||
vg = pb.VariableGroup([x,y,z])
|
||||
|
||||
f = pb.System()
|
||||
|
||||
f.add_function(x-y)
|
||||
f.add_function(x**2 + y**2 - 1)
|
||||
f.add_function(5*x**3 + 16*x*y**4 - 17*x*y*z - z**3)
|
||||
|
||||
f.add_variable_group(vg)
|
||||
|
||||
g = pb.system.start_system.TotalDegree(f)
|
||||
|
||||
homotopy = t*g + (1-t)*f
|
||||
|
||||
homotopy.add_path_variable(t);
|
||||
|
||||
|
||||
print(homotopy)
|
||||
|
||||
C = pb.multiprec.Complex
|
||||
|
||||
tracker = pb.tracking.AMPTracker(homotopy);
|
||||
|
||||
print(tracker)
|
||||
|
||||
result = np.empty((3,),dtype=C) # right now, if i don't preset to the correct size, i get abort traps.
|
||||
# there's something deeper wrong with the wrapper i wrote, cuz it should allow resizing, but it's not.
|
||||
|
||||
start_point = g.start_point_mp(0)
|
||||
|
||||
print(start_point)
|
||||
|
||||
tracker.track_path(result, C(1) , C(0), start_point)
|
||||
Reference in New Issue
Block a user