{ "cells": [ { "cell_type": "markdown", "id": "48940f9b", "metadata": {}, "source": [ "# The goal is to show that the use of backpropagation can capture properties of the input in the hidden layer that are not explicitly represented by the input." ] }, { "cell_type": "markdown", "id": "5b707007", "metadata": {}, "source": [ "The use of less hidden units than input units imposes a constraint on the problem and forces the neural network to rerepresent the input units. " ] }, { "cell_type": "code", "execution_count": 1, "id": "1460a1c9", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from sklearn.model_selection import train_test_split\n", "import pandas as pd\n", "from sklearn import preprocessing" ] }, { "cell_type": "markdown", "id": "579ff56c", "metadata": {}, "source": [ "This neural network's purpose is to learn the target function f(x) where f(x) is a vector which contains seven 0's and a 1. \n", "This has been represented below using a pandas dataframe where there are 8 rows which represent the 8 different vector combinations that can make up f(x)." ] }, { "cell_type": "code", "execution_count": 2, "id": "bba80b47", "metadata": {}, "outputs": [], "source": [ "index = [\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\"]\n", "vectors = [\"v_1\", \"v_2\", \"v_3\", \"v_4\", \"v_5\", \"v_6\", \"v_7\", \"v_8\"]\n", "\n", "data = np.array([[1, 0, 0, 0, 0, 0, 0 , 0],\n", " [0, 1, 0, 0, 0, 0, 0 , 0],\n", " [0, 0, 1, 0, 0, 0, 0 , 0],\n", " [0, 0, 0, 1, 0, 0, 0 , 0],\n", " [0, 0, 0, 0, 1, 0, 0 , 0],\n", " [0, 0, 0, 0, 0, 1, 0 , 0],\n", " [0, 0, 0, 0, 0, 0, 1 , 0],\n", " [0, 0, 0, 0, 0, 0, 0 , 1]])" ] }, { "cell_type": "code", "execution_count": 3, "id": "862be7a8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | 1 | \n", "2 | \n", "3 | \n", "4 | \n", "5 | \n", "6 | \n", "7 | \n", "8 | \n", "
---|---|---|---|---|---|---|---|---|
v_1 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
v_2 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
v_3 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
v_4 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
v_5 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "0 | \n", "
v_6 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "0 | \n", "
v_7 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "0 | \n", "
v_8 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "1 | \n", "