Reference

Reference

Benchmarks

Newtman.EasomType.
Easom

An unconstrained implementation of the 2-dimensional Easom function defined as:

\[f(\mathbf{x}) = -\cos{(x_1)} \cos{(x_2)} \exp{[-(x_1 - \pi)^2 - (x_2 - \pi)^2]}\]

where $x_1$ and $x_2$ refer to the first and second element of the input vector $\mathbf{x}$.

source
Newtman.SphereType.
Sphere

An unconstrained implementation of the Sphere function defined as:

\[f(\mathbf{x}) = \sum_{i=1}^{d} x_i^2\]

where $d$ is the dimension of the input vector $\mathbf{x}$.

source
TestFunctions

Abstract supertype for all benchmark functions.

source
Unconstrained

Abstract supertype for all unconstrained benchmark functions.

source

Algorithms

Newtman.PSOType.
PSO

PSO is the type associated with the implementation for the Particle Swarm Optimization with momentum. See Algorithms for more information.

source
Newtman.PSOMethod.
PSO(f::Function, population::AbstractArray,
    k_max::Int, total_iter::Int;w=0.9, c1=2.0, c2=2.0) ->
    Array{Array{Float64, N}, total_iter}

Method that implements PSO for a function f of type Function with multiple runs enabled in parallel. Using @threads to make an embarrassingly parallel implementation to obtain results quicker.

Arguments

  • population: can be any AbstractArray that contains Particle

instances, but it is expected to be generated by Population.

  • k_max: number of maximum iterations until "convergence" of the algorithm.
  • total_iter: number of maximum experiments to run in parallel.

Keyword arguments

It is recommended to use the default values provided

  • w: value that controls how much of the initial velocity is retained, i.e.

an inertia term. This values decays linearly over each iteration until it reaches the default miminum value of 0.4.

  • c1: balance between the influence of the individual's knowledge, i.e. the

best inidividual solution so far.

  • c2: balance between the influence of the population's knowledge, i.e. the

best global solution so far.

Examples

using Newtman

# Define the Sphere function
f_sphere(x) = sum(x .^ 2)

# Implement PSO for a 3-dimensional Sphere function, with
# 10000 iterations, 30 particles in the population and 50
# independent runs evaluated in parallel
val = PSO(f_sphere, Population(30, 3, -15.0, 15.0), 10000, 50)
source
Newtman.PSOMethod.
PSO(f::Function, population::AbstractArray, k_max::Int;
    w=0.9, c1=2.0, c2=2.0) -> Array{Float64, N}

Method that implements PSO for a function f of type Function. Returns an Array{Float64, N} with N the dimension of the function to evaluate.

Arguments

  • population: can be any AbstractArray that contains Particle

instances, but it is expected to be generated by Population.

  • k_max: number of maximum iterations until "convergence" of the algorithm.

Keyword arguments

It is recommended to use the default values provided

  • w: value that controls how much of the initial velocity is retained, i.e.

an inertia term. This values decays linearly over each iteration until it reaches the default miminum value of 0.4.

  • c1: balance between the influence of the individual's knowledge, i.e. the

best inidividual solution so far.

  • c2: balance between the influence of the population's knowledge, i.e. the

best global solution so far.

Examples

using Newtman

# Define the Sphere function
f_sphere(x) = sum(x .^ 2)

# Implement PSO for a 3-dimensional Sphere function, with
# 10000 iterations and 30 particles in the population.
val = PSO(f_sphere, Population(30, 3, -15.0, 15.0), 10000)
source
Newtman.PSOMethod.
PSO(f::TestFunctions, population::AbstractArray,
    k_max::Int, total_iter::Int;w=0.9, c1=2.0, c2=2.0) ->
    Array{Array{Float64, N}, total_iter}

Method that implements PSO for a function f of type TestFunctions with multiple runs enabled in parallel. Using @threads to make an embarrassingly parallel implementation to obtain results quicker.

Arguments

  • population: can be any AbstractArray that contains Particle

instances, but it is expected to be generated by Population.

  • k_max: number of maximum iterations until "convergence" of the algorithm.
  • total_iter: number of maximum experiments to run in parallel.

Keyword arguments

It is recommended to use the default values provided

  • w: value that controls how much of the initial velocity is retained, i.e.

