1 /* 2 Context for bounded Newton-Krylov type optimization algorithms 3 */ 4 5 #if !defined(__TAO_BNK_H) 6 #define __TAO_BNK_H 7 #include <petsc/private/taoimpl.h> 8 #include <../src/tao/matrix/lmvmmat.h> 9 10 typedef struct { 11 Mat M; 12 13 Vec D; 14 Vec W; 15 16 Vec Xold; 17 Vec Gold; 18 Vec Diag; 19 20 /* Scalar values for the solution */ 21 PetscReal f, gnorm; 22 23 /* Parameters when updating the perturbation added to the Hessian matrix 24 according to the following scheme: 25 26 pert = sval; 27 28 do until convergence 29 shift Hessian by pert 30 solve Newton system 31 32 if (linear solver failed or did not compute a descent direction) 33 use steepest descent direction and increase perturbation 34 35 if (0 == pert) 36 initialize perturbation 37 pert = min(imax, max(imin, imfac * norm(G))) 38 else 39 increase perturbation 40 pert = min(pmax, max(pgfac * pert, pmgfac * norm(G))) 41 fi 42 else 43 use linear solver direction and decrease perturbation 44 45 pert = min(psfac * pert, pmsfac * norm(G)) 46 if (pert < pmin) 47 pert = 0 48 fi 49 fi 50 51 perform line search 52 function and gradient evaluation 53 check convergence 54 od 55 */ 56 PetscReal sval; /* Starting perturbation value, default zero */ 57 58 PetscReal imin; /* Minimum perturbation added during initialization */ 59 PetscReal imax; /* Maximum perturbation added during initialization */ 60 PetscReal imfac; /* Merit function factor during initialization */ 61 62 PetscReal pert; /* Current perturbation value */ 63 PetscReal pmin; /* Minimim perturbation value */ 64 PetscReal pmax; /* Maximum perturbation value */ 65 PetscReal pgfac; /* Perturbation growth factor */ 66 PetscReal psfac; /* Perturbation shrink factor */ 67 PetscReal pmgfac; /* Merit function growth factor */ 68 PetscReal pmsfac; /* Merit function shrink factor */ 69 70 /* Parameters when updating the trust-region radius based on steplength 71 if step < nu1 (very bad step) 72 radius = omega1 * min(norm(d), radius) 73 elif step < nu2 (bad step) 74 radius = omega2 * min(norm(d), radius) 75 elif step < nu3 (okay step) 76 radius = omega3 * radius; 77 elif step < nu4 (good step) 78 radius = max(omega4 * norm(d), radius) 79 else (very good step) 80 radius = max(omega5 * norm(d), radius) 81 fi 82 */ 83 PetscReal nu1; /* used to compute trust-region radius */ 84 PetscReal nu2; /* used to compute trust-region radius */ 85 PetscReal nu3; /* used to compute trust-region radius */ 86 PetscReal nu4; /* used to compute trust-region radius */ 87 88 PetscReal omega1; /* factor used for trust-region update */ 89 PetscReal omega2; /* factor used for trust-region update */ 90 PetscReal omega3; /* factor used for trust-region update */ 91 PetscReal omega4; /* factor used for trust-region update */ 92 PetscReal omega5; /* factor used for trust-region update */ 93 94 /* Parameters when updating the trust-region radius based on reduction 95 96 kappa = ared / pred 97 if kappa < eta1 (very bad step) 98 radius = alpha1 * min(norm(d), radius) 99 elif kappa < eta2 (bad step) 100 radius = alpha2 * min(norm(d), radius) 101 elif kappa < eta3 (okay step) 102 radius = alpha3 * radius; 103 elif kappa < eta4 (good step) 104 radius = max(alpha4 * norm(d), radius) 105 else (very good step) 106 radius = max(alpha5 * norm(d), radius) 107 fi 108 */ 109 PetscReal eta1; /* used to compute trust-region radius */ 110 PetscReal eta2; /* used to compute trust-region radius */ 111 PetscReal eta3; /* used to compute trust-region radius */ 112 PetscReal eta4; /* used to compute trust-region radius */ 113 114 PetscReal alpha1; /* factor used for trust-region update */ 115 PetscReal alpha2; /* factor used for trust-region update */ 116 PetscReal alpha3; /* factor used for trust-region update */ 117 PetscReal alpha4; /* factor used for trust-region update */ 118 PetscReal alpha5; /* factor used for trust-region update */ 119 120 /* Parameters when updating the trust-region radius based on interpolation 121 122 kappa = ared / pred 123 if kappa >= 1.0 - mu1 (very good step) 124 choose tau in [gamma3, gamma4] 125 radius = max(tau * norm(d), radius) 126 elif kappa >= 1.0 - mu2 (good step) 127 choose tau in [gamma2, gamma3] 128 if (tau >= 1.0) 129 radius = max(tau * norm(d), radius) 130 else 131 radius = tau * min(norm(d), radius) 132 fi 133 else (bad step) 134 choose tau in [gamma1, 1.0] 135 radius = tau * min(norm(d), radius) 136 fi 137 */ 138 PetscReal mu1; /* used for model agreement in interpolation */ 139 PetscReal mu2; /* used for model agreement in interpolation */ 140 141 PetscReal gamma1; /* factor used for interpolation */ 142 PetscReal gamma2; /* factor used for interpolation */ 143 PetscReal gamma3; /* factor used for interpolation */ 144 PetscReal gamma4; /* factor used for interpolation */ 145 146 PetscReal theta; /* factor used for interpolation */ 147 148 /* Parameters when initializing trust-region radius based on interpolation */ 149 PetscReal mu1_i; /* used for model agreement in interpolation */ 150 PetscReal mu2_i; /* used for model agreement in interpolation */ 151 152 PetscReal gamma1_i; /* factor used for interpolation */ 153 PetscReal gamma2_i; /* factor used for interpolation */ 154 PetscReal gamma3_i; /* factor used for interpolation */ 155 PetscReal gamma4_i; /* factor used for interpolation */ 156 157 PetscReal theta_i; /* factor used for interpolation */ 158 159 /* Other parameters */ 160 PetscReal min_radius; /* lower bound on initial radius value */ 161 PetscReal max_radius; /* upper bound on trust region radius */ 162 PetscReal epsilon; /* tolerance used when computing ared/pred */ 163 164 PetscInt newt; /* Newton directions attempted */ 165 PetscInt bfgs; /* BFGS directions attempted */ 166 PetscInt sgrad; /* Scaled gradient directions attempted */ 167 PetscInt grad; /* Gradient directions attempted */ 168 169 PetscInt pc_type; /* Preconditioner for the code */ 170 PetscInt bfgs_scale_type; /* Scaling matrix to used for the bfgs preconditioner */ 171 PetscInt init_type; /* Trust-region initialization method */ 172 PetscInt update_type; /* Trust-region update method */ 173 174 PetscInt ksp_atol; 175 PetscInt ksp_rtol; 176 PetscInt ksp_ctol; 177 PetscInt ksp_negc; 178 PetscInt ksp_dtol; 179 PetscInt ksp_iter; 180 PetscInt ksp_othr; 181 PetscBool is_nash, is_stcg, is_gltr; 182 } TAO_BNK; 183 184 #endif /* if !defined(__TAO_BNK_H) */ 185 186 #define BNK_NEWTON 0 187 #define BNK_BFGS 1 188 #define BNK_SCALED_GRADIENT 2 189 #define BNK_GRADIENT 3 190 191 #define BNK_PC_NONE 0 192 #define BNK_PC_AHESS 1 193 #define BNK_PC_BFGS 2 194 #define BNK_PC_PETSC 3 195 #define BNK_PC_TYPES 4 196 197 #define BFGS_SCALE_AHESS 0 198 #define BFGS_SCALE_PHESS 1 199 #define BFGS_SCALE_BFGS 2 200 #define BFGS_SCALE_TYPES 3 201 202 #define BNK_INIT_CONSTANT 0 203 #define BNK_INIT_DIRECTION 1 204 #define BNK_INIT_INTERPOLATION 2 205 #define BNK_INIT_TYPES 3 206 207 #define BNK_UPDATE_STEP 0 208 #define BNK_UPDATE_REDUCTION 1 209 #define BNK_UPDATE_INTERPOLATION 2 210 #define BNK_UPDATE_TYPES 3 211 212 static const char *BNK_PC[64] = {"none", "ahess", "bfgs", "petsc"}; 213 214 static const char *BFGS_SCALE[64] = {"ahess", "phess", "bfgs"}; 215 216 static const char *BNK_INIT[64] = {"constant", "direction", "interpolation"}; 217 218 static const char *BNK_UPDATE[64] = {"step", "reduction", "interpolation"}; 219 220 PETSC_INTERN PetscErrorCode TaoCreate_BNK(Tao); 221 222 PETSC_INTERN PetscErrorCode MatLMVMSolveShell(PC, Vec, Vec); 223 PETSC_INTERN PetscErrorCode TaoBNKInitialize(Tao); 224 PETSC_INTERN PetscErrorCode TaoBNKComputeStep(Tao, PetscInt*);