{ "cells": [ { "cell_type": "code", "execution_count": 119, "metadata": {}, "outputs": [], "source": [ "from __future__ import division\n", "from sympy import *\n", "import numpy as np\n", "from numpy.linalg import *\n", "import time\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "def fixfloat(vec):\n", " return list(map(lambda i: '%0.4f' % i, vec))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This week we focus on the question how to calculate the binary clustering of a 1D dataset $S$ sampled from an unknown distribution f(x). We try to approximate f(x) by using the function\n", "\n", "$$f_N(x) = \\sum^N_{j=1} v_j \\varphi_j(x) \\approx f(x)$$\n", "\n", "where $N$ is the number of used basis functions.\n", "\n", "For the following exercises we will use the training dataset: \n", "$$S = [(0.1,1),(0.2,1),(0.3,-1),(0.35,1),(0.4,1),(0.55,-1),(0.6,-1),(0.65,-1),(0.7,-1),(0.8,1)]$$\n", "where the first element of our tuple is the variable $x_i$ $\\in [0,1]$ und the second is the label $y_i$ $\\in \\{-1,1\\}$.\n", "\n", "{\\bf Hint:} If not specified otherwise, the domain considered from now on is the unit interval $\\Omega = [0,1\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercise 1: Interpolation-like classification" ] }, { "cell_type": "code", "execution_count": 120, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAD8CAYAAABzTgP2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAFYhJREFUeJzt3X+M5PV93/HnK4fBtI1zh2/twMH5cHrBxrEFzZikspQmDpiLpXLEoc5RWTki3FOtkEh1gwwiUiycyDhIpa1CEl9s4rOVAg5xzKaxe+Vno0bGZa6cOQ7rzIGdchwyF2MSqVww4Hf/mO+l811mb3dvZnZ22OdD+mq+38/38/1+3/ud2Xnt9/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xLuSHLWgPnLYTG1/ijwo0n+KskDSbYsW3X/36J/n5pTsmcD9y5DXXMtps6PAh9o7pj5JXpHN2OzWoIhA9pW4sexFl1nkg8AHeDGsVY02KLqrKqbq+pH6N3C9TfGXtVgx601yQ8ANwH/ftkqGmwx+/TPgU1V9Q7gbmDX2KsabDG1nkTvdNJP0/tL/FNJ1o65rrmW8nu/Dbijql4eYz3zWUydlwOfqaozgfcCn2teu2OxWoLhEND/19WZjPlQ7AQtqs4kFwLXAZdU1QvLVFu/pe7P24BLx1rR/Baq9QeBHwPuT/It4CeB2QlcgF5wn1bVd/qe7z8EfnyZaptrMc//IeDOqnqxqr4JHKAXFMtpKa/TbUzmNBIsrs4rgc8DVNVXgNfS+x9K47HcF1omMdD76+UJeoeKxy7uvG2evp9hchefF6wTOJ/eharNK3l/9tcH/Eugu1JrndP/fiZz8Xkx+/T0vvGfBx5YqfsU2ALsasbX0ztV8vqVVmfT7xzgWzTf61qh+/PLwBXN+FvpBcfY6l32nTCpgd7h1zeaN9Xrmrbr6f3VDfBOesn9f4HvAPtXaJ13A98G9jbD7Aqt8z8B+5sa7zvem/Gka53TdyLBsMh9+vFmn36t2advWan7lN7pkf8APArsA7atxDqb6Y8CN0xqXy5yf54L/FXz3O8F3jPOevzmsySpZbVcY5AkLZLBIElqMRgkSS0GgySpxWCQJLUYDJKkFoNBktRiMEiSWv4fP+DVeTDyuUwAAAAASUVORK5CYII=\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#data set\n", "S = [(0.1,1),(0.2,1),(0.3,-1),(0.35,1),(0.4,1),(0.55,-1),(0.6,-1),(0.65,-1),(0.7,-1),(0.8,1)]\n", "#S = [(0.1,1),(0.2,1),(0.8,1)] #alternative training set\n", "#vector with 1D features\n", "xVec = [s[0] for s in S]\n", "#vector with labels of the training data\n", "yVec = [s[1] for s in S]\n", "#plotting training data\n", "plt.scatter(xVec, yVec)\n", "\n", "#extended x and y Vectors which are fixed to 0 at the boundaries\n", "xVecExtended = np.zeros(len(xVec)+2)\n", "xVecExtended[1:-1]= xVec\n", "xVecExtended[-1] = 1\n", "yVecExtended = np.zeros(len(yVec)+2)\n", "yVecExtended[1:-1]= yVec" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1a)\n", "Draw the individual hat functions" ] }, { "cell_type": "code", "execution_count": 121, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAD8CAYAAABzTgP2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAADsBJREFUeJzt23GonXd9x/H3x1xMUaFN2kRr0+xWWhjpBoqHFtkGnbVtOtAU7R/p/jBslfwx+8cUwUg3aqt/tN2kIrqNoEIQZusqYkBGia2FMUbtSduhmcZco9JrS42kFLpiS+Z3f9yn2/ldzu29uc+59+TW9wsO53l+v+95zveXA/nc53nOSVUhSdKr3jDtBiRJ5xaDQZLUMBgkSQ2DQZLUMBgkSQ2DQZLUMBgkSQ2DQZLUMBgkSY2ZaTewGhdddFHNzs5Ouw1J2lCOHj3666ratlzdhgyG2dlZhsPhtNuQpA0lyS9WUuelJElSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUMBklSw2CQJDUmEgxJdic5nmQuyYEx85uTPNDNP5ZkdtH8ziQvJvnEJPqRJK1e72BIsgn4EnAjsAu4JcmuRWW3As9X1eXAfcA9i+bvA/61by+SpP4mccZwFTBXVSer6hXgfmDPopo9wKFu+0Hg2iQBSHITcBI4NoFeJEk9TSIYLgGeHtmf78bG1lTVGeAF4MIkbwY+Cdw5gT4kSRMwiWDImLFaYc2dwH1V9eKyb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9Ctg+7fWs5Wc8cowNHwz+8lmS1PBbSZKkhsEgSWoYDJKkhsEgSWoYDJKkhsEgSWoYDJKkhsEgSWr8L4G+I6VKUcyzAAAAAElFTkSuQmCC\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#construct the hat functions for each interval\n", "for i in range(len(xVec)): #loop over all basis functions\n", " #get left border of support x_1\n", " xHat = yHat = []\n", " #toDo!\n", " \n", " #plot hat\n", " plt.plot(xHat,yHat)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1b)\n", "Datermine the coefficients of the basis functions and plot the resulting scaled hats + resulting function f_n(x)" ] }, { "cell_type": "code", "execution_count": 122, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 122, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAD8CAYAAABzTgP2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAF/RJREFUeJzt3X+Q1Pd93/HnK/wQuJUCgrOD+GGwSwC5ssBZSak1UhMHJOKZAvpRC814Ahm5TJkomakbxmjITDRSNMbBU7WdqImRpQh7VCFHldCptkv1s3Fj47IUJH7IZw6sVMcx1gWJhCknCdC7f+z33P2cdu/2+O7e7t69HjM7+/1+vp/v9/u+7+7t674/9r6KCMzMzAb8UrMLMDOz1uJgMDOzhIPBzMwSDgYzM0s4GMzMLOFgMDOzhIPBzMwSDgYzM0s4GMzMLDGx2QVcjJkzZ8b8+fObXYaZWVvZt2/f30VEx3D92jIY5s+fT7FYbHYZZmZtRdLf1tLPh5LMzCzhYDAzs4SDwczMEg4GMzNLOBjMzCzhYDAzs0RdgkHSo5LeknSoynRJ+o+SuiW9JukzZdPWSTqaPdbVox4zM7t49foew2PAnw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rt91H6qxvgGkrJ/X+BU8DhFq3zBeDnwIHs0dmidf4H4HBW48tDfRg3u9ZBfZsSDDVu069m2/TVbJsubtVtSunwyL8DjgAHgbWtWGc2fi+wtVnbssbteSXwN9lrfwC4qZH1+JvPZmaWGC/nGMzMrEYOBjMzSzgYzMws4WAwM7OEg8HMzBIOBjMzSzgYzMws4WAwM7PE/wN18fMYlgZXhgAAAABJRU5ErkJggg==\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#first plot the training data\n", "plt.scatter(xVec,yVec, label=\"data\")\n", "#the resulting function will just be the linear interpolation of the extended points\n", "\n", "#toDo\n", "\n", "#calculate the hat functions from before but now scale them with the height v_i\n", "for i in range(len(xVec)):\n", " xHat = yHat = []\n", " #toDo\n", " plt.plot(xHat,yHat)\n", "plt.legend()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1c)\n", "We are now formally defining the hat functions and $$f_N(x) = \\sum^N_{j=1} v_j \\varphi_j(x) \\approx f(x)$$ and evaluate it at 0.5" ] }, { "cell_type": "code", "execution_count": 130, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0\n" ] } ], "source": [ "#basis functions\n", "def phi_int(i,x):\n", " if i == 0:\n", " x_1 = 0\n", " else:\n", " x_1 = xVec[i-1]\n", " if i == len(xVec)-1:\n", " x_3 = 1\n", " else:\n", " x_3 = xVec[i+1]\n", " if( x >= x_3 or x <= x_1):\n", " return 0\n", " if(x >= xVec[i]):\n", " h = x_3 - xVec[i]\n", " return (x_3 - x)/h\n", " else:\n", " h = xVec[i] - x_1\n", " return (x - x_1)/h\n", "#f_n\n", "def f_n_inter(x):\n", " result = 0.0\n", " #loop over basis functions + calculate f_n(x)\n", " #toDo\n", " return result\n", "\n", "#evaluate f_n at 0.5\n", "print(f_n_inter(0.5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercise 2: Equidistant nodal basis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2a)\n", "Calculate the matrix$G$where$G_{ij} = \\varphi_j(x_i)$and$x_i$are the feature values of the training set (from xVec)" ] }, { "cell_type": "code", "execution_count": 131, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]]\n" ] } ], "source": [ "n=3 #number of basis functions used \n", "#n=7\n", "xVecHat = np.linspace(0,1,n+2) #create equidistant points x_0 to x_n+1 for hat functions\n", "#basis functions for equidistant grid\n", "def phi_nodal(n,i,x):\n", " h = 1.0/(n+1)\n", " if( x >= xVecHat[i+1]+ h or x <= xVecHat[i+1] - h):\n", " return 0\n", " if(x > xVecHat[i+1]):\n", " return (xVecHat[i+2] - x)/h\n", " else:\n", " return (x - xVecHat[i])/h\n", "#create matrix G where G_ij = phi_j(x_i) and x_i are the feature values of the training set (from xVec)\n", "G = np.matrix(np.zeros((len(xVec),n)))\n", "#fill G\n", "#toDo\n", "print(G)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2b)\n", "Solve the least squares problem ($G^T G v = G^T y$) using the normal equation + solving of resulting" ] }, { "cell_type": "code", "execution_count": 142, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "y:\n", "[[ 1]\n", " [ 1]\n", " [-1]\n", " [ 1]\n", " [ 1]\n", " [-1]\n", " [-1]\n", " [-1]\n", " [-1]\n", " [ 1]]\n", "v:\n", "[0. 0. 0.]\n" ] } ], "source": [ "yColumVec = np.matrix(yVec).T\n", "print(\"y:\")\n", "print(yColumVec)\n", "#solve the least squares problem using the normal equation + solving of resulting\n", "v_nodal = np.zeros(n)\n", "#toDo\n", "print(\"v:\")\n", "print(v_nodal)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2c)\n", "Calculate the final approximation$f_N(x)\$ that results from $$f_N(x) = \\sum^N_{j=1} v_j \\varphi_j(x) \\approx f(x)$$ and evaluate at 0.5" ] }, { "cell_type": "code", "execution_count": 143, "metadata": { "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 143, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAD8CAYAAABzTgP2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAGARJREFUeJzt3X2QVfWd5/H3Z3hQsosDAkmQh0AyDMHEBDI3uhtLdyYDgaR2AR82YlV2Ydcstak4U7XZUME1VVoaN2RIrTtVOjPBaCQpJ5hxfGgn47IquskmIctlQBGsDg86a9OM9qjMUEurgN/94x5S99fe2/d2n/vYfl5Vt+45v/M753w5fbifPg+3jyICMzOzs36j3QWYmVlncTCYmVnCwWBmZgkHg5mZJRwMZmaWcDCYmVnCwWBmZgkHg5mZJRwMZmaWGN/uAkZj+vTpMW/evHaXYWbWVXbv3v33ETGjVr+uDIZ58+ZRLBbbXYaZWVeR9Lf19POpJDMzSzgYzMws4WAwM7OEg8HMzBIOBjMzSzTkriRJ9wD/EnglIj5aYbqAPwY+B5wE1kXE32TT1gJfz7p+IyK2NqKmoR7ec5TN23vpPz7IBVMmsWH5QlYvmdWMVTVEt9XbDM3aBt621m1avc826nbVe4E7gO9Xmf5ZYEH2ugT4U+ASSecDNwEFIIDdknoi4vUG1QWUNuoND+5j8NQZAI4eH+SGB/cBdOQHQrfV2wzN2gbettZt2rHPNuRUUkT8BHhtmC6rgO9HyU5giqSZwHLg8Yh4LQuDx4EVjaip3Obtvb/eqGcNnjrD5u29jV5VQ3Rbvc3QrG3gb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lnAwmJlZwsFgZmYJB4OZmSUcDGZmlnAwmJlZ4v8DEd37XZDafvcAAAAASUVORK5CYII=\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#define f_n\n", "def f_n_nodal(x):\n", " result = 0.0\n", " #toDo\n", " return float(result)\n", "#evaluate f_n at 0.5\n", "print(f_n_nodal(0.5))\n", "\n", "#plot individual hat functions\n", "for i in range(n):\n", " xHat = yHat = []\n", " #toDo\n", " plt.plot(xHat,yHat)\n", " \n", "#plot f_n\n", "\n", "#toDo\n", "\n", "#plotting the data\n", "plt.scatter(xVec,yVec, label=\"data\")\n", "plt.legend()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercise 3: Hierarchical classification" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do the same as in Exercise 2 with Hierarchical Clustering." ] }, { "cell_type": "code", "execution_count": 144, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of levels: 2\n", "[[0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]\n", " [0. 0. 0.]]\n" ] } ], "source": [ "#n=7 #number of basis functions; Has to be 2^k - 1 for some integer k!\n", "numlevel=int(log(n+1,2)) #calculate the number of levels\n", "print(\"Number of levels: \" + str(numlevel))\n", "\n", "#basis functions for hierarchical approximation\n", "def phi_hier(level,i,x):\n", " h = 1.0/(2**level)\n", " xLevel = np.linspace(0,1,2**level+1)\n", " i=2*(i+1)-1 #only odd basis functions\n", " if( x >= xLevel[i]+ h or x <= xLevel[i] - h):\n", " return 0\n", " if(x >= xLevel[i]):\n", " return (xLevel[i+1] - x)/h\n", " else:\n", " return (x - xLevel[i-1])/h\n", "\n", "#fill G\n", "G = np.matrix(np.zeros((len(xVec),n)))\n", "#toDo\n", "print(G)" ] }, { "cell_type": "code", "execution_count": 145, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "y:\n", "[[ 1]\n", " [ 1]\n", " [-1]\n", " [ 1]\n", " [ 1]\n", " [-1]\n", " [-1]\n", " [-1]\n", " [-1]\n", " [ 1]]\n", "v:\n", "[0. 0. 0.]\n" ] } ], "source": [ "yColumVec = np.matrix(yVec).T\n", "print(\"y:\")\n", "print(yColumVec)\n", "#solve the least squares problem using the normal equation + solving of resulting\n", "v_hier = np.zeros(n)\n", "#toDo\n", "print(\"v:\")\n", "print(v_hier)" ] }, { "cell_type": "code", "execution_count": 146, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 146, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAD8CAYAAABzTgP2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAF/RJREFUeJzt3X+Q1Pd93/HnK/wQuJUCgrOD+GGwSwC5ssBZSak1UhMHJOKZAvpRC814Ahm5TJkomakbxmjITDRSNMbBU7WdqImRpQh7VCFHldCptkv1s3Fj47IUJH7IZw6sVMcx1gWJhCknCdC7f+z33P2cdu/2+O7e7t69HjM7+/1+vp/v9/u+7+7t674/9r6KCMzMzAb8UrMLMDOz1uJgMDOzhIPBzMwSDgYzM0s4GMzMLOFgMDOzhIPBzMwSDgYzM0s4GMzMLDGx2QVcjJkzZ8b8+fObXYaZWVvZt2/f30VEx3D92jIY5s+fT7FYbHYZZmZtRdLf1tLPh5LMzCzhYDAzs4SDwczMEg4GMzNLOBjMzCzhYDAzs0RdgkHSo5LeknSoynRJ+o+SuiW9JukzZdPWSTqaPdbVox4zM7t49foew2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ut2Rt91H6qxvgGkrJ/X+BU8DhFq3zBeDnwIHs0dmidf4H4HBW48tDfRg3u9ZBfZsSDDVu069m2/TVbJsubtVtSunwyL8DjgAHgbWtWGc2fi+wtVnbssbteSXwN9lrfwC4qZH1+JvPZmaWGC/nGMzMrEYOBjMzSzgYzMws4WAwM7OEg8HMzBIOBjMzSzgYzMws4WAwM7PE/wN18fMYlgZXhgAAAABJRU5ErkJggg==\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#f_n\n", "def f_n_hier(x):\n", " result = 0.0\n", " #toDo\n", " return result\n", "print(f_n_hier(0.5))\n", "#plot scaked hat functions\n", "#toDo\n", "\n", "#plot f_n\n", "\n", "plt.scatter(xVec,yVec, label=\"data\")\n", "plt.legend()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.14" } }, "nbformat": 4, "nbformat_minor": 1 }