# 13.13. Calculation algorithm “*ParticleSwarmOptimization*”¶

## Description¶

This algorithm realizes an estimation of the state of a system by minimization of a cost function by using an evolutionary strategy of particle swarm. It is a method that does not use the derivatives of the cost function. It falls in the same category than the Calculation algorithm “DerivativeFreeOptimization”, the Calculation algorithm “DifferentialEvolution” or the Calculation algorithm “TabuSearch”.

This is an optimization method allowing for global minimum search of a general error function of type , or , with or without weights. The default error function is the augmented weighted least squares function, classically used in data assimilation.

## Optional and required commands¶

The general required commands, available in the editing user graphical or textual interface, are the following:

- Background
*Vector*. The variable indicates the background or initial vector used, previously noted as . Its value is defined as a “*Vector*” or “*VectorSerie*” type object. Its availability in output is conditioned by the boolean “*Stored*” associated with input.

- BackgroundError
*Matrix*. This indicates the background error covariance matrix, previously noted as . Its value is defined as a “*Matrix*” type object, a “*ScalarSparseMatrix*” type object, or a “*DiagonalSparseMatrix*” type object, as described in detail in the section Requirements to describe covariance matrices. Its availability in output is conditioned by the boolean “*Stored*” associated with input.

- Observation
*List of vectors*. The variable indicates the observation vector used for data assimilation or optimization, and usually noted . Its value is defined as an object of type “*Vector*” if it is a single observation (temporal or not) or “*VectorSeries*” if it is a succession of observations. Its availability in output is conditioned by the boolean “*Stored*” associated in input.

- ObservationError
*Matrix*. The variable indicates the observation error covariance matrix, usually noted as . It is defined as a “*Matrix*” type object, a “*ScalarSparseMatrix*” type object, or a “*DiagonalSparseMatrix*” type object, as described in detail in the section Requirements to describe covariance matrices. Its availability in output is conditioned by the boolean “*Stored*” associated with input.

- ObservationOperator
*Operator*. The variable indicates the observation operator, usually noted as , which transforms the input parameters to results to be compared to observations . Its value is defined as a “*Function*” type object or a “*Matrix*” type one. In the case of “*Function*” type, different functional forms can be used, as described in the section Requirements for functions describing an operator. If there is some control included in the observation, the operator has to be applied to a pair .

The general optional commands, available in the editing user graphical or
textual interface, are indicated in List of commands and keywords for data assimilation or optimisation case.
Moreover, the parameters of the command “*AlgorithmParameters*” allows to
choose the specific options, described hereafter, of the algorithm. See
Description of options of an algorithm by “AlgorithmParameters” for the good use of this
command.

The options are the following:

- MaximumNumberOfIterations
*Integer value*. This key indicates the maximum number of internal iterations allowed for iterative optimization. The default is 50, which is an arbitrary limit. It is then recommended to adapt this parameter to the needs on real problems.Example:

`{"MaximumNumberOfIterations":50}`

- MaximumNumberOfFunctionEvaluations
*Integer value*. This key indicates the maximum number of evaluation of the cost function to be optimized. The default is 15000, which is an arbitrary limit. It is then recommended to adapt this parameter to the needs on real problems. For some optimizers, the effective number of function evaluations can be slightly different of the limit due to algorithm internal control requirements.Example:

`{"MaximumNumberOfFunctionEvaluations":50}`

- QualityCriterion
*Predefined name*. This key indicates the quality criterion, minimized to find the optimal state estimate. The default is the usual data assimilation criterion named “DA”, the augmented weighted least squares. The possible criteria has to be in the following list, where the equivalent names are indicated by the sign “<=>”: [“AugmentedWeightedLeastSquares” <=> “AWLS” <=> “DA”, “WeightedLeastSquares” <=> “WLS”, “LeastSquares” <=> “LS” <=> “L2”, “AbsoluteValue” <=> “L1”, “MaximumError” <=> “ME” <=> “Linf”].Example:

`{"QualityCriterion":"DA"}`

- NumberOfInsects
*Integer value*. This key indicates the number of insects or particles in the swarm. The default is 100, which is a usual default for this algorithm.Example :

`{"NumberOfInsects":100}`

- SwarmVelocity
*Real value*. This key indicates the part of the insect velocity which is imposed by the swarm, named “group velocity”. It is a positive floating point value. The default value is 1.Example :

`{"SwarmVelocity":1.}`

- GroupRecallRate
*Real value*. This key indicates the recall rate at the best swarm insect. It is a floating point value between 0 and 1. The default value is 0.5.Example :

`{"GroupRecallRate":0.5}`

- BoxBounds
*List of pairs of real values*. This key allows to define pairs of upper and lower bounds for*increments*on every state variable being optimized (and not on state variables themselves). Bounds have to be given by a list of list of pairs of lower/upper bounds for each increment on variable, with extreme values every time there is no bound (`None`

is not allowed when there is no bound). This key is required and there is no default values.Example :

`{"BoxBounds":[[-0.5,0.5], [0.01,2.], [0.,1.e99], [-1.e99,1.e99]]}`

- SetSeed
*Integer value*. This key allow to give an integer in order to fix the seed of the random generator used in the algorithm. By default, the seed is left uninitialized, and so use the default initialization from the computer, which then change at each study. To ensure the reproducibility of results involving random samples, it is strongly advised to initialize the seed. A simple convenient value is for example 123456789. It is recommended to put an integer with more than 6 or 7 digits to properly initialize the random generator.Example:

