NonLinearParticleSwarmOptimizationParameters¶
- class NonLinearParticleSwarmOptimizationParameters(population_size=None, number_of_generations_per_iteration=None, number_of_iterations=None, number_of_batches=None, initial_population=None, particle_swarm_optimization_parameters=None, processes_per_individual=None, radial_function_order=None, random_seed=None, initial_coefficients_from_file=None)¶
Class for storing the non-linear coefficients and parameters related to their optimization using particle-swarm-optimization.
- Parameters:
population_size (int) – The number of search particles in the swarm. Default: 32
number_of_generations_per_iteration (int) – How many generations each swarm optimization should carry out per iteration (batch). Default: 20
number_of_iterations (int) – The number of iterations (epochs) over different batches of the training data. This only needs to be increased if more than one batch is used. Default: 1
number_of_batches (int) – The number of batches the training dataset is divided into. This can be used to reduce the load of the fitting for large training sets. 1 means use all training data. If set to a value greater than 1, it is recommended to increase the number_of_iterations parameter, too, to. Default: 1
initial_population (numpy.ndarray | str | Random | None) – The initial values for the non-linear coefficients that the swarm should start from. Can be given as numpy array or as MTP filename. If given as filename the non-linear coefficients are read from the file. Missing coefficient values are filled with random values. If Random or None, random values are used for all coefficients.
particle_swarm_optimization_parameters (
ParticleSwarmOptimizationParameters
) – The particle swarm optimization parameters set.processes_per_individual (int | None) – The number of processes used for each individual MTP fit. Default: All available processes in the process group.
radial_function_order (int) – The order of Chebychev polynomials in the expansion of each radial function. Only used when CutoffFunctionChebyshevExpansion is selected as cutoff function. Default: 5
random_seed (int) – The random seed used to control the splitting of the training data into batches.
initial_coefficients_from_file (None | MTPParameters) – MTPParameters object containing pre calculated non-linear coefficients. Default:
None
- initialCoefficientsFromFile()¶
This has no corresponding instance variable
- initialPopulation()¶
- Returns:
The user-specified initial values for the non-linear coefficients.
- Return type:
numpy.ndarray | Random
- nlinfo()¶
- Returns:
The nlinfo.
- Return type:
dict
- numberOfBatches()¶
- Returns:
The number of batches.
- Return type:
int
- numberOfGenerationsPerIteration()¶
- Returns:
The number of generations per iteration (epoch).
- Return type:
int
- numberOfIterations()¶
- Returns:
The number of iterations (epochs) over different training data batches.
- Return type:
int
- particleSwarmOptimizationParameters()¶
- Returns:
The particle swarm optimization parameters set.
- Return type:
- populationSize()¶
- Returns:
The number of particles in the swarm.
- Return type:
int
- processesPerIndividual()¶
- Returns:
The number of processes used for each individual MTP fit.
- Return type:
int
- radialFunctionOrder()¶
- Returns:
The max. order of the Chebychev polynomial in the expansion of the radial functions.
- Return type:
int
- randomSeed()¶
- Returns:
The random seed used for generating the initial non-linear coefficients, or None if they should be generated automatically.
- Return type:
int | None
- setInitialPopulation(initial_population)¶
- Parameters:
initial_population (numpy.ndarray | str | Random | None) – The non-linear coefficients values that should be used to initialize the swarm.
- setNumberOfBatches(number_of_batches)¶
Set the number of batches.
- Parameters:
number_of_batches (int) – The number of batches.
- setNumberOfGenerationsPerIteration(number_of_generations_per_iteration)¶
- Parameters:
number_of_generations_per_iteration (int) – The number of generations per iteration (epoch).
- setNumberOfIterations(number_of_iterations)¶
- Parameters:
number_of_iterations (int) – The number of iterations (epochs) over different training data batches.
- setParticleSwarmOptimizationParameters(particle_swarm_optimization_parameters)¶
- Parameters:
particle_swarm_optimization_parameters (
ParticleSwarmOptimizationParameters
| None) – The particle swarm optimization parameters set.
- setPopulationSize(population_size)¶
- Parameters:
population_size (int) – The number of particles in the swarm.
- setProcessesPerIndividual(processes_per_individual)¶
- Parameters:
processes_per_individual (int) – The number of processes used for each individual MTP fit.
- setRadialFunctionOrder(radial_function_order)¶
Method for setting the radial function order.
- Parameters:
radial_function_order (int) – The order of Chebychev polynomials in the expansion of each radial function.
- setRandomSeed(random_seed)¶
Method for setting the random seed.
- Parameters:
random_seed (int) – The random seed used for generating the initial non-linear coefficients, if not given.
- uniqueString()¶
Return a unique string representing the state of the object.
Usage Examples¶
A default setup of the NonLinearParticleSwarmOptimizationParameters
object.
particle_swarm_optimization_parameters = ParticleSwarmOptimizationParameters(
inertia_weight=0.8,
local_acceleration=0.2,
global_acceleration=0.8,
omega=0.5,
)
non_linear_particle_swarm_optimization_parameters = NonLinearParticleSwarmOptimizationParameters(
population_size=32,
number_of_generations_per_iteration=20,
number_of_iterations=1,
number_of_batches=1,
particle_swarm_optimization_parameters=particle_swarm_optimization_parameters,
)
This instance can then be passed into MomentTensorPotentialFittingParameters
.
Notes¶
The NonLinearParticleSwarmOptimizationParameters
object serves as
input to MomentTensorPotentialFittingParameters
to specify parameters for the
particle swarm optimization (PSO) algorithm and further on to determine the
non-linear coefficients in a moment tensor potential (MTP) model.
The PSO algorithm is an optimization scheme which combines local and global
exploitation to find an optimum solution. As indicated by the
name the approach is initialized with a swarm of particles randomly distributed
in the search space. Each particle, \(i\), holds a vector of positions, velocities and local
best positions denoted by \(\vec{X}_i\), \(\vec{V}_i\) and \(\vec{P}_i\),
respectively. The global best positions by the entire swarm is denoted \(\vec{P}_g\).
The particle properties then evolves to obtain best positions in
search space going from increment \(t\) to \(t+1\) while being affected by
the local and global best positions of the swarm. The updated velocities at \(t+1\)
are determined according to [1],
where \(w\) is the inertia weight, \(\alpha\) is the local acceleration coefficient and \(\beta\) is the global acceleration coefficient. \(\textrm{r}_1\) and \(\textrm{r}_2\) are random numbers. The updated positions at \(t+1\) are calculates as,
where \(\omega\) is a velocity scaling factor.
The maximum number increments per MTP fit iteration is given by
number_of_generations_per_iteration
argument. The number of MTP fit iterations is specified
by number_of_iterations
argument. population_size
specifies the number of particles in
the swarm which corresponds to the number of coefficients.
For small and medium-sized training datasets, number_of_batches
and number_of_iterations
can be set to 1 to train on the entire dataset. For larger datasets these values can be increased,
which means the data will be divided into multiple batches and each iteration sees only a single
batch. With each new iteration the training uses a different batch. This can reduce memory and speed
up the fitting, especially if a subset of the training data is sufficient to optimize the non-linear
parameters.
At the end of each iteration a single linear fit on the entire training set using the current best
set of non-linear coefficients is carried out to obtain the total error of this iteration.
The parameter processes_per_individual
specifies how many processes are used for each linear fit.
This can be used to run multiple fits in parallel and balance the parallel efficiency versus memory
consumption.
PSO provides a more systematic optimization than scanning over different initial guesses or
using local optimization via NonLinearCoefficientsParameters
for the
non-linear coefficients, and can result in a lower training error particularly
for training datasets with many different elements, but it also takes longer time.