Changeset a20c202 in tol


Ignore:
Timestamp:
Feb 2, 2009, 3:28:54 PM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
462fc07
Parents:
c7a5e4e
Message:

Adding configuration parameters do.normalize and forze.lanczos

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@541 be4846ae-f051-483a-831f-b64e7d08527f

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tol/stdlib/math/_init_math.tol

    rc7a5e4e ra20c202  
    2020               NIntegrate);
    2121
     22Set Include("linalg/_init_linalg.tol");
    2223Set Include("optim/_init_optim.tol");
    2324Set Include("stat/_init_stat.tol");
  • tol/stdlib/math/linalg/_solve_precond_sym.tol

    rc7a5e4e ra20c202  
    1010"preconditioner of previously normalized system foilowing these steps:\n"
    1111"1. Original symmetric system M*z = y is previously normalized by non null "
    12 "elements of root squares of diagonal elements of M taht will called D:\n"
     12"elements of root squares of diagonal elements of M that will called D:\n"
    1313"  S*u = v where S=Di*M*Di; Di=D^-1; u=D*x; v=Di*y\n"
    1414"Then\n"
    … …  
    2222"((S+c*I)^-1)*S that is not neccessary so sparse as S nor L.\n"
    2323"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"
    2428"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"
    2731"  //Finds optimal preconditioner\n"
    2832"  Real SPDP::ScaleOptimize(1.E-7); \n"
    2933"  //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"
    3135"  //Takes the solution matrix\n"
    3236"  VMatrix x = solution::_.x;\n"
    3337"\n";
    3438
    35 NameBlock SolvePrecondSym(VMatrix M)
     39NameBlock SolvePrecondSym(VMatrix M, Real do.normalize)
    3640{[[
    3741  //Original symmetric system to be solved M*x = y
    3842  VMatrix _.M = M;
     43  Real _.do.normalize = do.normalize;
     44  Real _.m = VRows(_.M);
    3945
    4046  //Returns a diagonal normalizer VMatrix for a symmetric VMatrix
    41   VMatrix Normalizer(VMatrix S)
     47  VMatrix Normalizer(VMatrix M)
    4248  {
    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));
    4552    VMatrix d  = d2^(+1/2);
    4653    VMatrix di =
    … …  
    4956      Mat2VMat(IfMat(Eq(d_,d_*0),d_*0+1,d_^(-1)))
    5057    };
    51     Eye(r,r,0,di)
    52   };
     58    Eye(r,r,0,di) 
     59  })};
    5360
    5461  VMatrix _.Di = Normalizer(M);
    … …  
    6067  //  Di*M*Di*D*x = Di*y <=> M*x=y
    6168  //
    62   VMatrix _.S =
     69  VMatrix _.S = If(!_.do.normalize, _.M,
    6370  {
    6471    VMatrix S = _.Di*_.M*_.Di;
    6572    //Para evitar posibles errores de redondeo y asegurar la simetría
    6673    (S+Tra(S))*0.5
    67   };
     74  });
    6875
    6976  //Scale parameter of diagonal preconditioner
    … …  
    7178  //Tolerance of c parameter
    7279  Real    _.tol.scale = 1.E-7;
    73   Real    _.m   = VRows(_.S);
    7480  VMatrix _.Sc  = Rand(0,0,0,0);
    7581  VMatrix _.Lc  = Rand(0,0,0,0);
    76   //Intenta factorizar S+c*I y si lo consigue devuelve 1 y si no 0
     82  //Tries to factorize S+c*I and returns true if success
    7783  Real ScaleEval(Real c)
    7884  {
     85    Text _MID = "[SolvePrecondSym()::ScaleEval()] ";
    7986    VMatrix _.Sc := _.S + VMatrix Eye(_.m,_.m,0,c);
    8087    Real old = Show(0,"ALL");
    … …  
    8289    Real Show(old,"ALL");
    8390    Real ok = VRows(_.Lc)==_.m;
    84     WriteLn("SymPosDefPrecond(...)::eval("<<c+") = "<<ok);
     91    WriteLn(_MID+"("<<c+") = "<<ok);
    8592    ok
    8693  };
    87   //Aplica el método recursivo de la bisectriz en un intervalo buscando el
    88   //menor valor de c para el que S+c*I es definida positiva
     94  //Applies bisection method to find the lesser scale value c matching
     95  //S+c*I is not positive definite
    8996  Real ScaleBisect(Real a, Real b)
    9097  {
    … …  
    96103    })
    97104  };
    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
    101107  Real ScaleOptimize(Real tolerance)
    102108  {
    … …  
    124130    CholeskiSolve(SPDP::_.Lc,_.S*u,"PtLLtP")
    125131  };
    126   NameBlock Solve(VMatrix y, Real tolerance)
     132  //Solves linear system M*xy
     133  NameBlock Solve(VMatrix y, Real tolerance, Real forze.lanczos)
    127134  {[[
    128135    Text _MID = "[SolvePrecondSym()::Solve()] ";
    … …  
    130137    Real    _.tol.solver = tolerance;
    131138    Real    _.tol.mrs    = (tolerance^2)/_.m;
    132     VMatrix _.v = _.Di*_.y;
     139    VMatrix _.v = If(!_.do.normalize,_.y, _.Di*_.y);
    133140    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);
    136146    VMatrix _.residuals = _.M*_.x-_.y;
    137147    Real    _.stdErr = Sqrt(VMatDat(MtMSqr(_.residuals),1,1)/_.m);
  • tol_tests/tol/LinearAlgebra/vmatrix/test_0011/test.tol

    rc7a5e4e ra20c202  
    2626
    2727//Builds preconditioning handler
    28 NameBlock SPDP = SolvePrecondSym(M);
     28NameBlock SPDP = SolvePrecondSym(M, True);
    2929//Finds optimal preconditioner
    3030Real SPDP::ScaleOptimize(1.E-7);
    3131//Solves the system
    32 NameBlock solution = SPDP::Solve(y,1.E-11);
     32NameBlock solution = SPDP::Solve(y,1.E-11, True);
    3333//Takes the solution matrix
    3434VMatrix x = solution::_.x;
    … …  
    5656
    5757//This is a messure of the success of the test
    58 Real quality_ = And(numErr0 == numErr1)*Min(quality.x, quality.Z);
     58Real quality_ = Min(quality.x, quality.Z);
    5959
    6060//Return the results
Note: See TracChangeset for help on using the changeset viewer.