cmaes_opts_mod.f90 15 KB
Newer Older
ofgeorg's avatar
ofgeorg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
      !-------------------------------------------------------------------------
      !  Module       :                   cmaes_opts_mod
      !-------------------------------------------------------------------------
      !
      !  Purpose      : This module contains all CMA options the user can set
      !                
      !  Remarks      : User options can be set by including this module and
      !					assigning values to the options-type, i.e.
      !					options%StopFitness = ...
      !					PLEASE MIND: some options are arrays and need to be
      !					ALLOCATED EXPLICITLY before usage!!!
      !					Naming and default values taken from cmaes.m, variables
      !					are initialized in cmaesInit.f90, taking into account
      !					the user input and options settings
      !
      !  References   :
      !
      !  Revisions    :
      !-------------------------------------------------------------------------
      !-------------------------------------------------------------------------
21 22 23 24
      !  pCMALib: a parallel fortran 90 library for the evolution strategy with
      !           covariance matrix adaptation
      !  Christian L. Mueller, Benedikt Baumgartner, Georg Ofenbeck
      !  MOSAIC group, ETH Zurich, Switzerland
ofgeorg's avatar
ofgeorg committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
      !-------------------------------------------------------------------------  
      MODULE cmaes_opts_mod
      USE cmaes_param_mod
      IMPLICIT NONE
      SAVE
      REAL(MK), PARAMETER :: posInf = huge(posInf)
      REAL(MK), PARAMETER :: negInf = -huge(negInf)
      
      
      TYPE :: opts
        !-----------------------------------------------------------------------
        !  Cructial Parameters you might wanna set
        !-----------------------------------------------------------------------
        !defines the start sigma as absolut value (doesnt need boundaries - used if non zero
        !rel_sigma will be ignored if abs_sigma is set)
        REAL(MK)    :: abs_sigma = 0.0_MK
        !defines the start sigma relative to the boundaries (to init bounds if set)
        REAL(MK)    :: rel_sigma = 0.2_MK

        !Lower and Upper Boundary in all Dimensions
        REAL(MK)    :: alldim_lBounds = negInf
        REAL(MK)    :: alldim_uBounds = posInf

        !if set true CMA will start within init Bounds
        LOGICAL     :: use_init_bounds = .FALSE.
        REAL(MK)    :: init_lBounds = negInf
        REAL(MK)    :: init_uBounds = posInf

        !Number of Dimension the Optimization Problem has
        INTEGER     :: dimensions = 2
        
        !-----------------------------------------------------------------------
        !  Output Parameters
        !-----------------------------------------------------------------------
        !folder in which the output should be written (relative to program)
        CHARACTER(len=200)       :: output_folder

      
        !-----------------------------------------------------------------------
        !  Stopping criteria (value of stop flag)
        !-----------------------------------------------------------------------
        != '-Inf stop if f(xmin) < stopfitness, minimization'
        REAL(MK) 	:: StopFitness = negInf
        != 'Inf  maximal number of fevals'
        REAL(MK) 	:: StopMaxFunEvals = posInf 
        != '1e3*(N+5)^2/sqrt(popsize) maximal number of iterations'
        INTEGER :: StopMaxIter = 0    
        != 'Inf  stop after resp. evaluation'
        REAL(MK) 	:: StopFunEvals = posInf
        != 'Inf  stop after resp. iteration'
        REAL(MK) 	:: StopIter = posInf 
        != '1e-11*max(insigma) stop if x-change smaller TolX' 
        REAL(MK) 	:: StopTolX = 0. 
        != '1e3*max(insigma) stop if x-changes larger TolUpX'     
        REAL(MK) 	:: StopTolUpX = 0. 
        != '1e-12 stop if fun-changes smaller TolFun'     
        REAL(MK) 	:: StopTolFun = 1.E-12  
        != '1e-13 stop if back fun-changes smaller TolHistFun'    
        REAL(MK) 	:: StopTolHistFun = 1.E-13 
        ! = 'yes' 
        LOGICAL 	:: StopOnWarnings = .TRUE.
        LOGICAL     :: StopTime       = .FALSE.
        REAL(MK)    :: StopTimeHH     = 00_MK
        REAL(MK)    :: StopTimeMM     = 00_MK
        REAL(MK)    :: StopTimeSS     = 00_MK
        !-----------------------------------------------------------------------
        !  Others
        !-----------------------------------------------------------------------
        != 'Inf  maximal variable change(s)
        REAL(MK),POINTER,DIMENSION(:) 		:: DiffMaxChange 
        != '0    minimal variable change(s)
        REAL(MK),POINTER,DIMENSION(:) 		:: DiffMinChange 
        != 'on'
        LOGICAL 					  	:: WarnOnEqualFunctionValues = .TRUE. 
        != '-Inf lower bounds
        REAL(MK),POINTER,DIMENSION(:) 		:: LBounds 
        != 'Inf  upper bounds
        REAL(MK),POINTER,DIMENSION(:) 		:: UBounds 
        != 'yes  evaluation of initial solution'
        LOGICAL 					  		:: EvalInitialX = .TRUE.