`{"SetSeed":123456789}`

- StoreSupplementaryCalculations
*List of names*. This list indicates the names of the supplementary variables, that can be available during or at the end of the algorithm, if they are initially required by the user. Their avalability involves, potentially, costly calculations or memory consumptions. The default is then a void list, none of these variables being calculated and stored by default (excepted the unconditionnal variables). The possible names are in the following list (the detailed description of each named variable is given in the following part of this specific algorithmic documentation, in the sub-section “*Information and variables available at the end of the algorithm*”): [ “Analysis”, “BMA”, “CostFunctionJ”, “CostFunctionJb”, “CostFunctionJo”, “CurrentIterationNumber”, “CurrentState”, “Innovation”, “OMA”, “OMB”, “SimulatedObservationAtBackground”, “SimulatedObservationAtCurrentState”, “SimulatedObservationAtOptimum”, ].Example :

`{"StoreSupplementaryCalculations":["BMA", "CurrentState"]}`

## Information and variables available at the end of the algorithm¶

At the output, after executing the algorithm, there are information and
variables originating from the calculation. The description of
Variables and informations available at the output show the way to obtain them by the method
named `get`

, of the variable “*ADD*” of the post-processing in graphical
interface, or of the case in textual interface. The input variables, available
to the user at the output in order to facilitate the writing of post-processing
procedures, are described in the Inventory of potentially available information at the output.

**Permanent outputs (non conditional)**

The unconditional outputs of the algorithm are the following:

- Analysis
*List of vectors*. Each element of this variable is an optimal state in optimization or an analysis in data assimilation.Example:

`Xa = ADD.get("Analysis")[-1]`

- CostFunctionJ
*List of values*. Each element is a value of the chosen error function .Example:

`J = ADD.get("CostFunctionJ")[:]`

- CostFunctionJb
*List of values*. Each element is a value of the error function , that is of the background difference part. If this part does not exist in the error function, its value is zero.Example:

`Jb = ADD.get("CostFunctionJb")[:]`

- CostFunctionJo
*List of values*. Each element is a value of the error function , that is of the observation difference part.Example:

`Jo = ADD.get("CostFunctionJo")[:]`

**Set of on-demand outputs (conditional or not)**

The whole set of algorithm outputs (conditional or not), sorted by alphabetical order, is the following:

- Analysis
*List of vectors*. Each element of this variable is an optimal state in optimization or an analysis in data assimilation.Example:

`Xa = ADD.get("Analysis")[-1]`

- BMA
*List of vectors*. Each element is a vector of difference between the background and the optimal state.Example:

`bma = ADD.get("BMA")[-1]`

- CostFunctionJ
*List of values*. Each element is a value of the chosen error function .Example:

`J = ADD.get("CostFunctionJ")[:]`

- CostFunctionJb
*List of values*. Each element is a value of the error function , that is of the background difference part. If this part does not exist in the error function, its value is zero.Example:

`Jb = ADD.get("CostFunctionJb")[:]`

- CostFunctionJo
*List of values*. Each element is a value of the error function , that is of the observation difference part.Example:

`Jo = ADD.get("CostFunctionJo")[:]`

- CurrentIterationNumber
*List of integers*. Each element is the iteration index at the current step during the iterative algorithm procedure. There is one iteration index value per assimilation step corresponding to an observed state.Example:

`i = ADD.get("CurrentIterationNumber")[-1]`

- CurrentState
*List of vectors*. Each element is a usual state vector used during the iterative algorithm procedure.Example:

`Xs = ADD.get("CurrentState")[:]`

- Innovation
*List of vectors*. Each element is an innovation vector, which is in static the difference between the optimal and the background, and in dynamic the evolution increment.Example:

`d = ADD.get("Innovation")[-1]`

- OMA
*List of vectors*. Each element is a vector of difference between the observation and the optimal state in the observation space.Example:

`oma = ADD.get("OMA")[-1]`

- OMB
*List of vectors*. Each element is a vector of difference between the observation and the background state in the observation space.Example:

`omb = ADD.get("OMB")[-1]`

- SimulatedObservationAtBackground
*List of vectors*. Each element is a vector of observation simulated by the observation operator from the background . It is the forecast from the background, and it is sometimes called “*Dry*”.Example:

`hxb = ADD.get("SimulatedObservationAtBackground")[-1]`

- SimulatedObservationAtCurrentState
*List of vectors*. Each element is an observed vector simulated by the observation operator from the current state, that is, in the observation space.Example:

`hxs = ADD.get("SimulatedObservationAtCurrentState")[-1]`

- SimulatedObservationAtOptimum
*List of vectors*. Each element is a vector of observation obtained by the observation operator from simulation on the analysis or optimal state . It is the observed forecast from the analysis or the optimal state, and it is sometimes called “*Forecast*”.Example:

`hxa = ADD.get("SimulatedObservationAtOptimum")[-1]`

## See also¶

References to other sections:

- Calculation algorithm “DerivativeFreeOptimization”
- Calculation algorithm “DifferentialEvolution”
- Calculation algorithm “TabuSearch”

Bibliographical references: