Giter Site home page Giter Site logo

keurfonluu / stochoptim Goto Github PK

View Code? Open in Web Editor NEW
10.0 4.0 2.0 79 KB

StochOptim provides user friendly functions to solve optimization problems using stochastic algorithms

License: MIT License

Makefile 1.11% C++ 0.01% Fortran 98.25% Python 0.64%
evolutionary-algorithms stochastic-optimization monte-carlo particle-swarm-optimization differential-evolution cmaes mcmc parallel mpi fortran

stochoptim's Introduction

StochOptim

StochOptim provides user friendly functions to solve optimization problems using stochastic algorithms in a parallel environment (MPI).

Version: 1.0.4
Author: Keurfon Luu
Web site: https://github.com/keurfonluu/stochoptim
Copyright: This document has been placed in the public domain.
License: StochOptim is released under the MIT License.

NOTE: StochOptim has been implemented in the frame of my Ph. D. thesis. If you find any error or bug, or if you have any suggestion, please don't hesitate to contact me.

Features

StochOptim provides routines written in oriented-object Fortran to sample a parameter model space and optimize objective functions:

  • Metropolis-Hastings algorithm
  • Differential Evolution
  • Particle Swarm Optimization
  • Competitive Particle Swarm Optimization
  • Covariance Matrix Adaptation - Evolution Strategy

Usage

Place files in src/lib in your source directory and import stochoptim module:

  use stochoptim, only: Evolutionary, MonteCarlo

Methods available:

  • optimize / sample
  • print_parameters
  • print_results
  • print
  • save_models

For evolutionary optimizers, population individuals can be parallelized using MPI simply by adding the preprocessor option -Ddo_mpi.

Example

Examples codes can be found in src/tests, or you can try the following code:

program test

  use stochoptim, only: Evolutionary

  implicit none

  real(kind = 8), parameter :: pi = 3.141592653589793238460d0
  integer(kind = 4), parameter :: n_dim = 5, popsize = 10, max_iter = 500
  real(kind = 8), dimension(:), allocatable :: lower, upper
  type(Evolutionary) :: ea

  ! Define search boundaries
  allocate(lower(n_dim), upper(n_dim))
  lower = -5.12
  upper = 5.12

  ! Initialize evolutionary optimizer
  ea = Evolutionary(rastrigin, lower, upper, &
                    popsize = popsize, max_iter = max_iter)

  ! Optimize
  call ea % optimize(solver = "cpso")

  ! Display results
  call ea % print()

contains

  function rastrigin(x) result(f)
    real(kind = 8), dimension(:), intent(in) :: x
    integer(kind = 4) :: n_dim
    real(kind = 8) :: f, sum1

    n_dim = size(x)
    sum1 = sum( x**2 - 10.0d0 * cos( 2.0d0 * pi * x ) )
    f = 10.0d0 * n_dim + sum1
    return
  end function rastrigin

end program test

Results

            solver: 'cpso'
        parameters: w = 0.72, c1 = 1.49, c2 = 1.49, gamma = 1.00
           popsize: 10
          max_iter: 500
             n_dim: 5
          solution:
                           2.4281118235742959E-006
                          -1.8335474048010150E-006
                           1.0076754625181591E-006
                          -1.8331826109239015E-009
                           9.6263231204725598E-007
           fitness: 2.2219381889954093E-009
            n_iter: 358
            n_eval: 3580
         n_restart: 4
              flag: fitness is lower than threshold eps2 (9.9999999392252903E-009)

stochoptim's People

Contributors

keurfonluu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

eachonly afcarl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.