update week41

This commit is contained in:
Morten Hjorth-Jensen
2021-10-13 16:00:24 +02:00
parent b45f04756e
commit 027fe32f90
8 changed files with 798 additions and 44 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 439 KiB

+114
View File
@@ -1067,6 +1067,88 @@ plt.show()
!ec
!split
===== Testing our code for the XOR, OR and AND gates =====
Last week we discussed three different types of gates, the so-called
XOR, the OR and the AND gates. Their inputs and outputs can be
summarized using the following tables, first for the OR gate with
inputs $x_1$ and $x_2$ and outputs $y$:
|---------------------|
| $x_1$ | $x_2$ | $y$ |
|---------------------|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
|---------------------|
!split
===== The AND and XOR Gates =====
The _AND_ gate is defined as
|---------------------|
| $x_1$ | $x_2$ | $y$ |
|---------------------|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
|---------------------|
And finally we have the _XOR_ gate
|---------------------|
| $x_1$ | $x_2$ | $y$ |
|---------------------|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
|---------------------|
!split
===== Representing the Data Sets =====
Our design matrix is defined by the input values $x_1$ and $x_2$. Since we have four possible outputs, our design matrix reads
!bt
\bm{X}=\begin{bmatrix} 0 & 0 \\
0 & 1 \\
1 & 0 \\
1 & 1 \end{bmatrix},
!et
while the vector of outputs is $\bm{y}^T=[0,1,1,0]$ for the XOR gate, $\bm{y}^T=[0,0,0,1]$ for the AND gate and $\bm{y}^T=[0,1,1,1]$ for the OR gate.
!split
===== Setting up the Neural Network =====
We define first our design matrix and the various input vectors.
!bc pycod
"""
Simple code that tests XOR, OR and AND gates with linear regression
"""
import numpy as np
# Design matrix
X = np.array([ [1, 0, 0], [1, 0, 1], [1, 1, 0],[1, 1, 1]],dtype=np.float64)
# The XOR gate
yXOR = np.array( [ 0, 1 ,1, 0])
# The OR gate
yOR = np.array( [ 0, 1 ,1, 1])
# The AND gate
yAND = np.array( [ 0, 0 ,0, 1])
#print(f"The values of theta for the AND gate:{ThetaAND}")
#print(f"The linear regression prediction for the AND gate:{X @ ThetaAND}")
!ec
!split
===== Building neural networks in Tensorflow and Keras =====
@@ -1749,7 +1831,37 @@ Some of these remarks are particular to DNNs, others are shared by all supervise
!split
===== Overarching Views, a personal note =====
The author of these lecture notes has an overarching take on many of
the machine learning algorithms we discuss here.
If we wish to understand complex systems, we need to find some
effective degrees of freedom or features that we find essential,
simply in order to reduce the complexity of the systems we are
studying. This leads, in one way or the other to dimensionality
reductions. Most of the Machine Learning methods we encounter deal
with this, whether we opt for a principal component analysis, or
clustering, or convolutional neural networks, or Ridge or Lasso
regression or random forest, yes, perhaps most machine learning
methods at large.
For neural networks and our previous discussion, we have seen that we
in essence end up with matrix-matrix and matrix-vector
multiplications. In all cases, our matrices are dense ones, and the
more data we deal with the larger the dimensionalities of the matrices
and vectors. How can we reduce such dimensionalities? One possible
answer is offered by _convolutional neural networks_ (CNN), as
discussed below. The figure here shows a typical situation of the
reduction of information in an image and is typical of what CNNs
actually end up doing.
!split
===== From a Spherical Cow to a real one =====
FIGURE: [figslides/ImageReduction.png, width=500 frac=0.6]
!split
@@ -2148,3 +2260,5 @@ o "Abstract art using convolutional neural networks":"https://deepdreamgenerator