Struct argmin::solver::particleswarm::ParticleSwarm

source ·
pub struct ParticleSwarm<P, F, R> { /* private fields */ }
Expand description

§Particle Swarm Optimization (PSO)

Canonical implementation of the particle swarm optimization method as outlined in [0] in chapter II, section A.

The rayon feature enables parallel computation of the cost function. This can be beneficial for expensive cost functions, but may cause a drop in performance for cheap cost functions. Be sure to benchmark both parallel and sequential computation.

§Requirements on the optimization problem

The optimization problem is required to implement CostFunction.

§References

[0] Zambrano-Bigiarini, M. et.al. (2013): Standard Particle Swarm Optimisation 2011 at CEC-2013: A baseline for future PSO improvements. 2013 IEEE Congress on Evolutionary Computation. https://doi.org/10.1109/CEC.2013.6557848

[1] https://en.wikipedia.org/wiki/Particle_swarm_optimization

Implementations§

source§

impl<P, F> ParticleSwarm<P, F, StdRng>

source

pub fn new(bounds: (P, P), num_particles: usize) -> Self

Construct a new instance of ParticleSwarm

Takes the number of particles and bounds on the search space as inputs. bounds is a tuple (lower_bound, upper_bound), where lower_bound and upper_bound are of the same type as the position of a particle (P) and of the same length as the problem as dimensions.

The inertia weight on velocity and the social and cognitive acceleration factors can be adapted with with_inertia_factor, with_cognitive_factor and with_social_factor, respectively.

The weights and acceleration factors default to:

  • inertia: 1/(2 * ln(2))
  • cognitive: 0.5 + ln(2)
  • social: 0.5 + ln(2)
§Example
let pso: ParticleSwarm<_, f64, _> = ParticleSwarm::new((lower_bound, upper_bound), 40);
source§

impl<P, F, R0> ParticleSwarm<P, F, R0>
where P: Clone + SyncAlias + ArgminSub<P, P> + ArgminMul<F, P> + ArgminRandom + ArgminZeroLike, F: ArgminFloat, R0: Rng,

source

pub fn with_rng_generator<R1: Rng>( self, generator: R1, ) -> ParticleSwarm<P, F, R1>

Set the random number generator

Defaults to rand::rngs::StdRng::from_entropy()

§Example
let pso: ParticleSwarm<_, f64, _> =
    ParticleSwarm::new((lower_bound, upper_bound), 40)
    .with_rng_generator(rand_xoshiro::Xoroshiro128Plus::seed_from_u64(1729));
source§

impl<P, F, R> ParticleSwarm<P, F, R>

source

pub fn with_inertia_factor(self, factor: F) -> Result<Self, Error>

Set inertia factor on particle velocity

Defaults to 1/(2 * ln(2)).

§Example
let pso: ParticleSwarm<_, f64, _> =
    ParticleSwarm::new((lower_bound, upper_bound), 40).with_inertia_factor(0.5)?;
source

pub fn with_cognitive_factor(self, factor: F) -> Result<Self, Error>

Set cognitive acceleration factor

Defaults to 0.5 + ln(2).

§Example
let pso: ParticleSwarm<_, f64, _> =
    ParticleSwarm::new((lower_bound, upper_bound), 40).with_cognitive_factor(1.1)?;
source

pub fn with_social_factor(self, factor: F) -> Result<Self, Error>

Set social acceleration factor

Defaults to 0.5 + ln(2).

§Example
let pso: ParticleSwarm<_, f64, _> =
    ParticleSwarm::new((lower_bound, upper_bound), 40).with_social_factor(1.1)?;

Trait Implementations§

source§

impl<P: Clone, F: Clone, R: Clone> Clone for ParticleSwarm<P, F, R>

source§

fn clone(&self) -> ParticleSwarm<P, F, R>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'de, P, F, R> Deserialize<'de> for ParticleSwarm<P, F, R>
where P: Deserialize<'de>, F: Deserialize<'de>, R: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<P, F, R> Serialize for ParticleSwarm<P, F, R>
where P: Serialize, F: Serialize, R: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<O, P, F, R> Solver<O, PopulationState<Particle<P, F>, F>> for ParticleSwarm<P, F, R>
where O: CostFunction<Param = P, Output = F> + SyncAlias, P: Clone + SyncAlias + ArgminAdd<P, P> + ArgminSub<P, P> + ArgminMul<F, P> + ArgminZeroLike + ArgminRandom + ArgminMinMax, F: ArgminFloat, R: Rng,

source§

fn next_iter( &mut self, problem: &mut Problem<O>, state: PopulationState<Particle<P, F>, F>, ) -> Result<(PopulationState<Particle<P, F>, F>, Option<KV>), Error>

Perform one iteration of algorithm

source§

fn name(&self) -> &str

Name of the solver. Mainly used in Observers.
source§

fn init( &mut self, problem: &mut Problem<O>, state: PopulationState<Particle<P, F>, F>, ) -> Result<(PopulationState<Particle<P, F>, F>, Option<KV>), Error>

Initializes the algorithm. Read more
source§

fn terminate_internal(&mut self, state: &I) -> TerminationStatus

Checks whether basic termination reasons apply. Read more
source§

fn terminate(&mut self, _state: &I) -> TerminationStatus

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Auto Trait Implementations§

§

impl<P, F, R> Freeze for ParticleSwarm<P, F, R>
where F: Freeze, R: Freeze, P: Freeze,

§

impl<P, F, R> RefUnwindSafe for ParticleSwarm<P, F, R>

§

impl<P, F, R> Send for ParticleSwarm<P, F, R>
where F: Send, R: Send, P: Send,

§

impl<P, F, R> Sync for ParticleSwarm<P, F, R>
where F: Sync, R: Sync, P: Sync,

§

impl<P, F, R> Unpin for ParticleSwarm<P, F, R>
where F: Unpin, R: Unpin, P: Unpin,

§

impl<P, F, R> UnwindSafe for ParticleSwarm<P, F, R>
where F: UnwindSafe, R: UnwindSafe, P: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> SendAlias for T

source§

impl<T> SyncAlias for T