diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs000.html b/doc/pub/NeuralNet/html/._NeuralNet-bs000.html index 5b3bcff7c..da168971c 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs000.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs000.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -261,7 +274,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs001.html b/doc/pub/NeuralNet/html/._NeuralNet-bs001.html index e1cac0984..b5ad32372 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs001.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs001.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -246,7 +259,7 @@ a weight variable.
  • 10
  • 11
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs002.html b/doc/pub/NeuralNet/html/._NeuralNet-bs002.html index ffe1b4f1f..d8c58a5d8 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs002.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs002.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -296,7 +309,7 @@ humanities to life science and medicine.
  • 11
  • 12
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs003.html b/doc/pub/NeuralNet/html/._NeuralNet-bs003.html index af1f111d3..692933f0f 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs003.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs003.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -261,7 +274,7 @@ methods we discussed earlier.
  • 12
  • 13
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs004.html b/doc/pub/NeuralNet/html/._NeuralNet-bs004.html index d37a79f78..1bc44423b 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs004.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs004.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -253,7 +266,7 @@ to all nodes in the subsequent layer, making this a so-called
  • 13
  • 14
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs005.html b/doc/pub/NeuralNet/html/._NeuralNet-bs005.html index 2dba0326c..b914e2ccf 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs005.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs005.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -262,7 +275,7 @@ recognition.
  • 14
  • 15
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs006.html b/doc/pub/NeuralNet/html/._NeuralNet-bs006.html index 40b377319..7c29a685c 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs006.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs006.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -254,7 +267,7 @@ especially well-suited for handwriting and speech recognition.
  • 15
  • 16
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs007.html b/doc/pub/NeuralNet/html/._NeuralNet-bs007.html index 13c30f215..6526bfac9 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs007.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs007.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -255,7 +268,7 @@ type of NN due the unusual activation functions.
  • 16
  • 17
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs008.html b/doc/pub/NeuralNet/html/._NeuralNet-bs008.html index f879d2145..88085f60e 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs008.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs008.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -253,7 +266,7 @@ Such networks are often called multilayer perceptrons (MLPs).
  • 17
  • 18
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs009.html b/doc/pub/NeuralNet/html/._NeuralNet-bs009.html index f1d0fdb2b..83f1eb816 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs009.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs009.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -258,7 +271,7 @@ as to not restrict the range of output values.
  • 18
  • 19
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs010.html b/doc/pub/NeuralNet/html/._NeuralNet-bs010.html index bf352bfa8..a9d34b33e 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs010.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs010.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -259,7 +272,7 @@ of the outputs of all neurons in the previous layer.
  • 19
  • 20
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs011.html b/doc/pub/NeuralNet/html/._NeuralNet-bs011.html index ce610dcfc..5d2d2bc8c 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs011.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs011.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -288,7 +301,7 @@ is obtained.
  • 20
  • 21
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs012.html b/doc/pub/NeuralNet/html/._NeuralNet-bs012.html index 7a7cb1d49..e176eacef 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs012.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs012.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -270,7 +283,7 @@ $$
  • 21
  • 22
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs013.html b/doc/pub/NeuralNet/html/._NeuralNet-bs013.html index 95691f436..8fd346e29 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs013.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs013.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -261,7 +274,7 @@ variables are the input values \( x_n \).
  • 22
  • 23
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs014.html b/doc/pub/NeuralNet/html/._NeuralNet-bs014.html index a789902da..68330d629 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs014.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs014.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -270,7 +283,7 @@ flexibility of a neural network.
  • 23
  • 24
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs015.html b/doc/pub/NeuralNet/html/._NeuralNet-bs015.html index 7c3845e55..bb4744750 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs015.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs015.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -280,7 +293,7 @@ $$
  • 24
  • 25
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs016.html b/doc/pub/NeuralNet/html/._NeuralNet-bs016.html index ed32f39ef..256ec3d1a 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs016.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs016.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -264,7 +277,7 @@ used as input to the activation functions. For each operation
  • 25
  • 26
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs017.html b/doc/pub/NeuralNet/html/._NeuralNet-bs017.html index 6c84bd78a..a24bb7121 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs017.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs017.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -258,7 +271,7 @@ for a FFNN to fulfill the universal approximation theorem
  • 26
  • 27
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs018.html b/doc/pub/NeuralNet/html/._NeuralNet-bs018.html index 773b51dce..d948ee651 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs018.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs018.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -266,7 +279,7 @@ $$
  • 27
  • 28
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs019.html b/doc/pub/NeuralNet/html/._NeuralNet-bs019.html index 06d7a51d3..3136a9de4 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs019.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs019.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -328,7 +341,7 @@ plt.show()
  • 28
  • 29
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs020.html b/doc/pub/NeuralNet/html/._NeuralNet-bs020.html index 8c473fb7b..dd8a3e604 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs020.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs020.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -279,7 +292,7 @@ like logistic regression or linear regression and their modifications on the oth
  • 29
  • 30
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs021.html b/doc/pub/NeuralNet/html/._NeuralNet-bs021.html index 41b3ece1f..b9444ef1e 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs021.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs021.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -269,7 +282,7 @@ the potential of being universal approximators.
  • 30
  • 31
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs022.html b/doc/pub/NeuralNet/html/._NeuralNet-bs022.html index c4eadff0c..756587b22 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs022.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs022.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -275,7 +288,7 @@ classes.
  • 31
  • 32
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs023.html b/doc/pub/NeuralNet/html/._NeuralNet-bs023.html index f38b71774..a65de3cf6 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs023.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs023.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -280,7 +293,7 @@ $$
  • 32
  • 33
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs024.html b/doc/pub/NeuralNet/html/._NeuralNet-bs024.html index f450ff11f..f9cc99057 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs024.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs024.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -263,7 +276,7 @@ $$
  • 33
  • 34
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs025.html b/doc/pub/NeuralNet/html/._NeuralNet-bs025.html index 604adde41..5713df15a 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs025.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs025.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -266,7 +279,7 @@ $$
  • 34
  • 35
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs026.html b/doc/pub/NeuralNet/html/._NeuralNet-bs026.html index eaf25bb25..68448e75b 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs026.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs026.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -291,7 +304,7 @@ $$
  • 35
  • 36
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs027.html b/doc/pub/NeuralNet/html/._NeuralNet-bs027.html index eb9fe06d5..9677c8ef3 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs027.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs027.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -258,7 +271,7 @@ That is, the error \( \delta_j^L \) is exactly equal to the rate of change of th
  • 36
  • 37
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs028.html b/doc/pub/NeuralNet/html/._NeuralNet-bs028.html index d1dbc3f2d..7b1809730 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs028.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs028.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -301,7 +314,7 @@ one \( L-1 \) in terms of the errors in the final output layer.
  • 37
  • 38
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs029.html b/doc/pub/NeuralNet/html/._NeuralNet-bs029.html index 827f88dff..979c8097d 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs029.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs029.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -273,7 +286,7 @@ We are now ready to set up the algorithm for back propagation and learning the w
  • 38
  • 39
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs030.html b/doc/pub/NeuralNet/html/._NeuralNet-bs030.html index 892ec7e70..4c148d3de 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs030.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs030.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -317,7 +330,7 @@ Here it is convenient to use stochastic radient descent with mini-batches with a
  • 39
  • 40
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs031.html b/doc/pub/NeuralNet/html/._NeuralNet-bs031.html index aabed150b..8b3ef453f 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs031.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs031.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -279,7 +292,7 @@ of our network.
  • 40
  • 41
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs032.html b/doc/pub/NeuralNet/html/._NeuralNet-bs032.html index 4c9754428..44a65b22a 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs032.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs032.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -302,7 +315,7 @@ We leave it as an exercise in project 2 to derive these equations.
  • 41
  • 42
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs033.html b/doc/pub/NeuralNet/html/._NeuralNet-bs033.html index e6c0d33b3..c07325e1c 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs033.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs033.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -257,7 +270,7 @@ One can identify a set of key steps when using neural networks to solve supervis
  • 42
  • 43
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs034.html b/doc/pub/NeuralNet/html/._NeuralNet-bs034.html index aefa27168..3dfb98d10 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs034.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs034.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -336,7 +349,7 @@ plt.show()
  • 43
  • 44
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs035.html b/doc/pub/NeuralNet/html/._NeuralNet-bs035.html index 3c3a54967..548530f68 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs035.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs035.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -290,7 +303,7 @@ X_train, X_test, Y_train, Y_test = train_tes
  • 44
  • 45
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs036.html b/doc/pub/NeuralNet/html/._NeuralNet-bs036.html index 7fd158bdc..fb571d82e 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs036.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs036.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -287,7 +300,7 @@ which is inspired by probability theory (see logistic regression) and was most c
  • 45
  • 46
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs037.html b/doc/pub/NeuralNet/html/._NeuralNet-bs037.html index 0916e6c64..db12206fe 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs037.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs037.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -286,7 +299,7 @@ weights to the output layer.
  • 46
  • 47
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs038.html b/doc/pub/NeuralNet/html/._NeuralNet-bs038.html index 1b9625d0d..1609267e2 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs038.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs038.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -277,7 +290,7 @@ output_bias = np47
  • 48
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs039.html b/doc/pub/NeuralNet/html/._NeuralNet-bs039.html index b07644138..fcfeedb6a 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs039.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs039.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -268,7 +281,7 @@ $$ a_{j}^{o} = \frac{\exp{(z_j^{o})}}
  • 48
  • 49
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs040.html b/doc/pub/NeuralNet/html/._NeuralNet-bs040.html index 3ea3e5c6e..3ffd9ef4e 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs040.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs040.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -316,7 +329,7 @@ predictions = predict(X_train)
  • 49
  • 50
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs041.html b/doc/pub/NeuralNet/html/._NeuralNet-bs041.html index 8d44ccdd2..51252507d 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs041.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs041.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -282,6 +295,8 @@ A full derivation is given in the appendix at the end.
  • 49
  • 50
  • 51
  • +
  • ...
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs042.html b/doc/pub/NeuralNet/html/._NeuralNet-bs042.html index 5d80351c0..8dfba7c3c 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs042.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs042.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -276,6 +289,9 @@ This has two important benefits:
  • 49
  • 50
  • 51
  • +
  • 52
  • +
  • ...
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs043.html b/doc/pub/NeuralNet/html/._NeuralNet-bs043.html index f988a5716..bbd876bbb 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs043.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs043.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -271,6 +284,10 @@ calculate the gradient efficently.
  • 49
  • 50
  • 51
  • +
  • 52
  • +
  • 53
  • +
  • ...
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs044.html b/doc/pub/NeuralNet/html/._NeuralNet-bs044.html index 36af7d7a6..2c2944666 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs044.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs044.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -354,6 +367,11 @@ lmbd = 0.0149
  • 50
  • 51
  • +
  • 52
  • +
  • 53
  • +
  • 54
  • +
  • ...
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs045.html b/doc/pub/NeuralNet/html/._NeuralNet-bs045.html index 1b0ee8dc1..356ce9e6d 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs045.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs045.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -256,6 +269,12 @@ Andrew Ng goes through some of these considerations in this 49
  • 50
  • 51
  • +
  • 52
  • +
  • 53
  • +
  • 54
  • +
  • 55
  • +
  • ...
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs046.html b/doc/pub/NeuralNet/html/._NeuralNet-bs046.html index ad3981533..c77fbd648 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs046.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs046.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -348,6 +361,11 @@ being realizations of this object with different hyperparameters. An implementat
  • 49
  • 50
  • 51
  • +
  • 52
  • +
  • 53
  • +
  • 54
  • +
  • 55
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs047.html b/doc/pub/NeuralNet/html/._NeuralNet-bs047.html index 756672e41..74fd9059d 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs047.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs047.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -269,6 +282,11 @@ test_predict = dnn49
  • 50
  • 51
  • +
  • 52
  • +
  • 53
  • +
  • 54
  • +
  • 55
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs048.html b/doc/pub/NeuralNet/html/._NeuralNet-bs048.html index fe2a913f7..aa1b1245a 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs048.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs048.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -308,6 +321,11 @@ plt.show()
  • 49
  • 50
  • 51
  • +
  • 52
  • +
  • 53
  • +
  • 54
  • +
  • 55
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs049.html b/doc/pub/NeuralNet/html/._NeuralNet-bs049.html index 00c317dea..83a22456f 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs049.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs049.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -302,6 +315,11 @@ plt.show()
  • 49
  • 50
  • 51
  • +
  • 52
  • +
  • 53
  • +
  • 54
  • +
  • 55
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs050.html b/doc/pub/NeuralNet/html/._NeuralNet-bs050.html index 704140015..aaded931c 100644 --- a/doc/pub/NeuralNet/html/._NeuralNet-bs050.html +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs050.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -218,10 +231,19 @@ MathJax.Hub.Config({ -

    And then with Tensorflow

    +

    Building neural networks in Tensorflow and Keras

    +Now we want to build on the experience gained from our neural network implementation in NumPy and scikit-learn +and use it to construct a neural network in Tensorflow. Once we have constructed a neural network in NumPy +and Tensorflow, building one in Keras is really quite trivial, though the performance may suffer. +

    +In our previous example we used only one hidden layer, and in this we will use two. From this it should be quite +clear how to build one using an arbitrary number of hidden layers, using data structures such as Python lists or +NumPy arrays. + +

    diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs051.html b/doc/pub/NeuralNet/html/._NeuralNet-bs051.html new file mode 100644 index 000000000..41244e26b --- /dev/null +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs051.html @@ -0,0 +1,320 @@ + + + + + + + +Data Analysis and Machine Learning: Neural networks, from the simple perceptron to deep learning + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

     

     

     

    + + + + +

    Tensorflow

    + +

    +Tensorflow is an open source library machine learning library +developed by the Google Brain team for internal use. It was released +under the Apache 2.0 open source license in November 9, 2015. + +

    +Tensorflow is a computational framework that allows you to construct +machine learning models at different levels of abstraction, from +high-level, object-oriented APIs like Keras, down to the C++ kernels +that Tensorflow is built upon. The higher levels of abstraction are +simpler to use, but less flexible, and our choice of implementation +should reflect the problems we are trying to solve. + +

    +Tensorflow uses so-called graphs to represent your computation +in terms of the dependencies between individual operations, such that you first build a Tensorflow graph +to represent your model, and then create a Tensorflow session to run the graph. + +

    +In this guide we will analyze the same data as we did in our NumPy and +scikit-learn tutorial, gathered from the MNIST database of images. We +will give an introduction to the lower level Python Application +Program Interfaces (APIs), and see how we use them to build our graph. +Then we will build (effectively) the same graph in Keras, to see just +how simple solving a machine learning problem can be. + +

    +To install tensorflow on Unix/Linux systems, use pip as +

    + + +

    pip3 install tensorflow
    +
    +

    +and/or if you use anaconda, just write (or install from the graphical user interface) +

    + + +

    conda install tensorflow
    +
    +

    +

    + +

    + + +
    + + + + + + + +
    + +
    + + + + + + diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs052.html b/doc/pub/NeuralNet/html/._NeuralNet-bs052.html new file mode 100644 index 000000000..7e4e010f9 --- /dev/null +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs052.html @@ -0,0 +1,340 @@ + + + + + + + +Data Analysis and Machine Learning: Neural networks, from the simple perceptron to deep learning + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

     

     

     

    + + + + +

    Collect and pre-process data

    + +

    + + +

    # import necessary packages
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn import datasets
    +
    +
    +# ensure the same random numbers appear every time
    +np.random.seed(0)
    +
    +# display images in notebook
    +%matplotlib inline
    +plt.rcParams['figure.figsize'] = (12,12)
    +
    +
    +# download MNIST dataset
    +digits = datasets.load_digits()
    +
    +# define inputs and labels
    +inputs = digits.images
    +labels = digits.target
    +
    +print("inputs = (n_inputs, pixel_width, pixel_height) = " + str(inputs.shape))
    +print("labels = (n_inputs) = " + str(labels.shape))
    +
    +
    +# flatten the image
    +# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64
    +n_inputs = len(inputs)
    +inputs = inputs.reshape(n_inputs, -1)
    +print("X = (n_inputs, n_features) = " + str(inputs.shape))
    +
    +
    +# choose some random images to display
    +indices = np.arange(n_inputs)
    +random_indices = np.random.choice(indices, size=5)
    +
    +for i, image in enumerate(digits.images[random_indices]):
    +    plt.subplot(1, 5, i+1)
    +    plt.axis('off')
    +    plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    +    plt.title("Label: %d" % digits.target[random_indices[i]])
    +plt.show()
    +
    +

    + + +

    from keras.utils import to_categorical
    +from sklearn.model_selection import train_test_split
    +
    +# one-hot representation of labels
    +labels = to_categorical(labels)
    +
    +# split into train and test data
    +train_size = 0.8
    +test_size = 1 - train_size
    +X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
    +                                                    test_size=test_size)
    +
    +

    +

    + +

    + + +
    + + + + + + + +
    + +
    + + + + + + diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs053.html b/doc/pub/NeuralNet/html/._NeuralNet-bs053.html new file mode 100644 index 000000000..8a497167e --- /dev/null +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs053.html @@ -0,0 +1,418 @@ + + + + + + + +Data Analysis and Machine Learning: Neural networks, from the simple perceptron to deep learning + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

     

     

     

    + + + + +

    Using TensorFlow backend

    + +
      +
    1. Define model and architecture
    2. +
    3. Choose cost function and optimizer
    4. +
    + +

    + + +

    import tensorflow as tf
    +
    +class NeuralNetworkTensorflow:
    +    def __init__(
    +        self,
    +        X_train,
    +        Y_train,
    +        X_test,
    +        Y_test,
    +        n_neurons_layer1=100,
    +        n_neurons_layer2=50,
    +        n_categories=2,
    +        epochs=10,
    +        batch_size=100,
    +        eta=0.1,
    +        lmbd=0.0,
    +    ):
    +        
    +        # keep track of number of steps
    +        self.global_step = tf.Variable(0, dtype=tf.int32, trainable=False, name='global_step')
    +        
    +        self.X_train = X_train
    +        self.Y_train = Y_train
    +        self.X_test = X_test
    +        self.Y_test = Y_test
    +        
    +        self.n_inputs = X_train.shape[0]
    +        self.n_features = X_train.shape[1]
    +        self.n_neurons_layer1 = n_neurons_layer1
    +        self.n_neurons_layer2 = n_neurons_layer2
    +        self.n_categories = n_categories
    +        
    +        self.epochs = epochs
    +        self.batch_size = batch_size
    +        self.iterations = self.n_inputs // self.batch_size
    +        self.eta = eta
    +        self.lmbd = lmbd
    +        
    +        # build network piece by piece
    +        # name scopes (with) are used to enforce creation of new variables
    +        # https://www.tensorflow.org/guide/variables
    +        self.create_placeholders()
    +        self.create_DNN()
    +        self.create_loss()
    +        self.create_optimiser()
    +        self.create_accuracy()
    +    
    +    def create_placeholders(self):
    +        # placeholders are fine here, but "Datasets" are the preferred method
    +        # of streaming data into a model
    +        with tf.name_scope('data'):
    +            self.X = tf.placeholder(tf.float32, shape=(None, self.n_features), name='X_data')
    +            self.Y = tf.placeholder(tf.float32, shape=(None, self.n_categories), name='Y_data')
    +    
    +    def create_DNN(self):
    +        with tf.name_scope('DNN'):
    +            # the weights are stored to calculate regularization loss later
    +            
    +            # Fully connected layer 1
    +            self.W_fc1 = self.weight_variable([self.n_features, self.n_neurons_layer1], name='fc1', dtype=tf.float32)
    +            b_fc1 = self.bias_variable([self.n_neurons_layer1], name='fc1', dtype=tf.float32)
    +            a_fc1 = tf.nn.sigmoid(tf.matmul(self.X, self.W_fc1) + b_fc1)
    +            
    +            # Fully connected layer 2
    +            self.W_fc2 = self.weight_variable([self.n_neurons_layer1, self.n_neurons_layer2], name='fc2', dtype=tf.float32)
    +            b_fc2 = self.bias_variable([self.n_neurons_layer2], name='fc2', dtype=tf.float32)
    +            a_fc2 = tf.nn.sigmoid(tf.matmul(a_fc1, self.W_fc2) + b_fc2)
    +            
    +            # Output layer
    +            self.W_out = self.weight_variable([self.n_neurons_layer2, self.n_categories], name='out', dtype=tf.float32)
    +            b_out = self.bias_variable([self.n_categories], name='out', dtype=tf.float32)
    +            self.z_out = tf.matmul(a_fc2, self.W_out) + b_out
    +    
    +    def create_loss(self):
    +        with tf.name_scope('loss'):
    +            softmax_loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=self.Y, logits=self.z_out))
    +            
    +            regularizer_loss_fc1 = tf.nn.l2_loss(self.W_fc1)
    +            regularizer_loss_fc2 = tf.nn.l2_loss(self.W_fc2)
    +            regularizer_loss_out = tf.nn.l2_loss(self.W_out)
    +            regularizer_loss = self.lmbd*(regularizer_loss_fc1 + regularizer_loss_fc2 + regularizer_loss_out)
    +            
    +            self.loss = softmax_loss + regularizer_loss
    +
    +    def create_accuracy(self):
    +        with tf.name_scope('accuracy'):
    +            probabilities = tf.nn.softmax(self.z_out)
    +            predictions = tf.argmax(probabilities, axis=1)
    +            labels = tf.argmax(self.Y, axis=1)
    +            
    +            correct_predictions = tf.equal(predictions, labels)
    +            correct_predictions = tf.cast(correct_predictions, tf.float32)
    +            self.accuracy = tf.reduce_mean(correct_predictions)
    +    
    +    def create_optimiser(self):
    +        with tf.name_scope('optimizer'):
    +            self.optimizer = tf.train.GradientDescentOptimizer(learning_rate=self.eta).minimize(self.loss, global_step=self.global_step)
    +            
    +    def weight_variable(self, shape, name='', dtype=tf.float32):
    +        initial = tf.truncated_normal(shape, stddev=0.1)
    +        return tf.Variable(initial, name=name, dtype=dtype)
    +    
    +    def bias_variable(self, shape, name='', dtype=tf.float32):
    +        initial = tf.constant(0.1, shape=shape)
    +        return tf.Variable(initial, name=name, dtype=dtype)
    +    
    +    def fit(self):
    +        data_indices = np.arange(self.n_inputs)
    +
    +        with tf.Session() as sess:
    +            sess.run(tf.global_variables_initializer())
    +            for i in range(self.epochs):
    +                for j in range(self.iterations):
    +                    chosen_datapoints = np.random.choice(data_indices, size=self.batch_size, replace=False)
    +                    batch_X, batch_Y = self.X_train[chosen_datapoints], self.Y_train[chosen_datapoints]
    +            
    +                    sess.run([DNN.loss, DNN.optimizer],
    +                        feed_dict={DNN.X: batch_X,
    +                                   DNN.Y: batch_Y})
    +                    accuracy = sess.run(DNN.accuracy,
    +                        feed_dict={DNN.X: batch_X,
    +                                   DNN.Y: batch_Y})
    +                    step = sess.run(DNN.global_step)
    +    
    +            self.train_loss, self.train_accuracy = sess.run([DNN.loss, DNN.accuracy],
    +                feed_dict={DNN.X: self.X_train,
    +                           DNN.Y: self.Y_train})
    +        
    +            self.test_loss, self.test_accuracy = sess.run([DNN.loss, DNN.accuracy],
    +                feed_dict={DNN.X: self.X_test,
    +                           DNN.Y: self.Y_test})
    +
    +

    +

    + +

    + + +
    + + + + + + + +
    + +
    + + + + + + diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs054.html b/doc/pub/NeuralNet/html/._NeuralNet-bs054.html new file mode 100644 index 000000000..7922ab7ba --- /dev/null +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs054.html @@ -0,0 +1,352 @@ + + + + + + + +Data Analysis and Machine Learning: Neural networks, from the simple perceptron to deep learning + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

     

     

     

    + + + + +

    Optimizing and using gradient descent

    + +

    + + +

    epochs = 100
    +batch_size = 100
    +n_neurons_layer1 = 100
    +n_neurons_layer2 = 50
    +n_categories = 10
    +
    +eta_vals = np.logspace(-5, 1, 7)
    +lmbd_vals = np.logspace(-5, 1, 7)
    +
    +

    + + +

    DNN_tf = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    +        
    +for i, eta in enumerate(eta_vals):
    +    for j, lmbd in enumerate(lmbd_vals):
    +        DNN = NeuralNetworkTensorflow(X_train, Y_train, X_test, Y_test,
    +                                      n_neurons_layer1, n_neurons_layer2, n_categories,
    +                                      epochs=epochs, batch_size=batch_size, eta=eta, lmbd=lmbd)
    +        DNN.fit()
    +        
    +        DNN_tf[i][j] = DNN
    +        
    +        print("Learning rate = ", eta)
    +        print("Lambda = ", lmbd)
    +        print("Test accuracy: %.3f" % DNN.test_accuracy)
    +        print()
    +        
    +
    +

    + + +

    # optional
    +# visual representation of grid search
    +# uses seaborn heatmap, could probably do this in matplotlib
    +import seaborn as sns
    +
    +sns.set()
    +
    +train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +
    +for i in range(len(eta_vals)):
    +    for j in range(len(lmbd_vals)):
    +        DNN = DNN_tf[i][j]
    +
    +        train_accuracy[i][j] = DNN.train_accuracy
    +        test_accuracy[i][j] = DNN.test_accuracy
    +
    +        
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Training Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Test Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +

    + + +

    # optional
    +# we can use log files to visualize our graph in Tensorboard
    +writer = tf.summary.FileWriter('logs/')
    +writer.add_graph(tf.get_default_graph())
    +
    +

    +

    + +

    + + +
    + + + + + + + +
    + +
    + + + + + + diff --git a/doc/pub/NeuralNet/html/._NeuralNet-bs055.html b/doc/pub/NeuralNet/html/._NeuralNet-bs055.html new file mode 100644 index 000000000..b08124b41 --- /dev/null +++ b/doc/pub/NeuralNet/html/._NeuralNet-bs055.html @@ -0,0 +1,370 @@ + + + + + + + +Data Analysis and Machine Learning: Neural networks, from the simple perceptron to deep learning + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

     

     

     

    + + + + +

    Using Keras

    + +

    +Keras is a high level neural network +that supports Tensorflow, CTNK and Theano as backends. +If you have Tensorflow installed Keras is available through the tf.keras module. +If you have Anaconda installed you may run the following command +

    + + +

    conda install keras
    +
    +

    +Alternatively, if you have Tensorflow or one of the other supported backends install you may use the pip package manager: + +

    + + +

    pip3 install keras
    +
    +

    +or look up the instructions here. + +

    + + +

    from keras.models import Sequential
    +from keras.layers import Dense
    +from keras.regularizers import l2
    +from keras.optimizers import SGD
    +
    +def create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories, eta, lmbd):
    +    model = Sequential()
    +    model.add(Dense(n_neurons_layer1, activation='sigmoid', kernel_regularizer=l2(lmbd)))
    +    model.add(Dense(n_neurons_layer2, activation='sigmoid', kernel_regularizer=l2(lmbd)))
    +    model.add(Dense(n_categories, activation='softmax'))
    +    
    +    sgd = SGD(lr=eta)
    +    model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
    +    
    +    return model
    +
    +

    + + +

    DNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    +        
    +for i, eta in enumerate(eta_vals):
    +    for j, lmbd in enumerate(lmbd_vals):
    +        DNN = create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories,
    +                                         eta=eta, lmbd=lmbd)
    +        DNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)
    +        scores = DNN.evaluate(X_test, Y_test)
    +        
    +        DNN_keras[i][j] = DNN
    +        
    +        print("Learning rate = ", eta)
    +        print("Lambda = ", lmbd)
    +        print("Test accuracy: %.3f" % scores[1])
    +        print()
    +
    +

    + + +

    # optional
    +# visual representation of grid search
    +# uses seaborn heatmap, could probably do this in matplotlib
    +import seaborn as sns
    +
    +sns.set()
    +
    +train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +
    +for i in range(len(eta_vals)):
    +    for j in range(len(lmbd_vals)):
    +        DNN = DNN_keras[i][j]
    +
    +        train_accuracy[i][j] = DNN.evaluate(X_train, Y_train)[1]
    +        test_accuracy[i][j] = DNN.evaluate(X_test, Y_test)[1]
    +
    +        
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Training Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Test Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +

    + +

    + +

    + + +
    + + + + + + + +
    + +
    + + + + + + diff --git a/doc/pub/NeuralNet/html/NeuralNet-bs.html b/doc/pub/NeuralNet/html/NeuralNet-bs.html index 5b3bcff7c..da168971c 100644 --- a/doc/pub/NeuralNet/html/NeuralNet-bs.html +++ b/doc/pub/NeuralNet/html/NeuralNet-bs.html @@ -115,7 +115,15 @@ Automatically generated HTML file from DocOnce source None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -202,7 +210,12 @@ MathJax.Hub.Config({
  • Evaluate model performance on test data
  • Adjust hyperparameters (if necessary, network architecture
  • scikit-learn implementation
  • -
  • And then with Tensorflow
  • +
  • Building neural networks in Tensorflow and Keras
  • +
  • Tensorflow
  • +
  • Collect and pre-process data
  • +
  • Using TensorFlow backend
  • +
  • Optimizing and using gradient descent
  • +
  • Using Keras
  • @@ -261,7 +274,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 51
  • +
  • 56
  • »
  • diff --git a/doc/pub/NeuralNet/html/NeuralNet-reveal.html b/doc/pub/NeuralNet/html/NeuralNet-reveal.html index b7d63f645..a689e890e 100644 --- a/doc/pub/NeuralNet/html/NeuralNet-reveal.html +++ b/doc/pub/NeuralNet/html/NeuralNet-reveal.html @@ -2334,7 +2334,456 @@ plt.show()
    -

    And then with Tensorflow

    +

    Building neural networks in Tensorflow and Keras

    + +

    +Now we want to build on the experience gained from our neural network implementation in NumPy and scikit-learn +and use it to construct a neural network in Tensorflow. Once we have constructed a neural network in NumPy +and Tensorflow, building one in Keras is really quite trivial, though the performance may suffer. + +

    +In our previous example we used only one hidden layer, and in this we will use two. From this it should be quite +clear how to build one using an arbitrary number of hidden layers, using data structures such as Python lists or +NumPy arrays. +

    + + +
    +

    Tensorflow

    + +

    +Tensorflow is an open source library machine learning library +developed by the Google Brain team for internal use. It was released +under the Apache 2.0 open source license in November 9, 2015. + +

    +Tensorflow is a computational framework that allows you to construct +machine learning models at different levels of abstraction, from +high-level, object-oriented APIs like Keras, down to the C++ kernels +that Tensorflow is built upon. The higher levels of abstraction are +simpler to use, but less flexible, and our choice of implementation +should reflect the problems we are trying to solve. + +

    +Tensorflow uses so-called graphs to represent your computation +in terms of the dependencies between individual operations, such that you first build a Tensorflow graph +to represent your model, and then create a Tensorflow session to run the graph. + +

    +In this guide we will analyze the same data as we did in our NumPy and +scikit-learn tutorial, gathered from the MNIST database of images. We +will give an introduction to the lower level Python Application +Program Interfaces (APIs), and see how we use them to build our graph. +Then we will build (effectively) the same graph in Keras, to see just +how simple solving a machine learning problem can be. + +

    +To install tensorflow on Unix/Linux systems, use pip as +

    + + +

    pip3 install tensorflow
    +
    +

    +and/or if you use anaconda, just write (or install from the graphical user interface) +

    + + +

    conda install tensorflow
    +
    +
    + + +
    +

    Collect and pre-process data

    + +

    + + +

    # import necessary packages
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn import datasets
    +
    +
    +# ensure the same random numbers appear every time
    +np.random.seed(0)
    +
    +# display images in notebook
    +%matplotlib inline
    +plt.rcParams['figure.figsize'] = (12,12)
    +
    +
    +# download MNIST dataset
    +digits = datasets.load_digits()
    +
    +# define inputs and labels
    +inputs = digits.images
    +labels = digits.target
    +
    +print("inputs = (n_inputs, pixel_width, pixel_height) = " + str(inputs.shape))
    +print("labels = (n_inputs) = " + str(labels.shape))
    +
    +
    +# flatten the image
    +# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64
    +n_inputs = len(inputs)
    +inputs = inputs.reshape(n_inputs, -1)
    +print("X = (n_inputs, n_features) = " + str(inputs.shape))
    +
    +
    +# choose some random images to display
    +indices = np.arange(n_inputs)
    +random_indices = np.random.choice(indices, size=5)
    +
    +for i, image in enumerate(digits.images[random_indices]):
    +    plt.subplot(1, 5, i+1)
    +    plt.axis('off')
    +    plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    +    plt.title("Label: %d" % digits.target[random_indices[i]])
    +plt.show()
    +
    +

    + + +

    from keras.utils import to_categorical
    +from sklearn.model_selection import train_test_split
    +
    +# one-hot representation of labels
    +labels = to_categorical(labels)
    +
    +# split into train and test data
    +train_size = 0.8
    +test_size = 1 - train_size
    +X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
    +                                                    test_size=test_size)
    +
    +
    + + +
    +

    Using TensorFlow backend

    + +
      +

    1. Define model and architecture
    2. +

    3. Choose cost function and optimizer
    4. +
    +

    + + +

    import tensorflow as tf
    +
    +class NeuralNetworkTensorflow:
    +    def __init__(
    +        self,
    +        X_train,
    +        Y_train,
    +        X_test,
    +        Y_test,
    +        n_neurons_layer1=100,
    +        n_neurons_layer2=50,
    +        n_categories=2,
    +        epochs=10,
    +        batch_size=100,
    +        eta=0.1,
    +        lmbd=0.0,
    +    ):
    +        
    +        # keep track of number of steps
    +        self.global_step = tf.Variable(0, dtype=tf.int32, trainable=False, name='global_step')
    +        
    +        self.X_train = X_train
    +        self.Y_train = Y_train
    +        self.X_test = X_test
    +        self.Y_test = Y_test
    +        
    +        self.n_inputs = X_train.shape[0]
    +        self.n_features = X_train.shape[1]
    +        self.n_neurons_layer1 = n_neurons_layer1
    +        self.n_neurons_layer2 = n_neurons_layer2
    +        self.n_categories = n_categories
    +        
    +        self.epochs = epochs
    +        self.batch_size = batch_size
    +        self.iterations = self.n_inputs // self.batch_size
    +        self.eta = eta
    +        self.lmbd = lmbd
    +        
    +        # build network piece by piece
    +        # name scopes (with) are used to enforce creation of new variables
    +        # https://www.tensorflow.org/guide/variables
    +        self.create_placeholders()
    +        self.create_DNN()
    +        self.create_loss()
    +        self.create_optimiser()
    +        self.create_accuracy()
    +    
    +    def create_placeholders(self):
    +        # placeholders are fine here, but "Datasets" are the preferred method
    +        # of streaming data into a model
    +        with tf.name_scope('data'):
    +            self.X = tf.placeholder(tf.float32, shape=(None, self.n_features), name='X_data')
    +            self.Y = tf.placeholder(tf.float32, shape=(None, self.n_categories), name='Y_data')
    +    
    +    def create_DNN(self):
    +        with tf.name_scope('DNN'):
    +            # the weights are stored to calculate regularization loss later
    +            
    +            # Fully connected layer 1
    +            self.W_fc1 = self.weight_variable([self.n_features, self.n_neurons_layer1], name='fc1', dtype=tf.float32)
    +            b_fc1 = self.bias_variable([self.n_neurons_layer1], name='fc1', dtype=tf.float32)
    +            a_fc1 = tf.nn.sigmoid(tf.matmul(self.X, self.W_fc1) + b_fc1)
    +            
    +            # Fully connected layer 2
    +            self.W_fc2 = self.weight_variable([self.n_neurons_layer1, self.n_neurons_layer2], name='fc2', dtype=tf.float32)
    +            b_fc2 = self.bias_variable([self.n_neurons_layer2], name='fc2', dtype=tf.float32)
    +            a_fc2 = tf.nn.sigmoid(tf.matmul(a_fc1, self.W_fc2) + b_fc2)
    +            
    +            # Output layer
    +            self.W_out = self.weight_variable([self.n_neurons_layer2, self.n_categories], name='out', dtype=tf.float32)
    +            b_out = self.bias_variable([self.n_categories], name='out', dtype=tf.float32)
    +            self.z_out = tf.matmul(a_fc2, self.W_out) + b_out
    +    
    +    def create_loss(self):
    +        with tf.name_scope('loss'):
    +            softmax_loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=self.Y, logits=self.z_out))
    +            
    +            regularizer_loss_fc1 = tf.nn.l2_loss(self.W_fc1)
    +            regularizer_loss_fc2 = tf.nn.l2_loss(self.W_fc2)
    +            regularizer_loss_out = tf.nn.l2_loss(self.W_out)
    +            regularizer_loss = self.lmbd*(regularizer_loss_fc1 + regularizer_loss_fc2 + regularizer_loss_out)
    +            
    +            self.loss = softmax_loss + regularizer_loss
    +
    +    def create_accuracy(self):
    +        with tf.name_scope('accuracy'):
    +            probabilities = tf.nn.softmax(self.z_out)
    +            predictions = tf.argmax(probabilities, axis=1)
    +            labels = tf.argmax(self.Y, axis=1)
    +            
    +            correct_predictions = tf.equal(predictions, labels)
    +            correct_predictions = tf.cast(correct_predictions, tf.float32)
    +            self.accuracy = tf.reduce_mean(correct_predictions)
    +    
    +    def create_optimiser(self):
    +        with tf.name_scope('optimizer'):
    +            self.optimizer = tf.train.GradientDescentOptimizer(learning_rate=self.eta).minimize(self.loss, global_step=self.global_step)
    +            
    +    def weight_variable(self, shape, name='', dtype=tf.float32):
    +        initial = tf.truncated_normal(shape, stddev=0.1)
    +        return tf.Variable(initial, name=name, dtype=dtype)
    +    
    +    def bias_variable(self, shape, name='', dtype=tf.float32):
    +        initial = tf.constant(0.1, shape=shape)
    +        return tf.Variable(initial, name=name, dtype=dtype)
    +    
    +    def fit(self):
    +        data_indices = np.arange(self.n_inputs)
    +
    +        with tf.Session() as sess:
    +            sess.run(tf.global_variables_initializer())
    +            for i in range(self.epochs):
    +                for j in range(self.iterations):
    +                    chosen_datapoints = np.random.choice(data_indices, size=self.batch_size, replace=False)
    +                    batch_X, batch_Y = self.X_train[chosen_datapoints], self.Y_train[chosen_datapoints]
    +            
    +                    sess.run([DNN.loss, DNN.optimizer],
    +                        feed_dict={DNN.X: batch_X,
    +                                   DNN.Y: batch_Y})
    +                    accuracy = sess.run(DNN.accuracy,
    +                        feed_dict={DNN.X: batch_X,
    +                                   DNN.Y: batch_Y})
    +                    step = sess.run(DNN.global_step)
    +    
    +            self.train_loss, self.train_accuracy = sess.run([DNN.loss, DNN.accuracy],
    +                feed_dict={DNN.X: self.X_train,
    +                           DNN.Y: self.Y_train})
    +        
    +            self.test_loss, self.test_accuracy = sess.run([DNN.loss, DNN.accuracy],
    +                feed_dict={DNN.X: self.X_test,
    +                           DNN.Y: self.Y_test})
    +
    +
    + + +
    +

    Optimizing and using gradient descent

    + +

    + + +

    epochs = 100
    +batch_size = 100
    +n_neurons_layer1 = 100
    +n_neurons_layer2 = 50
    +n_categories = 10
    +
    +eta_vals = np.logspace(-5, 1, 7)
    +lmbd_vals = np.logspace(-5, 1, 7)
    +
    +

    + + +

    DNN_tf = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    +        
    +for i, eta in enumerate(eta_vals):
    +    for j, lmbd in enumerate(lmbd_vals):
    +        DNN = NeuralNetworkTensorflow(X_train, Y_train, X_test, Y_test,
    +                                      n_neurons_layer1, n_neurons_layer2, n_categories,
    +                                      epochs=epochs, batch_size=batch_size, eta=eta, lmbd=lmbd)
    +        DNN.fit()
    +        
    +        DNN_tf[i][j] = DNN
    +        
    +        print("Learning rate = ", eta)
    +        print("Lambda = ", lmbd)
    +        print("Test accuracy: %.3f" % DNN.test_accuracy)
    +        print()
    +        
    +
    +

    + + +

    # optional
    +# visual representation of grid search
    +# uses seaborn heatmap, could probably do this in matplotlib
    +import seaborn as sns
    +
    +sns.set()
    +
    +train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +
    +for i in range(len(eta_vals)):
    +    for j in range(len(lmbd_vals)):
    +        DNN = DNN_tf[i][j]
    +
    +        train_accuracy[i][j] = DNN.train_accuracy
    +        test_accuracy[i][j] = DNN.test_accuracy
    +
    +        
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Training Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Test Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +

    + + +

    # optional
    +# we can use log files to visualize our graph in Tensorboard
    +writer = tf.summary.FileWriter('logs/')
    +writer.add_graph(tf.get_default_graph())
    +
    +
    + + +
    +

    Using Keras

    + +

    +Keras is a high level neural network +that supports Tensorflow, CTNK and Theano as backends. +If you have Tensorflow installed Keras is available through the tf.keras module. +If you have Anaconda installed you may run the following command +

    + + +

    conda install keras
    +
    +

    +Alternatively, if you have Tensorflow or one of the other supported backends install you may use the pip package manager: + +

    + + +

    pip3 install keras
    +
    +

    +or look up the instructions here. + +

    + + +

    from keras.models import Sequential
    +from keras.layers import Dense
    +from keras.regularizers import l2
    +from keras.optimizers import SGD
    +
    +def create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories, eta, lmbd):
    +    model = Sequential()
    +    model.add(Dense(n_neurons_layer1, activation='sigmoid', kernel_regularizer=l2(lmbd)))
    +    model.add(Dense(n_neurons_layer2, activation='sigmoid', kernel_regularizer=l2(lmbd)))
    +    model.add(Dense(n_categories, activation='softmax'))
    +    
    +    sgd = SGD(lr=eta)
    +    model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
    +    
    +    return model
    +
    +

    + + +

    DNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    +        
    +for i, eta in enumerate(eta_vals):
    +    for j, lmbd in enumerate(lmbd_vals):
    +        DNN = create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories,
    +                                         eta=eta, lmbd=lmbd)
    +        DNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)
    +        scores = DNN.evaluate(X_test, Y_test)
    +        
    +        DNN_keras[i][j] = DNN
    +        
    +        print("Learning rate = ", eta)
    +        print("Lambda = ", lmbd)
    +        print("Test accuracy: %.3f" % scores[1])
    +        print()
    +
    +

    + + +

    # optional
    +# visual representation of grid search
    +# uses seaborn heatmap, could probably do this in matplotlib
    +import seaborn as sns
    +
    +sns.set()
    +
    +train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +
    +for i in range(len(eta_vals)):
    +    for j in range(len(lmbd_vals)):
    +        DNN = DNN_keras[i][j]
    +
    +        train_accuracy[i][j] = DNN.evaluate(X_train, Y_train)[1]
    +        test_accuracy[i][j] = DNN.evaluate(X_test, Y_test)[1]
    +
    +        
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Training Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Test Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    diff --git a/doc/pub/NeuralNet/html/NeuralNet-solarized.html b/doc/pub/NeuralNet/html/NeuralNet-solarized.html index a7d903ae5..34459708f 100644 --- a/doc/pub/NeuralNet/html/NeuralNet-solarized.html +++ b/doc/pub/NeuralNet/html/NeuralNet-solarized.html @@ -135,7 +135,15 @@ div { text-align: justify; text-justify: inter-word; } None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -2175,8 +2183,453 @@ plt.show()











    -

    And then with Tensorflow

    +

    Building neural networks in Tensorflow and Keras

    +

    +Now we want to build on the experience gained from our neural network implementation in NumPy and scikit-learn +and use it to construct a neural network in Tensorflow. Once we have constructed a neural network in NumPy +and Tensorflow, building one in Keras is really quite trivial, though the performance may suffer. + +

    +In our previous example we used only one hidden layer, and in this we will use two. From this it should be quite +clear how to build one using an arbitrary number of hidden layers, using data structures such as Python lists or +NumPy arrays. + +

    +









    + +

    Tensorflow

    + +

    +Tensorflow is an open source library machine learning library +developed by the Google Brain team for internal use. It was released +under the Apache 2.0 open source license in November 9, 2015. + +

    +Tensorflow is a computational framework that allows you to construct +machine learning models at different levels of abstraction, from +high-level, object-oriented APIs like Keras, down to the C++ kernels +that Tensorflow is built upon. The higher levels of abstraction are +simpler to use, but less flexible, and our choice of implementation +should reflect the problems we are trying to solve. + +

    +Tensorflow uses so-called graphs to represent your computation +in terms of the dependencies between individual operations, such that you first build a Tensorflow graph +to represent your model, and then create a Tensorflow session to run the graph. + +

    +In this guide we will analyze the same data as we did in our NumPy and +scikit-learn tutorial, gathered from the MNIST database of images. We +will give an introduction to the lower level Python Application +Program Interfaces (APIs), and see how we use them to build our graph. +Then we will build (effectively) the same graph in Keras, to see just +how simple solving a machine learning problem can be. + +

    +To install tensorflow on Unix/Linux systems, use pip as +

    + + +

    pip3 install tensorflow
    +
    +

    +and/or if you use anaconda, just write (or install from the graphical user interface) +

    + + +

    conda install tensorflow
    +
    +

    +









    + +

    Collect and pre-process data

    + +

    + + +

    # import necessary packages
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn import datasets
    +
    +
    +# ensure the same random numbers appear every time
    +np.random.seed(0)
    +
    +# display images in notebook
    +%matplotlib inline
    +plt.rcParams['figure.figsize'] = (12,12)
    +
    +
    +# download MNIST dataset
    +digits = datasets.load_digits()
    +
    +# define inputs and labels
    +inputs = digits.images
    +labels = digits.target
    +
    +print("inputs = (n_inputs, pixel_width, pixel_height) = " + str(inputs.shape))
    +print("labels = (n_inputs) = " + str(labels.shape))
    +
    +
    +# flatten the image
    +# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64
    +n_inputs = len(inputs)
    +inputs = inputs.reshape(n_inputs, -1)
    +print("X = (n_inputs, n_features) = " + str(inputs.shape))
    +
    +
    +# choose some random images to display
    +indices = np.arange(n_inputs)
    +random_indices = np.random.choice(indices, size=5)
    +
    +for i, image in enumerate(digits.images[random_indices]):
    +    plt.subplot(1, 5, i+1)
    +    plt.axis('off')
    +    plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    +    plt.title("Label: %d" % digits.target[random_indices[i]])
    +plt.show()
    +
    +

    + + +

    from keras.utils import to_categorical
    +from sklearn.model_selection import train_test_split
    +
    +# one-hot representation of labels
    +labels = to_categorical(labels)
    +
    +# split into train and test data
    +train_size = 0.8
    +test_size = 1 - train_size
    +X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
    +                                                    test_size=test_size)
    +
    +

    +









    + +

    Using TensorFlow backend

    + +
      +
    1. Define model and architecture
    2. +
    3. Choose cost function and optimizer
    4. +
    + +

    + + +

    import tensorflow as tf
    +
    +class NeuralNetworkTensorflow:
    +    def __init__(
    +        self,
    +        X_train,
    +        Y_train,
    +        X_test,
    +        Y_test,
    +        n_neurons_layer1=100,
    +        n_neurons_layer2=50,
    +        n_categories=2,
    +        epochs=10,
    +        batch_size=100,
    +        eta=0.1,
    +        lmbd=0.0,
    +    ):
    +        
    +        # keep track of number of steps
    +        self.global_step = tf.Variable(0, dtype=tf.int32, trainable=False, name='global_step')
    +        
    +        self.X_train = X_train
    +        self.Y_train = Y_train
    +        self.X_test = X_test
    +        self.Y_test = Y_test
    +        
    +        self.n_inputs = X_train.shape[0]
    +        self.n_features = X_train.shape[1]
    +        self.n_neurons_layer1 = n_neurons_layer1
    +        self.n_neurons_layer2 = n_neurons_layer2
    +        self.n_categories = n_categories
    +        
    +        self.epochs = epochs
    +        self.batch_size = batch_size
    +        self.iterations = self.n_inputs // self.batch_size
    +        self.eta = eta
    +        self.lmbd = lmbd
    +        
    +        # build network piece by piece
    +        # name scopes (with) are used to enforce creation of new variables
    +        # https://www.tensorflow.org/guide/variables
    +        self.create_placeholders()
    +        self.create_DNN()
    +        self.create_loss()
    +        self.create_optimiser()
    +        self.create_accuracy()
    +    
    +    def create_placeholders(self):
    +        # placeholders are fine here, but "Datasets" are the preferred method
    +        # of streaming data into a model
    +        with tf.name_scope('data'):
    +            self.X = tf.placeholder(tf.float32, shape=(None, self.n_features), name='X_data')
    +            self.Y = tf.placeholder(tf.float32, shape=(None, self.n_categories), name='Y_data')
    +    
    +    def create_DNN(self):
    +        with tf.name_scope('DNN'):
    +            # the weights are stored to calculate regularization loss later
    +            
    +            # Fully connected layer 1
    +            self.W_fc1 = self.weight_variable([self.n_features, self.n_neurons_layer1], name='fc1', dtype=tf.float32)
    +            b_fc1 = self.bias_variable([self.n_neurons_layer1], name='fc1', dtype=tf.float32)
    +            a_fc1 = tf.nn.sigmoid(tf.matmul(self.X, self.W_fc1) + b_fc1)
    +            
    +            # Fully connected layer 2
    +            self.W_fc2 = self.weight_variable([self.n_neurons_layer1, self.n_neurons_layer2], name='fc2', dtype=tf.float32)
    +            b_fc2 = self.bias_variable([self.n_neurons_layer2], name='fc2', dtype=tf.float32)
    +            a_fc2 = tf.nn.sigmoid(tf.matmul(a_fc1, self.W_fc2) + b_fc2)
    +            
    +            # Output layer
    +            self.W_out = self.weight_variable([self.n_neurons_layer2, self.n_categories], name='out', dtype=tf.float32)
    +            b_out = self.bias_variable([self.n_categories], name='out', dtype=tf.float32)
    +            self.z_out = tf.matmul(a_fc2, self.W_out) + b_out
    +    
    +    def create_loss(self):
    +        with tf.name_scope('loss'):
    +            softmax_loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=self.Y, logits=self.z_out))
    +            
    +            regularizer_loss_fc1 = tf.nn.l2_loss(self.W_fc1)
    +            regularizer_loss_fc2 = tf.nn.l2_loss(self.W_fc2)
    +            regularizer_loss_out = tf.nn.l2_loss(self.W_out)
    +            regularizer_loss = self.lmbd*(regularizer_loss_fc1 + regularizer_loss_fc2 + regularizer_loss_out)
    +            
    +            self.loss = softmax_loss + regularizer_loss
    +
    +    def create_accuracy(self):
    +        with tf.name_scope('accuracy'):
    +            probabilities = tf.nn.softmax(self.z_out)
    +            predictions = tf.argmax(probabilities, axis=1)
    +            labels = tf.argmax(self.Y, axis=1)
    +            
    +            correct_predictions = tf.equal(predictions, labels)
    +            correct_predictions = tf.cast(correct_predictions, tf.float32)
    +            self.accuracy = tf.reduce_mean(correct_predictions)
    +    
    +    def create_optimiser(self):
    +        with tf.name_scope('optimizer'):
    +            self.optimizer = tf.train.GradientDescentOptimizer(learning_rate=self.eta).minimize(self.loss, global_step=self.global_step)
    +            
    +    def weight_variable(self, shape, name='', dtype=tf.float32):
    +        initial = tf.truncated_normal(shape, stddev=0.1)
    +        return tf.Variable(initial, name=name, dtype=dtype)
    +    
    +    def bias_variable(self, shape, name='', dtype=tf.float32):
    +        initial = tf.constant(0.1, shape=shape)
    +        return tf.Variable(initial, name=name, dtype=dtype)
    +    
    +    def fit(self):
    +        data_indices = np.arange(self.n_inputs)
    +
    +        with tf.Session() as sess:
    +            sess.run(tf.global_variables_initializer())
    +            for i in range(self.epochs):
    +                for j in range(self.iterations):
    +                    chosen_datapoints = np.random.choice(data_indices, size=self.batch_size, replace=False)
    +                    batch_X, batch_Y = self.X_train[chosen_datapoints], self.Y_train[chosen_datapoints]
    +            
    +                    sess.run([DNN.loss, DNN.optimizer],
    +                        feed_dict={DNN.X: batch_X,
    +                                   DNN.Y: batch_Y})
    +                    accuracy = sess.run(DNN.accuracy,
    +                        feed_dict={DNN.X: batch_X,
    +                                   DNN.Y: batch_Y})
    +                    step = sess.run(DNN.global_step)
    +    
    +            self.train_loss, self.train_accuracy = sess.run([DNN.loss, DNN.accuracy],
    +                feed_dict={DNN.X: self.X_train,
    +                           DNN.Y: self.Y_train})
    +        
    +            self.test_loss, self.test_accuracy = sess.run([DNN.loss, DNN.accuracy],
    +                feed_dict={DNN.X: self.X_test,
    +                           DNN.Y: self.Y_test})
    +
    +

    +









    + +

    Optimizing and using gradient descent

    + +

    + + +

    epochs = 100
    +batch_size = 100
    +n_neurons_layer1 = 100
    +n_neurons_layer2 = 50
    +n_categories = 10
    +
    +eta_vals = np.logspace(-5, 1, 7)
    +lmbd_vals = np.logspace(-5, 1, 7)
    +
    +

    + + +

    DNN_tf = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    +        
    +for i, eta in enumerate(eta_vals):
    +    for j, lmbd in enumerate(lmbd_vals):
    +        DNN = NeuralNetworkTensorflow(X_train, Y_train, X_test, Y_test,
    +                                      n_neurons_layer1, n_neurons_layer2, n_categories,
    +                                      epochs=epochs, batch_size=batch_size, eta=eta, lmbd=lmbd)
    +        DNN.fit()
    +        
    +        DNN_tf[i][j] = DNN
    +        
    +        print("Learning rate = ", eta)
    +        print("Lambda = ", lmbd)
    +        print("Test accuracy: %.3f" % DNN.test_accuracy)
    +        print()
    +        
    +
    +

    + + +

    # optional
    +# visual representation of grid search
    +# uses seaborn heatmap, could probably do this in matplotlib
    +import seaborn as sns
    +
    +sns.set()
    +
    +train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +
    +for i in range(len(eta_vals)):
    +    for j in range(len(lmbd_vals)):
    +        DNN = DNN_tf[i][j]
    +
    +        train_accuracy[i][j] = DNN.train_accuracy
    +        test_accuracy[i][j] = DNN.test_accuracy
    +
    +        
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Training Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Test Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +

    + + +

    # optional
    +# we can use log files to visualize our graph in Tensorboard
    +writer = tf.summary.FileWriter('logs/')
    +writer.add_graph(tf.get_default_graph())
    +
    +

    +









    + +

    Using Keras

    + +

    +Keras is a high level neural network +that supports Tensorflow, CTNK and Theano as backends. +If you have Tensorflow installed Keras is available through the tf.keras module. +If you have Anaconda installed you may run the following command +

    + + +

    conda install keras
    +
    +

    +Alternatively, if you have Tensorflow or one of the other supported backends install you may use the pip package manager: + +

    + + +

    pip3 install keras
    +
    +

    +or look up the instructions here. + +

    + + +

    from keras.models import Sequential
    +from keras.layers import Dense
    +from keras.regularizers import l2
    +from keras.optimizers import SGD
    +
    +def create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories, eta, lmbd):
    +    model = Sequential()
    +    model.add(Dense(n_neurons_layer1, activation='sigmoid', kernel_regularizer=l2(lmbd)))
    +    model.add(Dense(n_neurons_layer2, activation='sigmoid', kernel_regularizer=l2(lmbd)))
    +    model.add(Dense(n_categories, activation='softmax'))
    +    
    +    sgd = SGD(lr=eta)
    +    model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
    +    
    +    return model
    +
    +

    + + +

    DNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    +        
    +for i, eta in enumerate(eta_vals):
    +    for j, lmbd in enumerate(lmbd_vals):
    +        DNN = create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories,
    +                                         eta=eta, lmbd=lmbd)
    +        DNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)
    +        scores = DNN.evaluate(X_test, Y_test)
    +        
    +        DNN_keras[i][j] = DNN
    +        
    +        print("Learning rate = ", eta)
    +        print("Lambda = ", lmbd)
    +        print("Test accuracy: %.3f" % scores[1])
    +        print()
    +
    +

    + + +

    # optional
    +# visual representation of grid search
    +# uses seaborn heatmap, could probably do this in matplotlib
    +import seaborn as sns
    +
    +sns.set()
    +
    +train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +
    +for i in range(len(eta_vals)):
    +    for j in range(len(lmbd_vals)):
    +        DNN = DNN_keras[i][j]
    +
    +        train_accuracy[i][j] = DNN.evaluate(X_train, Y_train)[1]
    +        test_accuracy[i][j] = DNN.evaluate(X_test, Y_test)[1]
    +
    +        
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Training Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Test Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +

    diff --git a/doc/pub/NeuralNet/html/NeuralNet.html b/doc/pub/NeuralNet/html/NeuralNet.html index 6356f4f14..cfb13c6ce 100644 --- a/doc/pub/NeuralNet/html/NeuralNet.html +++ b/doc/pub/NeuralNet/html/NeuralNet.html @@ -140,7 +140,15 @@ div { text-align: justify; text-justify: inter-word; } None, '___sec47'), ('scikit-learn implementation', 2, None, '___sec48'), - ('And then with Tensorflow', 2, None, '___sec49')]} + ('Building neural networks in Tensorflow and Keras', + 2, + None, + '___sec49'), + ('Tensorflow', 2, None, '___sec50'), + ('Collect and pre-process data', 2, None, '___sec51'), + ('Using TensorFlow backend', 2, None, '___sec52'), + ('Optimizing and using gradient descent', 2, None, '___sec53'), + ('Using Keras', 2, None, '___sec54')]} end of tocinfo --> @@ -2180,8 +2188,453 @@ plt.show()











    -

    And then with Tensorflow

    +

    Building neural networks in Tensorflow and Keras

    +

    +Now we want to build on the experience gained from our neural network implementation in NumPy and scikit-learn +and use it to construct a neural network in Tensorflow. Once we have constructed a neural network in NumPy +and Tensorflow, building one in Keras is really quite trivial, though the performance may suffer. + +

    +In our previous example we used only one hidden layer, and in this we will use two. From this it should be quite +clear how to build one using an arbitrary number of hidden layers, using data structures such as Python lists or +NumPy arrays. + +

    +









    + +

    Tensorflow

    + +

    +Tensorflow is an open source library machine learning library +developed by the Google Brain team for internal use. It was released +under the Apache 2.0 open source license in November 9, 2015. + +

    +Tensorflow is a computational framework that allows you to construct +machine learning models at different levels of abstraction, from +high-level, object-oriented APIs like Keras, down to the C++ kernels +that Tensorflow is built upon. The higher levels of abstraction are +simpler to use, but less flexible, and our choice of implementation +should reflect the problems we are trying to solve. + +

    +Tensorflow uses so-called graphs to represent your computation +in terms of the dependencies between individual operations, such that you first build a Tensorflow graph +to represent your model, and then create a Tensorflow session to run the graph. + +

    +In this guide we will analyze the same data as we did in our NumPy and +scikit-learn tutorial, gathered from the MNIST database of images. We +will give an introduction to the lower level Python Application +Program Interfaces (APIs), and see how we use them to build our graph. +Then we will build (effectively) the same graph in Keras, to see just +how simple solving a machine learning problem can be. + +

    +To install tensorflow on Unix/Linux systems, use pip as +

    + + +

    pip3 install tensorflow
    +
    +

    +and/or if you use anaconda, just write (or install from the graphical user interface) +

    + + +

    conda install tensorflow
    +
    +

    +









    + +

    Collect and pre-process data

    + +

    + + +

    # import necessary packages
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn import datasets
    +
    +
    +# ensure the same random numbers appear every time
    +np.random.seed(0)
    +
    +# display images in notebook
    +%matplotlib inline
    +plt.rcParams['figure.figsize'] = (12,12)
    +
    +
    +# download MNIST dataset
    +digits = datasets.load_digits()
    +
    +# define inputs and labels
    +inputs = digits.images
    +labels = digits.target
    +
    +print("inputs = (n_inputs, pixel_width, pixel_height) = " + str(inputs.shape))
    +print("labels = (n_inputs) = " + str(labels.shape))
    +
    +
    +# flatten the image
    +# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64
    +n_inputs = len(inputs)
    +inputs = inputs.reshape(n_inputs, -1)
    +print("X = (n_inputs, n_features) = " + str(inputs.shape))
    +
    +
    +# choose some random images to display
    +indices = np.arange(n_inputs)
    +random_indices = np.random.choice(indices, size=5)
    +
    +for i, image in enumerate(digits.images[random_indices]):
    +    plt.subplot(1, 5, i+1)
    +    plt.axis('off')
    +    plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    +    plt.title("Label: %d" % digits.target[random_indices[i]])
    +plt.show()
    +
    +

    + + +

    from keras.utils import to_categorical
    +from sklearn.model_selection import train_test_split
    +
    +# one-hot representation of labels
    +labels = to_categorical(labels)
    +
    +# split into train and test data
    +train_size = 0.8
    +test_size = 1 - train_size
    +X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
    +                                                    test_size=test_size)
    +
    +

    +









    + +

    Using TensorFlow backend

    + +
      +
    1. Define model and architecture
    2. +
    3. Choose cost function and optimizer
    4. +
    + +

    + + +

    import tensorflow as tf
    +
    +class NeuralNetworkTensorflow:
    +    def __init__(
    +        self,
    +        X_train,
    +        Y_train,
    +        X_test,
    +        Y_test,
    +        n_neurons_layer1=100,
    +        n_neurons_layer2=50,
    +        n_categories=2,
    +        epochs=10,
    +        batch_size=100,
    +        eta=0.1,
    +        lmbd=0.0,
    +    ):
    +        
    +        # keep track of number of steps
    +        self.global_step = tf.Variable(0, dtype=tf.int32, trainable=False, name='global_step')
    +        
    +        self.X_train = X_train
    +        self.Y_train = Y_train
    +        self.X_test = X_test
    +        self.Y_test = Y_test
    +        
    +        self.n_inputs = X_train.shape[0]
    +        self.n_features = X_train.shape[1]
    +        self.n_neurons_layer1 = n_neurons_layer1
    +        self.n_neurons_layer2 = n_neurons_layer2
    +        self.n_categories = n_categories
    +        
    +        self.epochs = epochs
    +        self.batch_size = batch_size
    +        self.iterations = self.n_inputs // self.batch_size
    +        self.eta = eta
    +        self.lmbd = lmbd
    +        
    +        # build network piece by piece
    +        # name scopes (with) are used to enforce creation of new variables
    +        # https://www.tensorflow.org/guide/variables
    +        self.create_placeholders()
    +        self.create_DNN()
    +        self.create_loss()
    +        self.create_optimiser()
    +        self.create_accuracy()
    +    
    +    def create_placeholders(self):
    +        # placeholders are fine here, but "Datasets" are the preferred method
    +        # of streaming data into a model
    +        with tf.name_scope('data'):
    +            self.X = tf.placeholder(tf.float32, shape=(None, self.n_features), name='X_data')
    +            self.Y = tf.placeholder(tf.float32, shape=(None, self.n_categories), name='Y_data')
    +    
    +    def create_DNN(self):
    +        with tf.name_scope('DNN'):
    +            # the weights are stored to calculate regularization loss later
    +            
    +            # Fully connected layer 1
    +            self.W_fc1 = self.weight_variable([self.n_features, self.n_neurons_layer1], name='fc1', dtype=tf.float32)
    +            b_fc1 = self.bias_variable([self.n_neurons_layer1], name='fc1', dtype=tf.float32)
    +            a_fc1 = tf.nn.sigmoid(tf.matmul(self.X, self.W_fc1) + b_fc1)
    +            
    +            # Fully connected layer 2
    +            self.W_fc2 = self.weight_variable([self.n_neurons_layer1, self.n_neurons_layer2], name='fc2', dtype=tf.float32)
    +            b_fc2 = self.bias_variable([self.n_neurons_layer2], name='fc2', dtype=tf.float32)
    +            a_fc2 = tf.nn.sigmoid(tf.matmul(a_fc1, self.W_fc2) + b_fc2)
    +            
    +            # Output layer
    +            self.W_out = self.weight_variable([self.n_neurons_layer2, self.n_categories], name='out', dtype=tf.float32)
    +            b_out = self.bias_variable([self.n_categories], name='out', dtype=tf.float32)
    +            self.z_out = tf.matmul(a_fc2, self.W_out) + b_out
    +    
    +    def create_loss(self):
    +        with tf.name_scope('loss'):
    +            softmax_loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=self.Y, logits=self.z_out))
    +            
    +            regularizer_loss_fc1 = tf.nn.l2_loss(self.W_fc1)
    +            regularizer_loss_fc2 = tf.nn.l2_loss(self.W_fc2)
    +            regularizer_loss_out = tf.nn.l2_loss(self.W_out)
    +            regularizer_loss = self.lmbd*(regularizer_loss_fc1 + regularizer_loss_fc2 + regularizer_loss_out)
    +            
    +            self.loss = softmax_loss + regularizer_loss
    +
    +    def create_accuracy(self):
    +        with tf.name_scope('accuracy'):
    +            probabilities = tf.nn.softmax(self.z_out)
    +            predictions = tf.argmax(probabilities, axis=1)
    +            labels = tf.argmax(self.Y, axis=1)
    +            
    +            correct_predictions = tf.equal(predictions, labels)
    +            correct_predictions = tf.cast(correct_predictions, tf.float32)
    +            self.accuracy = tf.reduce_mean(correct_predictions)
    +    
    +    def create_optimiser(self):
    +        with tf.name_scope('optimizer'):
    +            self.optimizer = tf.train.GradientDescentOptimizer(learning_rate=self.eta).minimize(self.loss, global_step=self.global_step)
    +            
    +    def weight_variable(self, shape, name='', dtype=tf.float32):
    +        initial = tf.truncated_normal(shape, stddev=0.1)
    +        return tf.Variable(initial, name=name, dtype=dtype)
    +    
    +    def bias_variable(self, shape, name='', dtype=tf.float32):
    +        initial = tf.constant(0.1, shape=shape)
    +        return tf.Variable(initial, name=name, dtype=dtype)
    +    
    +    def fit(self):
    +        data_indices = np.arange(self.n_inputs)
    +
    +        with tf.Session() as sess:
    +            sess.run(tf.global_variables_initializer())
    +            for i in range(self.epochs):
    +                for j in range(self.iterations):
    +                    chosen_datapoints = np.random.choice(data_indices, size=self.batch_size, replace=False)
    +                    batch_X, batch_Y = self.X_train[chosen_datapoints], self.Y_train[chosen_datapoints]
    +            
    +                    sess.run([DNN.loss, DNN.optimizer],
    +                        feed_dict={DNN.X: batch_X,
    +                                   DNN.Y: batch_Y})
    +                    accuracy = sess.run(DNN.accuracy,
    +                        feed_dict={DNN.X: batch_X,
    +                                   DNN.Y: batch_Y})
    +                    step = sess.run(DNN.global_step)
    +    
    +            self.train_loss, self.train_accuracy = sess.run([DNN.loss, DNN.accuracy],
    +                feed_dict={DNN.X: self.X_train,
    +                           DNN.Y: self.Y_train})
    +        
    +            self.test_loss, self.test_accuracy = sess.run([DNN.loss, DNN.accuracy],
    +                feed_dict={DNN.X: self.X_test,
    +                           DNN.Y: self.Y_test})
    +
    +

    +









    + +

    Optimizing and using gradient descent

    + +

    + + +

    epochs = 100
    +batch_size = 100
    +n_neurons_layer1 = 100
    +n_neurons_layer2 = 50
    +n_categories = 10
    +
    +eta_vals = np.logspace(-5, 1, 7)
    +lmbd_vals = np.logspace(-5, 1, 7)
    +
    +

    + + +

    DNN_tf = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    +        
    +for i, eta in enumerate(eta_vals):
    +    for j, lmbd in enumerate(lmbd_vals):
    +        DNN = NeuralNetworkTensorflow(X_train, Y_train, X_test, Y_test,
    +                                      n_neurons_layer1, n_neurons_layer2, n_categories,
    +                                      epochs=epochs, batch_size=batch_size, eta=eta, lmbd=lmbd)
    +        DNN.fit()
    +        
    +        DNN_tf[i][j] = DNN
    +        
    +        print("Learning rate = ", eta)
    +        print("Lambda = ", lmbd)
    +        print("Test accuracy: %.3f" % DNN.test_accuracy)
    +        print()
    +        
    +
    +

    + + +

    # optional
    +# visual representation of grid search
    +# uses seaborn heatmap, could probably do this in matplotlib
    +import seaborn as sns
    +
    +sns.set()
    +
    +train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +
    +for i in range(len(eta_vals)):
    +    for j in range(len(lmbd_vals)):
    +        DNN = DNN_tf[i][j]
    +
    +        train_accuracy[i][j] = DNN.train_accuracy
    +        test_accuracy[i][j] = DNN.test_accuracy
    +
    +        
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Training Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Test Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +

    + + +

    # optional
    +# we can use log files to visualize our graph in Tensorboard
    +writer = tf.summary.FileWriter('logs/')
    +writer.add_graph(tf.get_default_graph())
    +
    +

    +









    + +

    Using Keras

    + +

    +Keras is a high level neural network +that supports Tensorflow, CTNK and Theano as backends. +If you have Tensorflow installed Keras is available through the tf.keras module. +If you have Anaconda installed you may run the following command +

    + + +

    conda install keras
    +
    +

    +Alternatively, if you have Tensorflow or one of the other supported backends install you may use the pip package manager: + +

    + + +

    pip3 install keras
    +
    +

    +or look up the instructions here. + +

    + + +

    from keras.models import Sequential
    +from keras.layers import Dense
    +from keras.regularizers import l2
    +from keras.optimizers import SGD
    +
    +def create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories, eta, lmbd):
    +    model = Sequential()
    +    model.add(Dense(n_neurons_layer1, activation='sigmoid', kernel_regularizer=l2(lmbd)))
    +    model.add(Dense(n_neurons_layer2, activation='sigmoid', kernel_regularizer=l2(lmbd)))
    +    model.add(Dense(n_categories, activation='softmax'))
    +    
    +    sgd = SGD(lr=eta)
    +    model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
    +    
    +    return model
    +
    +

    + + +

    DNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    +        
    +for i, eta in enumerate(eta_vals):
    +    for j, lmbd in enumerate(lmbd_vals):
    +        DNN = create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories,
    +                                         eta=eta, lmbd=lmbd)
    +        DNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)
    +        scores = DNN.evaluate(X_test, Y_test)
    +        
    +        DNN_keras[i][j] = DNN
    +        
    +        print("Learning rate = ", eta)
    +        print("Lambda = ", lmbd)
    +        print("Test accuracy: %.3f" % scores[1])
    +        print()
    +
    +

    + + +

    # optional
    +# visual representation of grid search
    +# uses seaborn heatmap, could probably do this in matplotlib
    +import seaborn as sns
    +
    +sns.set()
    +
    +train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    +
    +for i in range(len(eta_vals)):
    +    for j in range(len(lmbd_vals)):
    +        DNN = DNN_keras[i][j]
    +
    +        train_accuracy[i][j] = DNN.evaluate(X_train, Y_train)[1]
    +        test_accuracy[i][j] = DNN.evaluate(X_test, Y_test)[1]
    +
    +        
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Training Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +
    +fig, ax = plt.subplots(figsize = (10, 10))
    +sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    +ax.set_title("Test Accuracy")
    +ax.set_ylabel("$\eta$")
    +ax.set_xlabel("$\lambda$")
    +plt.show()
    +

    diff --git a/doc/pub/NeuralNet/ipynb/NeuralNet.ipynb b/doc/pub/NeuralNet/ipynb/NeuralNet.ipynb index c56f955ed..fd6d5ee07 100644 --- a/doc/pub/NeuralNet/ipynb/NeuralNet.ipynb +++ b/doc/pub/NeuralNet/ipynb/NeuralNet.ipynb @@ -2447,7 +2447,546 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## And then with Tensorflow" + "## Building neural networks in Tensorflow and Keras\n", + "\n", + "Now we want to build on the experience gained from our neural network implementation in NumPy and scikit-learn\n", + "and use it to construct a neural network in Tensorflow. Once we have constructed a neural network in NumPy\n", + "and Tensorflow, building one in Keras is really quite trivial, though the performance may suffer. \n", + "\n", + "In our previous example we used only one hidden layer, and in this we will use two. From this it should be quite\n", + "clear how to build one using an arbitrary number of hidden layers, using data structures such as Python lists or\n", + "NumPy arrays.\n", + "\n", + "## Tensorflow\n", + "\n", + "Tensorflow is an open source library machine learning library\n", + "developed by the Google Brain team for internal use. It was released\n", + "under the Apache 2.0 open source license in November 9, 2015.\n", + "\n", + "Tensorflow is a computational framework that allows you to construct\n", + "machine learning models at different levels of abstraction, from\n", + "high-level, object-oriented APIs like Keras, down to the C++ kernels\n", + "that Tensorflow is built upon. The higher levels of abstraction are\n", + "simpler to use, but less flexible, and our choice of implementation\n", + "should reflect the problems we are trying to solve.\n", + "\n", + "[Tensorflow uses](https://www.tensorflow.org/guide/graphs) so-called graphs to represent your computation\n", + "in terms of the dependencies between individual operations, such that you first build a Tensorflow *graph*\n", + "to represent your model, and then create a Tensorflow *session* to run the graph.\n", + "\n", + "In this guide we will analyze the same data as we did in our NumPy and\n", + "scikit-learn tutorial, gathered from the MNIST database of images. We\n", + "will give an introduction to the lower level Python Application\n", + "Program Interfaces (APIs), and see how we use them to build our graph.\n", + "Then we will build (effectively) the same graph in Keras, to see just\n", + "how simple solving a machine learning problem can be.\n", + "\n", + "To install tensorflow on Unix/Linux systems, use pip as" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pip3 install tensorflow" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and/or if you use **anaconda**, just write (or install from the graphical user interface)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "conda install tensorflow" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Collect and pre-process data" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# import necessary packages\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from sklearn import datasets\n", + "\n", + "\n", + "# ensure the same random numbers appear every time\n", + "np.random.seed(0)\n", + "\n", + "# display images in notebook\n", + "%matplotlib inline\n", + "plt.rcParams['figure.figsize'] = (12,12)\n", + "\n", + "\n", + "# download MNIST dataset\n", + "digits = datasets.load_digits()\n", + "\n", + "# define inputs and labels\n", + "inputs = digits.images\n", + "labels = digits.target\n", + "\n", + "print(\"inputs = (n_inputs, pixel_width, pixel_height) = \" + str(inputs.shape))\n", + "print(\"labels = (n_inputs) = \" + str(labels.shape))\n", + "\n", + "\n", + "# flatten the image\n", + "# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64\n", + "n_inputs = len(inputs)\n", + "inputs = inputs.reshape(n_inputs, -1)\n", + "print(\"X = (n_inputs, n_features) = \" + str(inputs.shape))\n", + "\n", + "\n", + "# choose some random images to display\n", + "indices = np.arange(n_inputs)\n", + "random_indices = np.random.choice(indices, size=5)\n", + "\n", + "for i, image in enumerate(digits.images[random_indices]):\n", + " plt.subplot(1, 5, i+1)\n", + " plt.axis('off')\n", + " plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n", + " plt.title(\"Label: %d\" % digits.target[random_indices[i]])\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "from keras.utils import to_categorical\n", + "from sklearn.model_selection import train_test_split\n", + "\n", + "# one-hot representation of labels\n", + "labels = to_categorical(labels)\n", + "\n", + "# split into train and test data\n", + "train_size = 0.8\n", + "test_size = 1 - train_size\n", + "X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,\n", + " test_size=test_size)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using TensorFlow backend\n", + "\n", + "1. Define model and architecture\n", + "\n", + "2. Choose cost function and optimizer" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import tensorflow as tf\n", + "\n", + "class NeuralNetworkTensorflow:\n", + " def __init__(\n", + " self,\n", + " X_train,\n", + " Y_train,\n", + " X_test,\n", + " Y_test,\n", + " n_neurons_layer1=100,\n", + " n_neurons_layer2=50,\n", + " n_categories=2,\n", + " epochs=10,\n", + " batch_size=100,\n", + " eta=0.1,\n", + " lmbd=0.0,\n", + " ):\n", + " \n", + " # keep track of number of steps\n", + " self.global_step = tf.Variable(0, dtype=tf.int32, trainable=False, name='global_step')\n", + " \n", + " self.X_train = X_train\n", + " self.Y_train = Y_train\n", + " self.X_test = X_test\n", + " self.Y_test = Y_test\n", + " \n", + " self.n_inputs = X_train.shape[0]\n", + " self.n_features = X_train.shape[1]\n", + " self.n_neurons_layer1 = n_neurons_layer1\n", + " self.n_neurons_layer2 = n_neurons_layer2\n", + " self.n_categories = n_categories\n", + " \n", + " self.epochs = epochs\n", + " self.batch_size = batch_size\n", + " self.iterations = self.n_inputs // self.batch_size\n", + " self.eta = eta\n", + " self.lmbd = lmbd\n", + " \n", + " # build network piece by piece\n", + " # name scopes (with) are used to enforce creation of new variables\n", + " # https://www.tensorflow.org/guide/variables\n", + " self.create_placeholders()\n", + " self.create_DNN()\n", + " self.create_loss()\n", + " self.create_optimiser()\n", + " self.create_accuracy()\n", + " \n", + " def create_placeholders(self):\n", + " # placeholders are fine here, but \"Datasets\" are the preferred method\n", + " # of streaming data into a model\n", + " with tf.name_scope('data'):\n", + " self.X = tf.placeholder(tf.float32, shape=(None, self.n_features), name='X_data')\n", + " self.Y = tf.placeholder(tf.float32, shape=(None, self.n_categories), name='Y_data')\n", + " \n", + " def create_DNN(self):\n", + " with tf.name_scope('DNN'):\n", + " # the weights are stored to calculate regularization loss later\n", + " \n", + " # Fully connected layer 1\n", + " self.W_fc1 = self.weight_variable([self.n_features, self.n_neurons_layer1], name='fc1', dtype=tf.float32)\n", + " b_fc1 = self.bias_variable([self.n_neurons_layer1], name='fc1', dtype=tf.float32)\n", + " a_fc1 = tf.nn.sigmoid(tf.matmul(self.X, self.W_fc1) + b_fc1)\n", + " \n", + " # Fully connected layer 2\n", + " self.W_fc2 = self.weight_variable([self.n_neurons_layer1, self.n_neurons_layer2], name='fc2', dtype=tf.float32)\n", + " b_fc2 = self.bias_variable([self.n_neurons_layer2], name='fc2', dtype=tf.float32)\n", + " a_fc2 = tf.nn.sigmoid(tf.matmul(a_fc1, self.W_fc2) + b_fc2)\n", + " \n", + " # Output layer\n", + " self.W_out = self.weight_variable([self.n_neurons_layer2, self.n_categories], name='out', dtype=tf.float32)\n", + " b_out = self.bias_variable([self.n_categories], name='out', dtype=tf.float32)\n", + " self.z_out = tf.matmul(a_fc2, self.W_out) + b_out\n", + " \n", + " def create_loss(self):\n", + " with tf.name_scope('loss'):\n", + " softmax_loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=self.Y, logits=self.z_out))\n", + " \n", + " regularizer_loss_fc1 = tf.nn.l2_loss(self.W_fc1)\n", + " regularizer_loss_fc2 = tf.nn.l2_loss(self.W_fc2)\n", + " regularizer_loss_out = tf.nn.l2_loss(self.W_out)\n", + " regularizer_loss = self.lmbd*(regularizer_loss_fc1 + regularizer_loss_fc2 + regularizer_loss_out)\n", + " \n", + " self.loss = softmax_loss + regularizer_loss\n", + "\n", + " def create_accuracy(self):\n", + " with tf.name_scope('accuracy'):\n", + " probabilities = tf.nn.softmax(self.z_out)\n", + " predictions = tf.argmax(probabilities, axis=1)\n", + " labels = tf.argmax(self.Y, axis=1)\n", + " \n", + " correct_predictions = tf.equal(predictions, labels)\n", + " correct_predictions = tf.cast(correct_predictions, tf.float32)\n", + " self.accuracy = tf.reduce_mean(correct_predictions)\n", + " \n", + " def create_optimiser(self):\n", + " with tf.name_scope('optimizer'):\n", + " self.optimizer = tf.train.GradientDescentOptimizer(learning_rate=self.eta).minimize(self.loss, global_step=self.global_step)\n", + " \n", + " def weight_variable(self, shape, name='', dtype=tf.float32):\n", + " initial = tf.truncated_normal(shape, stddev=0.1)\n", + " return tf.Variable(initial, name=name, dtype=dtype)\n", + " \n", + " def bias_variable(self, shape, name='', dtype=tf.float32):\n", + " initial = tf.constant(0.1, shape=shape)\n", + " return tf.Variable(initial, name=name, dtype=dtype)\n", + " \n", + " def fit(self):\n", + " data_indices = np.arange(self.n_inputs)\n", + "\n", + " with tf.Session() as sess:\n", + " sess.run(tf.global_variables_initializer())\n", + " for i in range(self.epochs):\n", + " for j in range(self.iterations):\n", + " chosen_datapoints = np.random.choice(data_indices, size=self.batch_size, replace=False)\n", + " batch_X, batch_Y = self.X_train[chosen_datapoints], self.Y_train[chosen_datapoints]\n", + " \n", + " sess.run([DNN.loss, DNN.optimizer],\n", + " feed_dict={DNN.X: batch_X,\n", + " DNN.Y: batch_Y})\n", + " accuracy = sess.run(DNN.accuracy,\n", + " feed_dict={DNN.X: batch_X,\n", + " DNN.Y: batch_Y})\n", + " step = sess.run(DNN.global_step)\n", + " \n", + " self.train_loss, self.train_accuracy = sess.run([DNN.loss, DNN.accuracy],\n", + " feed_dict={DNN.X: self.X_train,\n", + " DNN.Y: self.Y_train})\n", + " \n", + " self.test_loss, self.test_accuracy = sess.run([DNN.loss, DNN.accuracy],\n", + " feed_dict={DNN.X: self.X_test,\n", + " DNN.Y: self.Y_test})" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Optimizing and using gradient descent" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "epochs = 100\n", + "batch_size = 100\n", + "n_neurons_layer1 = 100\n", + "n_neurons_layer2 = 50\n", + "n_categories = 10\n", + "\n", + "eta_vals = np.logspace(-5, 1, 7)\n", + "lmbd_vals = np.logspace(-5, 1, 7)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "DNN_tf = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", + " \n", + "for i, eta in enumerate(eta_vals):\n", + " for j, lmbd in enumerate(lmbd_vals):\n", + " DNN = NeuralNetworkTensorflow(X_train, Y_train, X_test, Y_test,\n", + " n_neurons_layer1, n_neurons_layer2, n_categories,\n", + " epochs=epochs, batch_size=batch_size, eta=eta, lmbd=lmbd)\n", + " DNN.fit()\n", + " \n", + " DNN_tf[i][j] = DNN\n", + " \n", + " print(\"Learning rate = \", eta)\n", + " print(\"Lambda = \", lmbd)\n", + " print(\"Test accuracy: %.3f\" % DNN.test_accuracy)\n", + " print()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# optional\n", + "# visual representation of grid search\n", + "# uses seaborn heatmap, could probably do this in matplotlib\n", + "import seaborn as sns\n", + "\n", + "sns.set()\n", + "\n", + "train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", + "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", + "\n", + "for i in range(len(eta_vals)):\n", + " for j in range(len(lmbd_vals)):\n", + " DNN = DNN_tf[i][j]\n", + "\n", + " train_accuracy[i][j] = DNN.train_accuracy\n", + " test_accuracy[i][j] = DNN.test_accuracy\n", + "\n", + " \n", + "fig, ax = plt.subplots(figsize = (10, 10))\n", + "sns.heatmap(train_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", + "ax.set_title(\"Training Accuracy\")\n", + "ax.set_ylabel(\"$\\eta$\")\n", + "ax.set_xlabel(\"$\\lambda$\")\n", + "plt.show()\n", + "\n", + "fig, ax = plt.subplots(figsize = (10, 10))\n", + "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", + "ax.set_title(\"Test Accuracy\")\n", + "ax.set_ylabel(\"$\\eta$\")\n", + "ax.set_xlabel(\"$\\lambda$\")\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# optional\n", + "# we can use log files to visualize our graph in Tensorboard\n", + "writer = tf.summary.FileWriter('logs/')\n", + "writer.add_graph(tf.get_default_graph())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using Keras\n", + "\n", + "Keras is a high level [neural network](https://en.wikipedia.org/wiki/Application_programming_interface)\n", + "that supports Tensorflow, CTNK and Theano as backends. \n", + "If you have Tensorflow installed Keras is available through the *tf.keras* module. \n", + "If you have Anaconda installed you may run the following command" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "conda install keras" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Alternatively, if you have Tensorflow or one of the other supported backends install you may use the pip package manager:" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "pip3 install keras" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "or look up the [instructions here](https://keras.io/)." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "from keras.models import Sequential\n", + "from keras.layers import Dense\n", + "from keras.regularizers import l2\n", + "from keras.optimizers import SGD\n", + "\n", + "def create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories, eta, lmbd):\n", + " model = Sequential()\n", + " model.add(Dense(n_neurons_layer1, activation='sigmoid', kernel_regularizer=l2(lmbd)))\n", + " model.add(Dense(n_neurons_layer2, activation='sigmoid', kernel_regularizer=l2(lmbd)))\n", + " model.add(Dense(n_categories, activation='softmax'))\n", + " \n", + " sgd = SGD(lr=eta)\n", + " model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])\n", + " \n", + " return model" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "DNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", + " \n", + "for i, eta in enumerate(eta_vals):\n", + " for j, lmbd in enumerate(lmbd_vals):\n", + " DNN = create_neural_network_keras(n_neurons_layer1, n_neurons_layer2, n_categories,\n", + " eta=eta, lmbd=lmbd)\n", + " DNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)\n", + " scores = DNN.evaluate(X_test, Y_test)\n", + " \n", + " DNN_keras[i][j] = DNN\n", + " \n", + " print(\"Learning rate = \", eta)\n", + " print(\"Lambda = \", lmbd)\n", + " print(\"Test accuracy: %.3f\" % scores[1])\n", + " print()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# optional\n", + "# visual representation of grid search\n", + "# uses seaborn heatmap, could probably do this in matplotlib\n", + "import seaborn as sns\n", + "\n", + "sns.set()\n", + "\n", + "train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", + "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", + "\n", + "for i in range(len(eta_vals)):\n", + " for j in range(len(lmbd_vals)):\n", + " DNN = DNN_keras[i][j]\n", + "\n", + " train_accuracy[i][j] = DNN.evaluate(X_train, Y_train)[1]\n", + " test_accuracy[i][j] = DNN.evaluate(X_test, Y_test)[1]\n", + "\n", + " \n", + "fig, ax = plt.subplots(figsize = (10, 10))\n", + "sns.heatmap(train_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", + "ax.set_title(\"Training Accuracy\")\n", + "ax.set_ylabel(\"$\\eta$\")\n", + "ax.set_xlabel(\"$\\lambda$\")\n", + "plt.show()\n", + "\n", + "fig, ax = plt.subplots(figsize = (10, 10))\n", + "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", + "ax.set_title(\"Test Accuracy\")\n", + "ax.set_ylabel(\"$\\eta$\")\n", + "ax.set_xlabel(\"$\\lambda$\")\n", + "plt.show()" ] } ], diff --git a/doc/pub/NeuralNet/ipynb/ipynb-NeuralNet-src.tar.gz b/doc/pub/NeuralNet/ipynb/ipynb-NeuralNet-src.tar.gz index 890c1fbf4..df4a2068c 100644 Binary files a/doc/pub/NeuralNet/ipynb/ipynb-NeuralNet-src.tar.gz and b/doc/pub/NeuralNet/ipynb/ipynb-NeuralNet-src.tar.gz differ diff --git a/doc/pub/NeuralNet/pdf/NeuralNet-minted.pdf b/doc/pub/NeuralNet/pdf/NeuralNet-minted.pdf index 730df384e..1f58cbc2a 100644 Binary files a/doc/pub/NeuralNet/pdf/NeuralNet-minted.pdf and b/doc/pub/NeuralNet/pdf/NeuralNet-minted.pdf differ diff --git a/doc/src/NeuralNet/NeuralNet.do.txt b/doc/src/NeuralNet/NeuralNet.do.txt index 11476bf3a..03bb895d7 100644 --- a/doc/src/NeuralNet/NeuralNet.do.txt +++ b/doc/src/NeuralNet/NeuralNet.do.txt @@ -1824,7 +1824,7 @@ conda install tensorflow !split ===== Collect and pre-process data ===== -bc pycod +!bc pycod # import necessary packages import numpy as np import matplotlib.pyplot as plt