Annotation of OpenXM_contrib/PHC/Ada/Homotopy/drivers_for_scaling.adb, Revision 1.1.1.1
1.1 maekawa 1: with integer_io; use integer_io;
2: with Communications_with_User; use Communications_with_User;
3: with Timing_Package; use Timing_Package;
4: with Standard_Floating_Numbers; use Standard_Floating_Numbers;
5: with Standard_Floating_Numbers_io; use Standard_Floating_Numbers_io;
6: with Standard_Complex_Vectors_io; use Standard_Complex_Vectors_io;
7: with Standard_Complex_Poly_Systems_io; use Standard_Complex_Poly_Systems_io;
8: with Scaling; use Scaling;
9:
10: package body Drivers_for_Scaling is
11:
12: procedure Display_Info is
13:
14: i : array(1..12) of string(1..65);
15:
16: begin
17: i( 1):="By scaling the coefficients are transformed so that they do not";
18: i( 2):="have extreme values. The purpose is to avoid numerical problems.";
19: i( 3):=" Equation scaling means that every polynomial is divided by its";
20: i( 4):="average coefficient. ";
21: i( 5):=" Variable scaling uses transformations like z = (2^c)*x. The";
22: i( 6):="transformation is such that real solutions remain real. The";
23: i( 7):="inverse of the condition number of the linear system that is";
24: i( 8):="solved to set up this transformation gives an indication on the";
25: i( 9):="condition of the original polynomial system. ";
26: i(10):=" Solution scaling transforms the solutions of a scaled system";
27: i(11):="back into the original coordinate system. Note that in the";
28: i(12):="original coordinates, the solutions can be ill-conditioned. ";
29: for k in i'range loop
30: put_line(i(k));
31: end loop;
32: end Display_Info;
33:
34: procedure Equation_Scaling
35: ( file : in file_type; p : in out Poly_Sys ) is
36:
37: timer : Timing_Widget;
38:
39: begin
40: put_line(file,"EQUATION SCALING :");
41: tstart(timer);
42: Scale(p);
43: tstop(timer);
44: new_line(file); print_times(file,timer,"Equation Scaling"); new_line(file);
45: end Equation_Scaling;
46:
47: procedure Variable_Scaling
48: ( file : in file_type; p : in out Poly_Sys;
49: basis : out natural; scvc : out Link_to_Vector ) is
50:
51: timer : Timing_Widget;
52: rcond : double_float;
53: bas : natural := 2;
54: scalecoeff : Vector(1..2*p'length);
55:
56: begin
57: put_line(file,"EQUATION AND VARIABLE SCALING :");
58: -- put(" Reducing the variability of coefficients ? (y/n) ");
59: -- Ask_Yes_or_No(yn);
60: -- if yn = 'y'
61: -- then put_line(file," Reduce the variability of coefficients.");
62: -- scale(p,bas,true,rcond,scalecoeff);
63: -- else put_line(file," No reduce of variability of coefficients.");
64: -- scale(p,bas,false,rcond,scalecoeff);
65: -- end if;
66: tstart(timer);
67: scale(p,bas,false,rcond,scalecoeff);
68: tstop(timer);
69: put(" The inverse condition is "); put(rcond,3,3,3); new_line;
70: put(file," The inverse condition is "); put(file,rcond); new_line(file);
71: basis := bas;
72: scvc := new Vector'(scalecoeff);
73: new_line(file); print_times(file,timer,"Variable Scaling"); new_line(file);
74: end Variable_Scaling;
75:
76: procedure Write_Results ( file : in file_type; p : in Poly_Sys;
77: basis : in natural; scvc : in Link_to_Vector ) is
78: begin
79: new_line(file);
80: put_line(file,"THE SCALED SYSTEM :");
81: new_line(file); put(file,p); new_line(file);
82: if basis /= 0
83: then new_line(file);
84: put_line(file,"SCALING COEFFICIENTS :");
85: new_line(file);
86: put(file,basis,1); new_line(file);
87: put_line(file,scvc);
88: end if;
89: end Write_Results;
90:
91: procedure Driver_for_Scaling
92: ( file : in file_type; p : in out Poly_Sys;
93: basis : out natural; scvc : out Link_to_Vector ) is
94:
95: ans : character;
96: res_scvc : Link_to_Vector;
97: bas : natural := 0;
98:
99: begin
100: loop
101: new_line;
102: put_line("MENU for Scaling Polynomial Systems :");
103: put_line(" 0 : No Scaling : leave the menu ");
104: put_line(" 1 : Equation Scaling : divide by average coefficient ");
105: put_line(" 2 : Variable Scaling : change of variables, as z = (2^c)*x");
106: put("Type 0, 1, or 2 to select scaling, or i for info : ");
107: Ask_Alternative(ans,"012i");
108: if ans = 'i'
109: then new_line; Display_Info;
110: end if;
111: exit when ans /= 'i';
112: end loop;
113: case ans is
114: when '1' => Equation_Scaling(file,p);
115: when '2' => Variable_Scaling(file,p,bas,res_scvc);
116: when others => null;
117: end case;
118: case ans is
119: when '1' | '2' => Write_Results(file,p,bas,res_scvc);
120: when others => null;
121: end case;
122: basis := bas; scvc := res_scvc;
123: end Driver_for_Scaling;
124:
125: end Drivers_for_Scaling;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>