!		!= '(4 + floor(3*log(N)))  population size, lambda'
        INTEGER 					 		:: PopSize = 0    
        != 'floor(popsize/2)     popsize equals lambda'  
        INTEGER 							:: ParentNumber = 0
        != 'superlinear decrease(3) or linear(2), or equal(1)'
        INTEGER 							:: RecombinationWeights = 3 
        ! >=0, messaging after every i-th iteration
        INTEGER 							:: VerboseModulo = 100 
        
        
        ! log data from each generation (C,D,sigma,etc)
        LOGICAL								:: flgGenData = .FALSE.
        ! generation interval to log data, default is interval = 1
        INTEGER								:: intGenData = 1
        !Objective Function Name
        CHARACTER(len=200)					:: funcName = ''
        ! only one process generates output
        LOGICAL                             :: silentMPI = .TRUE.

        
        !-----------------------------------------------------------------------
        !  Particle Swarm Parameters
        !-----------------------------------------------------------------------
        !Switch PS-CMA on or off
        LOGICAL 							:: pscma = .FALSE.
        !Set weight for coupling C(cma) with C(pso), any value between 0 and 1.
        !Example: psoWeight = 0.3 --> C = 0.3*C(cma) + 0.7*C(pso)
        REAL(MK)							:: psoWeight = 0.0_MK
        !Specify how often a PSO update is performed. For example psoFreq = 5 
        !means that every 5th iteration an update will be done
        INTEGER								:: psoFreq = 200
        
        
        !-----------------------------------------------------------------------
        !  Random Number Generator Parameters
        !-----------------------------------------------------------------------
        
        !Use Quasi Random Sampling on/off
        LOGICAL 							:: qr_sampling = .TRUE.
        !which sampler to use
      !                             0.............Sobol
      !                    (default)1.............Sobol with scrambling 
      !                             2.............Halton
      !                             3.............Halton R implementation
      !                             4.............Faure (buggy!)
      !                             5.............Niederreiter
        INTEGER                            :: qr_sampler = 1

      !inverter (I) which Inverter to use (Uniform -> Normal(0,1))
      !                             -1............dont use any inverter (uniform)
      !                             0.............Moros Inverse
      !                    (default)1             Peter J. Acklams Inverter
      !                             2.............Inverter from the R Implementation
        INTEGER                            :: qr_inverter = 1
 			!which type of scrambling to use when using Sobol with scrambling

		!                   0 - NO SCRAMBLING
		!                   1 - OWEN TYPE SCRAMBLING
		!                   2 - FAURE-TEZUKA TYPE SCRAMBLING
		!                   3 - OWEN + FAURE-TEZUKA TYPE SCRAMBLING
        INTEGER                            :: qr_scrambling = 0
        
        !----------------------------------------------------------------------
        ! Restart / Inc Popsize CMA Parameters
        !----------------------------------------------------------------------
        ! If true CMA will restart after converging 
        LOGICAL :: restart_cma = .FALSE.
        ! Type of Restart CMA should make after converging
        INTEGER :: restart_type = 0
        !                         0 restart randomly within bounds (default)
        !                         1 restart from point of convergence
        !                         2 restart from same startpoint all the time
         !% number of restarts '; 
        INTEGER :: Restarts  = 0   ! if set to zero CMA will run till max. Iteration or Funevals are reached
                                   ! 
        !% multiplier for population size before each restart';
        REAL(MK) :: IncPopSize   = 1.25_MK
        !% maximum size multiplier in comparison to the orignal size (ignoring negative values)
        INTEGER :: MaxIncFac = -1
        
        !-----------------------------------------------------------------------
        !  Benchmark variables
        !  Based on the CEC 2005 Benchmark, the following variables can be
        !  assigned to measure performance
        !-----------------------------------------------------------------------
        
        INTEGER             :: Benchfctnr = 1     ! also used for BOBB
        LOGICAL				:: benchmark = .FALSE. ! logs when certain f-val are reaced etc.
        REAL(MK)			:: global_min = 0.0_MK !0 mean no global min!!!!
        REAL(MK)			:: accuracy = 0.0_MK
        REAL(MK)            :: record_accuracy = 0.0_MK !used to check when optimization reaches gmin with this accuracy
        LOGICAL             :: use_seed = .FALSE.   !read in seed from file
        CHARACTER(len=200)  :: seed_folder = 'false'          !folder containing seed.txt
        LOGICAL             :: record_besthist = .FALSE.
        INTEGER             :: record_modulo = 100  !how many recordings (equal spaced) of the bestever should be made
        CHARACTER(len=200)  :: CECFolders = '' !path of the support Data Folder relative to the working dir (or absolut)
        LOGICAL             :: write_pdb = .FALSE. !if pdb should be written if using LJ/Water
        LOGICAL             :: use_BOBB = .FALSE.
        LOGICAL             :: use_CEC   = .FALSE.
        LOGICAL             :: use_LJ = .FALSE.
        LOGICAL             :: use_TIP = .FALSE.
        LOGICAL             :: use_LJ_comp = .FALSE.
        LOGICAL             :: use_DF = .FALSE.
        LOGICAL             :: use_RANDOM_LANDSCAPE = .FALSE.
        
        ! varialbes for the LJ Compression case
        REAL(MK)            :: LJ_comp = 1_MK
        
		! variables for the DoubleFunnel Test case
        REAL(MK)            :: DF_d = 0_MK
        REAL(MK)            :: DF_s = 0_MK
        LOGICAL             :: DF_rast = .TRUE.
        
        
        
        !-----------------------------------------------------------------------
        !  BFGS variables
        !  BFGS is a gradient search to assist CMA
        !-----------------------------------------------------------------------
        
        LOGICAL             :: BFGS_use = .FALSE.
        REAL(MK)            :: BFGS_factr  = 1.d+2
        REAL(MK)            :: BFGS_pgtol  = 1.0d-12
        REAL(MK)            :: BFGS_grad_stepsize = 10d-5
        LOGICAL             :: BFGS_central_difference = .FALSE.
        INTEGER(MK)         :: BFGS_position = 2
                               ! 1 = replace X Values by Local Minimum X
                               ! 2 = replace F Values with F Values at Local Minimum
        INTEGER             :: BFGS_maxit = -1
        REAL(MK)            :: BFGS_dguess = 1
        REAL(MK)            :: BFGS_STPMAX = -1 ! the maximum step of the line search (default adapted with sigma)
        REAL(MK)            :: BFGS_STPMIN = -1 ! the minimum step of the line search (default adapted with sigma)
        REAL(MK)            :: BFGS_GTOL = -1   ! the function tolarance for the line seach
        REAL(MK),DIMENSION(2):: BFGS_print = -1