an inertia term. This values decays linearly over each iteration until it reaches the default miminum value of 0.4.

  • c1: balance between the influence of the individual's knowledge, i.e. the

best inidividual solution so far.

  • c2: balance between the influence of the population's knowledge, i.e. the

best global solution so far.

Examples

using Newtman

# Implement PSO for a 3-dimensional Sphere function, with
# 10000 iterations, 25 particles in the population and 50 independent runs,
# evaluated in parallel
val = PSO(Sphere(), Population(25, 3, -15.0, 15.0), 10000, 50)
source
Newtman.PSOMethod.
PSO(f::TestFunctions, population::AbstractArray, k_max::Int;
    w=0.9, c1=2.0, c2=2.0) -> Array{Float64, N}

Method that implements PSO for a function f of type TestFunctions. Returns an Array{Float64, N} with N the dimension of the function to evaluate.

Arguments

  • population: can be any AbstractArray that contains Particle

instances, but it is expected to be generated by Population.

  • k_max: number of maximum iterations until "convergence" of the algorithm.

Keyword arguments

It is recommended to use the default values provided

  • w: value that controls how much of the initial velocity is retained, i.e.

an inertia term. This values decays linearly over each iteration until it reaches the default miminum value of 0.4.

  • c1: balance between the influence of the individual's knowledge, i.e. the

best inidividual solution so far.

  • c2: balance between the influence of the population's knowledge, i.e. the

best global solution so far.

Examples

using Newtman

# Implement PSO for a 3-dimensional Sphere function, with
# 10000 iterations and 25 particles in the population.
val = PSO(Sphere(), Population(25, 3, -15.0, 15.0), 10000)
source
Metaheuristic

Abstract type for metaheuristic algorithms, this makes a clear distinction between different classifications of metaheuristic algorithms.

source
PopulationBase

Type for population-based algorithms that employ Population, i.e. subroutines that mutate an array of possible candidates in-place. An example of this type is PSO.

source
Newtman.SolverType.
Solver

Abstract super-type for every algorithm implementation.

source

Population

Newtman.ParticleMethod.
Particle(x::T, v::T, x_best::T, a::V, b::V)
    where {T<:AbstractArray, V<:AbstractFloat}

A type that can hold information about current position, current velocity, the best candidate to a solution, as well as defining the bounds. The dimensions of the Particle are inferred from the length of the arrays.

Arguments

  • x: Array that holds the positions of possible solutions.
  • v: Array that holds velocities related to x.
  • x_best: An element of x that determines the best position for the particle.
  • a: lower bound for x
  • b: upper bound for v

Example

p = Particle(zeros(3), rand(3), zeros(3), -1.0, 1.0)
source
Newtman.ParticleMethod.
Particle(a::T, b::T, n::V)
    where {T<:AbstractFloat, V<:Int}

Particle that can be created randomly using the bounds and the dimension needed.

Arguments

  • a: lower bound for x
  • b: upper bound for v
  • n: dimension for x, v, and x_best.

Example

p = Particle(-1.0, 1.0, 3)
source
Newtman.PopulationMethod.
Population(num_particles::T, dim::T, a::V, b::V)
    where {T<:Int, V<:AbstractFloat} -> Vector{Particle}(undef, num_particles)

An array of Particles where each of them are bounded and are given a dimension. This is essentially a multi-dimensional array. It makes handling Particles much easier.

Arguments

  • num_particles: Number of particles in the Population.
  • dim: Dimension for every Particle.
  • a: Lower bound for every Particle, this is shared across every instance.
  • b: Upper bound for every Particle, this is shared across every instance.

Example

pop = Population(35, 4, -1.0, 1.0)
source
Newtman.PopulationMethod.
Population(dim::T, a::V, b::V)
    where {T<:Int, V<:AbstractFloat} -> Vector{Particle}(undef, num_particles)

If num_particles is not provided, it defaults to 5 Particles in the Population.

Arguments

  • dim: Dimension for every Particle.
  • a: Lower bound for every Particle, this is shared across every instance.
  • b: Upper bound for every Particle, this is shared across every instance.

Example

pop = Population(4, -1.0, 1.0) # The same as Population(5, 4, -1.0, 1.0)
source
Individual

Abstract super-type for types that contain their own information.

source