Created using Colaboratory
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"provenance": [],
|
"provenance": [],
|
||||||
"authorship_tag": "ABX9TyNx6kL7nMnRBAp48GoXD/0c",
|
"authorship_tag": "ABX9TyN/trn2b+dsX0Qcg4ZzNZEf",
|
||||||
"include_colab_link": true
|
"include_colab_link": true
|
||||||
},
|
},
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
@@ -457,7 +457,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"source": [
|
||||||
"def gradient_descent_step_fixed_learning_rate(phi, data, model, alpha):\n",
|
"def gradient_descent_step_fixed_learning_rate(phi, data, alpha):\n",
|
||||||
" # TODO -- fill in this routine so that we take a fixed size step of size alpha without using line search\n",
|
" # TODO -- fill in this routine so that we take a fixed size step of size alpha without using line search\n",
|
||||||
"\n",
|
"\n",
|
||||||
" return phi"
|
" return phi"
|
||||||
@@ -483,7 +483,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"for c_step in range (n_steps):\n",
|
"for c_step in range (n_steps):\n",
|
||||||
" # Do gradient descent step\n",
|
" # Do gradient descent step\n",
|
||||||
" phi_all[:,c_step+1:c_step+2] = gradient_descent_step_fixed_learning_rate(phi_all[:,c_step:c_step+1],data, model,alpha =0.2)\n",
|
" phi_all[:,c_step+1:c_step+2] = gradient_descent_step_fixed_learning_rate(phi_all[:,c_step:c_step+1],data, alpha =0.2)\n",
|
||||||
" # Measure loss and draw model every 4th step\n",
|
" # Measure loss and draw model every 4th step\n",
|
||||||
" if c_step % 4 == 0:\n",
|
" if c_step % 4 == 0:\n",
|
||||||
" loss = compute_loss(data[0,:], data[1,:], model, phi_all[:,c_step+1:c_step+2])\n",
|
" loss = compute_loss(data[0,:], data[1,:], model, phi_all[:,c_step+1:c_step+2])\n",
|
||||||
@@ -513,7 +513,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"source": [
|
||||||
"def stochastic_gradient_descent_step(phi, data, model, alpha, batch_size):\n",
|
"def stochastic_gradient_descent_step(phi, data, alpha, batch_size):\n",
|
||||||
" # TODO -- fill in this routine so that we take a fixed size step of size alpha but only using a subset (batch) of the data\n",
|
" # TODO -- fill in this routine so that we take a fixed size step of size alpha but only using a subset (batch) of the data\n",
|
||||||
" # at each step\n",
|
" # at each step\n",
|
||||||
" # You can use the function np.random.permutation to generate a random permutation of the n_data = data.shape[1] indices\n",
|
" # You can use the function np.random.permutation to generate a random permutation of the n_data = data.shape[1] indices\n",
|
||||||
@@ -546,7 +546,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"for c_step in range (n_steps):\n",
|
"for c_step in range (n_steps):\n",
|
||||||
" # Do gradient descent step\n",
|
" # Do gradient descent step\n",
|
||||||
" phi_all[:,c_step+1:c_step+2] = stochastic_gradient_descent_step(phi_all[:,c_step:c_step+1],data, model,alpha =0.8, batch_size=5)\n",
|
" phi_all[:,c_step+1:c_step+2] = stochastic_gradient_descent_step(phi_all[:,c_step:c_step+1],data, alpha =0.8, batch_size=5)\n",
|
||||||
" # Measure loss and draw model every 4th step\n",
|
" # Measure loss and draw model every 4th step\n",
|
||||||
" if c_step % 8 == 0:\n",
|
" if c_step % 8 == 0:\n",
|
||||||
" loss = compute_loss(data[0,:], data[1,:], model, phi_all[:,c_step+1:c_step+2])\n",
|
" loss = compute_loss(data[0,:], data[1,:], model, phi_all[:,c_step+1:c_step+2])\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user