Reference
Benchmarks
Newtman.Easom
— Type.Easom
An unconstrained implementation of the 2-dimensional Easom function defined as:
where $x_1$ and $x_2$ refer to the first and second element of the input vector $\mathbf{x}$.
Newtman.Sphere
— Type.Sphere
An unconstrained implementation of the Sphere function defined as:
where $d$ is the dimension of the input vector $\mathbf{x}$.
Newtman.TestFunctions
— Type.TestFunctions
Abstract supertype for all benchmark functions.
Newtman.Unconstrained
— Type.Unconstrained
Abstract supertype for all unconstrained benchmark functions.
Algorithms
Newtman.PSO
— Type.PSO
PSO
is the type associated with the implementation for the Particle Swarm Optimization with momentum. See Algorithms
for more information.
Newtman.PSO
— Method.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 anyAbstractArray
that containsParticle
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)
Newtman.PSO
— Method.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 anyAbstractArray
that containsParticle
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)
Newtman.PSO
— Method.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 anyAbstractArray
that containsParticle
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)
Newtman.PSO
— Method.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 anyAbstractArray
that containsParticle
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)
Newtman.Metaheuristic
— Type.Metaheuristic
Abstract type for metaheuristic algorithms, this makes a clear distinction between different classifications of metaheuristic algorithms.
Newtman.PopulationBase
— Type.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
.
Newtman.Solver
— Type.Solver
Abstract super-type for every algorithm implementation.
Population
Newtman.Particle
— Method.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 tox
.x_best
: An element ofx
that determines the best position for the particle.a
: lower bound forx
b
: upper bound forv
Example
p = Particle(zeros(3), rand(3), zeros(3), -1.0, 1.0)
Newtman.Particle
— Method.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 forx
b
: upper bound forv
n
: dimension forx
,v
, andx_best
.
Example
p = Particle(-1.0, 1.0, 3)
Newtman.Population
— Method.Population(num_particles::T, dim::T, a::V, b::V)
where {T<:Int, V<:AbstractFloat} -> Vector{Particle}(undef, num_particles)
An array of Particle
s where each of them are bounded and are given a dimension. This is essentially a multi-dimensional array. It makes handling Particle
s much easier.
Arguments
num_particles
: Number of particles in thePopulation
.dim
: Dimension for everyParticle
.a
: Lower bound for everyParticle
, this is shared across every instance.b
: Upper bound for everyParticle
, this is shared across every instance.
Example
pop = Population(35, 4, -1.0, 1.0)
Newtman.Population
— Method.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 Particle
s in the Population
.
Arguments
dim
: Dimension for everyParticle
.a
: Lower bound for everyParticle
, this is shared across every instance.b
: Upper bound for everyParticle
, this is shared across every instance.
Example
pop = Population(4, -1.0, 1.0) # The same as Population(5, 4, -1.0, 1.0)
Newtman.Individual
— Type.Individual
Abstract super-type for types that contain their own information.