This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from keras.layers import SimpleRNN | |
| from keras.models import Sequential | |
| import os | |
| os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' | |
| model_rnn = Sequential() | |
| model_rnn.add(SimpleRNN(units=20, activation='relu', input_shape=(10,5))) | |
| print(model_rnn.summary()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def AND(x1, x2): | |
| w1 = 0.5 | |
| w2 = 0.5 | |
| theta = 0.7 | |
| if w1 * x1 + w2 * x2 > theta: | |
| return 1 | |
| else: | |
| return 0 | |
| print(AND(0,0)) | |
| print(AND(0,1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def NAND(x1, x2): | |
| w1 = -0.5 | |
| w2 = -0.5 | |
| theta = -0.7 | |
| if w1 * x1 + w2 * x2 > theta: | |
| return 1 | |
| else: | |
| return 0 | |
| def OR(x1, x2): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def stepfunc(x): | |
| return np.where(x <= 0, 0, 1) # if x <= 0 return 0, else return 1 | |
| x = np.arange(-10, 10, 0.1) | |
| y = stepfunc(x) | |
| plt.plot(x, y) | |
| plt.title('Step Function') | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sigmoid(x): | |
| return 1 / (1 + np.exp(-x)) | |
| x = np.arange(-10, 10, 0.1) | |
| y = sigmoid(x) | |
| plt.plot(x,y) | |
| plt.title('Sigmoid Function') | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def tanh(x): | |
| return ((np.exp(2 * x) - 1) / (np.exp(2 * x) + 1) ) | |
| x = np.arange(-10, 10, 0.1) | |
| y = tanh(x) | |
| plt.plot(x,y) | |
| plt.title('tanh Function') | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def relu(x): | |
| return np.maximum(0, x) | |
| x = np.arange(-10, 10, 0.1) | |
| y = relu(x) | |
| plt.plot(x,y) | |
| plt.title('ReLU Function') | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def softmax(x): | |
| return np.exp(x) / np.sum(np.exp(x)) | |
| print(softmax([1,1,3,6,7])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import matplotlib.gridspec as gridspec | |
| import tensorflow as tf | |
| import seaborn as sns | |
| sns.set() | |
| x = [1, 2, 3, 4, 5] | |
| y = [2, 3, 4, 5, 6] | |
| w = tf.Variable(0.7) # we set weight to 0.7, smaller difference between initial value to actual weight is faster |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| import numpy as np | |
| import os | |
| from tensorflow import keras | |
| # Neural network and train variables | |
| EPOCHS = 200 | |
| BATCH_SIZE = 128 | |
| VERBOSE = 1 | |
| NB_CLASSES = 10 # Num of outputs |
OlderNewer