Skip to content

Commit

Permalink
Fix all lecture notebooks and slides.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyue Ping Ong committed Oct 4, 2023
1 parent 313914f commit 941c9a4
Show file tree
Hide file tree
Showing 10 changed files with 536 additions and 5,190 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
- name: black
run: |
black --version
black --check --diff --color ${{ github.event.repository.name }}
black --check --diff --color lectures
600 changes: 300 additions & 300 deletions lectures/notebooks/3_gaussians.txt

Large diffs are not rendered by default.

Large diffs are not rendered by default.

146 changes: 60 additions & 86 deletions lectures/notebooks/Lecture 05 - Unsupervised learning.ipynb

Large diffs are not rendered by default.

3,930 changes: 111 additions & 3,819 deletions lectures/notebooks/Lecture 09 - Neural Networks.ipynb

Large diffs are not rendered by default.

925 changes: 0 additions & 925 deletions lectures/notebooks/metal_insulator_tree.dot

This file was deleted.

16 changes: 9 additions & 7 deletions lectures/slides_tex/example_element_features.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import numpy as np
import pandas as pd
from pymatgen.core import Composition
binaries = pd.read_csv('binary_band_gap.csv')
# We create a column holding the Composition object.

binaries = pd.read_csv("binary_band_gap.csv")
# We create a column holding the Composition object.
# Note the use of list comprehension in Python.
binaries['composition'] = [Composition(c) for c in binaries['Formula']]
electronegs = [[el.X for el in c] for c in binaries['composition']]
binaries["composition"] = [Composition(c) for c in binaries["Formula"]]
electronegs = [[el.X for el in c] for c in binaries["composition"]]
# Create the features mean and difference between electronegativities
binaries['mean_X'] = [np.mean(e) for e in electronegs]
binaries['diff_X'] = [max(e) - min(e) for e in electronegs]
binaries["mean_X"] = [np.mean(e) for e in electronegs]
binaries["diff_X"] = [max(e) - min(e) for e in electronegs]
# Label metals (band gap of 0. 1e-5 is used as numerical tolerance) as class 0
# Insulators are labelled as class 1.
binaries['class'] = [0 if eg < 1e-5 else 1 for eg in binaries['Eg (eV)']]}
binaries["class"] = [0 if eg < 1e-5 else 1 for eg in binaries["Eg (eV)"]]
33 changes: 16 additions & 17 deletions lectures/slides_tex/example_numpy.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
>>> import numpy as np
>>> x = np.array([[1, 2, 3],
[4, 7, 6],
[9, 4, 2]])
>>> y = np.array([1.5, 0.5, 3])
>>> x * x
array([[ 1, 4, 9],
[16, 49, 36],
[81, 16, 4]])
>>> np.dot(x, x)
array([[36, 28, 21],
[86, 81, 66],
[43, 54, 55]])
>>> np.linalg.inv(x)
array([[ 0.16949153, -0.13559322, 0.15254237],
[-0.77966102, 0.42372881, -0.10169492],
[ 0.79661017, -0.23728814, 0.01694915]])
import numpy as np

x = np.array([[1, 2, 3], [4, 7, 6], [9, 4, 2]])
y = np.array([1.5, 0.5, 3])
x * x
# array([[ 1, 4, 9],
# [16, 49, 36],
# [81, 16, 4]])
np.dot(x, x)
# array([[36, 28, 21],
# [86, 81, 66],
# [43, 54, 55]])
np.linalg.inv(x)
# array([[ 0.16949153, -0.13559322, 0.15254237],
# [-0.77966102, 0.42372881, -0.10169492],
# [ 0.79661017, -0.23728814, 0.01694915]])
16 changes: 9 additions & 7 deletions lectures/slides_tex/example_scipy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
>>> from scipy import stats # Statistics package
>>> dist = stats.norm(0, 1) # Gaussian distribution
>>> dist.cdf(1.96)
0.9750021048517795
>>> from scipy import constants # Physical constants
>>> constants.e
1.6021766208e-19
from scipy import stats # Statistics package

dist = stats.norm(0, 1) # Gaussian distribution
print(dist.cdf(1.96))
# Result: 0.9750021048517795
from scipy import constants # Physical constants

print(constants.e)
# Result: 1.6021766208e-19
8 changes: 5 additions & 3 deletions lectures/slides_tex/example_sklearn_discriminant_analysis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis,
QuadraticDiscriminantAnalysis
from sklearn.discriminant_analysis import (
LinearDiscriminantAnalysis,
QuadraticDiscriminantAnalysis,
)

lda = LinearDiscriminantAnalysis(solver="svd", store_covariance=True)
X = binaries[["mean_X", "diff_X"]]
y = binaries["class"]
Expand All @@ -8,4 +11,3 @@

qda = QuadraticDiscriminantAnalysis(store_covariance=True)
y_pred = qda.fit(X, y).predict(X)
\end{minted}

0 comments on commit 941c9a4

Please sign in to comment.