| 1 | // -*- Mode: C++; tab-width: 2; -*- |
| 2 | // vi: set ts=2: |
| 3 | // |
| 4 | // $Id: shiftedLVMM.h,v 1.1.4.6 2007/08/07 09:12:35 aleru Exp $ |
| 5 | // |
| 6 | |
| 7 | #ifndef BALL_MOLMEC_MINIMIZATION_SHIFTEDLVMM_H |
| 8 | #define BALL_MOLMEC_MINIMIZATION_SHIFTEDLVMM_H |
| 9 | |
| 10 | #ifndef BALL_MOLMEC_MINIMIZATION_ENERGYMINIMIZER_H |
| 11 | # include <BALL/MOLMEC/MINIMIZATION/energyMinimizer.h> |
| 12 | #endif |
| 13 | |
| 14 | #ifndef BALL_MOLMEC_MINIMIZATION_LINESEARCH_H |
| 15 | # include <BALL/MOLMEC/MINIMIZATION/lineSearch.h> |
| 16 | #endif |
| 17 | |
| 18 | namespace BALL |
| 19 | { |
| 20 | /** Shifted limited-memory variable metric methods minimizer. |
| 21 | * A minimizer for geometry optimization based upon the shifted |
| 22 | * limited-memory variable metric methods proposed in |
| 23 | * |
| 24 | * [1] Vlcek J., Luksan L.. New variable metric methods for unconstrained |
| 25 | * minimization covering the large-scale case. Report V-876, Prague, |
| 26 | * ICS AS CR, 2002. |
| 27 | * |
| 28 | * [2] Vlcek J., Luksan L.. Additional properties of shifted variable metric |
| 29 | * methods. Report V-899, Prague, ICS AS CR, 2004. |
| 30 | * |
| 31 | * [3] Vlcek J., Luksan L.. Shifted limited-memory variable metric methods |
| 32 | * for large-scale unconstrained optimization. Journal of Computational |
| 33 | * and Applied Mathematics 186 (2), pp. 365-390. |
| 34 | * \ingroup MolmecEnergyMinimizer |
| 35 | */ |
| 36 | class BALL_EXPORT ShiftedLVMMMinimizer |
| 37 | : public EnergyMinimizer |
| 38 | { |
| 39 | public: |
| 40 | |
| 41 | BALL_CREATE(ShiftedLVMMMinimizer) |
| 42 | |
| 43 | /** @name Options and Defaults |
| 44 | */ |
| 45 | //@{ |
| 46 | |
| 47 | /** Symbolic names for option keys. |
| 48 | * This struct contains a symbolic name |
| 49 | * for each recognized key in ShiftedLVMMMinimizer::options. \par |
| 50 | * For each symbol the required type is given under parameters. |
| 51 | */ |
| 52 | struct Option |
| 53 | { |
| 54 | /** Which update method should be used? |
| 55 | */ |
| 56 | static const char* UPDATE_METHOD; |
| 57 | |
| 58 | /** Which correction parameter should be used? |
| 59 | */ |
| 60 | static const char* CORRECTION_PARAMETER; |
| 61 | |
| 62 | /** The number of columns of the factor of the shifted |
| 63 | * inverse hessian approximation. |
| 64 | */ |
| 65 | static const char* NUM_OF_COLUMNS; |
| 66 | }; |
| 67 | |
| 68 | struct BALL_EXPORT Default |
| 69 | { |
| 70 | /** Which update method should be used? |
| 71 | * Default is RANK_2. |
| 72 | */ |
| 73 | static const Size UPDATE_METHOD; |
| 74 | |
| 75 | /** Which correction parameter should be used? |
| 76 | * Default is RATIO_OF_SHIFT_PARAMS. |
| 77 | */ |
| 78 | static const Size CORRECTION_PARAMETER; |
| 79 | |
| 80 | /** The number of columns of the factor of the shifted |
| 81 | * inverse hessian approximation. Default is 5. |
| 82 | */ |
| 83 | static const Size NUM_OF_COLUMNS; |
| 84 | }; |
| 85 | |
| 86 | //@} |
| 87 | /** @name Enums |
| 88 | */ |
| 89 | //@{ |
| 90 | |
| 91 | /** The different variationally derived methods implemented. |
| 92 | */ |
| 93 | enum UpdateMethod |
| 94 | { |
| 95 | /** Rank 1 variationally derived method. |
| 96 | */ |
| 97 | RANK_1 = 1, |
| 98 | |
| 99 | /** Rank 2 variationally derived method. |
| 100 | */ |
| 101 | RANK_2 = 2 |
| 102 | }; |
| 103 | |
| 104 | /** The different correction parameters implemented. |
| 105 | */ |
| 106 | enum CorrectionParameter |
| 107 | { |
| 108 | /** Unit value, i.e. rho = 1.0. |
| 109 | */ |
| 110 | UNIT_VALUE = 1, |
| 111 | |
| 112 | /** Balancing value. |
| 113 | */ |
| 114 | BALANCING_VALUE = 2, |
| 115 | |
| 116 | /** Square root. |
| 117 | */ |
| 118 | SQUARE_ROOT = 3, |
| 119 | |
| 120 | /** Geometric mean. |
| 121 | */ |
| 122 | GEOMETRIC_MEAN = 4, |
| 123 | |
| 124 | /** Ratio of shift parameters. |
| 125 | */ |
| 126 | RATIO_OF_SHIFT_PARAMS = 5 |
| 127 | }; |
| 128 | |
| 129 | //@} |
| 130 | /** @name Constructors and Destructors |
| 131 | */ |
| 132 | //@{ |
| 133 | |
| 134 | /** Default constructor. |
| 135 | */ |
| 136 | ShiftedLVMMMinimizer(); |
| 137 | |
| 138 | /** Constructor expecting a valid force field |
| 139 | */ |
| 140 | ShiftedLVMMMinimizer(ForceField& force_field); |
| 141 | |
| 142 | /** Constructor expecting a valid force field and a snapshot manager |
| 143 | */ |
| 144 | ShiftedLVMMMinimizer(ForceField& force_field, SnapShotManager *ssm); |
| 145 | |
| 146 | /** Constructor expecting a valid force field, a snapshot manager and options |
| 147 | */ |
| 148 | ShiftedLVMMMinimizer(ForceField& force_field, SnapShotManager* ssm, const Options& options); |
| 149 | |
| 150 | /** Constructor expecting a valid force field and options |
| 151 | */ |
| 152 | ShiftedLVMMMinimizer(ForceField& force_field, const Options& options); |
| 153 | |
| 154 | /** Copy constructor |
| 155 | */ |
| 156 | ShiftedLVMMMinimizer(const ShiftedLVMMMinimizer& rhs); |
| 157 | |
| 158 | /** Destructor. |
| 159 | */ |
| 160 | virtual ~ShiftedLVMMMinimizer(); |
| 161 | |
| 162 | //@} |
| 163 | /** @name Assignments |
| 164 | */ |
| 165 | //@{ |
| 166 | |
| 167 | /** Assignment operator |
| 168 | */ |
| 169 | const ShiftedLVMMMinimizer& operator = (const ShiftedLVMMMinimizer& rhs); |
| 170 | |
| 171 | //@} |
| 172 | /** @name Setup methods. They do all necessary preparations. |
| 173 | */ |
| 174 | //@{ |
| 175 | |
| 176 | /** Specific setup |
| 177 | */ |
| 178 | virtual bool specificSetup(); |
| 179 | |
| 180 | //@} |
| 181 | /** @name Accessors |
| 182 | */ |
| 183 | //@{ |
| 184 | |
| 185 | /** Set explicitly the update method |
| 186 | */ |
| 187 | void setUpdateMethod(UpdateMethod updt); |
| 188 | |
| 189 | /** Return the update method |
| 190 | */ |
| 191 | UpdateMethod getUpdateMethod() const; |
| 192 | |
| 193 | /** Set explicitly the correction parameter |
| 194 | */ |
| 195 | void setCorrectionParameter(CorrectionParameter corr); |
| 196 | |
| 197 | /** Return the correction parameter |
| 198 | */ |
| 199 | CorrectionParameter getCorrectionParameter() const; |
| 200 | |
| 201 | /** Set explicitly the maximum number of columns of the |
| 202 | * factor of the shifted inverse hessian approximation. |
| 203 | */ |
| 204 | void setMaxNumOfColumns(Size num); |
| 205 | |
| 206 | /** Return the maximum number of columns of the |
| 207 | * factor of the shifted inverse hessian approximation. |
| 208 | */ |
| 209 | Size getMaxNumOfColumns() const; |
| 210 | |
| 211 | /** Calculate the next step. |
| 212 | * First, this method updates the model. Second, it performs a line search |
| 213 | * along the calculated direction afterwards. |
| 214 | * @return double \f$\geq 0\f$ if the line search found an acceptable solution, otherwise -1. |
| 215 | * @see EnergyMinimizer::findStep |
| 216 | */ |
| 217 | virtual double findStep(); |
| 218 | |
| 219 | /** Update the shifted inverse hessian approximation. |
| 220 | * Afterwards, compute the search direction. |
| 221 | */ |
| 222 | virtual void updateDirection(); |
| 223 | |
| 224 | /** Minimize the energy of the system. |
| 225 | * This method executes at most <tt>iterations</tt> minimization steps. |
| 226 | * If the number of iterations is not given, the number specified in the |
| 227 | * options is taken. |
| 228 | * @param iterations the maximum number of iterations |
| 229 | * @param resume <b>true</b> to resume a previous run |
| 230 | * @see EnergyMinimizer::minimize |
| 231 | */ |
| 232 | virtual bool minimize(Size iterations = 0, bool resume = false); |
| 233 | |
| 234 | protected: |
| 235 | |
| 236 | //@} |
| 237 | /** @name Protected Attributes |
| 238 | */ |
| 239 | //@{ |
| 240 | |
| 241 | /** The line search |
| 242 | */ |
| 243 | LineSearch line_search_; |
| 244 | |
| 245 | /** Is this an initial first iteration? |
| 246 | */ |
| 247 | bool first_iter_; |
| 248 | |
| 249 | /** Number of movable atoms. |
| 250 | */ |
| 251 | Size number_of_atoms_; |
| 252 | |
| 253 | /** Maximum number of columns of the |
| 254 | * factor of the shifted inverse hessian approximation. |
| 255 | */ |
| 256 | Size max_number_of_cols_; |
| 257 | |
| 258 | /** Current number of columns of the |
| 259 | * factor of the shifted inverse hessian approximation. |
| 260 | */ |
| 261 | Size curr_number_of_cols_; |
| 262 | |
| 263 | /** Update method |
| 264 | */ |
| 265 | Size updt_method_; |
| 266 | |
| 267 | /** Correction parameter |
| 268 | */ |
| 269 | Size corr_par_; |
| 270 | |
| 271 | /** Shift value of the previous iteration. |
| 272 | */ |
| 273 | double prev_shift_val_; |
| 274 | |
| 275 | /** Shifted previous step. |
| 276 | */ |
| 277 | vector<Vector3> shift_s_; |
| 278 | |
| 279 | /** Current gradient difference. |
| 280 | */ |
| 281 | vector<Vector3> grad_diff_; |
| 282 | |
| 283 | /** Needed vector for the update. |
| 284 | */ |
| 285 | vector<float> updt_u_; |
| 286 | |
| 287 | /** Needed vector for the update. |
| 288 | */ |
| 289 | vector<float> updt_v_; |
| 290 | |
| 291 | /** Direction of the shifted step, i.\ e.\ \f$-U_k \cdot U_k^T \cdot g_k\f$. |
| 292 | */ |
| 293 | vector<Vector3> shifted_direction_; |
| 294 | |
| 295 | /** Factor of the shifted inverse hessian approximation |
| 296 | * in column order, \f$U_k\f$ in [3]. |
| 297 | */ |
| 298 | vector<Vector3> hess_factor_; |
| 299 | |
| 300 | /** Positions of the movable atoms when we start an iteration. |
| 301 | * This is used to reduce slightly rounding errors |
| 302 | */ |
| 303 | vector<Vector3> initial_atoms_; |
| 304 | |
| 305 | //@} |
| 306 | |
| 307 | }; |
| 308 | } // end of namespace BALL |
| 309 | |
| 310 | #endif // BALL_MOLMEC_MINIMIZATION_SHIFTEDLVMM_H |