{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": "true" }, "source": [ "# Gradient Descent Intro\n", "
"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import math,sys,os,numpy as np\n",
"from numpy.random import random\n",
"from matplotlib import pyplot as plt, rcParams, animation, rc\n",
"from __future__ import print_function, division\n",
"from ipywidgets import interact, interactive, fixed\n",
"from ipywidgets.widgets import *\n",
"rc('animation', html='html5')\n",
"rcParams['figure.figsize'] = 3, 3\n",
"%precision 4\n",
"np.set_printoptions(precision=4, linewidth=100)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def lin(a,b,x): return a*x+b"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"a=3.\n",
"b=8."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n=30\n",
"x = random(n)\n",
"y = lin(a,b,x)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.0132, 0.4765, 0.0034, 0.8314, 0.5044, 0.0817, 0.7193, 0.8595, 0.7664, 0.0203,\n",
" 0.4296, 0.5188, 0.2627, 0.4388, 0.3663, 0.0792, 0.5146, 0.9705, 0.4546, 0.0884,\n",
" 0.9854, 0.3523, 0.5519, 0.1516, 0.1063, 0.0296, 0.9777, 0.3856, 0.5225, 0.2138])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 8.0395, 9.4294, 8.0103, 10.4941, 9.5131, 8.245 , 10.1578, 10.5785, 10.2991,\n",
" 8.061 , 9.2889, 9.5564, 8.7882, 9.3164, 9.099 , 8.2375, 9.5439, 10.9116,\n",
" 9.3637, 8.2653, 10.9562, 9.0568, 9.6556, 8.4548, 8.3188, 8.0888, 10.9331,\n",
" 9.1568, 9.5675, 8.6414])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"