!             IPRINT(1) spe!ifies the frequen!y of the output:
!                IPRINT(1) < 0 : no output is generated,
!                IPRINT(1) = 0 : output only at first and last iteration,
!                IPRINT(1) > 0 : output every IPRINT(1) iterations.
! 
!             IPRINT(2) spe!ifies the type of output generated:
!                IPRINT(2) = 0 : iteration !ount, number of fun!tion 
!                                evaluations, fun!tion value, norm of the
!                                gradient, and steplength,
!                IPRINT(2) = 1 : same as IPRINT(2)=0, plus ve!tor of
!                                variables and  gradient ve!tor at the
!                                initial point,
!                IPRINT(2) = 2 : same as IPRINT(2)=1, plus ve!tor of
!                                variables,
!                IPRINT(2) = 3 : same as IPRINT(2)=2, plus gradient ve!tor.
       INTEGER :: countBFGSit = 0
        
        !-----------------------------------------------------------------------
        !  MATLAB objective function
        !  Flag to indicate whether an objective function is used that is 
        !  called in MATLAB
        !-----------------------------------------------------------------------
        LOGICAL				:: matlab_func = .FALSE.
        
                
        !-----------------------------------------------------------------------
        !  internal used parameters (calculated from the parameters set above)
        !-----------------------------------------------------------------------
        REAL(MK),POINTER,DIMENSION(:) :: xstart
        !the final used sigma
        REAL(MK),POINTER,DIMENSION(:)   :: insigma
        INTEGER                         :: seed
        
        
        
        
        
        
        
        

        ! The following lines state variables from cmaes.m that haven't been
        ! implemented (yet)
        
        !% objective function FUN accepts NxM matrix, with M>1?';
        !INTEGER :: EvalParallel != 'no  
       
        !% display messages like initial and final message';
        !INTEGER :: Display  != 'on   
        !
        !INTEGER :: Plotting != 'on   % plot while running';
        !% resume former run from SaveFile';
        !INTEGER :: Resume  != 'no     
        !% off==do some additional (minor) problem capturing';
        !INTEGER :: Science != 'off  
        !% [on|final|off][-v6] save data to file';
        !INTEGER :: Saving  !=    'on   
        ! % if >1 record data less frequently after gen=100';
        !INTEGER :: SaveModulo != '1   
        !% max. percentage of time for recording data';
        !INTEGER :: SaveTime   != '25   
        
        
      END TYPE opts
      
      TYPE(opts) :: options
      


      
      END MODULE cmaes_opts_mod