ecbm4040/Homework 0/.ipynb_checkpoints/Homework 0-checkpoint.ipynb

1032 lines
50 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 1"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using gpu device 0: GRID K520 (CNMeM is disabled, cuDNN Version is too old. Update to v5, was 3007.)\n",
"... loading data\n",
"... building the model\n",
"... training the model\n",
"epoch 1, minibatch 83/83, validation error 12.458333 %\n",
" epoch 1, minibatch 83/83, test error of best model 12.375000 %\n",
"epoch 2, minibatch 83/83, validation error 11.010417 %\n",
" epoch 2, minibatch 83/83, test error of best model 10.958333 %\n",
"epoch 3, minibatch 83/83, validation error 10.312500 %\n",
" epoch 3, minibatch 83/83, test error of best model 10.312500 %\n",
"epoch 4, minibatch 83/83, validation error 9.875000 %\n",
" epoch 4, minibatch 83/83, test error of best model 9.833333 %\n",
"epoch 5, minibatch 83/83, validation error 9.562500 %\n",
" epoch 5, minibatch 83/83, test error of best model 9.479167 %\n",
"epoch 6, minibatch 83/83, validation error 9.322917 %\n",
" epoch 6, minibatch 83/83, test error of best model 9.291667 %\n",
"epoch 7, minibatch 83/83, validation error 9.187500 %\n",
" epoch 7, minibatch 83/83, test error of best model 9.000000 %\n",
"epoch 8, minibatch 83/83, validation error 8.989583 %\n",
" epoch 8, minibatch 83/83, test error of best model 8.958333 %\n",
"epoch 9, minibatch 83/83, validation error 8.937500 %\n",
" epoch 9, minibatch 83/83, test error of best model 8.812500 %\n",
"epoch 10, minibatch 83/83, validation error 8.750000 %\n",
" epoch 10, minibatch 83/83, test error of best model 8.666667 %\n",
"epoch 11, minibatch 83/83, validation error 8.666667 %\n",
" epoch 11, minibatch 83/83, test error of best model 8.520833 %\n",
"epoch 12, minibatch 83/83, validation error 8.583333 %\n",
" epoch 12, minibatch 83/83, test error of best model 8.416667 %\n",
"epoch 13, minibatch 83/83, validation error 8.489583 %\n",
" epoch 13, minibatch 83/83, test error of best model 8.291667 %\n",
"epoch 14, minibatch 83/83, validation error 8.427083 %\n",
" epoch 14, minibatch 83/83, test error of best model 8.281250 %\n",
"epoch 15, minibatch 83/83, validation error 8.354167 %\n",
" epoch 15, minibatch 83/83, test error of best model 8.270833 %\n",
"epoch 16, minibatch 83/83, validation error 8.302083 %\n",
" epoch 16, minibatch 83/83, test error of best model 8.239583 %\n",
"epoch 17, minibatch 83/83, validation error 8.250000 %\n",
" epoch 17, minibatch 83/83, test error of best model 8.177083 %\n",
"epoch 18, minibatch 83/83, validation error 8.229167 %\n",
" epoch 18, minibatch 83/83, test error of best model 8.062500 %\n",
"epoch 19, minibatch 83/83, validation error 8.260417 %\n",
"epoch 20, minibatch 83/83, validation error 8.260417 %\n",
"epoch 21, minibatch 83/83, validation error 8.208333 %\n",
" epoch 21, minibatch 83/83, test error of best model 7.947917 %\n",
"epoch 22, minibatch 83/83, validation error 8.187500 %\n",
" epoch 22, minibatch 83/83, test error of best model 7.927083 %\n",
"epoch 23, minibatch 83/83, validation error 8.156250 %\n",
" epoch 23, minibatch 83/83, test error of best model 7.958333 %\n",
"epoch 24, minibatch 83/83, validation error 8.114583 %\n",
" epoch 24, minibatch 83/83, test error of best model 7.947917 %\n",
"epoch 25, minibatch 83/83, validation error 8.093750 %\n",
" epoch 25, minibatch 83/83, test error of best model 7.947917 %\n",
"epoch 26, minibatch 83/83, validation error 8.104167 %\n",
"epoch 27, minibatch 83/83, validation error 8.104167 %\n",
"epoch 28, minibatch 83/83, validation error 8.052083 %\n",
" epoch 28, minibatch 83/83, test error of best model 7.843750 %\n",
"epoch 29, minibatch 83/83, validation error 8.052083 %\n",
"epoch 30, minibatch 83/83, validation error 8.031250 %\n",
" epoch 30, minibatch 83/83, test error of best model 7.843750 %\n",
"epoch 31, minibatch 83/83, validation error 8.010417 %\n",
" epoch 31, minibatch 83/83, test error of best model 7.833333 %\n",
"epoch 32, minibatch 83/83, validation error 7.979167 %\n",
" epoch 32, minibatch 83/83, test error of best model 7.812500 %\n",
"epoch 33, minibatch 83/83, validation error 7.947917 %\n",
" epoch 33, minibatch 83/83, test error of best model 7.739583 %\n",
"epoch 34, minibatch 83/83, validation error 7.875000 %\n",
" epoch 34, minibatch 83/83, test error of best model 7.729167 %\n",
"epoch 35, minibatch 83/83, validation error 7.885417 %\n",
"epoch 36, minibatch 83/83, validation error 7.843750 %\n",
" epoch 36, minibatch 83/83, test error of best model 7.697917 %\n",
"epoch 37, minibatch 83/83, validation error 7.802083 %\n",
" epoch 37, minibatch 83/83, test error of best model 7.635417 %\n",
"epoch 38, minibatch 83/83, validation error 7.812500 %\n",
"epoch 39, minibatch 83/83, validation error 7.812500 %\n",
"epoch 40, minibatch 83/83, validation error 7.822917 %\n",
"epoch 41, minibatch 83/83, validation error 7.791667 %\n",
" epoch 41, minibatch 83/83, test error of best model 7.625000 %\n",
"epoch 42, minibatch 83/83, validation error 7.770833 %\n",
" epoch 42, minibatch 83/83, test error of best model 7.614583 %\n",
"epoch 43, minibatch 83/83, validation error 7.750000 %\n",
" epoch 43, minibatch 83/83, test error of best model 7.593750 %\n",
"epoch 44, minibatch 83/83, validation error 7.739583 %\n",
" epoch 44, minibatch 83/83, test error of best model 7.593750 %\n",
"epoch 45, minibatch 83/83, validation error 7.739583 %\n",
"epoch 46, minibatch 83/83, validation error 7.739583 %\n",
"epoch 47, minibatch 83/83, validation error 7.739583 %\n",
"epoch 48, minibatch 83/83, validation error 7.708333 %\n",
" epoch 48, minibatch 83/83, test error of best model 7.583333 %\n",
"epoch 49, minibatch 83/83, validation error 7.677083 %\n",
" epoch 49, minibatch 83/83, test error of best model 7.572917 %\n",
"epoch 50, minibatch 83/83, validation error 7.677083 %\n",
"epoch 51, minibatch 83/83, validation error 7.677083 %\n",
"epoch 52, minibatch 83/83, validation error 7.656250 %\n",
" epoch 52, minibatch 83/83, test error of best model 7.541667 %\n",
"epoch 53, minibatch 83/83, validation error 7.656250 %\n",
"epoch 54, minibatch 83/83, validation error 7.635417 %\n",
" epoch 54, minibatch 83/83, test error of best model 7.520833 %\n",
"epoch 55, minibatch 83/83, validation error 7.635417 %\n",
"epoch 56, minibatch 83/83, validation error 7.635417 %\n",
"epoch 57, minibatch 83/83, validation error 7.604167 %\n",
" epoch 57, minibatch 83/83, test error of best model 7.489583 %\n",
"epoch 58, minibatch 83/83, validation error 7.583333 %\n",
" epoch 58, minibatch 83/83, test error of best model 7.458333 %\n",
"epoch 59, minibatch 83/83, validation error 7.572917 %\n",
" epoch 59, minibatch 83/83, test error of best model 7.468750 %\n",
"epoch 60, minibatch 83/83, validation error 7.572917 %\n",
"epoch 61, minibatch 83/83, validation error 7.583333 %\n",
"epoch 62, minibatch 83/83, validation error 7.572917 %\n",
" epoch 62, minibatch 83/83, test error of best model 7.520833 %\n",
"epoch 63, minibatch 83/83, validation error 7.562500 %\n",
" epoch 63, minibatch 83/83, test error of best model 7.510417 %\n",
"epoch 64, minibatch 83/83, validation error 7.572917 %\n",
"epoch 65, minibatch 83/83, validation error 7.562500 %\n",
"epoch 66, minibatch 83/83, validation error 7.552083 %\n",
" epoch 66, minibatch 83/83, test error of best model 7.520833 %\n",
"epoch 67, minibatch 83/83, validation error 7.552083 %\n",
"epoch 68, minibatch 83/83, validation error 7.531250 %\n",
" epoch 68, minibatch 83/83, test error of best model 7.520833 %\n",
"epoch 69, minibatch 83/83, validation error 7.531250 %\n",
"epoch 70, minibatch 83/83, validation error 7.510417 %\n",
" epoch 70, minibatch 83/83, test error of best model 7.500000 %\n",
"epoch 71, minibatch 83/83, validation error 7.520833 %\n",
"epoch 72, minibatch 83/83, validation error 7.510417 %\n",
"epoch 73, minibatch 83/83, validation error 7.500000 %\n",
" epoch 73, minibatch 83/83, test error of best model 7.489583 %\n",
"Optimization complete with best validation score of 7.500000 %,with test performance 7.489583 %\n",
"The code run for 74 epochs, with 12.449774 epochs/sec\n",
"The code for file logistic_sgd.py ran for 5.9s\n",
"CPU times: user 89.3 ms, sys: 7.6 ms, total: 96.9 ms\n",
"Wall time: 13.3 s\n"
]
}
],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=gpu,floatX=float32 python DeepLearningTutorials/code/logistic_sgd.py"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using gpu device 0: GRID K520 (CNMeM is disabled, cuDNN Version is too old. Update to v5, was 3007.)\n",
"... loading data\n",
"... building the model\n",
"... training\n",
"training @ iter = 0\n",
"epoch 1, minibatch 100/100, validation error 9.230000 %\n",
" epoch 1, minibatch 100/100, test error of best model 9.520000 %\n",
"training @ iter = 100\n",
"epoch 2, minibatch 100/100, validation error 6.190000 %\n",
" epoch 2, minibatch 100/100, test error of best model 6.500000 %\n",
"training @ iter = 200\n",
"epoch 3, minibatch 100/100, validation error 4.640000 %\n",
" epoch 3, minibatch 100/100, test error of best model 4.850000 %\n",
"training @ iter = 300\n",
"epoch 4, minibatch 100/100, validation error 3.500000 %\n",
" epoch 4, minibatch 100/100, test error of best model 3.910000 %\n",
"training @ iter = 400\n",
"epoch 5, minibatch 100/100, validation error 3.020000 %\n",
" epoch 5, minibatch 100/100, test error of best model 3.260000 %\n",
"training @ iter = 500\n",
"epoch 6, minibatch 100/100, validation error 2.780000 %\n",
" epoch 6, minibatch 100/100, test error of best model 2.800000 %\n",
"training @ iter = 600\n",
"epoch 7, minibatch 100/100, validation error 2.470000 %\n",
" epoch 7, minibatch 100/100, test error of best model 2.500000 %\n",
"training @ iter = 700\n",
"epoch 8, minibatch 100/100, validation error 2.290000 %\n",
" epoch 8, minibatch 100/100, test error of best model 2.220000 %\n",
"training @ iter = 800\n",
"epoch 9, minibatch 100/100, validation error 2.160000 %\n",
" epoch 9, minibatch 100/100, test error of best model 2.010000 %\n",
"training @ iter = 900\n",
"epoch 10, minibatch 100/100, validation error 1.960000 %\n",
" epoch 10, minibatch 100/100, test error of best model 1.880000 %\n",
"training @ iter = 1000\n",
"epoch 11, minibatch 100/100, validation error 1.880000 %\n",
" epoch 11, minibatch 100/100, test error of best model 1.790000 %\n",
"training @ iter = 1100\n",
"epoch 12, minibatch 100/100, validation error 1.790000 %\n",
" epoch 12, minibatch 100/100, test error of best model 1.660000 %\n",
"training @ iter = 1200\n",
"epoch 13, minibatch 100/100, validation error 1.760000 %\n",
" epoch 13, minibatch 100/100, test error of best model 1.580000 %\n",
"training @ iter = 1300\n",
"epoch 14, minibatch 100/100, validation error 1.710000 %\n",
" epoch 14, minibatch 100/100, test error of best model 1.550000 %\n",
"training @ iter = 1400\n",
"epoch 15, minibatch 100/100, validation error 1.670000 %\n",
" epoch 15, minibatch 100/100, test error of best model 1.500000 %\n",
"training @ iter = 1500\n",
"epoch 16, minibatch 100/100, validation error 1.620000 %\n",
" epoch 16, minibatch 100/100, test error of best model 1.440000 %\n",
"training @ iter = 1600\n",
"epoch 17, minibatch 100/100, validation error 1.590000 %\n",
" epoch 17, minibatch 100/100, test error of best model 1.410000 %\n",
"training @ iter = 1700\n",
"epoch 18, minibatch 100/100, validation error 1.570000 %\n",
" epoch 18, minibatch 100/100, test error of best model 1.420000 %\n",
"training @ iter = 1800\n",
"epoch 19, minibatch 100/100, validation error 1.530000 %\n",
" epoch 19, minibatch 100/100, test error of best model 1.380000 %\n",
"training @ iter = 1900\n",
"epoch 20, minibatch 100/100, validation error 1.520000 %\n",
" epoch 20, minibatch 100/100, test error of best model 1.330000 %\n",
"training @ iter = 2000\n",
"epoch 21, minibatch 100/100, validation error 1.480000 %\n",
" epoch 21, minibatch 100/100, test error of best model 1.270000 %\n",
"training @ iter = 2100\n",
"epoch 22, minibatch 100/100, validation error 1.460000 %\n",
" epoch 22, minibatch 100/100, test error of best model 1.270000 %\n",
"training @ iter = 2200\n",
"epoch 23, minibatch 100/100, validation error 1.430000 %\n",
" epoch 23, minibatch 100/100, test error of best model 1.240000 %\n",
"training @ iter = 2300\n",
"epoch 24, minibatch 100/100, validation error 1.410000 %\n",
" epoch 24, minibatch 100/100, test error of best model 1.240000 %\n",
"training @ iter = 2400\n",
"epoch 25, minibatch 100/100, validation error 1.370000 %\n",
" epoch 25, minibatch 100/100, test error of best model 1.200000 %\n",
"training @ iter = 2500\n",
"epoch 26, minibatch 100/100, validation error 1.340000 %\n",
" epoch 26, minibatch 100/100, test error of best model 1.150000 %\n",
"training @ iter = 2600\n",
"epoch 27, minibatch 100/100, validation error 1.320000 %\n",
" epoch 27, minibatch 100/100, test error of best model 1.150000 %\n",
"training @ iter = 2700\n",
"epoch 28, minibatch 100/100, validation error 1.300000 %\n",
" epoch 28, minibatch 100/100, test error of best model 1.130000 %\n",
"training @ iter = 2800\n",
"epoch 29, minibatch 100/100, validation error 1.280000 %\n",
" epoch 29, minibatch 100/100, test error of best model 1.120000 %\n",
"training @ iter = 2900\n",
"epoch 30, minibatch 100/100, validation error 1.260000 %\n",
" epoch 30, minibatch 100/100, test error of best model 1.110000 %\n",
"training @ iter = 3000\n",
"epoch 31, minibatch 100/100, validation error 1.260000 %\n",
"training @ iter = 3100\n",
"epoch 32, minibatch 100/100, validation error 1.250000 %\n",
" epoch 32, minibatch 100/100, test error of best model 1.100000 %\n",
"training @ iter = 3200\n",
"epoch 33, minibatch 100/100, validation error 1.240000 %\n",
" epoch 33, minibatch 100/100, test error of best model 1.080000 %\n",
"training @ iter = 3300\n",
"epoch 34, minibatch 100/100, validation error 1.220000 %\n",
" epoch 34, minibatch 100/100, test error of best model 1.070000 %\n",
"training @ iter = 3400\n",
"epoch 35, minibatch 100/100, validation error 1.220000 %\n",
"training @ iter = 3500\n",
"epoch 36, minibatch 100/100, validation error 1.200000 %\n",
" epoch 36, minibatch 100/100, test error of best model 1.050000 %\n",
"training @ iter = 3600\n",
"epoch 37, minibatch 100/100, validation error 1.190000 %\n",
" epoch 37, minibatch 100/100, test error of best model 1.050000 %\n",
"training @ iter = 3700\n",
"epoch 38, minibatch 100/100, validation error 1.180000 %\n",
" epoch 38, minibatch 100/100, test error of best model 1.070000 %\n",
"training @ iter = 3800\n",
"epoch 39, minibatch 100/100, validation error 1.180000 %\n",
"training @ iter = 3900\n",
"epoch 40, minibatch 100/100, validation error 1.170000 %\n",
" epoch 40, minibatch 100/100, test error of best model 1.080000 %\n",
"training @ iter = 4000\n",
"epoch 41, minibatch 100/100, validation error 1.150000 %\n",
" epoch 41, minibatch 100/100, test error of best model 1.090000 %\n",
"training @ iter = 4100\n",
"epoch 42, minibatch 100/100, validation error 1.150000 %\n",
"training @ iter = 4200\n",
"epoch 43, minibatch 100/100, validation error 1.140000 %\n",
" epoch 43, minibatch 100/100, test error of best model 1.060000 %\n",
"training @ iter = 4300\n",
"epoch 44, minibatch 100/100, validation error 1.130000 %\n",
" epoch 44, minibatch 100/100, test error of best model 1.060000 %\n",
"training @ iter = 4400\n",
"epoch 45, minibatch 100/100, validation error 1.130000 %\n",
"training @ iter = 4500\n",
"epoch 46, minibatch 100/100, validation error 1.120000 %\n",
" epoch 46, minibatch 100/100, test error of best model 1.050000 %\n",
"training @ iter = 4600\n",
"epoch 47, minibatch 100/100, validation error 1.110000 %\n",
" epoch 47, minibatch 100/100, test error of best model 1.040000 %\n",
"training @ iter = 4700\n",
"epoch 48, minibatch 100/100, validation error 1.090000 %\n",
" epoch 48, minibatch 100/100, test error of best model 1.050000 %\n",
"training @ iter = 4800\n",
"epoch 49, minibatch 100/100, validation error 1.090000 %\n",
"training @ iter = 4900\n",
"epoch 50, minibatch 100/100, validation error 1.090000 %\n",
"training @ iter = 5000\n",
"epoch 51, minibatch 100/100, validation error 1.100000 %\n",
"training @ iter = 5100\n",
"epoch 52, minibatch 100/100, validation error 1.100000 %\n",
"training @ iter = 5200\n",
"epoch 53, minibatch 100/100, validation error 1.070000 %\n",
" epoch 53, minibatch 100/100, test error of best model 1.030000 %\n",
"training @ iter = 5300\n",
"epoch 54, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 5400\n",
"epoch 55, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 5500\n",
"epoch 56, minibatch 100/100, validation error 1.080000 %\n",
"training @ iter = 5600\n",
"epoch 57, minibatch 100/100, validation error 1.080000 %\n",
"training @ iter = 5700\n",
"epoch 58, minibatch 100/100, validation error 1.080000 %\n",
"training @ iter = 5800\n",
"epoch 59, minibatch 100/100, validation error 1.060000 %\n",
" epoch 59, minibatch 100/100, test error of best model 0.990000 %\n",
"training @ iter = 5900\n",
"epoch 60, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 6000\n",
"epoch 61, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 6100\n",
"epoch 62, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 6200\n",
"epoch 63, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 6300\n",
"epoch 64, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 6400\n",
"epoch 65, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 6500\n",
"epoch 66, minibatch 100/100, validation error 1.060000 %\n",
"training @ iter = 6600\n",
"epoch 67, minibatch 100/100, validation error 1.060000 %\n",
"training @ iter = 6700\n",
"epoch 68, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 6800\n",
"epoch 69, minibatch 100/100, validation error 1.070000 %\n",
"training @ iter = 6900\n",
"epoch 70, minibatch 100/100, validation error 1.060000 %\n",
"training @ iter = 7000\n",
"epoch 71, minibatch 100/100, validation error 1.030000 %\n",
" epoch 71, minibatch 100/100, test error of best model 0.970000 %\n",
"training @ iter = 7100\n",
"epoch 72, minibatch 100/100, validation error 1.020000 %\n",
" epoch 72, minibatch 100/100, test error of best model 0.970000 %\n",
"training @ iter = 7200\n",
"epoch 73, minibatch 100/100, validation error 1.020000 %\n",
"training @ iter = 7300\n",
"epoch 74, minibatch 100/100, validation error 1.000000 %\n",
" epoch 74, minibatch 100/100, test error of best model 0.960000 %\n",
"training @ iter = 7400\n",
"epoch 75, minibatch 100/100, validation error 0.990000 %\n",
" epoch 75, minibatch 100/100, test error of best model 0.970000 %\n",
"training @ iter = 7500\n",
"epoch 76, minibatch 100/100, validation error 0.970000 %\n",
" epoch 76, minibatch 100/100, test error of best model 0.970000 %\n",
"training @ iter = 7600\n",
"epoch 77, minibatch 100/100, validation error 0.970000 %\n",
"training @ iter = 7700\n",
"epoch 78, minibatch 100/100, validation error 0.970000 %\n",
"training @ iter = 7800\n",
"epoch 79, minibatch 100/100, validation error 0.970000 %\n",
"training @ iter = 7900\n",
"epoch 80, minibatch 100/100, validation error 0.970000 %\n",
"training @ iter = 8000\n",
"epoch 81, minibatch 100/100, validation error 0.980000 %\n",
"training @ iter = 8100\n",
"epoch 82, minibatch 100/100, validation error 0.980000 %\n",
"training @ iter = 8200\n",
"epoch 83, minibatch 100/100, validation error 0.980000 %\n",
"training @ iter = 8300\n",
"epoch 84, minibatch 100/100, validation error 0.990000 %\n",
"training @ iter = 8400\n",
"epoch 85, minibatch 100/100, validation error 0.990000 %\n",
"training @ iter = 8500\n",
"epoch 86, minibatch 100/100, validation error 0.990000 %\n",
"training @ iter = 8600\n",
"epoch 87, minibatch 100/100, validation error 0.980000 %\n",
"training @ iter = 8700\n",
"epoch 88, minibatch 100/100, validation error 0.960000 %\n",
" epoch 88, minibatch 100/100, test error of best model 0.970000 %\n",
"training @ iter = 8800\n",
"epoch 89, minibatch 100/100, validation error 0.960000 %\n",
"training @ iter = 8900\n",
"epoch 90, minibatch 100/100, validation error 0.960000 %\n",
"training @ iter = 9000\n",
"epoch 91, minibatch 100/100, validation error 0.940000 %\n",
" epoch 91, minibatch 100/100, test error of best model 0.960000 %\n",
"training @ iter = 9100\n",
"epoch 92, minibatch 100/100, validation error 0.950000 %\n",
"training @ iter = 9200\n",
"epoch 93, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 9300\n",
"epoch 94, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 9400\n",
"epoch 95, minibatch 100/100, validation error 0.930000 %\n",
" epoch 95, minibatch 100/100, test error of best model 0.960000 %\n",
"training @ iter = 9500\n",
"epoch 96, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 9600\n",
"epoch 97, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 9700\n",
"epoch 98, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 9800\n",
"epoch 99, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 9900\n",
"epoch 100, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 10000\n",
"epoch 101, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 10100\n",
"epoch 102, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 10200\n",
"epoch 103, minibatch 100/100, validation error 0.950000 %\n",
"training @ iter = 10300\n",
"epoch 104, minibatch 100/100, validation error 0.950000 %\n",
"training @ iter = 10400\n",
"epoch 105, minibatch 100/100, validation error 0.950000 %\n",
"training @ iter = 10500\n",
"epoch 106, minibatch 100/100, validation error 0.950000 %\n",
"training @ iter = 10600\n",
"epoch 107, minibatch 100/100, validation error 0.950000 %\n",
"training @ iter = 10700\n",
"epoch 108, minibatch 100/100, validation error 0.950000 %\n",
"training @ iter = 10800\n",
"epoch 109, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 10900\n",
"epoch 110, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 11000\n",
"epoch 111, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 11100\n",
"epoch 112, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 11200\n",
"epoch 113, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 11300\n",
"epoch 114, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 11400\n",
"epoch 115, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 11500\n",
"epoch 116, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 11600\n",
"epoch 117, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 11700\n",
"epoch 118, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 11800\n",
"epoch 119, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 11900\n",
"epoch 120, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12000\n",
"epoch 121, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12100\n",
"epoch 122, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12200\n",
"epoch 123, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12300\n",
"epoch 124, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12400\n",
"epoch 125, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12500\n",
"epoch 126, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12600\n",
"epoch 127, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12700\n",
"epoch 128, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12800\n",
"epoch 129, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 12900\n",
"epoch 130, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 13000\n",
"epoch 131, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 13100\n",
"epoch 132, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 13200\n",
"epoch 133, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 13300\n",
"epoch 134, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 13400\n",
"epoch 135, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 13500\n",
"epoch 136, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 13600\n",
"epoch 137, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 13700\n",
"epoch 138, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 13800\n",
"epoch 139, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 13900\n",
"epoch 140, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 14000\n",
"epoch 141, minibatch 100/100, validation error 0.950000 %\n",
"training @ iter = 14100\n",
"epoch 142, minibatch 100/100, validation error 0.950000 %\n",
"training @ iter = 14200\n",
"epoch 143, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 14300\n",
"epoch 144, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 14400\n",
"epoch 145, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 14500\n",
"epoch 146, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 14600\n",
"epoch 147, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 14700\n",
"epoch 148, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 14800\n",
"epoch 149, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 14900\n",
"epoch 150, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 15000\n",
"epoch 151, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 15100\n",
"epoch 152, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 15200\n",
"epoch 153, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 15300\n",
"epoch 154, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 15400\n",
"epoch 155, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 15500\n",
"epoch 156, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 15600\n",
"epoch 157, minibatch 100/100, validation error 0.940000 %\n",
"training @ iter = 15700\n",
"epoch 158, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 15800\n",
"epoch 159, minibatch 100/100, validation error 0.930000 %\n",
"training @ iter = 15900\n",
"epoch 160, minibatch 100/100, validation error 0.920000 %\n",
" epoch 160, minibatch 100/100, test error of best model 0.930000 %\n",
"training @ iter = 16000\n",
"epoch 161, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 16100\n",
"epoch 162, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 16200\n",
"epoch 163, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 16300\n",
"epoch 164, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 16400\n",
"epoch 165, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 16500\n",
"epoch 166, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 16600\n",
"epoch 167, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 16700\n",
"epoch 168, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 16800\n",
"epoch 169, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 16900\n",
"epoch 170, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17000\n",
"epoch 171, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17100\n",
"epoch 172, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17200\n",
"epoch 173, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17300\n",
"epoch 174, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17400\n",
"epoch 175, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17500\n",
"epoch 176, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17600\n",
"epoch 177, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17700\n",
"epoch 178, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17800\n",
"epoch 179, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 17900\n",
"epoch 180, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18000\n",
"epoch 181, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18100\n",
"epoch 182, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18200\n",
"epoch 183, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18300\n",
"epoch 184, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18400\n",
"epoch 185, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18500\n",
"epoch 186, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18600\n",
"epoch 187, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18700\n",
"epoch 188, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18800\n",
"epoch 189, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 18900\n",
"epoch 190, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 19000\n",
"epoch 191, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 19100\n",
"epoch 192, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 19200\n",
"epoch 193, minibatch 100/100, validation error 0.920000 %\n",
"training @ iter = 19300\n",
"epoch 194, minibatch 100/100, validation error 0.910000 %\n",
" epoch 194, minibatch 100/100, test error of best model 0.920000 %\n",
"training @ iter = 19400\n",
"epoch 195, minibatch 100/100, validation error 0.910000 %\n",
"training @ iter = 19500\n",
"epoch 196, minibatch 100/100, validation error 0.910000 %\n",
"training @ iter = 19600\n",
"epoch 197, minibatch 100/100, validation error 0.910000 %\n",
"training @ iter = 19700\n",
"epoch 198, minibatch 100/100, validation error 0.910000 %\n",
"training @ iter = 19800\n",
"epoch 199, minibatch 100/100, validation error 0.910000 %\n",
"training @ iter = 19900\n",
"epoch 200, minibatch 100/100, validation error 0.910000 %\n",
"Optimization complete.\n",
"Best validation score of 0.910000 % obtained at iteration 19400, with test performance 0.920000 %\n",
"The code for file convolutional_mlp.py ran for 42.60m\n",
"CPU times: user 6.49 s, sys: 603 ms, total: 7.09 s\n",
"Wall time: 42min 43s\n"
]
}
],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=gpu,floatX=float32 python DeepLearningTutorials/code/convolutional_mlp.py"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"... loading data\n",
"... building the model\n",
"... training the model\n",
"epoch 1, minibatch 83/83, validation error 12.458333 %\n",
" epoch 1, minibatch 83/83, test error of best model 12.375000 %\n",
"epoch 2, minibatch 83/83, validation error 11.010417 %\n",
" epoch 2, minibatch 83/83, test error of best model 10.958333 %\n",
"epoch 3, minibatch 83/83, validation error 10.312500 %\n",
" epoch 3, minibatch 83/83, test error of best model 10.312500 %\n",
"epoch 4, minibatch 83/83, validation error 9.875000 %\n",
" epoch 4, minibatch 83/83, test error of best model 9.833333 %\n",
"epoch 5, minibatch 83/83, validation error 9.562500 %\n",
" epoch 5, minibatch 83/83, test error of best model 9.479167 %\n",
"epoch 6, minibatch 83/83, validation error 9.322917 %\n",
" epoch 6, minibatch 83/83, test error of best model 9.291667 %\n",
"epoch 7, minibatch 83/83, validation error 9.187500 %\n",
" epoch 7, minibatch 83/83, test error of best model 9.000000 %\n",
"epoch 8, minibatch 83/83, validation error 8.989583 %\n",
" epoch 8, minibatch 83/83, test error of best model 8.958333 %\n",
"epoch 9, minibatch 83/83, validation error 8.937500 %\n",
" epoch 9, minibatch 83/83, test error of best model 8.812500 %\n",
"epoch 10, minibatch 83/83, validation error 8.750000 %\n",
" epoch 10, minibatch 83/83, test error of best model 8.666667 %\n",
"epoch 11, minibatch 83/83, validation error 8.666667 %\n",
" epoch 11, minibatch 83/83, test error of best model 8.520833 %\n",
"epoch 12, minibatch 83/83, validation error 8.583333 %\n",
" epoch 12, minibatch 83/83, test error of best model 8.416667 %\n",
"epoch 13, minibatch 83/83, validation error 8.489583 %\n",
" epoch 13, minibatch 83/83, test error of best model 8.291667 %\n",
"epoch 14, minibatch 83/83, validation error 8.427083 %\n",
" epoch 14, minibatch 83/83, test error of best model 8.281250 %\n",
"epoch 15, minibatch 83/83, validation error 8.354167 %\n",
" epoch 15, minibatch 83/83, test error of best model 8.270833 %\n",
"epoch 16, minibatch 83/83, validation error 8.302083 %\n",
" epoch 16, minibatch 83/83, test error of best model 8.239583 %\n",
"epoch 17, minibatch 83/83, validation error 8.250000 %\n",
" epoch 17, minibatch 83/83, test error of best model 8.177083 %\n",
"epoch 18, minibatch 83/83, validation error 8.229167 %\n",
" epoch 18, minibatch 83/83, test error of best model 8.062500 %\n",
"epoch 19, minibatch 83/83, validation error 8.260417 %\n",
"epoch 20, minibatch 83/83, validation error 8.260417 %\n",
"epoch 21, minibatch 83/83, validation error 8.208333 %\n",
" epoch 21, minibatch 83/83, test error of best model 7.947917 %\n",
"epoch 22, minibatch 83/83, validation error 8.187500 %\n",
" epoch 22, minibatch 83/83, test error of best model 7.927083 %\n",
"epoch 23, minibatch 83/83, validation error 8.156250 %\n",
" epoch 23, minibatch 83/83, test error of best model 7.958333 %\n",
"epoch 24, minibatch 83/83, validation error 8.114583 %\n",
" epoch 24, minibatch 83/83, test error of best model 7.947917 %\n",
"epoch 25, minibatch 83/83, validation error 8.093750 %\n",
" epoch 25, minibatch 83/83, test error of best model 7.947917 %\n",
"epoch 26, minibatch 83/83, validation error 8.104167 %\n",
"epoch 27, minibatch 83/83, validation error 8.104167 %\n",
"epoch 28, minibatch 83/83, validation error 8.052083 %\n",
" epoch 28, minibatch 83/83, test error of best model 7.843750 %\n",
"epoch 29, minibatch 83/83, validation error 8.052083 %\n",
"epoch 30, minibatch 83/83, validation error 8.031250 %\n",
" epoch 30, minibatch 83/83, test error of best model 7.843750 %\n",
"epoch 31, minibatch 83/83, validation error 8.010417 %\n",
" epoch 31, minibatch 83/83, test error of best model 7.833333 %\n",
"epoch 32, minibatch 83/83, validation error 7.979167 %\n",
" epoch 32, minibatch 83/83, test error of best model 7.812500 %\n",
"epoch 33, minibatch 83/83, validation error 7.947917 %\n",
" epoch 33, minibatch 83/83, test error of best model 7.739583 %\n",
"epoch 34, minibatch 83/83, validation error 7.875000 %\n",
" epoch 34, minibatch 83/83, test error of best model 7.729167 %\n",
"epoch 35, minibatch 83/83, validation error 7.885417 %\n",
"epoch 36, minibatch 83/83, validation error 7.843750 %\n",
" epoch 36, minibatch 83/83, test error of best model 7.697917 %\n",
"epoch 37, minibatch 83/83, validation error 7.802083 %\n",
" epoch 37, minibatch 83/83, test error of best model 7.635417 %\n",
"epoch 38, minibatch 83/83, validation error 7.812500 %\n",
"epoch 39, minibatch 83/83, validation error 7.812500 %\n",
"epoch 40, minibatch 83/83, validation error 7.822917 %\n",
"epoch 41, minibatch 83/83, validation error 7.791667 %\n",
" epoch 41, minibatch 83/83, test error of best model 7.625000 %\n",
"epoch 42, minibatch 83/83, validation error 7.770833 %\n",
" epoch 42, minibatch 83/83, test error of best model 7.614583 %\n",
"epoch 43, minibatch 83/83, validation error 7.750000 %\n",
" epoch 43, minibatch 83/83, test error of best model 7.593750 %\n",
"epoch 44, minibatch 83/83, validation error 7.739583 %\n",
" epoch 44, minibatch 83/83, test error of best model 7.593750 %\n",
"epoch 45, minibatch 83/83, validation error 7.739583 %\n",
"epoch 46, minibatch 83/83, validation error 7.739583 %\n",
"epoch 47, minibatch 83/83, validation error 7.739583 %\n",
"epoch 48, minibatch 83/83, validation error 7.708333 %\n",
" epoch 48, minibatch 83/83, test error of best model 7.583333 %\n",
"epoch 49, minibatch 83/83, validation error 7.677083 %\n",
" epoch 49, minibatch 83/83, test error of best model 7.572917 %\n",
"epoch 50, minibatch 83/83, validation error 7.677083 %\n",
"epoch 51, minibatch 83/83, validation error 7.677083 %\n",
"epoch 52, minibatch 83/83, validation error 7.656250 %\n",
" epoch 52, minibatch 83/83, test error of best model 7.541667 %\n",
"epoch 53, minibatch 83/83, validation error 7.656250 %\n",
"epoch 54, minibatch 83/83, validation error 7.635417 %\n",
" epoch 54, minibatch 83/83, test error of best model 7.520833 %\n",
"epoch 55, minibatch 83/83, validation error 7.635417 %\n",
"epoch 56, minibatch 83/83, validation error 7.635417 %\n",
"epoch 57, minibatch 83/83, validation error 7.604167 %\n",
" epoch 57, minibatch 83/83, test error of best model 7.489583 %\n",
"epoch 58, minibatch 83/83, validation error 7.583333 %\n",
" epoch 58, minibatch 83/83, test error of best model 7.458333 %\n",
"epoch 59, minibatch 83/83, validation error 7.572917 %\n",
" epoch 59, minibatch 83/83, test error of best model 7.468750 %\n",
"epoch 60, minibatch 83/83, validation error 7.572917 %\n",
"epoch 61, minibatch 83/83, validation error 7.583333 %\n",
"epoch 62, minibatch 83/83, validation error 7.572917 %\n",
" epoch 62, minibatch 83/83, test error of best model 7.520833 %\n",
"epoch 63, minibatch 83/83, validation error 7.562500 %\n",
" epoch 63, minibatch 83/83, test error of best model 7.510417 %\n",
"epoch 64, minibatch 83/83, validation error 7.572917 %\n",
"epoch 65, minibatch 83/83, validation error 7.562500 %\n",
"epoch 66, minibatch 83/83, validation error 7.552083 %\n",
" epoch 66, minibatch 83/83, test error of best model 7.520833 %\n",
"epoch 67, minibatch 83/83, validation error 7.552083 %\n",
"epoch 68, minibatch 83/83, validation error 7.531250 %\n",
" epoch 68, minibatch 83/83, test error of best model 7.520833 %\n",
"epoch 69, minibatch 83/83, validation error 7.531250 %\n",
"epoch 70, minibatch 83/83, validation error 7.510417 %\n",
" epoch 70, minibatch 83/83, test error of best model 7.500000 %\n",
"epoch 71, minibatch 83/83, validation error 7.520833 %\n",
"epoch 72, minibatch 83/83, validation error 7.510417 %\n",
"epoch 73, minibatch 83/83, validation error 7.500000 %\n",
" epoch 73, minibatch 83/83, test error of best model 7.489583 %\n",
"Optimization complete with best validation score of 7.500000 %,with test performance 7.489583 %\n",
"The code run for 74 epochs, with 3.236080 epochs/sec\n",
"The code for file logistic_sgd.py ran for 22.9s\n",
"CPU times: user 195 ms, sys: 27.6 ms, total: 223 ms\n",
"Wall time: 26.3 s\n"
]
}
],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=cpu python DeepLearningTutorials/code/logistic_sgd.py"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"... loading data\n",
"... building the model\n",
"... training\n",
"training @ iter = 0\n",
"epoch 1, minibatch 100/100, validation error 9.230000 %\n",
" epoch 1, minibatch 100/100, test error of best model 9.520000 %\n",
"training @ iter = 100\n",
"epoch 2, minibatch 100/100, validation error 6.180000 %\n",
" epoch 2, minibatch 100/100, test error of best model 6.500000 %\n",
"training @ iter = 200\n",
"epoch 3, minibatch 100/100, validation error 4.640000 %\n",
" epoch 3, minibatch 100/100, test error of best model 4.850000 %\n",
"training @ iter = 300\n",
"epoch 4, minibatch 100/100, validation error 3.500000 %\n",
" epoch 4, minibatch 100/100, test error of best model 3.910000 %\n",
"training @ iter = 400\n",
"epoch 5, minibatch 100/100, validation error 3.020000 %\n",
" epoch 5, minibatch 100/100, test error of best model 3.260000 %\n",
"training @ iter = 500\n",
"epoch 6, minibatch 100/100, validation error 2.780000 %\n",
" epoch 6, minibatch 100/100, test error of best model 2.800000 %\n",
"training @ iter = 600\n",
"epoch 7, minibatch 100/100, validation error 2.480000 %\n",
" epoch 7, minibatch 100/100, test error of best model 2.500000 %\n",
"training @ iter = 700\n",
"epoch 8, minibatch 100/100, validation error 2.290000 %\n",
" epoch 8, minibatch 100/100, test error of best model 2.220000 %\n",
"training @ iter = 800\n",
"epoch 9, minibatch 100/100, validation error 2.160000 %\n",
" epoch 9, minibatch 100/100, test error of best model 2.010000 %\n",
"training @ iter = 900\n",
"epoch 10, minibatch 100/100, validation error 1.970000 %\n",
" epoch 10, minibatch 100/100, test error of best model 1.880000 %\n",
"training @ iter = 1000\n",
"CPU times: user 6.97 s, sys: 93 ms, total: 7.06 s\n",
"Wall time: 20min\n"
]
}
],
"source": [
"%%time\n",
"!THEANO_FLAGS=device=cpu timeout 1200 python DeepLearningTutorials/code/convolutional_mlp.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 2"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using gpu device 0: GRID K520 (CNMeM is disabled, cuDNN Version is too old. Update to v5, was 3007.)\n"
]
},
{
"data": {
"text/plain": [
"array(6.748379707336426, dtype=float32)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import theano.tensor as T\n",
"from theano.tensor.shared_randomstreams import RandomStreams\n",
"from theano import function, shared\n",
"from theano.compile.sharedvalue import SharedVariable\n",
"import numpy as np\n",
"\n",
"srng = RandomStreams(seed=1234)\n",
"\n",
"x = T.fvector()\n",
"a = srng.uniform((10,))\n",
"a_shared = shared(np.zeros(10, dtype=np.float32))\n",
"\n",
"b = srng.uniform((10,))\n",
"b_shared = shared(np.zeros(10, dtype=np.float32))\n",
"\n",
"z = (x + a).T.dot(b)\n",
"f = function([x], z, updates=[(a_shared, a), (b_shared, b)], allow_input_downcast=True)\n",
"\n",
"f(np.ones(10))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.75718063, 0.1130526 , 0.00607781, 0.87213892, 0.31027076,\n",
" 0.24150866, 0.56740797, 0.73226672, 0.97511917, 0.43544379], dtype=float32)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_shared.get_value()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.71752667, 0.55341953, 0.78824526, 0.49578699, 0.81835175,\n",
" 0.22796483, 0.05997206, 0.18579371, 0.31112736, 0.53273529], dtype=float32)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b_shared.get_value()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"6.7483800318398748"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(np.ones((10,)) + a_shared.get_value()).T.dot(b_shared.get_value())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 3"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fib(10): 55\n",
"fib(20): 6765\n"
]
}
],
"source": [
"def fib(n):\n",
" if n <= 1:\n",
" return 0\n",
" elif n == 2:\n",
" return 1\n",
" else:\n",
" a = shared(0)\n",
" b = shared(1)\n",
" f = function([], a + b, updates=[(b, a + b), (a, b)])\n",
" for i in range(1, n):\n",
" f()\n",
" \n",
" return b.get_value()\n",
" \n",
"print('fib(10): {}'.format(fib(10)))\n",
"print('fib(20): {}'.format(fib(20)))"
]
}
],
"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.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}