"Let us load the data from the NOMAD Archive and the atomicfeaturespackage. It consists of RS-ZB energy differences (in eV/atom) of the 82 octet binary compounds, structure objects containing the atomic positions of the materials and properties of the atomic constituents. The following atomic features are considered:\n",
"Let us load the data from the NOMAD Archive and the atomicfeaturespackage. It consists of RS-ZB energy differences (in eV/atom) of the 82 octet binary compounds, structural information (e.g. atomic positions) of the materials, and properties of the atomic constituents. The following atomic features are considered:\n",
"\n",
"<div >\n",
" <ul>\n",
...
...
@@ -150,8 +150,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.037772Z",
"start_time": "2021-02-08T13:51:13.170622Z"
"end_time": "2021-02-08T20:33:08.427703Z",
"start_time": "2021-02-08T20:33:06.175593Z"
}
},
"outputs": [],
...
...
@@ -185,6 +185,23 @@
" max=200)\n",
" return query\n",
"\n",
"def write_xyz(df):\n",
" for compound, (A, B, pos, lat) in df[['A', 'B', 'atomic_positions', 'lattice_vectors']].iterrows():\n",
"# get data (chemical formulas and RS-ZB energy difference) from query\n",
...
...
@@ -244,8 +263,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.060958Z",
"start_time": "2021-02-08T13:51:16.040921Z"
"end_time": "2021-02-08T20:33:08.464082Z",
"start_time": "2021-02-08T20:33:08.429950Z"
},
"scrolled": true
},
...
...
@@ -272,8 +291,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.080154Z",
"start_time": "2021-02-08T13:51:16.062309Z"
"end_time": "2021-02-08T20:33:08.497905Z",
"start_time": "2021-02-08T20:33:08.466110Z"
}
},
"outputs": [],
...
...
@@ -298,8 +317,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.141626Z",
"start_time": "2021-02-08T13:51:16.081628Z"
"end_time": "2021-02-08T20:33:08.577514Z",
"start_time": "2021-02-08T20:33:08.499974Z"
}
},
"outputs": [],
...
...
@@ -326,8 +345,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.546500Z",
"start_time": "2021-02-08T13:51:16.143452Z"
"end_time": "2021-02-08T20:33:09.184095Z",
"start_time": "2021-02-08T20:33:08.579531Z"
}
},
"outputs": [],
...
...
@@ -353,8 +372,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.551139Z",
"start_time": "2021-02-08T13:51:16.548048Z"
"end_time": "2021-02-08T20:33:09.190366Z",
"start_time": "2021-02-08T20:33:09.186009Z"
}
},
"outputs": [],
...
...
@@ -378,8 +397,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.620249Z",
"start_time": "2021-02-08T13:51:16.552600Z"
"end_time": "2021-02-08T20:33:09.254875Z",
"start_time": "2021-02-08T20:33:09.193573Z"
},
"scrolled": true
},
...
...
@@ -421,8 +440,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.626622Z",
"start_time": "2021-02-08T13:51:16.621742Z"
"end_time": "2021-02-08T20:33:09.260671Z",
"start_time": "2021-02-08T20:33:09.256261Z"
}
},
"outputs": [],
...
...
@@ -457,8 +476,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.656484Z",
"start_time": "2021-02-08T13:51:16.628554Z"
"end_time": "2021-02-08T20:33:09.292113Z",
"start_time": "2021-02-08T20:33:09.262056Z"
},
"scrolled": true
},
...
...
@@ -472,8 +491,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:16.763864Z",
"start_time": "2021-02-08T13:51:16.657819Z"
"end_time": "2021-02-08T20:33:09.428263Z",
"start_time": "2021-02-08T20:33:09.294657Z"
},
"scrolled": true
},
...
...
@@ -506,8 +525,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:37.834144Z",
"start_time": "2021-02-08T13:51:16.765421Z"
"end_time": "2021-02-08T20:33:31.391117Z",
"start_time": "2021-02-08T20:33:09.430197Z"
},
"scrolled": false
},
...
...
@@ -542,8 +561,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:38.104687Z",
"start_time": "2021-02-08T13:51:37.835766Z"
"end_time": "2021-02-08T20:33:31.696678Z",
"start_time": "2021-02-08T20:33:31.392682Z"
}
},
"outputs": [],
...
...
@@ -596,8 +615,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:38.110486Z",
"start_time": "2021-02-08T13:51:38.106011Z"
"end_time": "2021-02-08T20:33:31.705234Z",
"start_time": "2021-02-08T20:33:31.698594Z"
}
},
"outputs": [],
...
...
@@ -637,8 +656,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:38.479613Z",
"start_time": "2021-02-08T13:51:38.111880Z"
"end_time": "2021-02-08T20:33:32.080607Z",
"start_time": "2021-02-08T20:33:31.706951Z"
},
"scrolled": true
},
...
...
@@ -657,8 +676,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:38.766814Z",
"start_time": "2021-02-08T13:51:38.481195Z"
"end_time": "2021-02-08T20:33:32.459091Z",
"start_time": "2021-02-08T20:33:32.082282Z"
}
},
"outputs": [],
...
...
@@ -701,8 +720,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:39.113981Z",
"start_time": "2021-02-08T13:51:38.769152Z"
"end_time": "2021-02-08T20:33:32.840916Z",
"start_time": "2021-02-08T20:33:32.461049Z"
}
},
"outputs": [],
...
...
@@ -727,8 +746,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:39.375223Z",
"start_time": "2021-02-08T13:51:39.115648Z"
"end_time": "2021-02-08T20:33:33.163048Z",
"start_time": "2021-02-08T20:33:32.843504Z"
},
"scrolled": true
},
...
...
@@ -759,8 +778,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:44.105352Z",
"start_time": "2021-02-08T13:51:44.087496Z"
"end_time": "2021-02-08T20:33:33.181713Z",
"start_time": "2021-02-08T20:33:33.164677Z"
}
},
"outputs": [],
...
...
@@ -795,8 +814,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:50.268397Z",
"start_time": "2021-02-08T13:51:44.988511Z"
"end_time": "2021-02-08T20:33:39.353216Z",
"start_time": "2021-02-08T20:33:33.183541Z"
},
"scrolled": false
},
...
...
@@ -852,8 +871,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-02-08T13:51:50.737037Z",
"start_time": "2021-02-08T13:51:50.270139Z"
"end_time": "2021-02-08T20:33:39.816501Z",
"start_time": "2021-02-08T20:33:39.355058Z"
},
"scrolled": false
},
...
...
@@ -901,14 +920,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Firstly the atomic coordinates of all compounds are stored in a .xyz file for the successive visualization."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Below the plot containing all octet binary materials, shown in the coordinate reference system given by the SISSO descriptors. By hovering over a point in the plot, information regarding that compound is displayed. By clicking a point, an interactive 3D visualization of the most stable structure will be displayed below the plot. To facilitate comparison between different materials, we make available two separate viewers. The specific viewer to be employed for visualization can be selected with a check box placed on top-right of each visualizer. Once a compound is selected from the plot, the marker on the plot changes shape accordingly to a marker that is specific of the viewer and whose shape is shown next to the checkbox. The name of the compound viewed is shown on top of the visualizer, and it is also possible to modify the name in the text box with the name of another compound, which can be displayed by clicking the \"Display\" button. Consequently, the new compound is also marked on the plot, that allows to easily identify the position of each compound in the plot. \n",
"Below the plot containing all octet binary materials, shown in the coordinate reference system given by the SISSO descriptors. By hovering over a point in the plot, information regarding that compound is displayed. By clicking a point, an interactive 3D visualization of the most stable structure will be displayed below the plot. To facilitate comparison between different materials, we make available two separate viewers. The specific viewer to be employed for visualization can be selected with a check box placed on top-right of each visualizer. Once a compound is selected from the plot, the marker on the plot changes shape accordingly to a marker that is specific of the viewer and whose shape is shown next to the checkbox. The name of the compound viewed is shown on top of the visualizer, and it is also possible to modify the name in the text box with the name of another compound, which can be displayed by clicking the \"Display\" button. Consequently, the new compound is also marked on the plot, that allows to easily identify the position of each compound in the plot. Note that the structures of all compounds were stored in a .xyz file at the beginning of the tutorial, i.e. using the function 'write_xyz'.\n",
"\n",
"The markers represent the compounds and their colors the reference energy differences. How well does the descriptor separate the compounds with respect to their crystal structure?"
This tutorial shows how to find descriptive parameters (short formulas) to predict materials properties using compressed sensing tools. As an example, we address the prediction of the zincblende (ZB) versus rocksalt (RS) relative stability of 82 octet binary materials.
The idea of using compressed sensing tools: Starting from simple physical quantities ("building blocks", here properties of the constituent free atoms such as orbital radii), millions (or billions) of candidate formulas are generated by applying arithmetic operations combining building blocks, for example forming sums and products of them. These candidate formulas constitute the so-called "feature space". Then a compressed sensing based method is used to select only a few of these formulas that explain the data, as described in
L. M. Ghiringhelli, J. Vybiral, S. V. Levchenko, C. Draxl, M. Scheffler: <spanstyle="font-style: italic;">Big Data of Materials Science: Critical Role of the Descriptor</span>, Phys. Rev. Lett. 114, 105503 (2015) <ahref="http://journals.aps.org/prl/abstract/10.1103/PhysRevLett.114.105503"target="_blank">[PDF]</a>.</div>
In this tutorial we use the Sure Independence Screening and Sparsifying Operator (SISSO) as introduced in
R. Ouyang, S. Curtarolo, E. Ahmetcik, M. Scheffler, L. M. Ghiringhelli: <spanstyle="font-style: italic;">SISSO: a compressed-sensing method for identifying the best low-dimensional descriptor in an immensity of offered candidates</span>, Phys. Rev. Materials 2, 083802 (2018) <ahref="https://journals.aps.org/prmaterials/abstract/10.1103/PhysRevMaterials.2.083802"target="_blank">[PDF]</a> .
</div>
# Introduction to the compressed sensing methods
The feature space is generated by creating a list of analytical expressions (the derived features), obtained by combining <i> primary features </i> and arithmetic operations. In this example, the primary features are properties of isolated atoms, such as electron affinity or the radial extension of valence orbitals. We put all $m$ derived features into a descriptor matrix $\mathbf{D} \in \mathbb{R}^{82 \times m}$ where each column stands for a derived feature and each row for a compound. An $\ell_0$-regularization
determines those few feature columns which approximate a property vector $\mathbf{P} \in \mathbb{R}^{82}$ (i.e RS vs. ZB energy differences) best. The subscript 0 stands for the $\ell_0$-quasinorm, that counts the number of non-zero elements of $\mathbf{c}$ and $\lambda > 0$ is called the regularization parameter. Performing the $\ell_0$-regularization becomes fast computational infeasable and often approximations (i.e. LASSO, orthogonal matching pursuit) are needed since in practice the $\ell_0$-regularization needs to be solved combinatorial: All singletons, pairs, triplets, ... $n$-tuples (up to the selected maximum dimension of the descriptor) are listed and for each set a least-square regression is performed. The $n$-tuple that gives the lowest mean square error for the least-square regression fit is selected as the resulting $n$-dimensional descriptor.
### The LASSO method
A convex optimization problem can be introduced by the Least Absolute Shrinkage and Selection Operator (LASSO):
Under certain conditions on the matrix $\mathbf{D}$, it can find the exact solution of, or a good approximation to, the $\ell_0$-regularization problem.
### The SISSO method
SISSO works iteratively. In the first iteration, a number $k$ of features is collected that have the largest correlation (scalar product) with $\mathbf{P}$. The feature with the largest correlation is simply the 1D descriptor. Next, a residual is constructed as the error made in the first iteration. A new set of $k$ features is now selected as those having the largest correlation with the residual. The 2D descriptor is the pair of features that yield the smallest fitting error upon least-square regression, among all possible pairs contained in the union of the sets selected in this and the first iteration. In each next iteration a new residual is constructed as the error made in the previous iteration, then a new set of $k$ features is extracted as those that have largest correlation with each new residual. The $n$D descriptor is the $n$-tuple of features that yield the smallest fitting error upon least square regression, among all possible $n$-tuples contained in the union of the sets obtained in each new iteration and all the previous iterations. If $k=1$ the method collapses to the so-called orthogonal matching pursuit.
Let us load the data from the NOMAD Archive and the atomicfeaturespackage. It consists of RS-ZB energy differences (in eV/atom) of the 82 octet binary compounds, structure objects containing the atomic positions of the materials and properties of the atomic constituents. The following atomic features are considered:
Let us load the data from the NOMAD Archive and the atomicfeaturespackage. It consists of RS-ZB energy differences (in eV/atom) of the 82 octet binary compounds, structural information (e.g. atomic positions) of the materials, and properties of the atomic constituents. The following atomic features are considered:
<div>
<ul>
<li>Z: atomic number</li>
<li>period: period in the periodic table</li>
<li>IP: ionization potential</li>
<li>EA: electron affinity</li>
<li>E_HOMO: energy of the highest occupied atomic orbital</li>
<li>E_LUMO: energy of the lowest unoccupied atomic orbital</li>
<li>r_(s, p, d): radius where the radial distribution of s, p or d orbital has its maximum.</li>
With the SISSO method, we are able to predict the energy differences from the atomic features with an accuracy of 0.035 eV/atom. However, due to computational limit we will target an accuracy of around 0.1 eV/atom in this tutorial.
Now let us define a function get_data that uses the data frame df to define the target vector $\mathbf{P}$ of energy differences and constructs the descriptor matrix $\mathbf{D}$ of combined features. The arguments selected_feature_list and allowed_operations specify which primary features and which arithmetic operations should be used to build the new derived features.
<li> Perform an $\ell_0$-regularization to identify the best low dimensional descriptors using the primary features.</li>
<li> Show that non-linear functions of the primary features improve the models significantly. </li>
<li> See that the $\ell_0$-regularization can rapidly become computational infeasible.</li>
</div>
Our target is to find the best low dimensional descriptor for a linear model $\mathbf{P} = \mathbf{D^\ast}\mathbf{c^\ast}$, where $\mathbf{c^\ast}$ is the vector of nonzero elements of the solution vector $\mathbf{c}$ and $\mathbf{D^\ast}$ is the matrix of the columns of $\mathbf{D}$ corresponding to the nonzero elements of $\mathbf{c}$. The $\ell_0$ regularization
Perform the $\ell_0$-regularization for different dimensions (numbers of non-zero coefficients in the model) and see the root mean square errors (RMSE) and the selected features.
The result of performing the $\ell_0$-regularization shows that the accuracy converges fast, e.g. we could leave out some components in the linear model without decreasing the accuracy. The second observation is that a linear model of the atomic features is not enough to describe the RS-ZB energy differences. A way out could be using non-linear machine learning models, e.g. kernel ridge regression or a neural network, instead of linear regression. Another way is to put the non-linearity into the descriptors by building algebraic combinations of the atomic features and mapping the few best of these more complex features onto the target again with a linear model.
Run the following script to build larger feature spaces of more complex features and select the best 1D, 2D and 3D descriptor for a linear model using $\ell_0$-regularization. Plot the results afterwards. How does the accuracy of the models change? How does the feature space size and the dimension of the descriptors depend on the needed time to solve the $\ell_0$-problem?
Before performing the LASSO regression we standardize the data to have mean 0 and variance 1, since otherwise the $\ell_2$-norm of a column would affect bias its contribution to the model. <br>
Note that we can use the LASSO also only for feature selection. We use then a least-square model with the selected features afterwards instead of the LASSO model directly.
$\lambda$ regulates the sparsity of the coefficient vector of the model. Get the data and try different $\lambda$ by adjusting the varibale lam. How good does LASSO (directly or with a least-square fit afterwards) approximate the L0-method (when the same feature space is used for both)?
Now apply the SISSO algorithm. How does the SISSO method compare to the LASSO and to the $\ell_0$-regularization in terms of accuracy (again when using the same feature space)? How fast is SISSO compared to the $\ell_0$-regularization? How does n_features_per_sis_iter (the number of features collected per sis iteration) affect the performance? Note, that for n_features_per_sis_iter=1 SISSO becomes the so-called orthogonal matching pursuit, another well-known compressed sensing method.
<li>Reproduce the results from the <ahref="http://journals.aps.org/prl/abstract/10.1103/PhysRevLett.114.105503"target="_blank">reference publication</a> by including further features.</li>
<li>Visualize the 2D descriptors in a structure map.</li>
<li>Experiment with different settings and investigate the influence of the input parameters on the results. (OPTIONAL)</li>
</div>
Note the size of the feature space, the needed time to run the code and the accuracy (using the default settings)!
To deal with larger feature spaces, note that in this chapter an optimized c++ implementation of the SISSO code will be used.
%% Cell type:code id: tags:
``` python
# here we define a different dataframe to make it compatible with the c++ implementation of SISSO
Firstly the atomic coordinates of all compounds are stored in a .xyz file for the successive visualization.
%% Cell type:markdown id: tags:
Below the plot containing all octet binary materials, shown in the coordinate reference system given by the SISSO descriptors. By hovering over a point in the plot, information regarding that compound is displayed. By clicking a point, an interactive 3D visualization of the most stable structure will be displayed below the plot. To facilitate comparison between different materials, we make available two separate viewers. The specific viewer to be employed for visualization can be selected with a check box placed on top-right of each visualizer. Once a compound is selected from the plot, the marker on the plot changes shape accordingly to a marker that is specific of the viewer and whose shape is shown next to the checkbox. The name of the compound viewed is shown on top of the visualizer, and it is also possible to modify the name in the text box with the name of another compound, which can be displayed by clicking the "Display" button. Consequently, the new compound is also marked on the plot, that allows to easily identify the position of each compound in the plot.
Below the plot containing all octet binary materials, shown in the coordinate reference system given by the SISSO descriptors. By hovering over a point in the plot, information regarding that compound is displayed. By clicking a point, an interactive 3D visualization of the most stable structure will be displayed below the plot. To facilitate comparison between different materials, we make available two separate viewers. The specific viewer to be employed for visualization can be selected with a check box placed on top-right of each visualizer. Once a compound is selected from the plot, the marker on the plot changes shape accordingly to a marker that is specific of the viewer and whose shape is shown next to the checkbox. The name of the compound viewed is shown on top of the visualizer, and it is also possible to modify the name in the text box with the name of another compound, which can be displayed by clicking the "Display" button. Consequently, the new compound is also marked on the plot, that allows to easily identify the position of each compound in the plot. Note that the structures of all compounds were stored in a .xyz file at the beginning of the tutorial, i.e. using the function 'write_xyz'.
The markers represent the compounds and their colors the reference energy differences. How well does the descriptor separate the compounds with respect to their crystal structure?
<li>Perform a leave-one-out cross-validation (LOOCV) using SISSO.</li>
<li>Analyze the prediction accuracy and how often the same descriptor is selected.</li>
</div>
We have seen that we can fit the energy differences of materials accurately. But what about predicting the energy difference of a 'new' material (which was not included when determining the model)? We test the prediction performance via LOOCV. In a LOOCV for each material the following procedure is performed: the selected material is excluded, the model is built on the remaining materials and the model accurcy is tested on the excluded material. This means that we need to run SISSO function 82 times. <br>
Get the data in the next cell and run the LOOCV one cell after. Note that running the LOOCV could take up to ten minutes. Use the remaining two cells of this chapter to analyse the results.<br>
How is the prediction error compared to the fitting error? How often is the same descriptor selected? Are there materials that yield an outlying high/low error?
It is instructive to compare the performance of the just identified model with a model trained with the popular kernel ridge regression (KRR) approach, by using the same list of atomic features as input.
KRR solves a $\ell_2$ regularized linear regression problem, with (typically) a nonlinear kernel.
This can be descirbed in the following manner. The $\ell_2$ regularized linear regression problem is:
Acoording to Hilbert space representaiton theorem, we can write the solution vector $\mathbf{c}$ as a linear expansion over the data points represented acoording to the chosen descriptor. In other words, $\mathbf{c}$ can be represented as a linear expansion over the rows $\mathbf{d}_j$ of the matrix $\mathbf{D}$.
where the kernel $\mathbf{K}$ is: $K_{ij} = <\mathbf{d}_i,\mathbf{d}_j> $.
The rewritten problem has solution $\boldsymbol{\alpha} = \left( \mathbf{K} + \lambda \mathbf{I} \right)^{-1} \mathbf{P} \quad (2)$
This rewriting did not add anything to the regularized linear regression approoach. If, however, we now expand the vector $\mathbf{c}$ as an expansion of nonlinear functions $\Phi()$ of the vectors $\mathbf{d}_j:
and the kernel as: $K_{ij} = <\Phi(\mathbf{d}_i),\Phi(\mathbf{d}_j)> $, one can prove that the same problem (1) with the same solution (2) holds. Normally, people do not specify the function $\Phi()$, but rahter the kernel.
Actually, $\Phi()$ does not need to be known at all. We refer to the specialized literature on KRR for more details on this method.
Here, we make use of the Gaussian kernel, i.e., the most popular one:
$K(x, y) = \exp(-\gamma ||x-y||^2)$.
The parameters $\lambda$ and $\gamma$ are called <i> hyperparameters </i> and are set via CV.
Specifically, at each LOOCV step, the hyperparameters ($\ell_2$-regularization parameter $\lambda$ and inverse gaussian width $\gamma$) are optimized via a grid search and a so-called 5-fold cross-validation on the training set. This means splitting the training set in 5 subsets, 1 subset is used for evaluating the performance (RMSE) and the other 4 for training. The procedure is repeated 5 times by changing the test subset and the overall perfrmance is the RMSE over all repetitions.
What can one observe by comparing the SISSO and KRR results?