{ "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": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n=30\n",
"x = random(n)\n",
"y = lin(a,b,x)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.3046, 0.918 , 0.7925, 0.8476, 0.2508, 0.3504, 0.8326, 0.6875, 0.4449, 0.4687,\n",
" 0.5901, 0.2757, 0.6629, 0.169 , 0.8677, 0.6612, 0.112 , 0.1669, 0.6226, 0.6174,\n",
" 0.3871, 0.4724, 0.3242, 0.7871, 0.0157, 0.8589, 0.7008, 0.2942, 0.3166, 0.5847])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 8.9138, 10.7541, 10.3775, 10.5428, 8.7525, 9.0511, 10.4977, 10.0626, 9.3347,\n",
" 9.4062, 9.7704, 8.827 , 9.9888, 8.507 , 10.603 , 9.9836, 8.336 , 8.5006,\n",
" 9.8678, 9.8523, 9.1614, 9.4172, 8.9725, 10.3614, 8.0471, 10.5766, 10.1025,\n",
" 8.8827, 8.9497, 9.7542])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"