Changeset a20c202 in tol
- Timestamp:
- Feb 2, 2009, 3:28:54 PM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 462fc07
- Parents:
- c7a5e4e
- Files:
-
- 3 edited
-
tol/stdlib/math/_init_math.tol (modified) (1 diff)
-
tol/stdlib/math/linalg/_solve_precond_sym.tol (modified) (9 diffs)
-
tol_tests/tol/LinearAlgebra/vmatrix/test_0011/test.tol (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/_init_math.tol
rc7a5e4e ra20c202 20 20 NIntegrate); 21 21 22 Set Include("linalg/_init_linalg.tol"); 22 23 Set Include("optim/_init_optim.tol"); 23 24 Set Include("stat/_init_stat.tol"); -
tol/stdlib/math/linalg/_solve_precond_sym.tol
rc7a5e4e ra20c202 10 10 "preconditioner of previously normalized system foilowing these steps:\n" 11 11 "1. Original symmetric system M*z = y is previously normalized by non null " 12 "elements of root squares of diagonal elements of M t aht will called D:\n"12 "elements of root squares of diagonal elements of M that will called D:\n" 13 13 " S*u = v where S=Di*M*Di; Di=D^-1; u=D*x; v=Di*y\n" 14 14 "Then\n" … … 22 22 "((S+c*I)^-1)*S that is not neccessary so sparse as S nor L.\n" 23 23 "4. Solution is denormalized to solve original problem.\n" 24 "Normalization is an optional task that is specified by argument " 25 "do.normalize\n" 26 "If M is numerically definite positive (c=0) then CholeskiSolve will " 27 "be used directly if argument forze.lanczos of Solve method is true.\n" 24 28 "Using instructions to solve M*x=y :\n" 25 " //Builds preconditioning handler \n"26 " NameBlock SPDP = SymPosDefPrecond(H ); \n"29 " //Builds preconditioning handler with normalization\n" 30 " NameBlock SPDP = SymPosDefPrecond(H, True); \n" 27 31 " //Finds optimal preconditioner\n" 28 32 " Real SPDP::ScaleOptimize(1.E-7); \n" 29 33 " //Solves the system\n" 30 " NameBlock solution = SPDP::Solve(y,1.E-10 ); \n"34 " NameBlock solution = SPDP::Solve(y,1.E-10,True); \n" 31 35 " //Takes the solution matrix\n" 32 36 " VMatrix x = solution::_.x;\n" 33 37 "\n"; 34 38 35 NameBlock SolvePrecondSym(VMatrix M )39 NameBlock SolvePrecondSym(VMatrix M, Real do.normalize) 36 40 {[[ 37 41 //Original symmetric system to be solved M*x = y 38 42 VMatrix _.M = M; 43 Real _.do.normalize = do.normalize; 44 Real _.m = VRows(_.M); 39 45 40 46 //Returns a diagonal normalizer VMatrix for a symmetric VMatrix 41 VMatrix Normalizer(VMatrix S)47 VMatrix Normalizer(VMatrix M) 42 48 { 43 Real r = VRows(S); 44 VMatrix d2 = Tra(SubDiag(S,0)); 49 If(!_.do.normalize, Eye(_.m), { 50 Real r = VRows(M); 51 VMatrix d2 = Tra(SubDiag(M,0)); 45 52 VMatrix d = d2^(+1/2); 46 53 VMatrix di = … … 49 56 Mat2VMat(IfMat(Eq(d_,d_*0),d_*0+1,d_^(-1))) 50 57 }; 51 Eye(r,r,0,di) 52 } ;58 Eye(r,r,0,di) 59 })}; 53 60 54 61 VMatrix _.Di = Normalizer(M); … … 60 67 // Di*M*Di*D*x = Di*y <=> M*x=y 61 68 // 62 VMatrix _.S = 69 VMatrix _.S = If(!_.do.normalize, _.M, 63 70 { 64 71 VMatrix S = _.Di*_.M*_.Di; 65 72 //Para evitar posibles errores de redondeo y asegurar la simetría 66 73 (S+Tra(S))*0.5 67 } ;74 }); 68 75 69 76 //Scale parameter of diagonal preconditioner … … 71 78 //Tolerance of c parameter 72 79 Real _.tol.scale = 1.E-7; 73 Real _.m = VRows(_.S);74 80 VMatrix _.Sc = Rand(0,0,0,0); 75 81 VMatrix _.Lc = Rand(0,0,0,0); 76 // Intenta factorizar S+c*I y si lo consigue devuelve 1 y si no 082 //Tries to factorize S+c*I and returns true if success 77 83 Real ScaleEval(Real c) 78 84 { 85 Text _MID = "[SolvePrecondSym()::ScaleEval()] "; 79 86 VMatrix _.Sc := _.S + VMatrix Eye(_.m,_.m,0,c); 80 87 Real old = Show(0,"ALL"); … … 82 89 Real Show(old,"ALL"); 83 90 Real ok = VRows(_.Lc)==_.m; 84 WriteLn( "SymPosDefPrecond(...)::eval("<<c+") = "<<ok);91 WriteLn(_MID+"("<<c+") = "<<ok); 85 92 ok 86 93 }; 87 //Ap lica el método recursivo de la bisectriz en un intervalo buscando el88 // menor valor de c para el que S+c*I es definida positiva94 //Applies bisection method to find the lesser scale value c matching 95 //S+c*I is not positive definite 89 96 Real ScaleBisect(Real a, Real b) 90 97 { … … 96 103 }) 97 104 }; 98 //Busca un intervalo inicial [a,b] tal que S+a*I no sea definida positiva y 99 //S+b*I sí lo sea y luego aplica el método de la bisectriz para encontrar la 100 //frontera 105 //Searches for an initial interval [a,b] matching S+a*I is not positive 106 //definite and S+b*I is it, and then call ScaleBisect 101 107 Real ScaleOptimize(Real tolerance) 102 108 { … … 124 130 CholeskiSolve(SPDP::_.Lc,_.S*u,"PtLLtP") 125 131 }; 126 NameBlock Solve(VMatrix y, Real tolerance) 132 //Solves linear system M*xy 133 NameBlock Solve(VMatrix y, Real tolerance, Real forze.lanczos) 127 134 {[[ 128 135 Text _MID = "[SolvePrecondSym()::Solve()] "; … … 130 137 Real _.tol.solver = tolerance; 131 138 Real _.tol.mrs = (tolerance^2)/_.m; 132 VMatrix _.v = _.Di*_.y;139 VMatrix _.v = If(!_.do.normalize,_.y, _.Di*_.y); 133 140 VMatrix _.u0 = CholeskiSolve(SPDP::_.Lc,_.v,"PtLLtP"); 134 VMatrix _.u = MinimumResidualsSolve(PreCndLinOpr, _.u0,_.tol.mrs,_.u0); 135 VMatrix _.x = _.Di*_.u; 141 VMatrix _.u = If(And(!forze.lanczos, !_.c), _.u0, 142 { 143 MinimumResidualsSolve(PreCndLinOpr, _.u0,_.tol.mrs,_.u0) 144 }); 145 VMatrix _.x = If(!_.do.normalize,_.u,_.Di*_.u); 136 146 VMatrix _.residuals = _.M*_.x-_.y; 137 147 Real _.stdErr = Sqrt(VMatDat(MtMSqr(_.residuals),1,1)/_.m); -
tol_tests/tol/LinearAlgebra/vmatrix/test_0011/test.tol
rc7a5e4e ra20c202 26 26 27 27 //Builds preconditioning handler 28 NameBlock SPDP = SolvePrecondSym(M );28 NameBlock SPDP = SolvePrecondSym(M, True); 29 29 //Finds optimal preconditioner 30 30 Real SPDP::ScaleOptimize(1.E-7); 31 31 //Solves the system 32 NameBlock solution = SPDP::Solve(y,1.E-11 );32 NameBlock solution = SPDP::Solve(y,1.E-11, True); 33 33 //Takes the solution matrix 34 34 VMatrix x = solution::_.x; … … 56 56 57 57 //This is a messure of the success of the test 58 Real quality_ = And(numErr0 == numErr1)*Min(quality.x, quality.Z);58 Real quality_ = Min(quality.x, quality.Z); 59 59 60 60 //Return the results
Note: See TracChangeset
for help on using the changeset viewer.
