项目作者: Konrad1991

项目描述 :
Particle swarm optimization in fortran.
高级语言: Fortran
项目地址: git://github.com/Konrad1991/pso.git
创建时间: 2021-02-02T17:14:02Z
项目社区:https://github.com/Konrad1991/pso

开源协议:GNU General Public License v2.0

下载


Overview

The repository opti contains a particle swarm optimizer (PSO) written in fortran. In the future more optimizer are planed.
For the PSO the user can chose between two topologies. Either the traditional star topology or an random adaptive neighberhood which is better for exploration of parameter spaces. This is useful when many parameters have to be optimized.

Installation

The project structured as a fpm (fortran package manager) project. Thus, the project can be used by adding the following two lines to the toml file:

[dependencies] \
opti = { git=”https://github.com/Konrad1991/opti"}

Documentation

The project contains only one subroutine called optimizer. It accepts the following parameter:

  1. integer :: number of particles (particle)
  2. integer :: number of generations (n_gen)
  3. integer :: how many parameters have to be optimized (n_params)
  4. real(8), dimension(n_params) :: An array containing the lower boundaries for the optimization (dimension(n_params))
  5. real(8), dimension(n_params) :: An array containing the upper boundaries for the optimization (dimension(n_params))
  6. real(8) :: The desired minimal error
  7. The loss function is of type:
  1. interface
  2. function fct (inp, problem_size) result(out)
  3. implicit none
  4. integer, intent(in) :: problem_size
  5. real(8), intent(in), dimension(problem_size) :: inp
  6. real(8) :: out
  7. end function fct
  8. end interface
  1. real(8), dimension(n_params) :: An array where the optimized parameter are stored (dimension(n_params))
  2. integer :: An optional parameter defining the topology. If chosen 1 the star topology is used. If chosen 2 the random adaptive topology is used. The default value is 1 (topo)
  3. integer :: An optional parameter defining the number of neighbours if the topology is the random adaptive topology. Otherwise the parameter is ignored. The default value is set to 4.

An easy example:

  1. module objectivefct
  2. contains
  3. function f(inp, problem_size) result(out)
  4. !! This function defines a multidimensional rosenbrock function
  5. !! For problem_size = 3 Minimum at (1,1,1)
  6. !! For 4 <= problem_size <= 7 local minima near (-1, 1, ...,1)
  7. implicit none
  8. integer, intent(in) :: problem_size
  9. real(8), intent(in), dimension(problem_size) :: inp
  10. real(8) :: out
  11. integer :: i
  12. out = 0.0
  13. do i = 1, (problem_size -1)
  14. out = out + 100.0*(inp(i+1) - inp(i)**2)**2 + (1 - inp(i) )**2
  15. end do
  16. end function
  17. end module
  18. program example
  19. use objectivefct
  20. use psomod
  21. implicit none
  22. integer:: n_swarm, n_generations, n_params
  23. real(8) :: lb(3), ub(3)
  24. real(8) :: desired_error
  25. real(8) :: result(3)
  26. n_swarm = 40
  27. n_generations = 10000
  28. n_params = 3
  29. lb = -10
  30. ub = 10
  31. desired_error = 0.00001
  32. call optimizer(n_swarm, n_generations, n_params, lb, ub, desired_error, f, result)
  33. print*, result
  34. end program example