|
123 | 123 | "outputs": [], |
124 | 124 | "source": [ |
125 | 125 | "# call this every iteration that we need to get\n", |
126 | | - "# a batch of episodes. All environment interaction happend here \n", |
| 126 | + "# a batch of episodes. All environment interactions happend here \n", |
127 | 127 | "def iterate_batches(env, net, batch_size):\n", |
128 | 128 | " # this function is called to generate training batches\n", |
129 | 129 | " # as discussed in lecture, the algorithm will \n", |
|
379 | 379 | " # change observation space to one hot encoded version \n", |
380 | 380 | " # we do this so that our neural network can stay the same\n", |
381 | 381 | " # this defines the vector of length N, with values of 0.0 up to 1.0\n", |
382 | | - " # In the gym a box is like a tensor (ugh)\n", |
| 382 | + " # In the gym a box is like a tensor...\n", |
383 | 383 | " self.observation_space = gym.spaces.Box(0.0, 1.0, (env.observation_space.n, ), \n", |
384 | 384 | " dtype=np.float32)\n", |
385 | 385 | "\n", |
|
465 | 465 | { |
466 | 466 | "cell_type": "code", |
467 | 467 | "execution_count": 20, |
468 | | - "metadata": { |
469 | | - "scrolled": false |
470 | | - }, |
| 468 | + "metadata": {}, |
471 | 469 | "outputs": [ |
472 | 470 | { |
473 | 471 | "name": "stdout", |
|
545 | 543 | "\n", |
546 | 544 | "**Why was this not working?**\n", |
547 | 545 | "\n", |
548 | | - "Firstly, the input space is sparse so its harder to learn new observations from the randomized neural network, especially for rarely occurring observations (like when we get past the first few steps). Also, the reward is only given at the end and its unlikely for us to reach the end, so we need to do alot of exploring... And most of the time, there is not percentile that actually worked, so we never learn to emulate the output. \n", |
| 546 | + "Firstly, the input space is sparse so its harder to learn new observations from the randomized neural network, especially for rarely occurring observations (like when we get past the first few steps). This is oour first insight into sample efficiency of an algorithm. The cross entropy method does not seem to be sample efficient when working with a sparse state space. Also, the reward is only given at the end and its unlikely for us to reach the end, so we need to do alot of exploring... And most of the time, there is not percentile that actually worked, so we never learn to emulate the output. \n", |
549 | 547 | "\n", |
550 | 548 | "It seems like even this simple problem is hard for cross entropy to solve. Perhaps we should go back to the basics of learning optimal policies? Yes! Let's see about value iteration.\n", |
551 | 549 | "\n", |
|
678 | 676 | { |
679 | 677 | "cell_type": "code", |
680 | 678 | "execution_count": 20, |
681 | | - "metadata": { |
682 | | - "scrolled": false |
683 | | - }, |
| 679 | + "metadata": {}, |
684 | 680 | "outputs": [ |
685 | 681 | { |
686 | 682 | "name": "stdout", |
|
729 | 725 | { |
730 | 726 | "cell_type": "code", |
731 | 727 | "execution_count": 21, |
732 | | - "metadata": { |
733 | | - "scrolled": false |
734 | | - }, |
| 728 | + "metadata": {}, |
735 | 729 | "outputs": [ |
736 | 730 | { |
737 | 731 | "name": "stdout", |
|
924 | 918 | { |
925 | 919 | "cell_type": "code", |
926 | 920 | "execution_count": 4, |
927 | | - "metadata": { |
928 | | - "scrolled": false |
929 | | - }, |
| 921 | + "metadata": {}, |
930 | 922 | "outputs": [ |
931 | 923 | { |
932 | 924 | "name": "stdout", |
|
1176 | 1168 | { |
1177 | 1169 | "cell_type": "code", |
1178 | 1170 | "execution_count": 10, |
1179 | | - "metadata": { |
1180 | | - "scrolled": false |
1181 | | - }, |
| 1171 | + "metadata": {}, |
1182 | 1172 | "outputs": [ |
1183 | 1173 | { |
1184 | 1174 | "name": "stdout", |
|
1508 | 1498 | "cell_type": "code", |
1509 | 1499 | "execution_count": 1, |
1510 | 1500 | "metadata": { |
1511 | | - "collapsed": true |
| 1501 | + "collapsed": true, |
| 1502 | + "jupyter": { |
| 1503 | + "outputs_hidden": true |
| 1504 | + } |
1512 | 1505 | }, |
1513 | 1506 | "outputs": [], |
1514 | 1507 | "source": [ |
|
1649 | 1642 | "cell_type": "code", |
1650 | 1643 | "execution_count": 2, |
1651 | 1644 | "metadata": { |
1652 | | - "collapsed": true |
| 1645 | + "collapsed": true, |
| 1646 | + "jupyter": { |
| 1647 | + "outputs_hidden": true |
| 1648 | + } |
1653 | 1649 | }, |
1654 | 1650 | "outputs": [], |
1655 | 1651 | "source": [ |
|
1700 | 1696 | { |
1701 | 1697 | "cell_type": "code", |
1702 | 1698 | "execution_count": 4, |
1703 | | - "metadata": { |
1704 | | - "scrolled": false |
1705 | | - }, |
| 1699 | + "metadata": {}, |
1706 | 1700 | "outputs": [ |
1707 | 1701 | { |
1708 | 1702 | "name": "stdout", |
|
1861 | 1855 | "Best mean reward updated 0.540 -> 0.550, model saved\n", |
1862 | 1856 | "Best mean reward updated 0.550 -> 0.560, model saved\n", |
1863 | 1857 | "Best mean reward updated 0.560 -> 0.570, model saved\n", |
1864 | | - "Best mean reward updated 0.570 -> 0.580, model saved\n" |
| 1858 | + "Best mean reward updated 0.570 -> 0.580, model saved\n", |
| 1859 | + "Best mean reward updated 0.580 -> 0.590, model saved\n", |
| 1860 | + "Best mean reward updated 0.590 -> 0.600, model saved\n", |
| 1861 | + "Best mean reward updated 0.600 -> 0.610, model saved\n", |
| 1862 | + "Best mean reward updated 0.610 -> 0.620, model saved\n", |
| 1863 | + "103300: done 8920 iterations, mean reward 0.620, eps 0.00\n", |
| 1864 | + "Best mean reward updated 0.620 -> 0.630, model saved\n", |
| 1865 | + "Best mean reward updated 0.630 -> 0.640, model saved\n", |
| 1866 | + "Best mean reward updated 0.640 -> 0.650, model saved\n", |
| 1867 | + "Best mean reward updated 0.650 -> 0.660, model saved\n", |
| 1868 | + "Best mean reward updated 0.660 -> 0.670, model saved\n", |
| 1869 | + "Best mean reward updated 0.670 -> 0.680, model saved\n", |
| 1870 | + "Best mean reward updated 0.680 -> 0.690, model saved\n", |
| 1871 | + "Best mean reward updated 0.690 -> 0.700, model saved\n", |
| 1872 | + "Best mean reward updated 0.700 -> 0.710, model saved\n", |
| 1873 | + "Best mean reward updated 0.710 -> 0.720, model saved\n", |
| 1874 | + "Best mean reward updated 0.720 -> 0.730, model saved\n", |
| 1875 | + "Best mean reward updated 0.730 -> 0.740, model saved\n", |
| 1876 | + "108400: done 9053 iterations, mean reward 0.690, eps 0.00\n", |
| 1877 | + "112700: done 9163 iterations, mean reward 0.580, eps 0.00\n", |
| 1878 | + "113200: done 9172 iterations, mean reward 0.590, eps 0.00\n", |
| 1879 | + "113900: done 9191 iterations, mean reward 0.570, eps 0.00\n", |
| 1880 | + "121200: done 9360 iterations, mean reward 0.690, eps 0.00\n", |
| 1881 | + "123400: done 9408 iterations, mean reward 0.710, eps 0.00\n", |
| 1882 | + "123600: done 9415 iterations, mean reward 0.710, eps 0.00\n", |
| 1883 | + "123800: done 9420 iterations, mean reward 0.730, eps 0.00\n", |
| 1884 | + "125300: done 9454 iterations, mean reward 0.650, eps 0.00\n", |
| 1885 | + "126500: done 9479 iterations, mean reward 0.630, eps 0.00\n", |
| 1886 | + "130100: done 9561 iterations, mean reward 0.730, eps 0.00\n", |
| 1887 | + "Best mean reward updated 0.740 -> 0.750, model saved\n", |
| 1888 | + "Best mean reward updated 0.750 -> 0.760, model saved\n", |
| 1889 | + "Best mean reward updated 0.760 -> 0.770, model saved\n", |
| 1890 | + "131000: done 9585 iterations, mean reward 0.770, eps 0.00\n", |
| 1891 | + "Best mean reward updated 0.770 -> 0.780, model saved\n", |
| 1892 | + "Best mean reward updated 0.780 -> 0.790, model saved\n", |
| 1893 | + "Best mean reward updated 0.790 -> 0.800, model saved\n", |
| 1894 | + "Best mean reward updated 0.800 -> 0.810, model saved\n", |
| 1895 | + "Solved in 132361 frames!\n" |
1865 | 1896 | ] |
1866 | 1897 | }, |
1867 | 1898 | { |
|
2023 | 2054 | "cell_type": "code", |
2024 | 2055 | "execution_count": 5, |
2025 | 2056 | "metadata": { |
2026 | | - "collapsed": true |
| 2057 | + "collapsed": true, |
| 2058 | + "jupyter": { |
| 2059 | + "outputs_hidden": true |
| 2060 | + } |
2027 | 2061 | }, |
2028 | 2062 | "outputs": [], |
2029 | 2063 | "source": [ |
|
2138 | 2172 | { |
2139 | 2173 | "cell_type": "code", |
2140 | 2174 | "execution_count": null, |
2141 | | - "metadata": { |
2142 | | - "scrolled": false |
2143 | | - }, |
| 2175 | + "metadata": {}, |
2144 | 2176 | "outputs": [], |
2145 | 2177 | "source": [ |
2146 | 2178 | "# load up some utilities \n", |
|
2208 | 2240 | { |
2209 | 2241 | "cell_type": "code", |
2210 | 2242 | "execution_count": null, |
2211 | | - "metadata": { |
2212 | | - "scrolled": false |
2213 | | - }, |
| 2243 | + "metadata": {}, |
2214 | 2244 | "outputs": [], |
2215 | 2245 | "source": [ |
2216 | 2246 | "# training (no resets of the Agent or training values)\n", |
|
2495 | 2525 | "name": "python", |
2496 | 2526 | "nbconvert_exporter": "python", |
2497 | 2527 | "pygments_lexer": "ipython3", |
2498 | | - "version": "3.8.16" |
| 2528 | + "version": "3.11.9" |
2499 | 2529 | } |
2500 | 2530 | }, |
2501 | 2531 | "nbformat": 4, |
2502 | | - "nbformat_minor": 2 |
| 2532 | + "nbformat_minor": 4 |
2503 | 2533 | } |
0 commit comments