NonLinearCoefficientsParameters¶
- class NonLinearCoefficientsParameters(initial_coefficients=None, perform_optimization=None, max_force_rmse_change=None, max_steps=None, random_seed=None, regularization=None, energy_only=None, radial_function_order=None, zero_interaction_pairs=None, initial_coefficients_from_file=None)¶
Class for storing the non-linear coefficients and parameters related to their optimization.
- Parameters:
initial_coefficients (dict of {tuple (size 2) of
Element
: numpy-ndarray} | str | Random | FromAtomicNumbers) – The initial non-linear coefficients to use. Can either be a dict mapping the element pairs to the array with the initial coefficient values, or a filename pointing to a .mtp file to read the coefficients from. If an initial_coefficients_from_file is provided, this argument is ignored and initial coefficients are taken from the MTPParameters. Alternatively the parameter can be set to Random to use random initial values or set to FromAtomicNumbers to use the product of the element pair’s atomic numbers. Default: Random if perform_optimization is True, FromAtomicNumbers otherwise.perform_optimization (bool) – Whether to optimize the non-linear coefficients during the fitting. Default:
False
max_force_rmse_change (int) – The convergence criterion for the change in the RMSE on the force values between subsequent steps in the optimization of the non-linear coefficients. Ignored if perform_optimization is False. Default:
0.05 * eV / Angstrom
max_steps (int) – The maximum number of optimization steps to take. Ignored if perform_optimization is False. Default:
100
random_seed (int) – The random seed used for generating the initial non-linear coefficients, if not given. Default: Generated automatically.
regularization (float) – The regularization strength for the optimization. Ignored if perform_optimization is False. Default:
1.0e-2
energy_only (bool) – Whether to only optimize on the energy values. Ignored if perform_optimization is False. Default:
True
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
zero_interaction_pairs (None | Sequence of tuples (size 2) of
PeriodicTableElement
) – If not None, the interactions between the given element pairs will be set to zero. Default:None
initial_coefficients_from_file (None | MTPParameters) – MTPParameters object containing pre calculated non-linear coefficients. Default:
None
- energyOnly()¶
- Returns:
Whether to only optimize on the energy values.
- Return type:
float
- initialCoefficients()¶
- Returns:
The initial non-linear coefficients, or None if not used.
- Return type:
numpy.ndarray (size N, N, M) of float | None
- initialCoefficientsFromFile()¶
This has no corresponding instance variable
- maxForceRMSEChange()¶
- Returns:
The convergence criterion for the change in the RMSE on the force values between subsequent steps in the optimization of the non-linear coefficients.
- Return type:
PhysicalQuantity of type force
- maxForceRmseChange()¶
- Returns:
The convergence criterion for the change in the RMSE on the force values between subsequent steps in the optimization of the non-linear coefficients.
- Return type:
PhysicalQuantity of type force
- maxSteps()¶
- Returns:
The maximum number of optimization steps to take.
- Return type:
int
- nlinfo()¶
- Returns:
The nlinfo.
- Return type:
dict
- performOptimization()¶
- Returns:
Whether to optimize the non-linear coefficients during the fitting.
- Return type:
float
- 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
- regularization()¶
- Returns:
The regularization strength for the optimization.
- Return type:
float
- setEnergyOnly(energy_only)¶
Method for setting the energy_only.
- Parameters:
energy_only (bool) – Whether to only optimize on the energy values.
- setInitialCoefficients(initial_coefficients, perform_optimization)¶
Method for setting the initial coefficients.
- Parameters:
initial_coefficients (dict of {tuple (size 2) of
Element
: numpy-ndarray} | str | Random | FromAtomicNumbers) – The initial non-linear coefficients to use. Can either be a dict mapping the element pairs to the array with the initial coefficient values, or a filename pointing to a .mtp file to read the coefficients from. Alternatively the parameter can be set to Random to use random initial values or set to FromAtomicNumbers to use the product of the element pair’s atomic numbers.perform_optimization (bool) – Whether to optimize the non-linear coefficients during the fitting.
- setMaxForceRmseChange(max_force_rmse_change)¶
Method for setting the max_force_rmse_change.
- Parameters:
max_force_rmse_change (int) – The convergence criterion for the change in the RMSE on the force values between subsequent steps in the optimization of the non-linear coefficients.
- setMaxSteps(max_steps)¶
Method for setting the max steps.
- Parameters:
max_steps (int) – The maximum number of optimization steps to take.
- setPerformOptimization(perform_optimization)¶
Method for setting the perform_optimization.
- Parameters:
perform_optimization (bool) – Whether to optimize the non-linear coefficients during the fitting.
- 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.
- setRegularization(regularization)¶
Method for setting the regularization.
- Parameters:
regularization (float) – The regularization strength for the optimization.
- setZeroInteractionPairs(zero_interaction_pairs)¶
Method for setting the zero_interaction_pairs.
- Parameters:
zero_interaction_pairs (None | Sequence of tuples of
PeriodicTableElement
) – If not None, the interactions between the given element pairs will be set to zero.
- uniqueString()¶
Return a unique string representing the state of the object.
- zeroInteractionPairs()¶
- Returns:
The element pairs whose interaction should be set to zero.
- Return type:
list | None
Usage Examples¶
Set up of an example of NonLinearCoefficientsParameters using a specific random seed to initialize the initial non-linear coefficients:
# Define non-linear coefficients and enable optimization.
non_linear_coefficients_parameters = NonLinearCoefficientsParameters(
perform_optimization=True,
initial_coefficiants=Random,
random_seed=12345,
)
Scan over different initial guesses for the non-linear coefficients:
Note
This can be automated using the function scanOverNonLinearCoefficients
# Scan over different random initial guesses.
number_of_initial_guesses = 8
all_fitting_parameters = []
for i in range(number_of_initial_guesses):
# Set up different initial guesses for the non-linear coefficients.
non_linear_coefficients_parameters = NonLinearCoefficientsParameters(
perform_optimization=True,
random_seed=randomSeed(12345, i),
)
fitting_parameters = MomentTensorPotentialFittingParameters(
basis_size=PredefinedBasisSmall,
outer_cutoff_radii=4.0*Angstrom,
mtp_filename='mtp_{}.mtp'.format(i+1),
non_linear_coefficients_parameters=non_linear_coefficients_parameters,
)
all_fitting_parameters.append(fitting_parameters)
Read the initial non-linear coefficients from a .mtp file and include full energy, forces, and stress error in the optimization:
non_linear_coefficients_parameters = NonLinearCoefficientsParameters(
perform_optimization=True,
train_on_energy_only=False,
initial_coefficients='mtp_parameters.mtp',
)
Notes¶
NonLinearCoefficientsParameters serves as an input argument for
MomentTensorPotentialFittingParameters. The non-linear parameters
determine the setting and optimization of the coefficients for the radial
functions for each element pair. Two different kinds of radial function can be
chosen: The original polynomial functions used in [1],
which are orthonormalized via Chebyshev poynomials (default and recommended
option), and the Chebyshev expansion as explained in [2]. These
are set via the parameter cutoff_function
in
MomentTensorPotentialFittingParameters. Optimizing the non-linear
coefficients can improve the accuracy when training a MTP to multi-element
systems.
Note that different MTP basis numbers may require different number of non-linear coefficients.
The optimization of the non-linear coefficients is a local optimization which
means the solution depends on the initial guess. In order to obtain a lower
training and testing error it is recommended to scan over different initial
guesses and use the one with the lowest training and test error, as reported
in the nlprint()
output of the MomentTensorPotentialTraining
object.
For performance, it is recommended to train on energy only, which means that
the non-linear optimization is carried out by only minimizing the energy
error. Once a good fit is achieved, one can optionally run a final
optimization, starting from the optimized non-linear coefficients, including
the full energy, forces, and stress error by setting
train_on_energy_only=False
. This usually results in a slight additional
reduction of forces and stress error.
The initial values of the non-linear coefficients can either be set randomly,
read from an existing MTP parameter file, or specified explicitly.
If the initial non-linear coefficients are given explicitly, they must be
specified as dictionary that maps an element pair to the coefficients array.
The shape of the array is \((\mu_{max},)\) for original polynomial
functions and \((\mu_{max}, radial\_function\_order)\) for the Chebyshev
expansion, where \(\mu_{max}\) is the maximum value of the radial coefficients,
used by the given MTP basis (\(\mu_{max}=4\) for PredefinedBasisSmall
and typically \(\mu_{max}=6\) when specifying the number of basis functions explicitly).