{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Learning\n", "\n", "In this notebook we'll discuss what it means for a computer to learn." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Function\n", "\n", "![Euclid](https://upload.wikimedia.org/wikipedia/commons/3/30/Euklid-von-Alexandria_1.jpg)\n", "\n", "The term function is often not clearly defined and has many different uses.\n", "\n", "In programming, we usually write functions where we know exactly what the return value should be for given inputs.\n", "\n", "We also know the precise, basic steps the function should take in sequence to determine the return value.\n", "\n", "For instance, consider the following function to calculate the greatest common divisor of two numbers." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "def gcd(a, b):\n", " \"\"\"Calculate the Greatest Common Divisor of the integers a and b.\"\"\"\n", " # b evaluates as true unless it is zero.\n", " while b:\n", " # Set the new value of a to the old value of b, and the new value of\n", " # b to the old value of a modulo the old value of a.\n", " a, b = b, (a % b)\n", " # Once b is zero, a is the GCD.\n", " return a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "The function, while not trivial, is straight-forward and precise.\n", "\n", "It's clear that the inputs should be two numbers (natural numbers, in fact), and the return value will also be a (natural) number.\n", "\n", "There is an infinity of natural numbers, so we can't write a list of all the inputs and their respective outputs. \n", "\n", "However, in practice a computer can only store a limited amount of natural numbers of limited size.\n", "\n", "In any case, it's clear we know a lot about the task of calculating the greatest common divisor.\n", "\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Driving a car\n", "\n", "![Tesla's Self-Driving Car](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Tesla_Autopilot_Engaged_in_Model_X.jpg/640px-Tesla_Autopilot_Engaged_in_Model_X.jpg)\n", "\n", "Consider instead something quite complex: driving a car.\n", "\n", "Can we write a function to do this task?\n", "\n", "We'll suppose the function will be called on an infinite loop, say every 1000th of a second.\n", "\n", "At each call the function should return the action to take to safely drive the car.\n", "\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Outputs\n", "\n", "![Car Interface](https://cdn.arstechnica.net/wp-content/uploads/2016/12/Internal_Raw_02-760x380.jpg)\n", "\n", "The outputs of the function are straight-forward.\n", "\n", "The user interface for a car mainly comprises of a steering wheel, an accelerator, and a brake.\n", "\n", "We'll assume the car is an automatic and we won't worry about the handbrake or turning signals or lights.\n", "\n", "We can measure the turning of the steering wheel in degrees, with zero degrees meaning the steering wheel is straight, -90 meaning the wheel has a quarter turn counter-clockwise and 90 meaning it has a quarter turn clockwise, etc.\n", "\n", "We can measure each of the accelerator and brake in terms of how hard they are pressed on a linear scale from 0 to 100. If we are not pressing the pedal we'll say that's 0, and at a full press it's 100. 50 means we half press it.\n", "\n", "So, the output of our function will be a triple, e.g. (-180, 0, 20) meaning turn the wheel to -180 degrees, don't press the accelerator at all, and press the break to 20%.\n", "\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Inputs\n", "\n", "The inputs to the function are also somewhat straight-forward.\n", "\n", "First, the current positions of the steering wheel, break and accelerator are relevant inputs. We don't want to go from 100 on the accelerator to 100 on the break in 1 millisecond.\n", "\n", "In fact, we probably need to use the array of positions from the past minute or so, as inputs to give a smooth driving experience. Either way, while it's a lot of data, it's not very complex.\n", "\n", "\n", "![View from driver's seat](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Tesla_Autopilot_Engaged_in_Model_X.jpg/640px-Tesla_Autopilot_Engaged_in_Model_X.jpg)\n", "\n", "\n", "The main input you would imagine we need is the view from the driver's seat.\n", "\n", "This can be provided by a digital camera (or an array of cameras).\n", "\n", "The camera will give us a big array of pixels (millions of them). Each pixel will have a red value (say, between 0 and 255), a blue value, and a green value.\n", "\n", "These are just small integers, albeit a lot of them.\n", "\n", "We can go one step further in that we can use lots of sensors placed on the outside of the car to gauge how close the car is to outside objects, and again we'll got lots of numbers.\n", "\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Difficulties\n", "\n", "\n", "![John McCarthy](http://images.computerhistory.org/fellows/2-4a.stanford_university.mccarthy-john.c1967.l062302006.stanford_university.src.jpg)\n", "\n", "> I believed in realism, as summarized by John McCarthy’s comment to the effect that if we worked really hard, we’d have an intelligent system in from four to four hundred years. - *Marvin Minsky*\n", "\n", "Now we have two difficult (maybe impossible) problems.\n", "\n", "First, when we say that we want the function to correctly drive the car, how do define **correct**. Different humans would drive the car differently. There are some obvious criteria such as not crashing into walls or people. However, it's not clear that an exhaustive (meaning covering all aspects) list of criteria and heuristics could be defined.\n", "\n", "Second, should we be able to give a concrete description of correctness, can we convert the inputs into correct outputs? If so, how?\n", "\n", "In the machine learning community, there seems to be an acceptance that there is not going to be a deterministically-based answer to these questions any time soon, and perhaps never.\n", "\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Supervised learning\n", "\n", "![Tom Mitchell](http://www.cs.cmu.edu/~tom/TomWEF2017.jpg)\n", "\n", "> A computer program learns from experience E, with respect to some task T, and some performance measure P, if its performance on T as measured by P improves with experience E. - *Tom Mitchell*\n", "\n", "Most attempts at self-driving cars try to sidestep these two difficulties using supervised learning.\n", "\n", "We start with a set of inputs for which we know the outputs we want.\n", "You have a training set of some kind: examples of correct driving for the computer to learn from.\n", "When you were a child in the back seat of the car, you were probably doing some sort of supervised learning in your brain: you watched an adult drive the car (probably) correctly.\n", "\n", "Supervised learning tries to replicate that situation: we train a model with the input-output pairs.\n", "We try to design a model (whatever that might mean) to mimic how a human learned to drive a car.\n", "\n", "We have to pick a model but we can pick a generic one that can be moulded to mimic a whole load of other functions depending on how we train it.\n", "Internally the model holds some state in the form of a collection of values of variables defined by the model.\n", "These variables are usually called parameters of the model.\n", "The goal is to pick a good model and then train it get really good values for the parameters.\n", "Success is defined as a trained model that, when tested, drives the car as well as a human could.\n", "\n", "So, we train the model by giving it the known input-output pairs and programmatically tweaking the model parameters to give (at least approximately) the given output when provided with the given input.\n", "\n", "\n", "#### References\n", "\n", "**[Progress and Future of Artificial Intelligence AI 2017 CMU Machine Learning Chair Tom Mitchell](https://www.youtube.com/watch?v=0Xj0n-HYtAM)**\n", "\n", "*[https://www.youtube.com/watch?v=0Xj0n-HYtAM](https://www.youtube.com/watch?v=0Xj0n-HYtAM)*\n", "\n", "A talk by Tom Mitchel on AI.\n", "\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## End" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 2 }