├── .gitignore ├── .gitmodules ├── .ipynb_checkpoints └── Untitled-checkpoint.ipynb ├── .travis.yml ├── README.md ├── docs ├── backprop_free_dpg │ ├── diagrams │ │ ├── com1v1.tex │ │ ├── com1v2.tex │ │ └── com1v3.tex │ ├── experimentation.tex │ ├── main.pdf │ ├── main.tex │ └── nips15submit_e.sty ├── presentations │ ├── demoday1 │ │ ├── 5-Figure6-1.png │ │ ├── BlueGold_fill_small.png │ │ ├── BlueGold_fill_small_name.png │ │ ├── Pac-man.png │ │ ├── White_outline_small_name_transparent.png │ │ ├── White_outline_small_transparent.png │ │ ├── doom.png │ │ ├── dope.png │ │ ├── pres.pdf │ │ └── pres.tex │ ├── progress │ │ ├── progress1.tex │ │ └── progress2.tex │ └── symposium_poster │ │ ├── beamerposter.sty │ │ ├── beamerthemeconfposter.sty │ │ ├── logo.png │ │ ├── placeholder.jpg │ │ ├── poster.tex │ │ └── sample.bib └── whitepaper │ ├── .gitignore │ ├── appendices.tex │ ├── conclusion.tex │ ├── implementation.tex │ ├── introduction.tex │ ├── learning.tex │ ├── main.tex │ ├── model.tex │ ├── model │ ├── core.tex │ ├── ctuim.tex │ ├── ctuimdiag.tex │ └── univ.tex │ ├── nips15submit_e.sty │ └── openbrain.bib ├── experiments ├── brain │ ├── __init__.py │ ├── actor_network.py │ ├── common │ │ ├── filter_env.py │ │ ├── ou_noise.py │ │ ├── replay_buffer.py │ │ └── utils.py │ ├── critic_network.py │ ├── ddpg.py │ ├── polynomial_critic.py │ └── sub_critics.py ├── dataInterface.py ├── experiment1.py ├── experiment2.py ├── extractData.sh └── serialize_tensorboard.py ├── explorations └── README.md └── old ├── erl └── brainlib │ └── src │ ├── brain.erl │ ├── connector.erl │ ├── extra_math.erl │ ├── game.erl │ ├── mcdemo.erl │ ├── neuron.erl │ └── test.erl └── src ├── brain.py ├── pacman_demo ├── __init__.py ├── autograder.py ├── commands.txt ├── eightpuzzle.py ├── game.py ├── ghostAgents.py ├── grading.py ├── graphicsDisplay.py ├── graphicsUtils.py ├── keyboardAgents.py ├── layout.py ├── layouts │ ├── bigCorners.lay │ ├── bigMaze.lay │ ├── bigSafeSearch.lay │ ├── bigSearch.lay │ ├── boxSearch.lay │ ├── capsuleClassic.lay │ ├── contestClassic.lay │ ├── contoursMaze.lay │ ├── greedySearch.lay │ ├── mediumClassic.lay │ ├── mediumCorners.lay │ ├── mediumDottedMaze.lay │ ├── mediumMaze.lay │ ├── mediumSafeSearch.lay │ ├── mediumScaryMaze.lay │ ├── mediumSearch.lay │ ├── minimaxClassic.lay │ ├── oddSearch.lay │ ├── openClassic.lay │ ├── openMaze.lay │ ├── openSearch.lay │ ├── originalClassic.lay │ ├── smallClassic.lay │ ├── smallMaze.lay │ ├── smallSafeSearch.lay │ ├── smallSearch.lay │ ├── testClassic.lay │ ├── testMaze.lay │ ├── testSearch.lay │ ├── tinyCorners.lay │ ├── tinyMaze.lay │ ├── tinySafeSearch.lay │ ├── tinySearch.lay │ ├── trappedClassic.lay │ ├── trickyClassic.lay │ └── trickySearch.lay ├── multiAgents.py ├── pacman.py ├── pacmanAgents.py ├── projectParams.py ├── search.py ├── searchAgents.py ├── search_and_gamesTestClasses.py ├── testClasses.py ├── testParser.py ├── test_cases │ ├── CONFIG │ ├── q1 │ │ ├── CONFIG │ │ ├── graph_backtrack.solution │ │ ├── graph_backtrack.test │ │ ├── graph_bfs_vs_dfs.solution │ │ ├── graph_bfs_vs_dfs.test │ │ ├── graph_infinite.solution │ │ ├── graph_infinite.test │ │ ├── graph_manypaths.solution │ │ ├── graph_manypaths.test │ │ ├── pacman_1.solution │ │ └── pacman_1.test │ ├── q2 │ │ ├── CONFIG │ │ ├── astar_0.solution │ │ ├── astar_0.test │ │ ├── astar_1_graph_heuristic.solution │ │ ├── astar_1_graph_heuristic.test │ │ ├── astar_2_manhattan.solution │ │ ├── astar_2_manhattan.test │ │ ├── astar_3_goalAtDequeue.solution │ │ ├── astar_3_goalAtDequeue.test │ │ ├── graph_backtrack.solution │ │ ├── graph_backtrack.test │ │ ├── graph_manypaths.solution │ │ └── graph_manypaths.test │ ├── q3 │ │ ├── CONFIG │ │ ├── corner_tiny_corner.solution │ │ └── corner_tiny_corner.test │ ├── q4 │ │ ├── CONFIG │ │ ├── corner_sanity_1.solution │ │ ├── corner_sanity_1.test │ │ ├── corner_sanity_2.solution │ │ ├── corner_sanity_2.test │ │ ├── corner_sanity_3.solution │ │ ├── corner_sanity_3.test │ │ ├── medium_corners.solution │ │ └── medium_corners.test │ ├── q5 │ │ ├── CONFIG │ │ ├── food_heuristic_1.solution │ │ ├── food_heuristic_1.test │ │ ├── food_heuristic_10.solution │ │ ├── food_heuristic_10.test │ │ ├── food_heuristic_11.solution │ │ ├── food_heuristic_11.test │ │ ├── food_heuristic_12.solution │ │ ├── food_heuristic_12.test │ │ ├── food_heuristic_13.solution │ │ ├── food_heuristic_13.test │ │ ├── food_heuristic_14.solution │ │ ├── food_heuristic_14.test │ │ ├── food_heuristic_15.solution │ │ ├── food_heuristic_15.test │ │ ├── food_heuristic_16.solution │ │ ├── food_heuristic_16.test │ │ ├── food_heuristic_17.solution │ │ ├── food_heuristic_17.test │ │ ├── food_heuristic_2.solution │ │ ├── food_heuristic_2.test │ │ ├── food_heuristic_3.solution │ │ ├── food_heuristic_3.test │ │ ├── food_heuristic_4.solution │ │ ├── food_heuristic_4.test │ │ ├── food_heuristic_5.solution │ │ ├── food_heuristic_5.test │ │ ├── food_heuristic_6.solution │ │ ├── food_heuristic_6.test │ │ ├── food_heuristic_7.solution │ │ ├── food_heuristic_7.test │ │ ├── food_heuristic_8.solution │ │ ├── food_heuristic_8.test │ │ ├── food_heuristic_9.solution │ │ ├── food_heuristic_9.test │ │ ├── food_heuristic_grade_tricky.solution │ │ └── food_heuristic_grade_tricky.test │ ├── q6 │ │ ├── CONFIG │ │ ├── grade-agent.solution │ │ └── grade-agent.test │ ├── q7 │ │ ├── 0-lecture-6-tree.solution │ │ ├── 0-lecture-6-tree.test │ │ ├── 0-small-tree.solution │ │ ├── 0-small-tree.test │ │ ├── 1-1-minmax.solution │ │ ├── 1-1-minmax.test │ │ ├── 1-2-minmax.solution │ │ ├── 1-2-minmax.test │ │ ├── 1-3-minmax.solution │ │ ├── 1-3-minmax.test │ │ ├── 1-4-minmax.solution │ │ ├── 1-4-minmax.test │ │ ├── 1-5-minmax.solution │ │ ├── 1-5-minmax.test │ │ ├── 1-6-minmax.solution │ │ ├── 1-6-minmax.test │ │ ├── 1-7-minmax.solution │ │ ├── 1-7-minmax.test │ │ ├── 1-8-minmax.solution │ │ ├── 1-8-minmax.test │ │ ├── 2-1a-vary-depth.solution │ │ ├── 2-1a-vary-depth.test │ │ ├── 2-1b-vary-depth.solution │ │ ├── 2-1b-vary-depth.test │ │ ├── 2-2a-vary-depth.solution │ │ ├── 2-2a-vary-depth.test │ │ ├── 2-2b-vary-depth.solution │ │ ├── 2-2b-vary-depth.test │ │ ├── 2-3a-vary-depth.solution │ │ ├── 2-3a-vary-depth.test │ │ ├── 2-3b-vary-depth.solution │ │ ├── 2-3b-vary-depth.test │ │ ├── 2-4a-vary-depth.solution │ │ ├── 2-4a-vary-depth.test │ │ ├── 2-4b-vary-depth.solution │ │ ├── 2-4b-vary-depth.test │ │ ├── 2-one-ghost-3level.solution │ │ ├── 2-one-ghost-3level.test │ │ ├── 3-one-ghost-4level.solution │ │ ├── 3-one-ghost-4level.test │ │ ├── 4-two-ghosts-3level.solution │ │ ├── 4-two-ghosts-3level.test │ │ ├── 5-two-ghosts-4level.solution │ │ ├── 5-two-ghosts-4level.test │ │ ├── 6-tied-root.solution │ │ ├── 6-tied-root.test │ │ ├── 7-pacman-game.solution │ │ ├── 7-pacman-game.test │ │ └── CONFIG │ ├── q8 │ │ ├── 0-expectimax1.solution │ │ ├── 0-expectimax1.test │ │ ├── 1-expectimax2.solution │ │ ├── 1-expectimax2.test │ │ ├── 2-one-ghost-3level.solution │ │ ├── 2-one-ghost-3level.test │ │ ├── 3-one-ghost-4level.solution │ │ ├── 3-one-ghost-4level.test │ │ ├── 4-two-ghosts-3level.solution │ │ ├── 4-two-ghosts-3level.test │ │ ├── 5-two-ghosts-4level.solution │ │ ├── 5-two-ghosts-4level.test │ │ ├── 6-pacman-game.solution │ │ ├── 6-pacman-game.test │ │ └── CONFIG │ └── q9 │ │ ├── CONFIG │ │ ├── grade-agent.solution │ │ └── grade-agent.test ├── textDisplay.py └── util.py └── utils ├── __init__.py ├── gnumpy.py ├── npmat.py └── ubigraph.py /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "mcdemo/erlvpn"] 2 | path = mcdemo/erlvpn 3 | url = https://github.com/mlberkeley/erlvpn.git 4 | [submodule "erlvpn"] 5 | path = erlvpn 6 | url = https://github.com/mlberkeley/erlvpn.git 7 | [submodule "docs/progress/pres1"] 8 | path = docs/progress/pres1 9 | url = https://git.overleaf.com/4949857cxxzqw 10 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Untitled-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 1 6 | } 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | before_install: 2 | - wget https://github.com/scottkosty/install-tl-ubuntu/raw/master/install-tl-ubuntu 3 | - chmod +x ./install-tl-ubuntu 4 | - sudo ./install-tl-ubuntu 5 | script: 6 | - mkdir _build 7 | - cd docs/backprop_free_dpg && pdflatex -output-directory ../../_build main.tex 8 | deploy: 9 | provider: releases 10 | api_key: 11 | secure: FBELeg1aHDO5a3jTLfSHHUytCEu3yDldfO4TjoMIdG0dpkIMiaWo+TL6X2aBYg46i4YxkSIU4TH02gw7VJlHrgMsbkFetHTs5V/2Ght/jIjMBcDj/x25u7GfRPGD+wuYkpk7kzIJpBkxzYkrDp9ebShGrFGW2dKgvFh5wOVtxuVl4X0VX+1HGCRCeCHCNbOPYOaCCqNtiNz0vHYFrZboQ1fRJ3Wq/CSYTzw9kvOaRHB/FrAcYm7yHVVFwFZP0lYsWYQseHBWjsLiTAFidtJ5Pwk0BzC9qw+TOOCDT2tHA+bPazhTVNnGRDbB2V9f23oQfQ30UtM7GxwW94+tBEi5gxxK5SbztkaTWVam+w36Hp31kziwOPkzIHGAUd2Vfg/ro45CxgtwGzo4tFVTfuN4xv2Qvc937oNJ29BKVpecKuYqRRU+/zkolosVey8+xPraBf+m3wnlHPQBOcUNa+qxKrGkMSpMnkYBZbBffsphXDk1LqRrm6D2/3i9ztiQu+FZ9cPwlxAopdcK51uQsFaXx84NnLBPu2Sj4hqYh0zEUKLBnqEUUSpPxtJclwYw5s5E8FgItXCv0Ip/fiA60Q1l1SXe6XcA/71j8VsnlcUD8xr0uP6TSzOg7kPGLqtoMdZ1U2byhQNwr/OtyhgoTc17g0jsQimRF8qsXIvPaqfmZHk= 12 | file: _build/main.pdf 13 | on: 14 | repo: mlberkeley/openbrain 15 | branch: master 16 | tag: true 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenBrain [[PDF Status](https://www.sharelatex.com/github/repos/mlberkeley/openbrain/builds/latest/badge.svg)](https://www.sharelatex.com/github/repos/mlberkeley/openbrain/builds/latest/output.pdf) 2 | The openBrain project for massive asynchronous neurocomputation. 3 | Read our [white paper here](https://www.sharelatex.com/github/repos/mlberkeley/openbrain/builds/latest/output.pdf). 4 | -------------------------------------------------------------------------------- /docs/backprop_free_dpg/diagrams/com1v1.tex: -------------------------------------------------------------------------------- 1 | \begin{tikzcd} %THe diagram for Q function decomposition. 2 | && && && \scripts 3 | \times 4 | \scripta 5 | \arrow{r} 6 | {Q^\mu} 7 | \arrow{d} 8 | {\pi_\scripta} 9 | \arrow{lllllld} 10 | {\pi_\scripts} & \mathbb{R} \\ 11 | %-------------------------------------------------------------------------------------% 12 | \scripts 13 | \arrow{rrrrrr} 14 | {\mu} 15 | \arrow{d} 16 | {\epsilon} && && && \scripta \\ 17 | %-------------------------------------------------------------------------------------%% 18 | \scriptv 19 | \arrow{rr} 20 | {V(\tau+1)} 21 | \arrow{rd} 22 | {\mu^n} && \scriptv 23 | \arrow{rr} 24 | {V(\tau+2)} 25 | \arrow{ld} 26 | {\pi_n} 27 | \arrow{rd} 28 | {\mu^n} && \dots 29 | \arrow{rr} 30 | {V(\tau 31 | + \ell -1)} 32 | \arrow{ld} 33 | {\pi_n} 34 | \arrow{rd} 35 | {\mu^n} && \scriptv 36 | \arrow{u}{\delta} 37 | \arrow{ld} 38 | {\pi_n} \\ 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 40 | \scriptv \times \reals &\reals &\scriptv \times \reals 41 | &\reals & \scriptv \times \reals&\reals 42 | 43 | 44 | 45 | \end{tikzcd} -------------------------------------------------------------------------------- /docs/backprop_free_dpg/diagrams/com1v2.tex: -------------------------------------------------------------------------------- 1 | \begin{tikzcd} %THe diagram for Q function decomposition. 2 | &[-25pt]&[-25pt] &[-25pt]&[-25pt] \scripts 3 | \times 4 | \scripta 5 | \arrow{r} 6 | {Q^\mu} 7 | \arrow{d} 8 | {\pi_\scripta} 9 | \arrow{lllld} 10 | {\pi_\scripts} & \mathbb{R} \\ 11 | %-------------------------------------------------------------------------------------% 12 | \scripts 13 | \arrow{rrrr} 14 | {\mu} 15 | \arrow{d} 16 | {\epsilon} && && \scripta \\ 17 | %-------------------------------------------------------------------------------------%% 18 | \scriptv 19 | \arrow{rr} 20 | {V(\tau+1)} 21 | \arrow{rd} 22 | {\mu^n} && \cdots 23 | \arrow{rr} 24 | {V(\tau+\ell-1)} 25 | \arrow{ld} 26 | {\pi_n} 27 | \arrow{rd} 28 | {\mu^n} && \scriptv 29 | \arrow{u}{\delta} 30 | \arrow{ld} 31 | {\pi_n} \\ 32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 33 | \scriptv\times\reals 34 | \arrow{u}{\pi_\scriptv} &\reals &\scriptv\times\reals&\reals& 35 | 36 | 37 | 38 | \end{tikzcd} -------------------------------------------------------------------------------- /docs/backprop_free_dpg/diagrams/com1v3.tex: -------------------------------------------------------------------------------- 1 | \begin{tikzcd} %THe diagram for Q function decomposition. 2 | & & & \scripts 3 | \times 4 | \scripta 5 | \arrow{rdd} 6 | {Q^\mu} 7 | \arrow{d}[swap] 8 | {\pi_\scripta} 9 | \arrow{llld}[swap] 10 | {\pi_\scripts}\\ 11 | %-------------------------------------------------------------------------------------% 12 | \scripts 13 | \arrow{rrr} 14 | {\mu} 15 | \arrow{d} 16 | {\epsilon} & & & \scripta \\ 17 | %-------------------------------------------------------------------------------------%% 18 | \scriptv 19 | \arrow{r} 20 | {V(\tau+1)} 21 | \arrow{rd} 22 | {\mu^n} & \scriptv 23 | \arrow{r} 24 | {V(\tau+2)} 25 | \arrow{d} 26 | {\pi_n} 27 | \arrow{rd} 28 | {\mu^n} & \dots 29 | \arrow{r} 30 | {V(\tau 31 | + \ell -1)} 32 | \arrow{d}[swap] 33 | {\pi_n} 34 | \arrow{rd} 35 | {\mu^n} & \scriptv 36 | \arrow{u}{\delta} 37 | \arrow{d}[swap] 38 | {\pi_n} &\mathbb{R} \\ 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 40 | & \reals & \reals & \reals \\ 41 | && \tens_{k=\tau}^{\tau + \ell} \left(\scriptv \otimes \mathbb{R}\right) 42 | \arrow{ur}{\pi_\mathbb{R}} 43 | \arrow[uu, bend right, swap,"\pi_\scriptv"] 44 | \arrow{u}{\pi_\reals} 45 | \arrow{uul}[swap]{\pi_\scriptv} 46 | \arrow{ul}[swap]{\pi_\reals} 47 | \arrow[uull, bend left,"\pi_\scriptv"] 48 | \arrow[uurr, bend right, swap, "Q_{AGG}^n"] 49 | 50 | % \scriptv \times \reals 51 | % \arrow{u}{\pi_\scriptv} 52 | % \arrow{r}{\pi_\reals}&\reals &\scriptv \times \reals 53 | % \arrow{u}{\pi_\scriptv} 54 | % \arrow{r}{\pi_\reals} 55 | % &\reals & \scriptv \times \reals 56 | % \arrow{u}{\pi_\scriptv} 57 | % \arrow{r}{\pi_\reals}&\reals 58 | % 59 | 60 | 61 | \end{tikzcd} -------------------------------------------------------------------------------- /docs/backprop_free_dpg/main.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/backprop_free_dpg/main.pdf -------------------------------------------------------------------------------- /docs/presentations/demoday1/5-Figure6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/demoday1/5-Figure6-1.png -------------------------------------------------------------------------------- /docs/presentations/demoday1/BlueGold_fill_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/demoday1/BlueGold_fill_small.png -------------------------------------------------------------------------------- /docs/presentations/demoday1/BlueGold_fill_small_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/demoday1/BlueGold_fill_small_name.png -------------------------------------------------------------------------------- /docs/presentations/demoday1/Pac-man.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/demoday1/Pac-man.png -------------------------------------------------------------------------------- /docs/presentations/demoday1/White_outline_small_name_transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/demoday1/White_outline_small_name_transparent.png -------------------------------------------------------------------------------- /docs/presentations/demoday1/White_outline_small_transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/demoday1/White_outline_small_transparent.png -------------------------------------------------------------------------------- /docs/presentations/demoday1/doom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/demoday1/doom.png -------------------------------------------------------------------------------- /docs/presentations/demoday1/dope.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/demoday1/dope.png -------------------------------------------------------------------------------- /docs/presentations/demoday1/pres.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/demoday1/pres.pdf -------------------------------------------------------------------------------- /docs/presentations/symposium_poster/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/symposium_poster/logo.png -------------------------------------------------------------------------------- /docs/presentations/symposium_poster/placeholder.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/docs/presentations/symposium_poster/placeholder.jpg -------------------------------------------------------------------------------- /docs/presentations/symposium_poster/sample.bib: -------------------------------------------------------------------------------- 1 | @BOOK{Smith:2012qr, 2 | title = {{B}ook {T}itle}, 3 | publisher = {Publisher}, 4 | author = {Smith, J.~M. and Jones, A.~B.}, 5 | year = {2012}, 6 | edition = {7th}, 7 | } 8 | 9 | @ARTICLE{Smith:2013jd, 10 | author = {Jones, A.~B. and Smith, J.~M.}, 11 | title = {{A}rticle {T}itle}, 12 | journal = {Journal title}, 13 | year = {2013}, 14 | volume = {13}, 15 | pages = {123-456}, 16 | number = {52}, 17 | month = {March}, 18 | publisher = {Publisher} 19 | } -------------------------------------------------------------------------------- /docs/whitepaper/.gitignore: -------------------------------------------------------------------------------- 1 | main.pdf -------------------------------------------------------------------------------- /docs/whitepaper/appendices.tex: -------------------------------------------------------------------------------- 1 | \begin{appendices} 2 | \section{Universal Intelligence Definitions} 3 | \end{appendices} -------------------------------------------------------------------------------- /docs/whitepaper/conclusion.tex: -------------------------------------------------------------------------------- 1 | \section{Conclusion [Omitted]} 2 | \subsection{Future Work [Omitted]} -------------------------------------------------------------------------------- /docs/whitepaper/implementation.tex: -------------------------------------------------------------------------------- 1 | \section{Experimentation [Omitted]} 2 | \subsection{Implementation [Omitted]} 3 | \subsection{Results [Omitted]} -------------------------------------------------------------------------------- /docs/whitepaper/introduction.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = main.tex 2 | \section{Introduction} 3 | 4 | Most standard neural network models depart from the biological neuron in a number of ways. Our asynchronous continuous-time model draws inspiration from physiological and biological principles for neuron dynamics. 5 | 6 | In a biological neuron, there are leak Na+ and K+ current channels that constantly push the neuron's voltage towards its equilibrium voltage. We have included an exponential decay term to model this homeostatic tendency towards equilibrium. Likewise, we have also loosely modelled the refractory period, the period immediately after an action period in which a neuron cannot send a signal, instead of having resetting the voltage of a neuron immediately back to zero. 7 | 8 | There are many features of a biological neuron that we have chosen not to implement (most notably the dynamics of a neuron's voltage during a action potential, by implementing a Hodgkins-Huxley model (see wikipedia)) in that there is a trade-off between having a model that is more biological realisticity and one that is mathematically and computationally simple. There are projects like BlueBrain that aim for the most biologically realistic model, and a plethora of projects (deep learning, etc.) that are vaguely biologically inspired but have been massively implemented and successful at a small class of tasks. Our hope is by striving for a balance between the two ideals by implementing a system that is both biologically inspired and computationally simple, we would be able to make a massive implementation that succeeds in a wide variety of tasks that require both creativity and intelligence. 9 | 10 | %\emph{Note:} 11 | %We need to motivate substantially the proposal of a drastically different framework of neurocomputation. This motivation should be given according to the latest neuroscience, and a general problem in the field. 12 | 13 | %\todo[inline]{Argue against 14 | %the current state of ML's approach to the problem of AGI 15 | %by surveying field.} 16 | %\subsection{Intelligence as an Emergence Phenomenon} 17 | %\todo[inline]{Establish Conwaynian philosophy on emergent neurocomputation.} 18 | %\todo[inline]{Motivate asynchrynous neurocomputation.} 19 | -------------------------------------------------------------------------------- /docs/whitepaper/main.tex: -------------------------------------------------------------------------------- 1 | % In your .tex file 2 | 3 | \documentclass{article} % For LaTeX2e 4 | \usepackage{nips15submit_e,times} 5 | \usepackage{xparse} 6 | 7 | \usepackage{hyperref} 8 | \usepackage{url} 9 | \usepackage[toc,page]{appendix} 10 | 11 | %citation 12 | \usepackage[backend=bibtex]{biblatex} 13 | \bibliography{openbrain} 14 | % 15 | 16 | % tikz and associated macros 17 | \usepackage{tikz} 18 | \usepackage{tikz-cd} 19 | 20 | \usepackage{pgfplots} 21 | \newcommand\sep{1.9cm} 22 | \newcommand\height{0.9cm} 23 | \usetikzlibrary{decorations.pathmorphing, backgrounds} 24 | \tikzset{snake it/.style={decorate, decoration=snake}} 25 | % 26 | % 27 | 28 | % math 29 | \usepackage{amsthm} 30 | \usepackage{amsmath} 31 | \usepackage{amssymb} 32 | \usepackage{mathabx} 33 | 34 | \newcommand{\BlackBox}{\rule{1.5ex}{1.5ex}} % end of proof 35 | \newtheorem{example}{Example} 36 | \newtheorem{theorem}{Theorem} 37 | \newtheorem{lemma}[theorem]{Lemma} 38 | \newtheorem{proposition}[theorem]{Proposition} 39 | \newtheorem{remark}[theorem]{Remark} 40 | \newtheorem{corollary}[theorem]{Corollary} 41 | \newtheorem{definition}[theorem]{Definition} 42 | \newtheorem{conjecture}[theorem]{Conjecture} 43 | \newtheorem{axiom}[theorem]{Axiom} 44 | 45 | \numberwithin{equation}{subsection} 46 | \numberwithin{theorem}{subsection} 47 | 48 | \DeclareSymbolFont{cmlargesymbols}{OMX}{cmex}{m}{n} 49 | \let\sumop\relax 50 | \DeclareMathSymbol{\sumop}{\mathop}{cmlargesymbols}{"50} 51 | \NewDocumentCommand{\tens}{t_} 52 | {% 53 | \IfBooleanTF{#1} 54 | {\tensop} 55 | {\otimes}% 56 | } 57 | \NewDocumentCommand{\tensop}{m} 58 | {% 59 | \mathbin{\mathop{\otimes}\displaylimits_{#1}}% 60 | } 61 | 62 | %% todo[inline] NOTES. To remove for camera ready version. 63 | \usepackage{todonotes} 64 | \usepackage{regexpatch} 65 | %end to notes 66 | 67 | \title{OpenBrain: Massively Asynchronous Neurocomputation} 68 | 69 | 70 | \author{ 71 | William H.~Guss \\ 72 | Machine Learning at Berkeley\\ 73 | 2650 Durant Ave, Berkeley CA, 94720 \\ 74 | \texttt{wguss@ml.berkeley.edu} \\ 75 | \And 76 | Mike Zhong \\ 77 | Machine Learning at Berkeley \\ 78 | Berkeley CA, 94720 \\ 79 | \texttt{lol@gmail.com} \\ 80 | \And 81 | Phillip Kuznetsov \\ 82 | Machine Learning at Berkeley \\ 83 | Berkeley CA, 94720 \\ 84 | \texttt{philkuz@ml.berkeley.edu} \\ 85 | \And 86 | Jacky Liang \\ 87 | Machine Learning at Berkeley \\ 88 | Berkeley CA, 94720 \\ 89 | \texttt{jackyliang@berkeley.edu} \\ 90 | } 91 | 92 | 93 | \nipsfinalcopy % Uncomment for camera-ready version 94 | 95 | \begin{document} 96 | 97 | 98 | \maketitle 99 | 100 | \begin{abstract} 101 | In this paper we introduce a new framework and philosophy for recurrent neurocomputation. By requiring that all neurons act asynchrynously and independently, we introduce a new metric for evaluating the universal intelligence of continuous time agents. We proved representation and universal approximation results in this context which lead to a set of learning rules in the spirt of John Conway's game of life. Finally evaluate this framework against different intelligent agent algorithms by implementing an approximate universal intelligence measure for agents embedded in turing computable environments in Minecraft, BF, and a variety of other reference machines. 102 | \end{abstract} 103 | 104 | 105 | %\listoftodos 106 | \input{introduction} 107 | \input{model} 108 | \input{learning} 109 | \input{implementation} 110 | \input{conclusion} 111 | 112 | \printbibliography 113 | 114 | \input{appendices} 115 | 116 | \end{document} 117 | -------------------------------------------------------------------------------- /docs/whitepaper/model.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = main.tex 2 | \section{Asynchronous Neurocomputation} 3 | 4 | \input{model/core} 5 | \input{model/ctuim} 6 | \input{model/univ} 7 | \subsection{Multiprocess Turing Completeness [Omitted]} 8 | %If we decide to go down this route, we'll add it's own \TeX file. 9 | -------------------------------------------------------------------------------- /docs/whitepaper/model/core.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = ../main.tex 2 | \subsection{The Core Framework} 3 | 4 | %%\todo[inline]{This section needs an actuall discussion. For now here are the working definitions of Openbrain.} 5 | We begin by giving basic abstractions on neurons. 6 | 7 | \begin{definition}\label{neuron} 8 | A \textbf{neuron} $n \in N$ is defined by 9 | \begin{itemize} 10 | \item a voltage $V_n(t)$ 11 | \item a decay time $\tau_n$ 12 | \item a refactory period $\rho_n$ 13 | \item a voltaic threshold $\theta_n$ 14 | \end{itemize} 15 | \end{definition} 16 | \begin{definition}\label{connection} 17 | A \textbf{connection} $c \in C$ is a tuple $(n_i, n_j, w_{ij}) \in N \times N \times \mathbb{R}$ 18 | where $n_i$ is the \textbf{anterior neuron}, $n_j$ is the \textbf{posterior neuron}, and $w_ij$ 19 | is the standard synaptic weight. 20 | \end{definition} 21 | 22 | %\todo[inline]{Make connection diagram.} 23 | 24 | 25 | For a neuron $n$, we denote the set of anterior neurons $A_n$ and the dendritic connections, $C_{n}^a$. In the same light we will use the notations $P_n$ and $C_n^p$ to denote the sets of posterior neurons and posterior connections for $n$ respectively. 26 | 27 | Because it is impossible to implement time as a continuous parameter on any computer, we introduce the time-step, $\Delta t$, as a numerical simulation step-size in time. The conversion between discrete algorithm iterations, with $k = 0, 1, 2, ...$ and continuous time $t$ is $V(t_{k}) = V(k\Delta t) = V[k]$. As computational power permits, a smaller $\Delta t$ gives a more accurate simulation. 28 | 29 | \begin{definition}\label{decay} 30 | We say that a neuron $n$ experiences \textbf{voltage decay} so that for all $k$, 31 | \begin{equation} 32 | V_n[k+1] \leftarrow V_n[k]e^{-\Delta t/\tau}. \label{eq:decay} 33 | \end{equation} 34 | so that unless it obtains voltage from anterior neurons' firing, its voltage will decay exponentially to 0. 35 | \end{definition} 36 | 37 | 38 | \begin{definition}\label{fire} 39 | A neuron $n$ is said to \textbf{fire} if it is not in its refractory period and $V_n(t_{k}) = V_n[k] > \theta_n$. Then for all $m \in P_n$, 40 | \begin{equation} 41 | V_m[k+1] += w_{nm} \sigma(V_n[k]); \label{eq:fire} 42 | \end{equation} 43 | that is, voltage is propagated to the posterior neurons. Immediately after neuron $n$ fires, it enters a \textbf{refractory period} until time $t_{k} + \rho_n$, or iteration $k + \frac{\rho_n}{\Delta t}$. 44 | \end{definition} 45 | 46 | 47 | Combining \eqref{eq:fire} and \eqref{eq:decay} we get that for a neuron $m$ at time $k+1$ 48 | \begin{equation} 49 | V_m[k+1] = V_m[k]e^{-\Delta t/\tau} + \sumop_{\substack{n \in A'_m}} w_{nm} \sigma(V_n[k]) 50 | \end{equation} 51 | such that $A'_m$ is the set of anterior neurons which fired at time $k.$ 52 | -------------------------------------------------------------------------------- /docs/whitepaper/model/ctuim.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = ../main.tex 2 | \subsection{Continuous Time Universal Intelligence Measure} 3 | 4 | In alignment with the philosophy which predicates OpenBrain, we wish to extend the evaluation of our algorithm well beyond its performance in supervised learning tasks; that is, what can be said about the intelligence of OpenBrain as an agent in an environment? A metric more condusive to implementing general intelligence is needed. The answer will motivate an important discussion of representation theory annd learning rules. 5 | \subsection{Universal Intelligence} 6 | A well established\cite{legg2008machine, mnih2015human, rathmanner2011philosophical} machine intelligence measure is the Universal Intelligence Measure proposed by Legg and Hutter \cite{legg2007universal}. Drawing from a large amount of disparate literature on the subject they develop a consise definition of the intelligence of an \emph{agent} in an \emph{environment}. 7 | %\todo[inline]{The following exposition may be unnecessary, and we should consider just stating the result of Legg and Hutter.} 8 | 9 | Environment-agent interaction is defined with respect to an observation space, $\mathcal{O}$, and an action space, $\mathcal{A}$, both of which consist of abstract symbols. The perception space, $\mathcal{P} \subset \mathcal{O} \times \mathbb{R}$, is the combination of observations and rewards. 10 | \begin{definition} 11 | An \textbf{environment} $\mu$ is a probability measure, specifically defining 12 | \begin{equation} 13 | \mu(o_kr_k | o_1r_1a_1 \dots o_{k-1}r_{k-1}a_{k-1}), 14 | \end{equation} 15 | the probability of observing $o_kr_k \in \mathcal{P}$ given a history, a string $o_1\dots a_{k-1} \in \bigtimes_{i=1}^k \mathcal{P} \times \mathcal{A}.$ 16 | \end{definition} 17 | 18 | In the same light the agent definition is given. 19 | \begin{definition} 20 | An \textbf{agent} $\pi$ is a probability measure, giving 21 | \begin{equation} 22 | \pi(a_k | o_1r_1a_1 \dots a_{k-1}o_kr_k) 23 | \end{equation} 24 | the probability of the possible action $a_k$ being enacted by $\pi$ being the environment-agent interaction history. 25 | \end{definition} 26 | 27 | Having defined the basic framework, \cite{legg2007universal} gives a definition for Universal Intelligence. Let $E$ be the space of all turing complete reward environments, and $K: E \to \mathbb{R}$ be the Kolmogorov complexity of an environment. This complexity is calculated with respect to the length of the string with which a reference machine $\mathcal{U}$ generates the environment. 28 | \begin{definition} \label{uim} 29 | If $\pi$ is an agent then we say that the \textbf{universal intelligence} of $\pi$ is 30 | \begin{equation} \label{eq:uim} 31 | \Upsilon(\pi) = \sumop_{\mu \in E}2^{-K(\mu)}V_\mu^\pi 32 | \end{equation} 33 | where $V_\mu^\pi$ is the expected reward of the agent in $\mu$, 34 | \begin{equation} \label{eq:exprewarduim} 35 | V_\mu^\pi = \mathbb{E}\left(\sumop_{i=1}^\infty r_i\right) \leq 1. 36 | \end{equation} 37 | \end{definition} 38 | 39 | The definition is satisfactory for agents which act synchronously with their environments; that is, the environment waits for the agent to act before giving a new observation. Therefore in Hutter's sense, the framework of \cite{legg2007universal} describes an agent $\pi$ embedded in $\mu$. 40 | 41 | Despite this, the environments which we normally consider an intelligent agent to 'act well' in are often chaotic and operate with noise which is temporally independent from the agent-environment interaction itself. %\todo{Why!?} For example, a real time game does not wait for a player to press a key, and yet the player still receives perceptual information. The intelligence measure proposed fails to encompass agent-environment interactions where the agent has some delay in acting as the environment continues; modeling such delays as $a_k = \emptyset$ is no more enlightening. 42 | 43 | In order to integrate OpenBrain with this framework, we will propose a continuous time universal intelligence measure. 44 | 45 | \subsection{Continuous Time Intelligence} 46 | \input{model/ctuimdiag} 47 | To make a continuous time intelligence measure which is compatible with agents who act instantaneously within an environment, we will define a completed perception space. 48 | 49 | Since different agents 50 | 51 | \begin{definition} 52 | Given an environment $\mu$ with an associated 53 | perception space $\mathcal{P}$ we define the 54 | \textbf{completion} $\tilde{\mathcal{P}}$ with respect to the admissible sequences of observations in $\mu$; that is, 55 | \begin{equation} 56 | \tilde{\mathcal{P}} = \bigsqcup_{k=1}^\infty \mathcal{P}^k. 57 | \end{equation} 58 | \end{definition} 59 | -------------------------------------------------------------------------------- /docs/whitepaper/model/ctuimdiag.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = ../main.tex 2 | \begin{figure} 3 | \begin{center} 4 | \begin{tikzpicture} 5 | 6 | % Top nodes 7 | \node[circle, fill=white] (akm1) at (0,\height + 0.3cm ) {$\pmb{a_{k-1}}$} ; 8 | \foreach \a in {1,2,3,4}{ 9 | \node[circle, fill=white] (ok\a) at (\a*\sep,\height) {$o_{k\a}$} ; 10 | 11 | \node[circle, fill=white] (ok\a) at (\a*\sep,\height) {$o_{k\a}$} ; 12 | } 13 | 14 | 15 | \node[circle, fill=white] (ak) at (5*\sep,\height+0.3cm ) {$\pmb{a_{k}}$} ; 16 | 17 | 18 | %Generate neurons 19 | \foreach \a in {1,2,3,4}{ 20 | \node[ scale=0.7, fill=green!30, inner sep=1pt] (NI\a) at (\a*\sep,-0.3) {$N_I$} ; 21 | \path[draw, ->] (ok\a) -- (NI\a); 22 | 23 | \node[ scale=0.7, inner sep=1pt,] (N1\a) at (\a*\sep -0.7cm,-0.5) {$N_1$} ; 24 | \node[ scale=0.7, inner sep=1pt,] (N2\a) at (\a*\sep +0.6cm,-0.8) {$N_2$} ; 25 | \node[ scale=0.7, inner sep=1pt,] (N3\a) at (\a*\sep +0.5cm,-1.7) {$N_3$} ; 26 | \node[ scale=0.7, inner sep=1pt,] (N4\a) at (\a*\sep +0.1cm,-1.1) {$N_4$} ; 27 | \node[ scale=0.7, inner sep=1pt,] (N5\a) at (\a*\sep -0.4cm,-1.4) {$N_5$} ; 28 | \node[ scale=0.7, fill=red!30, inner sep=1pt ] (NO\a) at (\a*\sep +0.68cm,-0.3) {$N_O$} ; 29 | 30 | 31 | 32 | } 33 | \node[ scale=0.7, fill=green!30, inner sep=1pt ] (NO4) at (4*\sep +0.68cm,-0.3) {$N_O$} ; 34 | 35 | 36 | %WEIGHT DEQAY 37 | \foreach \a in {1,2,3}{ 38 | \foreach \b in {1,2,3,4,5}{ 39 | \begin{scope}[on background layer] 40 | \pgfmathsetmacro\q{int(\a + 1)} 41 | \path[draw, color=gray!20, ->, snake it] (N\b\a) -- (N\b\q) ; 42 | \end{scope} 43 | 44 | } 45 | } 46 | 47 | %NEURO FIRINGS 48 | \path[draw, ->, dashed] (NI1) -- (N11); 49 | \path[draw, ->] (N11) -- (N21); 50 | \path[draw, ->] (N11) -- (N51); 51 | 52 | \path[draw, ->, dashed] (NI2) -- (N12); 53 | \path[draw, ->, dashed] (NI2) -- (N42); 54 | \path[draw, ->] (N12) -- (N22); 55 | \path[draw, ->] (N12) -- (N52); 56 | \path[draw, ->] (N42) -- (N52); 57 | \path[draw, ->] (N52) -- (N32); 58 | \path[draw, ->] (N32) -- (N13); 59 | 60 | \path[draw, ->, dashed] (NI3) -- (N33); 61 | \path[draw, ->, dashed] (NI3) -- (N43); 62 | \path[draw, ->] (N43) -- (N53); 63 | \path[draw, ->] (N53) -- (N33); 64 | \path[draw, ->] (N33) -- (N13); 65 | \path[draw, ->] (N13) -- (N53); 66 | \path[draw, ->] (N13) -- (N23); 67 | \path[draw, ->] (N53) -- (N34); 68 | 69 | \path[draw, ->, dashed] (NI4) -- (N34); 70 | \path[draw, ->] (N34) -- (N14); 71 | \path[draw, ->] (N14) -- (N24); 72 | \path[draw, ->] (N24) -- (NO4); 73 | \path[draw, -] (NO4) -- (\sep*5,0); 74 | 75 | 76 | 77 | 78 | %TIME! 79 | \foreach \a in {1,2,...,5} { 80 | \node[circle, fill=white] (tka\a) at (\a*\sep -\sep/2,\height+0.3cm) {$t_{k\a}$} ; 81 | \path[draw, -] (tka\a) -- +(0,-3); 82 | } 83 | 84 | 85 | %a bridge. 86 | \path[draw, <->] (akm1) -- +(0,-\height -0.3cm) -- (5*\sep,0) -- (ak); 87 | 88 | \draw [decorate,decoration={brace,amplitude=12pt},xshift=-0pt] 89 | (\sep,\height+0.3cm) -- (4*\sep,\height+0.3cm) node [black,midway,yshift=.6cm] 90 | { $\pmb{o_k}$}; 91 | 92 | 93 | 94 | \end{tikzpicture} 95 | \caption{The diagram of sub-observation neural interaction for $\pi_O$.} 96 | 97 | \end{center} 98 | \end{figure} 99 | -------------------------------------------------------------------------------- /docs/whitepaper/model/univ.tex: -------------------------------------------------------------------------------- 1 | %!TEX root = ../main.tex 2 | \subsection{Universal Approximation and Representation} 3 | 4 | We first propose the following decomposition theorem. 5 | 6 | 7 | 8 | \begin{conjecture} 9 | Given a sequence of symbols $a_1r_1o_2a_2r_2...$ there exists an agent $\pi$ functioning according to some OpenBrain $O$ such that the probability of taking an action $a_k$ given $o_1r_1a_1...$ is 1. Formally, 10 | $$\exists \pi_{O} : P[\pi_{O}(a_k|o_1r_1a_1...)] = 1$$ 11 | \end{conjecture} 12 | 13 | But this particular agent might not necessarily work well in other environments; it can have a low overall intelligence score. The ideal Openbrain agent would take the same actions as Hutter's AIXI in every environment $\mu$, that is, $\forall \mu,\ \pi_o$ = $\pi^*$. However, due to the finite nature of this agent, it is unreasonable to expect a single openbrain agent to match AIXI in every possible environment at every time step. This motivates a learning nature in which the Openbrain agent makes mistakes in the beginning, but slowly converges to Hutter's AIXI, and starts maximising the sum of expected rewards after some time step $t_o$. 14 | 15 | \begin{conjecture} 16 | $\exists \pi_o$ such that $\forall \mu \ \exists t_o \ s.t.\ V_\mu^{\pi_o}[t_o] = V_\mu^*[t_o] $, where $V_\mu^{\pi}[t_o]$ is the expected sum of rewards for agent $\pi$ after time step $t_o$ 17 | \end{conjecture} 18 | 19 | This is a nice property to have, but this conjecture falls apart in environments that are chaotic or have absorbing states. For example, consider a simple MDP with an absorbing state neighbouring the initial state. If the agent accidentally steps into the absorbing state, then by definition it is stuck there forever, and it can never get good rewards. Since every learning agent is bound to make mistakes at some point, we limit our environments to those where it is possible to recover from mistakes. 20 | 21 | \begin{definition} 22 | An environment $\mu$ is \textbf{recoverable} iff for every state $s, \epsilon > 0, \exists t_o > 0\ s.t.\ |V_\mu^*[t_o]-V_{\mu,s}^*[t_o]| < \epsilon$, where $V_{\mu,s}^*$ is the expected sum of rewards starting from state s and acting optimally 23 | \end{definition} 24 | 25 | %\todo[inline]{Make the $V_{\mu,s}^*[t_o]$ part more formal with proper RL notation.} 26 | 27 | \begin{conjecture} 28 | There is a $\pi_o$ such that for all recoverable environments $\mu, \epsilon > 0$, $\exists t_o$ such that $|V_\mu^{\pi_o}[t_o]-V_\mu^*[t_o]|<\epsilon$ 29 | \end{conjecture} -------------------------------------------------------------------------------- /docs/whitepaper/openbrain.bib: -------------------------------------------------------------------------------- 1 | @article{mnih2015human, 2 | title={Human-level control through deep reinforcement learning}, 3 | author={Mnih, Volodymyr and Kavukcuoglu, Koray and Silver, David and Rusu, Andrei A and Veness, Joel and Bellemare, Marc G and Graves, Alex and Riedmiller, Martin and Fidjeland, Andreas K and Ostrovski, Georg and others}, 4 | journal={Nature}, 5 | volume={518}, 6 | number={7540}, 7 | pages={529--533}, 8 | year={2015}, 9 | publisher={Nature Publishing Group} 10 | } 11 | @article{rathmanner2011philosophical, 12 | title={A philosophical treatise of universal induction}, 13 | author={Rathmanner, Samuel and Hutter, Marcus}, 14 | journal={Entropy}, 15 | volume={13}, 16 | number={6}, 17 | pages={1076--1136}, 18 | year={2011}, 19 | publisher={Molecular Diversity Preservation International} 20 | } 21 | @phdthesis{legg2008machine, 22 | title={Machine super intelligence}, 23 | author={Legg, Shane}, 24 | year={2008}, 25 | school={University of Lugano} 26 | } 27 | @article{legg2007universal, 28 | title={Universal intelligence: A definition of machine intelligence}, 29 | author={Legg, Shane and Hutter, Marcus}, 30 | journal={Minds and Machines}, 31 | volume={17}, 32 | number={4}, 33 | pages={391--444}, 34 | year={2007}, 35 | publisher={Springer} 36 | } -------------------------------------------------------------------------------- /experiments/brain/__init__.py: -------------------------------------------------------------------------------- 1 | from .ddpg import DDPG 2 | from .sub_critics import SubCritics -------------------------------------------------------------------------------- /experiments/brain/actor_network.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import math 4 | 5 | from .common.utils import variable 6 | 7 | # Hyper Parameters 8 | REPLAY_BUFFER_SIZE = 1000000 9 | LAYER1_SIZE = 10 10 | LAYER2_SIZE = 10 11 | LEARNING_RATE = 1e-4 12 | TAU = 0.001 13 | BATCH_SIZE = 64 14 | GAMMA = 0.99 15 | 16 | class ActorNetwork: 17 | """docstring for ActorNetwork""" 18 | def __init__(self,sess,state_dim,action_dim,has_subcritics=False): 19 | #"""Constructor 20 | #param: subcritics : flag to turn on subcritic networks (critic networks per Q layer) """ 21 | self.sess = sess 22 | self.state_dim = state_dim 23 | self.action_dim = action_dim 24 | self.has_subcritics = has_subcritics 25 | self.layers = [] 26 | self.target_layers = [] 27 | # create actor network 28 | self.state_input,self.action_output,self.net = self.create_network(state_dim,action_dim) 29 | 30 | # create target actor network 31 | self.target_state_input,\ 32 | self.target_action_output,\ 33 | self.target_update,\ 34 | self.target_net = self.create_target_network(state_dim,action_dim,self.net) 35 | 36 | # define training rules 37 | self.create_training_method() 38 | 39 | self.sess.run(tf.initialize_all_variables()) 40 | 41 | self.update_target() 42 | 43 | #self.load_network() 44 | 45 | def create_training_method(self): 46 | self.q_gradient_input = tf.placeholder("float",[None,self.action_dim]) 47 | self.parameters_gradients = tf.gradients(self.action_output,self.net,-self.q_gradient_input) 48 | self.optimizer = tf.train.AdamOptimizer(LEARNING_RATE).apply_gradients(list(zip(self.parameters_gradients,self.net))) 49 | 50 | def create_network(self,state_dim,action_dim): 51 | layer1_size = LAYER1_SIZE 52 | layer2_size = LAYER2_SIZE 53 | 54 | state_input = tf.placeholder("float",[None,state_dim]) 55 | self.layers += [tf.identity(state_input)] 56 | 57 | W1 = variable([state_dim,layer1_size],state_dim) 58 | b1 = variable([layer1_size],state_dim) 59 | W2 = variable([layer1_size,layer2_size],layer1_size) 60 | b2 = variable([layer2_size],layer1_size) 61 | W3 = tf.Variable(tf.random_uniform([layer2_size,action_dim],-3e-3,3e-3)) 62 | b3 = tf.Variable(tf.random_uniform([action_dim],-3e-3,3e-3)) 63 | 64 | layer1 = tf.nn.relu(tf.matmul(state_input,W1) + b1) 65 | self.layers += [layer1] 66 | 67 | layer2 = tf.nn.relu(tf.matmul(layer1,W2) + b2) 68 | self.layers += [layer2] 69 | 70 | action_output = tf.tanh(tf.matmul(layer2,W3) + b3) 71 | self.layers += [action_output] 72 | 73 | return state_input,action_output,[W1,b1,W2,b2,W3,b3] 74 | 75 | 76 | def create_target_network(self,state_dim,action_dim,net): 77 | state_input = tf.placeholder("float",[None,state_dim]) 78 | self.target_layers += [tf.identity(state_input)] 79 | ema = tf.train.ExponentialMovingAverage(decay=1-TAU) 80 | target_update = ema.apply(net) 81 | target_net = [ema.average(x) for x in net] 82 | layer1 = tf.nn.relu(tf.matmul(state_input,target_net[0]) + target_net[1]) 83 | self.target_layers += [layer1] 84 | layer2 = tf.nn.relu(tf.matmul(layer1,target_net[2]) + target_net[3]) 85 | self.target_layers += [layer2] 86 | action_output = tf.tanh(tf.matmul(layer2,target_net[4]) + target_net[5]) 87 | self.target_layers += [action_output] 88 | 89 | return state_input,action_output,target_update,target_net 90 | 91 | def update_target(self): 92 | self.sess.run(self.target_update) 93 | 94 | def train(self,q_gradient_batch,state_batch): 95 | 96 | self.sess.run(self.optimizer,feed_dict={ 97 | self.q_gradient_input:q_gradient_batch, 98 | self.state_input:state_batch 99 | }) 100 | 101 | def actions(self,state_batch): 102 | """ 103 | """ 104 | action_batch = self.sess.run(self.action_output,feed_dict={ 105 | self.state_input:state_batch 106 | }) 107 | return action_batch 108 | 109 | def action(self,state): 110 | """ Performs an action by propogating through the net""" 111 | action_output = self.sess.run(self.action_output,feed_dict={ 112 | self.state_input:[state] 113 | })[0] 114 | return action_output 115 | 116 | 117 | def action_activations(self, state): 118 | """ Gets a pair of action, [state, layer1, layer2, ...] """ 119 | output = self.sess.run([self.action_output, 120 | self.layers],feed_dict={ 121 | self.state_input:[state] 122 | }) 123 | action = output[0][0] 124 | activations = [activation[0] for activation in output[1]] 125 | return action, activations 126 | 127 | 128 | def target_actions(self,state_batch): 129 | """ Lag actor network """ 130 | 131 | next_action_batch = self.sess.run(self.target_action_output,feed_dict={ 132 | self.target_state_input:state_batch 133 | }) 134 | return next_action_batch 135 | 136 | def target_action_activations(self, state_batch): 137 | next_action_batch = self.sess.run( 138 | [self.target_action_output,self.target_layers],feed_dict={ 139 | self.target_state_input:state_batch 140 | }) -------------------------------------------------------------------------------- /experiments/brain/common/filter_env.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import gym 3 | 4 | def makeFilteredEnv(env): 5 | """ crate a new environment class with actions and states normalized to [-1,1] """ 6 | acsp = env.action_space 7 | obsp = env.observation_space 8 | if not type(acsp)==gym.spaces.box.Box: 9 | raise RuntimeError('Environment with continous action space (i.e. Box) required.') 10 | if not type(obsp)==gym.spaces.box.Box: 11 | raise RuntimeError('Environment with continous observation space (i.e. Box) required.') 12 | 13 | env_type = type(env) 14 | 15 | class FilteredEnv(env_type): 16 | def __init__(self): 17 | self.__dict__.update(env.__dict__) # transfer properties 18 | 19 | # Observation space 20 | if np.any(obsp.high < 1e10): 21 | h = obsp.high 22 | l = obsp.low 23 | sc = h-l 24 | self.o_c = (h+l)/2. 25 | self.o_sc = sc / 2. 26 | else: 27 | self.o_c = np.zeros_like(obsp.high) 28 | self.o_sc = np.ones_like(obsp.high) 29 | 30 | # Action space 31 | h = acsp.high 32 | l = acsp.low 33 | sc = (h-l) 34 | self.a_c = (h+l)/2. 35 | self.a_sc = sc / 2. 36 | 37 | # Rewards 38 | self.r_sc = 0.1 39 | self.r_c = 0. 40 | 41 | # Special cases 42 | ''' 43 | if self.spec.id == "Reacher-v1": 44 | print "is Reacher!!!" 45 | self.o_sc[6] = 40. 46 | self.o_sc[7] = 20. 47 | self.r_sc = 200. 48 | self.r_c = 0. 49 | ''' 50 | # Check and assign transformed spaces 51 | self.observation_space = gym.spaces.Box(self.filter_observation(obsp.low), 52 | self.filter_observation(obsp.high)) 53 | self.action_space = gym.spaces.Box(-np.ones_like(acsp.high),np.ones_like(acsp.high)) 54 | def assertEqual(a,b): assert np.all(a == b), "{} != {}".format(a,b) 55 | assertEqual(self.filter_action(self.action_space.low), acsp.low) 56 | assertEqual(self.filter_action(self.action_space.high), acsp.high) 57 | 58 | def filter_observation(self,obs): 59 | return (obs-self.o_c) / self.o_sc 60 | 61 | def filter_action(self,action): 62 | return self.a_sc*action+self.a_c 63 | 64 | def filter_reward(self,reward): 65 | ''' has to be applied manually otherwise it makes the reward_threshold invalid ''' 66 | return self.r_sc*reward+self.r_c 67 | 68 | def step(self,action): 69 | 70 | ac_f = np.clip(self.filter_action(action),self.action_space.low,self.action_space.high) 71 | 72 | obs, reward, term, info = env_type.step(self,ac_f) # super function 73 | 74 | obs_f = self.filter_observation(obs) 75 | 76 | return obs_f, reward, term, info 77 | 78 | fenv = FilteredEnv() 79 | 80 | print(('True action space: ' + str(acsp.low) + ', ' + str(acsp.high))) 81 | print(('True state space: ' + str(obsp.low) + ', ' + str(obsp.high))) 82 | print(('Filtered action space: ' + str(fenv.action_space.low) + ', ' + str(fenv.action_space.high))) 83 | print(('Filtered state space: ' + str(fenv.observation_space.low) + ', ' + str(fenv.observation_space.high))) 84 | 85 | return fenv -------------------------------------------------------------------------------- /experiments/brain/common/ou_noise.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------- 2 | # Ornstein-Uhlenbeck Noise 3 | # Author: Flood Sung 4 | # Date: 2016.5.4 5 | # Reference: https://github.com/rllab/rllab/blob/master/rllab/exploration_strategies/ou_strategy.py 6 | # -------------------------------------- 7 | 8 | import numpy as np 9 | import numpy.random as nr 10 | 11 | class OUNoise: 12 | """docstring for OUNoise""" 13 | def __init__(self,action_dimension,mu=0, theta=0.15, sigma=0.2): 14 | self.action_dimension = action_dimension 15 | self.mu = mu 16 | self.theta = theta 17 | self.sigma = sigma 18 | self.state = np.ones(self.action_dimension) * self.mu 19 | self.reset() 20 | 21 | def reset(self): 22 | self.state = np.ones(self.action_dimension) * self.mu 23 | 24 | def noise(self): 25 | x = self.state 26 | dx = self.theta * (self.mu - x) + self.sigma * nr.randn(len(x)) 27 | self.state = x + dx 28 | return self.state 29 | 30 | if __name__ == '__main__': 31 | ou = OUNoise(3) 32 | states = [] 33 | for i in range(1000): 34 | states.append(ou.noise()) 35 | import matplotlib.pyplot as plt 36 | 37 | plt.plot(states) 38 | plt.show() 39 | -------------------------------------------------------------------------------- /experiments/brain/common/replay_buffer.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | import numpy as np 3 | import random 4 | 5 | class ReplayBuffer(object): 6 | 7 | def __init__(self, buffer_size, scale_param = 0.5, uniform = False): 8 | self.buffer_size = buffer_size 9 | self.num_experiences = 0 10 | self.buffer = deque() 11 | self.uniform = uniform 12 | 13 | def get_batch(self, batch_size): 14 | if self.uniform: 15 | return random.sample(list(self.buffer), batch_size) 16 | scale = self.scale_param * len(self.buffer) 17 | inds = np.rint(np.random.exponential(scale = scale, size = batch_size)) 18 | # only go as far back as the start of the deque... 19 | inds[inds > len(self.buffer)] = len(self.buffer) 20 | # start from the end of the deque 21 | inds = -inds 22 | return [self.buffer[int(i)] for i in inds] 23 | 24 | def size(self): 25 | return self.buffer_size 26 | 27 | def add(self, state, action, reward, new_state, done): 28 | experience = (state, action, reward, new_state, done) 29 | if self.num_experiences < self.buffer_size: 30 | self.buffer.append(experience) 31 | self.num_experiences += 1 32 | else: 33 | self.buffer.popleft() 34 | self.buffer.append(experience) 35 | 36 | def count(self): 37 | # if buffer is full, return buffer size 38 | # otherwise, return experience counter 39 | return self.num_experiences 40 | 41 | def erase(self): 42 | self.buffer = deque() 43 | self.num_experiences = 0 44 | -------------------------------------------------------------------------------- /experiments/brain/common/utils.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import math 3 | import csv 4 | import os 5 | 6 | TRACK_VARS=False 7 | episode_stats = {'names': [], 'variables' : []} 8 | output_dir = '' 9 | cur_episode = -1 10 | csv_writer = None 11 | def variable_summaries(var, name): 12 | """Attach a lot of summaries to a Tensor.""" 13 | with tf.name_scope('summaries'): 14 | mean = tf.reduce_mean(var) 15 | tf.scalar_summary('mean/' + name, mean) 16 | with tf.name_scope('stddev'): 17 | stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean))) 18 | tf.scalar_summary('stddev/' + name, stddev) 19 | stat_max = tf.reduce_max(var) 20 | stat_min = tf.reduce_min(var) 21 | episode_stats['names'].extend([name+'_mean', name+'_stddev', name+'_max', name+'_min']) 22 | episode_stats['variables'].extend([mean, stddev, stat_max, stat_min]) 23 | tf.scalar_summary('max/' + name, stat_max) 24 | tf.scalar_summary('min/' + name, stat_min) 25 | tf.histogram_summary(name, var) 26 | def set_output_dir(directory): 27 | global output_dir 28 | # make dir if it doesn't exist 29 | if not os.path.exists(directory): 30 | os.makedirs(directory) 31 | output_dir = directory 32 | 33 | def write_row(episode, timestep, row): 34 | """ 35 | Writes the current values for episode stats 36 | as a new row for the data 37 | """ 38 | # check what the current file buffer is open 39 | global cur_episode, output_dir 40 | if cur_episode != episode: 41 | cur_episode = episode 42 | # TODO test to make sure episode{} doesn't exist 43 | 44 | filename = '{}episode{}.csv'.format(output_dir,episode) 45 | if os.path.exists(filename): 46 | raise ValueError('{} already exists'.format(filename)) 47 | with open(filename, 'a+') as f: 48 | csv_writer = csv.writer(f) 49 | titles = ['timestep'] + episode_stats['names'] 50 | newrow = [timestep] + row 51 | csv_writer.writerow(titles) 52 | csv_writer.writerow(newrow) 53 | 54 | else: 55 | with open('{}episode{}.csv'.format(output_dir,episode), 'a') as f: 56 | csv_writer = csv.writer(f) 57 | csv_writer.writerow([timestep] + row) 58 | 59 | 60 | 61 | 62 | 63 | # open the file buffer 64 | # write the line 65 | # close the file buffer 66 | def variable(shape,f, name="Variable"): 67 | """ 68 | Creates a tensor of SHAPE drawn from 69 | a random uniform distribution in 0 +/- 1/sqrt(f) 70 | """ 71 | #TODO: fix this. currently shape is a [Dimension, int] object 72 | v = tf.Variable(tf.random_uniform(shape,-1/math.sqrt(f),1/math.sqrt(f)), name=name) 73 | if TRACK_VARS: variable_summaries(var, name) 74 | return v 75 | -------------------------------------------------------------------------------- /experiments/brain/critic_network.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | import numpy as np 4 | import math 5 | 6 | from .common.utils import variable 7 | from .common.utils import variable_summaries 8 | 9 | LAYER1_SIZE = 400 10 | LAYER2_SIZE = 300 11 | LEARNING_RATE = 1e-3 12 | TAU = 0.001 13 | L2 = 0.01 14 | 15 | class CriticNetwork: 16 | """docstring for CriticNetwork""" 17 | def __init__(self,sess,state_dim,action_dim): 18 | self.time_step = 0 19 | self.sess = sess 20 | self.state_dim = state_dim 21 | self.action_dim = action_dim 22 | # create q network 23 | self.state_input,\ 24 | self.action_input,\ 25 | self.q_value_output,\ 26 | self.net = self.create_q_network(state_dim,action_dim) 27 | 28 | # create target q network (the same structure with q network) 29 | self.target_state_input,\ 30 | self.target_action_input,\ 31 | self.target_q_value_output,\ 32 | self.target_update = self.create_target_q_network(state_dim,action_dim,self.net) 33 | 34 | self.create_training_method() 35 | 36 | # initialization 37 | self.sess.run(tf.initialize_all_variables()) 38 | 39 | self.update_target() 40 | 41 | 42 | def create_training_method(self): 43 | # Define training optimizer 44 | self.y_input = tf.placeholder("float",[None,1]) 45 | weight_decay = tf.add_n([L2 * tf.nn.l2_loss(var) for var in self.net]) 46 | self.cost = tf.reduce_mean(tf.square(self.y_input - self.q_value_output)) + weight_decay 47 | self.optimizer = tf.train.AdamOptimizer(LEARNING_RATE).minimize(self.cost) 48 | self.action_gradients = tf.gradients(self.q_value_output,self.action_input) 49 | 50 | def create_q_network(self,state_dim,action_dim): 51 | # the layer size could be changed 52 | layer1_size = LAYER1_SIZE 53 | layer2_size = LAYER2_SIZE 54 | 55 | state_input = tf.placeholder("float",[None,state_dim]) 56 | action_input = tf.placeholder("float",[None,action_dim]) 57 | 58 | W1 = variable([state_dim,layer1_size],state_dim) 59 | b1 = variable([layer1_size],state_dim) 60 | W2 = variable([layer1_size,layer2_size],layer1_size+action_dim) 61 | W2_action = variable([action_dim,layer2_size],layer1_size+action_dim) 62 | b2 = variable([layer2_size],layer1_size+action_dim) 63 | W3 = tf.Variable(tf.random_uniform([layer2_size,1],-3e-3,3e-3)) 64 | b3 = tf.Variable(tf.random_uniform([1],-3e-3,3e-3)) 65 | 66 | layer1 = tf.nn.relu(tf.matmul(state_input,W1) + b1) 67 | layer2 = tf.nn.relu(tf.matmul(layer1,W2) + tf.matmul(action_input,W2_action) + b2) 68 | q_value_output = tf.identity(tf.matmul(layer2,W3) + b3) 69 | variable_summaries(q_value_output, "Critic_Q") 70 | return state_input,action_input,q_value_output,[W1,b1,W2,W2_action,b2,W3,b3] 71 | 72 | def create_target_q_network(self,state_dim,action_dim,net): 73 | state_input = tf.placeholder("float",[None,state_dim]) 74 | action_input = tf.placeholder("float",[None,action_dim]) 75 | 76 | ema = tf.train.ExponentialMovingAverage(decay=1-TAU) 77 | target_update = ema.apply(net) 78 | target_net = [ema.average(x) for x in net] 79 | 80 | layer1 = tf.nn.relu(tf.matmul(state_input,target_net[0]) + target_net[1]) 81 | layer2 = tf.nn.relu(tf.matmul(layer1,target_net[2]) + tf.matmul(action_input,target_net[3]) + target_net[4]) 82 | q_value_output = tf.identity(tf.matmul(layer2,target_net[5]) + target_net[6]) 83 | variable_summaries(q_value_output, "Critic_T_Q") 84 | return state_input,action_input,q_value_output,target_update 85 | 86 | def update_target(self): 87 | self.sess.run(self.target_update) 88 | 89 | def train(self,y_batch,state_batch,action_batch): 90 | self.time_step += 1 91 | self.sess.run(self.optimizer,feed_dict={ 92 | self.y_input:y_batch, 93 | self.state_input:state_batch, 94 | self.action_input:action_batch 95 | }) 96 | 97 | def gradients(self,state_batch,action_batch): 98 | return self.sess.run(self.action_gradients,feed_dict={ 99 | self.state_input:state_batch, 100 | self.action_input:action_batch 101 | })[0] 102 | 103 | def target_q(self,state_batch,action_batch): 104 | return self.sess.run(self.target_q_value_output,feed_dict={ 105 | self.target_state_input:state_batch, 106 | self.target_action_input:action_batch 107 | }) 108 | 109 | def q_value(self,state_batch,action_batch): 110 | return self.sess.run(self.q_value_output,feed_dict={ 111 | self.state_input:state_batch, 112 | self.action_input:action_batch}) -------------------------------------------------------------------------------- /experiments/brain/ddpg.py: -------------------------------------------------------------------------------- 1 | # ----------------------------------- 2 | # Deep Deterministic Policy Gradient 3 | # Author: Flood Sung 4 | # Date: 2016.5.4 5 | # ----------------------------------- 6 | import gym 7 | import tensorflow as tf 8 | import numpy as np 9 | from .common.ou_noise import OUNoise 10 | from .critic_network import CriticNetwork 11 | from .actor_network import ActorNetwork 12 | from .common.replay_buffer import ReplayBuffer 13 | 14 | 15 | # Hyper Parameters: 16 | 17 | REPLAY_BUFFER_SIZE = 1000000 18 | REPLAY_START_SIZE = 64 19 | BATCH_SIZE = 64 20 | GAMMA = 0.99 21 | 22 | 23 | class DDPG: 24 | """docstring for DDPG""" 25 | def __init__(self, env): 26 | self.name = 'DDPG' # name for uploading results 27 | self.environment = env 28 | # Randomly initialize actor network and critic network 29 | # with both their target networks 30 | self.state_dim = env.observation_space.shape[0] 31 | self.action_dim = env.action_space.shape[0] 32 | print("DIMS",self.state_dim, self.action_dim) 33 | self.sess = tf.InteractiveSession() 34 | 35 | with tf.variable_scope("Actor"): 36 | self.actor_network = ActorNetwork(self.sess,self.state_dim,self.action_dim) 37 | with tf.variable_scope("Critic"): 38 | self.critic_network = CriticNetwork(self.sess,self.state_dim,self.action_dim) 39 | 40 | # initialize replay buffer 41 | self.replay_buffer = ReplayBuffer(REPLAY_BUFFER_SIZE, uniform=True) 42 | 43 | # Initialize a random process the Ornstein-Uhlenbeck process for action exploration 44 | self.exploration_noise = OUNoise(self.action_dim) 45 | 46 | def train(self): 47 | #print "train step",self.time_step 48 | # Sample a random minibatch of N transitions from replay buffer 49 | minibatch = self.replay_buffer.get_batch(BATCH_SIZE) 50 | state_batch = np.asarray([data[0] for data in minibatch]) 51 | action_batch = np.asarray([data[1] for data in minibatch]) 52 | reward_batch = np.asarray([data[2] for data in minibatch]) 53 | next_state_batch = np.asarray([data[3] for data in minibatch]) 54 | done_batch = np.asarray([data[4] for data in minibatch]) 55 | 56 | ###################### 57 | # Do NORMAL Q LEARNING 58 | ###################### 59 | # for action_dim = 1 60 | action_batch = np.resize(action_batch,[BATCH_SIZE,self.action_dim]) 61 | 62 | # Calculate y_batch 63 | next_action_batch = self.actor_network.target_actions(next_state_batch) 64 | q_value_batch = self.critic_network.target_q(next_state_batch, next_action_batch) 65 | 66 | y_batch = [] 67 | for i in range(len(minibatch)): 68 | if done_batch[i]: 69 | y_batch.append(reward_batch[i]) 70 | else : 71 | y_batch.append(reward_batch[i] + GAMMA * q_value_batch[i]) 72 | y_batch = np.resize(y_batch,[BATCH_SIZE,1]) 73 | 74 | # Update critic by minimizing the loss L 75 | self.critic_network.train(y_batch,state_batch,action_batch) 76 | ###################### 77 | 78 | # Update the actor policy using the sampled gradient: 79 | action_batch_for_gradients = self.actor_network.actions(state_batch) 80 | q_gradient_batch = self.critic_network.gradients(state_batch, action_batch_for_gradients) 81 | 82 | self.actor_network.train(q_gradient_batch,state_batch) 83 | 84 | # Update the target networks 85 | self.actor_network.update_target() 86 | self.critic_network.update_target() 87 | 88 | def noise_action_activations(self,state): 89 | # Select action a_t according to the current policy and exploration noise 90 | action, activations = self.actor_network.action_activations(state) 91 | action += self.exploration_noise.noise() 92 | return action, activations 93 | 94 | def action(self,state): 95 | action = self.actor_network.action(state) 96 | return action 97 | 98 | def action_activations(self, state): 99 | action, activations = self.actor_network.action_activations(state) 100 | return action, activations 101 | 102 | def perceive(self,state, action,reward,next_state, done): 103 | # Store transition (s_t,v_t,a_t,r_t,s_{t+1}) in replay buffer 104 | self.replay_buffer.add( 105 | state,action,reward,next_state, done) 106 | 107 | # Store transitions to replay start size then start training 108 | if self.replay_buffer.count() > REPLAY_START_SIZE: 109 | self.train() 110 | 111 | # Re-iniitialize the random process when an episode ends 112 | if done: 113 | self.exploration_noise.reset() 114 | -------------------------------------------------------------------------------- /experiments/brain/polynomial_critic.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | import numpy as np 4 | import math 5 | 6 | from .common.utils import variable 7 | from .common.utils import variable_summaries 8 | 9 | LAYER1_SIZE = 400 10 | LAYER2_SIZE = 300 11 | LEARNING_RATE = 1e-3 12 | TAU = 0.0001 13 | L2 = 0.01 14 | GAMMA=0.9 15 | 16 | 17 | class PolynomialCritic: 18 | def __init__( 19 | self,sess, 20 | state_placeholder, 21 | action_placeholder, 22 | t_state_placeholder, 23 | t_action_placeholder, 24 | reward_placeholder, 25 | done_placeholder, order=1, gamma=GAMMA, 26 | summaries=True): 27 | """ 28 | Creates a polynomial critic 29 | action-dim is always [1] considering that we are doing 30 | a critic per neuron 31 | """ 32 | self.order = order 33 | self.sess = sess 34 | self.summaries = summaries 35 | 36 | # Set up placeholders 37 | self.state_placeholder = state_placeholder 38 | self.action_placeholder = action_placeholder 39 | self.t_state_placeholder = t_state_placeholder 40 | self.t_action_placeholder = t_action_placeholder 41 | self.reward_placeholder = reward_placeholder 42 | self.done_placeholder = done_placeholder 43 | 44 | self.gamma = gamma 45 | 46 | # Set up dimensions= 47 | self.action_dim = 1 # Very specific, but necisarry. 48 | self.state_dim= state_placeholder.get_shape()[-1].value 49 | 50 | cur_act = tf.identity(self.t_state_placeholder) 51 | if self.summaries: variable_summaries(cur_act, cur_act.name) 52 | # create q network 53 | with tf.variable_scope("Q"): 54 | self.q_value_output,\ 55 | self.net = self.create_poly_q() 56 | 57 | # create target q network (the same structure with q network) 58 | with tf.variable_scope("Qtarget"): 59 | self.target_q_value_output,\ 60 | self.target_update = self.create_target_q_network(self.net, order <= 1) 61 | 62 | with tf.variable_scope("loss"): 63 | self.create_loss() 64 | 65 | 66 | def setup_graph(self, state_input, action_input, net, linear): 67 | """ 68 | Sets up the network graph. 69 | """ 70 | concat_input = tf.concat(1, [state_input, action_input]) 71 | print(concat_input) 72 | # TODO generalize this for order n (might be hard) 73 | if linear: 74 | q_value_output = tf.identity(tf.matmul(concat_input, net[0]) + net[1]) 75 | else: 76 | # enforce symmetry of W 77 | W1 = 0.5 * (net[0] + tf.transpose(net[0])) 78 | xT = tf.transpose(concat_input) 79 | q_value_output = tf.identity(tf.matmul(xT, tf.matmul(W1,concat_input)) + net[1]) 80 | net = [W1, net[1]] 81 | print("state_input {0}. action_input {1}".format(state_input, action_input)) 82 | return q_value_output, net 83 | 84 | def create_poly_q(self): 85 | """ Initialize the polynomial critic network""" 86 | # TODO: FIX TO REFLECT NEW CHANGES TO OBJECT. 87 | # Create the variables. 88 | linear = self.order <= 1 89 | layer_size = self.state_dim + self.action_dim if not linear else 1 90 | # TODO: ensure no conflict between dimension objects and ints 91 | W1 = variable([self.state_dim + self.action_dim, layer_size],self.state_dim) 92 | # might not want to hardcode the 1 if we want something like x^T (Wx + b) 93 | b1 = variable([1], self.state_dim) 94 | 95 | net = [W1, b1] 96 | q_value_output, net = self.setup_graph(self.state_placeholder , self.action_placeholder, net, linear) 97 | 98 | # then let x =tf.concat(state_placeholder, action_placeholder) and the output of this polynomial 99 | # critic will be Qn = x^TWx if order=2, or Qn = xW, if order =1, etc... 100 | return q_value_output, net 101 | 102 | def create_target_q_network(self, net, linear): 103 | """ Initialize the target polynomial critic network""" 104 | # TODO: FIX TO REFLECT NEW CHANGES TO OBJECT. 105 | # Implement 106 | ema = tf.train.ExponentialMovingAverage(decay=1 - TAU) 107 | target_update = ema.apply(net) 108 | target_net = [ema.average(x) for x in net] 109 | 110 | q_value_output, _ = self.setup_graph(self.t_state_placeholder, self.t_action_placeholder, target_net, linear) 111 | 112 | # then let x =tf.concat(state_placeholder, action_placeholder) and 113 | if self.summaries: variable_summaries(q_value_output, q_value_output.name) 114 | return q_value_output, target_update 115 | 116 | def update_target(self): 117 | self.sess.run(self.target_update) 118 | 119 | def create_loss(self): 120 | """ Define training loss """ 121 | weight_decay = tf.add_n([L2 * tf.nn.l2_loss(var) for var in self.net]) 122 | diff = tf.cond( 123 | self.done_placeholder, 124 | lambda: self.q_value_output - self.reward_placeholder, 125 | lambda: self.q_value_output - self.reward_placeholder - self.gamma*self.target_q_value_output) 126 | 127 | self.loss = tf.reduce_mean(tf.square(diff)) #+ weight_decay 128 | #variable_summaries(self.loss, "loss") 129 | 130 | def target_q(self,state_batch,action_batch): 131 | """ 132 | Feeds the state and action batch to calculate 133 | the q value through the target network. 134 | """ 135 | return self.sess.run(self.target_q_value_output,feed_dict={ 136 | self.target_state_input:state_batch, 137 | self.target_action_input:action_batch 138 | }) 139 | 140 | def q_value(self,state_batch,action_batch): 141 | """ 142 | Feeds the state and action batch to calculate 143 | the q value through the regular network. 144 | """ 145 | return self.sess.run(self.q_value_output,feed_dict={ 146 | self.state_input:state_batch, 147 | self.action_input:action_batch}) 148 | -------------------------------------------------------------------------------- /experiments/brain/sub_critics.py: -------------------------------------------------------------------------------- 1 | # ----------------------------------- 2 | # Deep Deterministic Policy Gradient 3 | # Author: William Guss 4 | # Date: 2016.5.4 5 | # ----------------------------------- 6 | import gym 7 | import tensorflow as tf 8 | import numpy as np 9 | from .ddpg import DDPG 10 | from .critic_network import CriticNetwork 11 | from .actor_network import ActorNetwork 12 | from .common.replay_buffer import ReplayBuffer 13 | from .common.utils import variable_summaries 14 | 15 | from .polynomial_critic import PolynomialCritic 16 | 17 | LEARNING_RATE=1e-3 18 | 19 | class SubCritics: 20 | def __init__(self, ddpg_agent : DDPG, order=1): 21 | """ 22 | Initializes the subcritics based on a particular ddpg agent. 23 | ORDER is currently unused. 24 | """ 25 | self.agent = ddpg_agent 26 | self.sess = ddpg_agent.sess 27 | self.actor = ddpg_agent.actor_network 28 | self.critics = [] 29 | self.activation_inputs = [] 30 | self.t_activation_inputs = [] 31 | 32 | self.reward_input = tf.placeholder("float",[None], name="reward") 33 | # To make this into a batch based subcritic, we need to batch 34 | # the episode done inputs and do batched tensorflow conditions 35 | # on the reward function. 36 | self.done_input = tf.placeholder("bool", name="episode_done") 37 | 38 | #TODO Build the rest of the subcritic system. 39 | # actor.layers = [state, output_layer1, output_layer2, output_layer3, ..., action = output_layer[-1]] 40 | for l, layer in enumerate(self.actor.layers[:-1]): 41 | # This could be cleaned up. 42 | # Make the placeholders 43 | 44 | action_dim = self.actor.layers[l+1].get_shape()[1] # Only works for 1d 45 | state_dim = layer.get_shape()[1] 46 | if not self.activation_inputs: 47 | self.activation_inputs = [ 48 | tf.placeholder("float",[None,state_dim], name="activ_{}".format(l))] 49 | state_input = self.activation_inputs[-1] 50 | action_input = tf.placeholder("float",[None,action_dim], name="activ_{}".format(l+1)) 51 | 52 | 53 | self.activation_inputs += [action_input] 54 | 55 | if not self.t_activation_inputs: 56 | self.t_activation_inputs = [ 57 | tf.placeholder("float",[None,state_dim], name="t_activ_{}".format(l))] 58 | t_state_input = self.t_activation_inputs[-1] 59 | t_action_input = tf.placeholder("float",[None,action_dim], name="t_activ_{}".format(l+1)) 60 | 61 | self.t_activation_inputs += [t_action_input] 62 | 63 | # Now make the sub critic laeyr. 64 | 65 | with tf.variable_scope("subcritic_layer{}".format(l)): 66 | 67 | # Make a true and target placeholders (This is an optimization) 68 | 69 | b_size = tf.shape(state_input)[0] 70 | #Create critics for each input 71 | for j in range(action_dim): 72 | with tf.variable_scope("subcritic_n{}".format(l,j)): 73 | self.critics.append( 74 | PolynomialCritic( 75 | self.sess, 76 | state_input, tf.reshape(action_input[:,j], tf.pack([b_size, 1])), 77 | t_state_input, tf.reshape(t_action_input[:,j], tf.pack([b_size, 1])), 78 | self.reward_input, self.done_input, 79 | order)) 80 | 81 | # Create optimizer on all critics 82 | with tf.variable_scope("subcritic_training"): 83 | constituent_loss = [cn.loss for cn in self.critics] 84 | self.loss = tf.add_n(constituent_loss) 85 | self.optimizer = tf.train.AdamOptimizer(LEARNING_RATE).minimize(self.loss) 86 | variable_summaries(self.loss, "loss") 87 | 88 | 89 | self.target_update = [cn.target_update for cn in self.critics] 90 | 91 | def get_perceive_run(self, activations, next_activations, reward, done): 92 | # Update the targets of the critics. 93 | self.sess.run(self.target_update) 94 | 95 | # TODO Enable batching. 96 | feeds = {} 97 | feeds.update({ 98 | activation: [activations[i]] for i, activation in enumerate(self.activation_inputs)}) 99 | feeds.update({ 100 | t_activation: [next_activations[i]] for i, t_activation in enumerate(self.t_activation_inputs)}) 101 | feeds.update({ 102 | self.reward_input: [reward], 103 | self.done_input: done}) 104 | 105 | return [self.optimizer], feeds 106 | 107 | def get_count(self): 108 | return len(self.critics) 109 | -------------------------------------------------------------------------------- /experiments/dataInterface.py: -------------------------------------------------------------------------------- 1 | import json 2 | import numpy as np 3 | import os 4 | 5 | def getScalar(dir, stat, layer, neuron, func, run='.'): ### stat is one of max, mean, min, stddev, neuron is something like '1_4', func is one of action, Q or Qtarget 6 | if func == 'action': 7 | func = '' 8 | funcAddon = '' 9 | else: 10 | funcAddon = '_2F' 11 | filename = "scalars_run_{}_tag_{}_2Fsubcritic_layer{}_2Fsubcritic_n{}_2F{}{}Identity_3A0.json".format(run, \ 12 | stat, \ 13 | layer, \ 14 | neuron, \ 15 | func, \ 16 | funcAddon) 17 | with open(os.path.join(dir, filename)) as f: 18 | arr = np.array(json.loads(f.read())) 19 | 20 | arr = arr[:, 1:] # First Column doesn't contain useful data 21 | 22 | return arr # first column is timestep, second column is value 23 | 24 | def getDistribution(dir, layer, neuron, func, run='.'): 25 | if func == 'action': 26 | func = '' 27 | funcAddon = '' 28 | else: 29 | funcAddon = '_2F' 30 | filename = "compressedHistograms_run_{}_tag_subcritic_layer{}_2Fsubcritic_n{}_2F{}{}Identity_3A0.json".format(run, \ 31 | layer, \ 32 | neuron, \ 33 | func, \ 34 | funcAddon) 35 | with open(os.path.join(dir, filename)) as f: 36 | arr = list(json.loads(f.read())) 37 | 38 | num_dists = 9 39 | data = np.zeros(len(arr) * num_dists * 2).reshape((num_dists, len(arr), 2)) 40 | for i in range(len(arr)): 41 | for j in range(num_dists): 42 | data[j][i] = [arr[i][1], arr[i][2][j][1]] 43 | return data 44 | 45 | ## Example usage 46 | if __name__ == '__main__': 47 | import matplotlib.pyplot as plt 48 | max = getScalar('data', 'max', '2', '2', 'Q') 49 | dist = getDistribution('data', '2', '2', 'Q') 50 | plt.plot(max[:, 0], max[:, 1]) 51 | plt.show() 52 | 53 | plt.plot(dist[0][:,0], dist[0][:, 1]) 54 | plt.show() -------------------------------------------------------------------------------- /experiments/experiment1.py: -------------------------------------------------------------------------------- 1 | ################################################################ 2 | # EXPERIMENT 1: 3 | # 4 | # In this experiment we will train an actor according to a critic 5 | # and then simultaneously learn and plot the resulting 6 | ################################################################ 7 | import gym 8 | import numpy as np 9 | import tensorflow as tf 10 | import matplotlib.pyplot as plt 11 | from IPython import display 12 | from itertools import chain 13 | import gc 14 | import argparse 15 | gc.enable() 16 | 17 | from brain import DDPG 18 | from brain import SubCritics 19 | from brain.common.filter_env import makeFilteredEnv 20 | import brain.common.utils as utils 21 | from brain.common.utils import episode_stats, write_row 22 | 23 | 24 | def test(env, agent, num_tests): 25 | """ 26 | Tests the agent. 27 | """ 28 | total_reward = 0 29 | for i in range(num_tests): 30 | state = env.reset() 31 | for j in range(env.spec.timestep_limit): 32 | #env.render() 33 | action = agent.action(state) # direct action for test 34 | state,reward,done,_ = env.step(action) 35 | total_reward += reward 36 | if done: 37 | break 38 | avg_reward = total_reward/num_tests 39 | return avg_reward 40 | 41 | 42 | def run_experiment(exp_name, ENV_NAME='LunarLanderContinuous-v2', EPISODES=10000, TEST=10): 43 | """ 44 | Runs the experiment on the target en 45 | """ 46 | env = makeFilteredEnv(gym.make(ENV_NAME)) 47 | 48 | # Create the standard DDPG agent. 49 | agent = DDPG(env) 50 | 51 | sub_critics = SubCritics(agent, order=1) # Make linear (order 1) subcritics 52 | 53 | # Set up tensorboard. 54 | merged = tf.merge_all_summaries() 55 | train_writer = tf.train.SummaryWriter('/tmp/tboard/{}'.format(exp_name), 56 | agent.sess.graph) 57 | # To see graph run tensorboard --logdir=/tmp/exp1/tboard 58 | init_op = tf.initialize_all_variables() 59 | agent.sess.run(init_op) 60 | 61 | t = 0 62 | for episode in range(EPISODES): 63 | state = env.reset() 64 | activations = None 65 | print("Episode: ", episode, end="") 66 | r_tot = 0 67 | 68 | for step in range(env.spec.timestep_limit): 69 | t+= 1 70 | # Explore state space. 71 | next_action, next_activations = agent.noise_action_activations(state) 72 | 73 | # Deal with the environment 74 | next_state,reward,done,_ = env.step(next_action) 75 | r_tot += reward 76 | env.render() 77 | 78 | # Train subcrticis and plot to tensorflow 79 | if activations is not None and action is not None: 80 | ops, feeds = sub_critics.get_perceive_run(activations, next_activations, reward, done) 81 | ops += [ 82 | agent.critic_network.q_value_output, 83 | agent.critic_network.target_q_value_output] 84 | feeds.update({ 85 | agent.critic_network.state_input: [state], 86 | agent.critic_network.action_input: [action], 87 | agent.critic_network.target_state_input: [next_state], 88 | agent.critic_network.target_action_input: [next_action] 89 | }) 90 | ops = [merged] + ops 91 | result = agent.sess.run(ops, feeds) 92 | # use ordered dict for stats_map 93 | stats_result = agent.sess.run(episode_stats['variables'], feeds) 94 | write_row(episode, step, stats_result) 95 | train_writer.add_summary(result[0], t) 96 | 97 | # Train DDPG 98 | agent.perceive(state,next_action,reward,next_state,done) 99 | if done: 100 | break 101 | # Move on to next frame. 102 | state = next_state 103 | activations = next_activations 104 | action = next_action 105 | print(" ", r_tot) 106 | 107 | # Testing: 108 | if episode % 100 == 0 and episode > 100: 109 | avg_reward = test(env, agent, TEST) 110 | print(('episode: ',episode,'Evaluation Average Reward:',avg_reward)) 111 | 112 | if __name__ == '__main__': 113 | parser = argparse.ArgumentParser() 114 | parser.add_argument( 115 | '--name', 116 | type=str, 117 | default='tboard', 118 | help="""\ 119 | the name of the experiment to run.\ 120 | """ 121 | ) 122 | parser.add_argument( 123 | '--output_dir', 124 | type=str, 125 | default='output/', 126 | help="""\ 127 | The directory to output training csvs\ 128 | """ 129 | ) 130 | parser.add_argument( 131 | '--output_csv', 132 | dest='output_csv', 133 | action='store_true', 134 | help="""\ 135 | Flag to save the experiments as csv\ 136 | """ 137 | ) 138 | parser.set_defaults(output_csv=False) 139 | args = parser.parse_args() 140 | utils.set_output_dir(args.output_dir) 141 | run_experiment(args.name) 142 | -------------------------------------------------------------------------------- /experiments/experiment2.py: -------------------------------------------------------------------------------- 1 | ################################################################ 2 | # EXPERIMENT 2: 3 | # 4 | # In this experiment we will train an actor according to its subcritics 5 | ################################################################ 6 | import gym 7 | import numpy as np 8 | import tensorflow as tf 9 | import matplotlib.pyplot as plt 10 | from IPython import display 11 | from itertools import chain 12 | import gc 13 | gc.enable() 14 | 15 | from brain import DDPG 16 | from brain import SubCritics 17 | from brain.common.filter_env import makeFilteredEnv 18 | 19 | def run_experiment(ENV_NAME='MountainCarContinuous-v0', EPISODES=10000, TEST=10): 20 | """ 21 | Runs the experiment. 22 | """ 23 | pass 24 | if __name__ == '__main__': 25 | run_experiment() 26 | -------------------------------------------------------------------------------- /experiments/extractData.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ]; then 3 | echo usage: $0 logdir 4 | exit 5 | fi 6 | if [ -n "$2" ]; then 7 | target=$2 8 | else 9 | target=data 10 | fi 11 | 12 | echo logdir $1 13 | python serialize_tensorboard.py --logdir "$1" --target $target --overwrite -------------------------------------------------------------------------------- /explorations/README.md: -------------------------------------------------------------------------------- 1 | # Explorations 2 | The explorations folder is a collection of various explorations into local learning rules via iPython notebooks. 3 | The purpose of this directory is to seperate concerns with respect to different explorations; a single codebase is 4 | not efficient when so many different strategies are bing tried. 5 | -------------------------------------------------------------------------------- /old/erl/brainlib/src/connector.erl: -------------------------------------------------------------------------------- 1 | %%%------------------------------------------------------------------- 2 | %%% @author Phillip Kuznetsov 3 | %%% @copyright (C) 2016, Machine Learning at Berkeley 4 | %%% @doc Handles the connections between neurons 5 | %%% 6 | %%% @end 7 | %%% Created : 04. Mar 2016 2:08 PM 8 | %%%------------------------------------------------------------------- 9 | -module(connector). 10 | -author("philkuz"). 11 | 12 | %% API 13 | -export([]). 14 | -------------------------------------------------------------------------------- /old/erl/brainlib/src/extra_math.erl: -------------------------------------------------------------------------------- 1 | %% @author philkuz 2 | %% @doc @todo Add description to utils. 3 | 4 | %% @description Handles all of that math utility stuff necessary for 5 | %% the project. 6 | -module(extra_math). 7 | 8 | %% ==================================================================== 9 | %% API functions 10 | %% ==================================================================== 11 | -export([floor/1, ceiling/1, mod/2]). 12 | 13 | % function which rounds a number to the nearest int <= x 14 | floor(X) when X < 0 -> 15 | T = trunc(X), 16 | case X - T == 0 of 17 | true -> T; 18 | false -> T - 1 19 | end; 20 | floor(X) -> 21 | trunc(X). 22 | 23 | % function which rounds a number to the nearest int >= x 24 | ceiling(X) when X < 0 -> 25 | trunc(X); 26 | ceiling(X) -> 27 | T = trunc(X), 28 | case X - T == 0 of 29 | true -> T; 30 | false -> T + 1 31 | end. 32 | 33 | % modulus operator 34 | mod(X,Y) -> 35 | R = X rem Y, 36 | if R < 0 -> 37 | R + Y; 38 | true -> 39 | R 40 | end. 41 | 42 | %% ==================================================================== 43 | %% Internal functions 44 | %% ==================================================================== 45 | 46 | 47 | -------------------------------------------------------------------------------- /old/erl/brainlib/src/game.erl: -------------------------------------------------------------------------------- 1 | -module(game). 2 | 3 | -export([start/0, erl_master/0, pixels/1, start_input/0, input/0, stop/0]). 4 | 5 | 6 | erl_master() -> 7 | receive 8 | {setup_java, JavaPid} -> 9 | io:format("Received Java input ~w~n", [JavaPid]), 10 | PixelPid = spawn(game, pixels, [brain]), 11 | JavaPid ! {pixelpid, PixelPid}, 12 | register(input_listener, spawn(game, input, [])) 13 | end. 14 | 15 | pixels(NNPid) -> 16 | receive 17 | %send pixels to neural network. 18 | {pixels, Pixels} -> 19 | NNPid ! {feed, Pixels}, 20 | 21 | pixels(NNPid) 22 | end. 23 | 24 | start_input()-> 25 | receive 26 | {connect, Pid} -> 27 | io:format("~p connected to input listener!~n", [Pid]), 28 | input() 29 | end. 30 | 31 | input() -> 32 | receive 33 | w -> 34 | {actioninbox, 'actionserver@maxbook'} ! w, 35 | input(); 36 | a -> 37 | {actioninbox, 'actionserver@maxbook'} ! a, 38 | input(); 39 | s -> 40 | {actioninbox, 'actionserver@maxbook'} ! s, 41 | input(); 42 | d -> 43 | {actioninbox, 'actionserver@maxbook'} ! d, 44 | input(); 45 | space -> 46 | {actioninbox, 'actionserver@maxbook'} ! space, 47 | input(); 48 | mouse -> 49 | {actioninbox, 'actionserver@maxbook'} ! mouse, 50 | input() 51 | end. 52 | 53 | start() -> 54 | brain:start(), 55 | ErlMaster = spawn(game, erl_master, []), 56 | {pxinbox, 'pxserver@maxbook'} ! {ErlMaster, "Hello, Java!"}. 57 | 58 | 59 | 60 | stop() -> 61 | unregister(pixel_register), 62 | unregister(input_listener). 63 | -------------------------------------------------------------------------------- /old/erl/brainlib/src/mcdemo.erl: -------------------------------------------------------------------------------- 1 | %% @author philkuz 2 | %% @doc @todo Add description to mcdemo. 3 | 4 | 5 | -module(mcdemo). 6 | 7 | %% ==================================================================== 8 | %% API functions 9 | %% ==================================================================== 10 | -export([start/0,start/2, stop/0]). 11 | start() -> 12 | start(normal, placeholder). 13 | %% @doc Starts the module 14 | start(normal, _Args) -> 15 | brain:start(), 16 | game:start(). 17 | %% @doc Stops the module 18 | stop() -> 19 | game:stop(), 20 | brain ! stop. 21 | 22 | %% ==================================================================== 23 | %% Internal functions 24 | %% ==================================================================== 25 | 26 | 27 | -------------------------------------------------------------------------------- /old/erl/brainlib/src/neuron.erl: -------------------------------------------------------------------------------- 1 | %%%------------------------------------------------------------------- 2 | %%% @author Phillip Kuznetsov 3 | %%% @copyright (C) 2016, Machine Learning at Berkeley 4 | %%% @doc 5 | %%% 6 | %%% @end 7 | %%% Created : 10. Mar 2016 5:28 PM 8 | %%%------------------------------------------------------------------- 9 | -module(neuron). 10 | -author("Phillip Kuznetsov"). 11 | 12 | %% API 13 | -export([]). 14 | -callback fire(Neuron :: term()) -> 15 | ok. 16 | 17 | -callback update_internal_state(InternalState :: tuple(), 18 | TimeStep :: non_neg_integer(), ReceivedInputs :: list(term())) -> 19 | {ok, NewState :: tuple()}. 20 | 21 | -callback handle() 22 | 23 | fire() -> 24 | 25 | 26 | -------------------------------------------------------------------------------- /old/erl/brainlib/src/test.erl: -------------------------------------------------------------------------------- 1 | -module(test). 2 | 3 | -export([makeNopeTimes/0]). 4 | 5 | makeNopeTimes() -> 6 | {echo,java@maxbook} ! {self(),"Hello, Java!"}, 7 | getMessages(). 8 | 9 | getMessages() -> 10 | receive 11 | {connect,Sender} -> 12 | io:format("Got a message from ~p~n", [Sender]); 13 | {pixels, PixelData} -> 14 | io:format("Got pixels~n", []) 15 | end, 16 | getMessages(). 17 | -------------------------------------------------------------------------------- /old/src/brain.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import networkx 3 | import time 4 | import utils.gnumpy as gpu 5 | import gym 6 | 7 | from utils.ubigraph import Ubigraph 8 | 9 | class Brain(object): 10 | """ 11 | The brain class for openbrain. 12 | """ 13 | 14 | def __init__(self, num_input, num_hidden, num_output, density=0.5): 15 | """ 16 | Constructs an open brain object. 17 | :param num_input: The number of inputs 18 | :param num_output: The number of outputs 19 | :param num_hidden: The number of hidden neurons. 20 | """ 21 | self.initialize_graph(num_input,num_hidden, num_output, density=0.5) 22 | self.visualize() 23 | 24 | 25 | def initialize_graph(self, num_input, num_hidden, num_output,density): 26 | """ 27 | Initializes the open brain graph. 28 | :param num_input: 29 | :param num_hidden: 30 | :param num_output: 31 | :param density: 32 | :return: 33 | """ 34 | self.num_neurons = num_input + num_output + num_hidden 35 | self.C = np.zeros((self.num_neurons, self.num_neurons)) 36 | 37 | adjacency_list = self.define_toplogy(num_input, num_hidden, num_output, density) 38 | 39 | for i, adjacent in enumerate(adjacency_list): 40 | for node in adjacent: 41 | self.C[i, node] = np.random.rand(1)*0.9 42 | 43 | self.C = gpu.garray(self.C) 44 | 45 | def define_toplogy(self, num_input, num_hidden, num_output, density): 46 | """ 47 | Defines the topology of the OpenBrain network. 48 | :param num_input: 49 | :param num_hidden: 50 | :param num_output: 51 | :param density: 52 | :return: 53 | """ 54 | topo = networkx.DiGraph(networkx.watts_strogatz_graph(self.num_neurons, 5, density, seed=None)).to_directed() 55 | adjacency_list = topo.adjacency_list() 56 | 57 | 58 | # Pick the output neurons to be those with highest in degree 59 | in_deg = np.array([topo.in_degree(x) for x,_ in enumerate(adjacency_list)]) 60 | self.output_neurons = np.argpartition(in_deg, -num_output)[-num_output:] 61 | print(self.output_neurons) 62 | print([topo.in_degree(x) for x in self.output_neurons]) 63 | 64 | # Pick the input neurons to be those with highest out degree 65 | out_deg = np.array([topo.out_degree(x) if x not in self.output_neurons else -1 66 | for x,_ in enumerate(adjacency_list)]) 67 | self.input_neurons = np.argpartition(out_deg, -num_input)[-num_input:] 68 | 69 | # Output neurons do not fire out. 70 | for adjacent_neurons in adjacency_list: 71 | for out_neuron in self.output_neurons: 72 | if out_neuron in adjacent_neurons: 73 | adjacent_neurons.remove(out_neuron) 74 | 75 | # Disconnect input -> output 76 | for out in self.output_neurons: 77 | for inp in self.input_neurons: 78 | if out in adjacency_list[inp]: adjacency_list[inp].remove(out) 79 | if inp in adjacency_list[out]: adjacency_list[out].remove(inp) 80 | 81 | 82 | for i, adjacent in enumerate(adjacency_list): 83 | if i not in self.input_neurons and i not in self.output_neurons: 84 | for n in adjacent: 85 | if i in adjacency_list[n]: 86 | if np.random.rand(1)>0.5: 87 | adjacent.remove(n) 88 | else: 89 | adjacency_list[n].remove(i) 90 | 91 | # Let nothing enter the input neurons 92 | for inp in self.input_neurons: 93 | adjacency_list[inp] = [] 94 | 95 | return adjacency_list 96 | 97 | 98 | def visualize(self): 99 | self.ubi = Ubigraph(self.C) 100 | # Color the input and output neurons 101 | self.ubi.set_properties({ 102 | "color": "#1E90FF" 103 | }, self.input_neurons) 104 | 105 | self.ubi.set_properties({ 106 | "color": "#FFD700" 107 | }, self.output_neurons) 108 | 109 | def get_random_input(b): 110 | return gpu.garray(np.array([np.random.rand(1) * 2 - 1.0 if i in b.input_neurons else 0.0 for i in range(b.num_neurons)], 111 | dtype=np.float32)) 112 | 113 | 114 | if __name__ == '__main__': 115 | b = Brain(2,120,1, 0.2) 116 | v =get_random_input(b) 117 | i =0 118 | 119 | grad = list() 120 | 121 | for i,x in enumerate(v.as_numpy_array()): 122 | b.ubi.set_properties({ 123 | "size": str(x) 124 | }, [i]) 125 | for i_episode in range(500): 126 | for t in range(100): 127 | 128 | 129 | 130 | 131 | x = get_random_input(b) 132 | net = b.C.dot(v*0.9 + x) 133 | #dsigma = gpu.diagflat(gpu.tanh(net)*(1 - gpu.tanh(net))) 134 | #dnet = gpu.garray(np.multiply.outer(np.identity(v.shape[0]), v.as_numpy_array())) 135 | #dsigmadv = gpu.tensordot(dsigma, gpu.diagflat(v)) 136 | #grad.append(dsigmadv) 137 | v = gpu.tanh(net) 138 | 139 | #diff = gpu.garray (v.as_numpy_array()[b.output_neurons] - np.array([0.2])) 140 | #dsigmadC = gpu.tensordot(dsigma, dnet, 1) 141 | #dpidC = gpu.garray(dsigmadC.as_numpy_array()[b.output_neurons,:,:]) 142 | 143 | 144 | b.C += 0.1*dEdC 145 | print(i, v.as_numpy_array()[b.output_neurons]) 146 | 147 | #dEdC = gpu.tensordot(diff, dpidC,1) 148 | 149 | 150 | #b.C += 0.01*dEdC 151 | #print(i, v.as_numpy_array()[b.output_neurons]) 152 | 153 | for n, volt in enumerate(v): 154 | if not( n in b.input_neurons or n in b.output_neurons): 155 | b.ubi.set_properties({ 156 | "size": str(abs(volt)*2), 157 | "color": "#FF0000" 158 | }, [n]) 159 | -------------------------------------------------------------------------------- /old/src/pacman_demo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/old/src/pacman_demo/__init__.py -------------------------------------------------------------------------------- /old/src/pacman_demo/commands.txt: -------------------------------------------------------------------------------- 1 | python pacman.py 2 | python pacman.py --layout testMaze --pacman GoWestAgent 3 | python pacman.py --layout tinyMaze --pacman GoWestAgent 4 | python pacman.py -h 5 | python pacman.py -l tinyMaze -p SearchAgent -a fn=tinyMazeSearch 6 | python pacman.py -l tinyMaze -p SearchAgent 7 | python pacman.py -l mediumMaze -p SearchAgent 8 | python pacman.py -l bigMaze -z .5 -p SearchAgent 9 | python eightpuzzle.py 10 | python pacman.py -l mediumDottedMaze -p StayEastSearchAgent 11 | python pacman.py -l mediumScaryMaze -p StayWestSearchAgent 12 | python pacman.py -l bigMaze -z .5 -p SearchAgent -a fn=astar,heuristic=manhattanHeuristic 13 | python pacman.py -l mediumCorners -p AStarCornersAgent -z 0.5 14 | python pacman.py -l testSearch -p AStarFoodSearchAgent 15 | python pacman.py -l trickySearch -p AStarFoodSearchAgent 16 | python pacman.py -p ReflexAgent 17 | python pacman.py -p ReflexAgent -l testClassic 18 | python pacman.py -p ReflexAgent -l testClassic 19 | python pacman.py --frameTime 0 -p ReflexAgent -k 1 20 | python pacman.py --frameTime 0 -p ReflexAgent -k 2 21 | python pacman.py -p ReflexAgent -l openClassic -n 10 -q 22 | python pacman.py -p MinimaxAgent -l minimaxClassic -a depth=4 23 | python pacman.py -p MinimaxAgent -l trappedClassic -a depth=3 24 | python pacman.py -l contestClassic -p ContestAgent -g DirectionalGhost -q -n 10 25 | 26 | -------------------------------------------------------------------------------- /old/src/pacman_demo/ghostAgents.py: -------------------------------------------------------------------------------- 1 | # ghostAgents.py 2 | # -------------- 3 | # Licensing Information: You are free to use or extend these projects for 4 | # educational purposes provided that (1) you do not distribute or publish 5 | # solutions, (2) you retain this notice, and (3) you provide clear 6 | # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. 7 | # 8 | # Attribution Information: The Pacman AI projects were developed at UC Berkeley. 9 | # The core projects and autograders were primarily created by John DeNero 10 | # (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu). 11 | # Student side autograding was added by Brad Miller, Nick Hay, and 12 | # Pieter Abbeel (pabbeel@cs.berkeley.edu). 13 | 14 | 15 | from game import Agent 16 | from game import Actions 17 | from game import Directions 18 | import random 19 | from util import manhattanDistance 20 | import util 21 | 22 | class GhostAgent( Agent ): 23 | def __init__( self, index ): 24 | self.index = index 25 | 26 | def getAction( self, state ): 27 | dist = self.getDistribution(state) 28 | if len(dist) == 0: 29 | return Directions.STOP 30 | else: 31 | return util.chooseFromDistribution( dist ) 32 | 33 | def getDistribution(self, state): 34 | "Returns a Counter encoding a distribution over actions from the provided state." 35 | util.raiseNotDefined() 36 | 37 | class RandomGhost( GhostAgent ): 38 | "A ghost that chooses a legal action uniformly at random." 39 | def getDistribution( self, state ): 40 | dist = util.Counter() 41 | for a in state.getLegalActions( self.index ): dist[a] = 1.0 42 | dist.normalize() 43 | return dist 44 | 45 | class DirectionalGhost( GhostAgent ): 46 | "A ghost that prefers to rush Pacman, or flee when scared." 47 | def __init__( self, index, prob_attack=0.8, prob_scaredFlee=0.8 ): 48 | self.index = index 49 | self.prob_attack = prob_attack 50 | self.prob_scaredFlee = prob_scaredFlee 51 | 52 | def getDistribution( self, state ): 53 | # Read variables from state 54 | ghostState = state.getGhostState( self.index ) 55 | legalActions = state.getLegalActions( self.index ) 56 | pos = state.getGhostPosition( self.index ) 57 | isScared = ghostState.scaredTimer > 0 58 | 59 | speed = 1 60 | if isScared: speed = 0.5 61 | 62 | actionVectors = [Actions.directionToVector( a, speed ) for a in legalActions] 63 | newPositions = [( pos[0]+a[0], pos[1]+a[1] ) for a in actionVectors] 64 | pacmanPosition = state.getPacmanPosition() 65 | 66 | # Select best actions given the state 67 | distancesToPacman = [manhattanDistance( pos, pacmanPosition ) for pos in newPositions] 68 | if isScared: 69 | bestScore = max( distancesToPacman ) 70 | bestProb = self.prob_scaredFlee 71 | else: 72 | bestScore = min( distancesToPacman ) 73 | bestProb = self.prob_attack 74 | bestActions = [action for action, distance in zip( legalActions, distancesToPacman ) if distance == bestScore] 75 | 76 | # Construct distribution 77 | dist = util.Counter() 78 | for a in bestActions: dist[a] = bestProb / len(bestActions) 79 | for a in legalActions: dist[a] += ( 1-bestProb ) / len(legalActions) 80 | dist.normalize() 81 | return dist 82 | -------------------------------------------------------------------------------- /old/src/pacman_demo/keyboardAgents.py: -------------------------------------------------------------------------------- 1 | # keyboardAgents.py 2 | # ----------------- 3 | # Licensing Information: You are free to use or extend these projects for 4 | # educational purposes provided that (1) you do not distribute or publish 5 | # solutions, (2) you retain this notice, and (3) you provide clear 6 | # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. 7 | # 8 | # Attribution Information: The Pacman AI projects were developed at UC Berkeley. 9 | # The core projects and autograders were primarily created by John DeNero 10 | # (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu). 11 | # Student side autograding was added by Brad Miller, Nick Hay, and 12 | # Pieter Abbeel (pabbeel@cs.berkeley.edu). 13 | 14 | 15 | from game import Agent 16 | from game import Directions 17 | import random 18 | 19 | class KeyboardAgent(Agent): 20 | """ 21 | An agent controlled by the keyboard. 22 | """ 23 | # NOTE: Arrow keys also work. 24 | WEST_KEY = 'a' 25 | EAST_KEY = 'd' 26 | NORTH_KEY = 'w' 27 | SOUTH_KEY = 's' 28 | STOP_KEY = 'q' 29 | 30 | def __init__( self, index = 0 ): 31 | 32 | self.lastMove = Directions.STOP 33 | self.index = index 34 | self.keys = [] 35 | 36 | def getAction( self, state): 37 | from graphicsUtils import keys_waiting 38 | from graphicsUtils import keys_pressed 39 | keys = keys_waiting() + keys_pressed() 40 | if keys != []: 41 | self.keys = keys 42 | 43 | legal = state.getLegalActions(self.index) 44 | move = self.getMove(legal) 45 | 46 | if move == Directions.STOP: 47 | # Try to move in the same direction as before 48 | if self.lastMove in legal: 49 | move = self.lastMove 50 | 51 | if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP 52 | 53 | if move not in legal: 54 | move = random.choice(legal) 55 | 56 | self.lastMove = move 57 | return move 58 | 59 | def getMove(self, legal): 60 | move = Directions.STOP 61 | if (self.WEST_KEY in self.keys or 'Left' in self.keys) and Directions.WEST in legal: move = Directions.WEST 62 | if (self.EAST_KEY in self.keys or 'Right' in self.keys) and Directions.EAST in legal: move = Directions.EAST 63 | if (self.NORTH_KEY in self.keys or 'Up' in self.keys) and Directions.NORTH in legal: move = Directions.NORTH 64 | if (self.SOUTH_KEY in self.keys or 'Down' in self.keys) and Directions.SOUTH in legal: move = Directions.SOUTH 65 | return move 66 | 67 | class KeyboardAgent2(KeyboardAgent): 68 | """ 69 | A second agent controlled by the keyboard. 70 | """ 71 | # NOTE: Arrow keys also work. 72 | WEST_KEY = 'j' 73 | EAST_KEY = "l" 74 | NORTH_KEY = 'i' 75 | SOUTH_KEY = 'k' 76 | STOP_KEY = 'u' 77 | 78 | def getMove(self, legal): 79 | move = Directions.STOP 80 | if (self.WEST_KEY in self.keys) and Directions.WEST in legal: move = Directions.WEST 81 | if (self.EAST_KEY in self.keys) and Directions.EAST in legal: move = Directions.EAST 82 | if (self.NORTH_KEY in self.keys) and Directions.NORTH in legal: move = Directions.NORTH 83 | if (self.SOUTH_KEY in self.keys) and Directions.SOUTH in legal: move = Directions.SOUTH 84 | return move 85 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/bigCorners.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %. % %.% 3 | % %%%%% % %%% %%% %%%%%%% % % 4 | % % % % % % % % 5 | %%%%% %%%%% %%% % % % %%% %%%%% % %%% 6 | % % % % % % % % % % % % % 7 | % %%% % % % %%% %%%%% %%% % %%% %%% % 8 | % % % % % % % % % 9 | %%% %%%%%%%%% %%%%%%% %%% %%% % % % % 10 | % % % % % % % 11 | % % %%%%% % %%% % % %%% % %%% %%% % % 12 | % % % % % % % % % % % % % % 13 | % % % %%%%%%% % %%%%%%%%% %%% % %%% % 14 | % % % % % % % % % % 15 | %%% %%% % %%%%% %%%%% %%% %%% %%%%% % 16 | % % % % % % % % % 17 | % % % % % % %%% %%% %%% % % % % % % 18 | % % % % % %% % % % % % % % % % 19 | % % %%%%% % %%% %%% % %%% %%% %%%%% 20 | % % % % % % % % % % % 21 | % %%% % % % %%% %%% %%%%%%%%% % %%% 22 | % % % % % % % 23 | % %%% %%%%%%%%%%%%%%%%%%%%% % % %%% % 24 | % % % % 25 | % % % %%%%% %%% % % % % %%%%%%%%%%%%% 26 | % % % % % % % % % % % % 27 | % % %%% %%% % % % %%%%%%%%% %%% % % % 28 | % % % % % % %P % % % % % % 29 | % %%% %%% %%% % %%% % % %%%%% % %%%%% 30 | % % % % % % % % 31 | %%% % %%%%% %%%%% %%% %%% % %%% % %%% 32 | % % % % % % % % % % % % % % % 33 | % % %%% % % % % %%%%%%%%% % % % % % % 34 | % % % % 35 | % % % %%% %%% %%%%%%% %%% %%% %%% % 36 | %.% % % % % .% 37 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/bigMaze.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % % % % % % % % 3 | % %%%%%%% % %%% % %%% %%% %%%%%%% % % 4 | % % % % % % % % 5 | %%%%% %%%%% %%% % % % %%% %%%%% % %%% 6 | % % % % % % % % % % % % % % 7 | % %%% % % % %%% %%%%% %%% % %%% %%% % 8 | % % % % % % % % % 9 | %%% %%%%%%%%% %%%%%%% %%% %%% % % % % 10 | % % % % % % % 11 | % % %%%%% % %%% % % %%% % %%% %%% % % 12 | % % % % % % % % % % % % % % 13 | % % % %%%%%%% % %%%%%%%%% %%% % %%% % 14 | % % % % % % % % % % 15 | %%% %%% % %%%%% %%%%% %%% %%% %%%%% % 16 | % % % % % % % % % % % % 17 | % % % % % %%% %%% %%% %%% % % % % % % 18 | % % % % % % % % % 19 | %%% %%%%%%% % % %%%%% %%% % %%% %%%%% 20 | % % % % % % % % % % 21 | %%%%% % % %%%%%%%%% %%%%%%%%%%% % %%% 22 | % % % % % % % % % 23 | % %%% %%%%% %%%%%%%%% %%%%% % % %%% % 24 | % % % % % % % 25 | % % % %%%%% %%% % % % % %%%%%%%%%%%%% 26 | % % % % % % % % % % % % 27 | % % %%% %%% % % % %%%%%%%%% %%% % % % 28 | % % % % % % % % % % % % % 29 | % %%% %%% %%%%% %%% % % %%%%% % %%%%% 30 | % % % % % % % % % 31 | %%% % %%%%% %%%%% %%% %%% % %%% % %%% 32 | % % % % % % % % % % % % % % % 33 | % % %%% % % % % %%%%%%%%% % % % % % % 34 | % % % % % % 35 | % % % % %%% %%% %%%%%%% %%% %%% %%% % 36 | %.% % % % % % % % P% 37 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/bigSafeSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %.%.........%% G % o%%%%.....% 3 | %.%.%%%%%%%.%%%%%% %%%%%%%.%%.% 4 | %............%...%............% 5 | %%%%%...%%%.. ..%.%...%.%%% 6 | %o%%%.%%%%%.%%%%%%%.%%%.%.%%%%% 7 | % ..........Po...%...%. o% 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/bigSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %.....%.................%.....% 3 | %.%%%.%.%%%.%%%%%%%.%%%.%.....% 4 | %.%...%.%......%......%.%.....% 5 | %...%%%.%.%%%%.%.%%%%...%%%...% 6 | %%%.%.%.%.%......%..%.%...%.%%% 7 | %...%.%%%.%.%%% %%%.%.%%%.%...% 8 | %.%%%.......% %.......%%%.% 9 | %...%.%%%%%.%%%%%%%.%.%%%.%...% 10 | %%%.%...%.%....%....%.%...%.%%% 11 | %...%%%.%.%%%%.%.%%%%.%.%%%...% 12 | %.......%......%......%.....%.% 13 | %.....%.%%%.%%%%%%%.%%%.%.%%%.% 14 | %.....%........P....%...%.....% 15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/boxSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%% 2 | %. . . . . % % 3 | % % % 4 | %. . . . . %G% 5 | % % % 6 | %. . . . . % % 7 | % % % 8 | %. . . . . % % 9 | % P %G% 10 | %. . . . . % % 11 | % % % 12 | %. . . . . % % 13 | % % % 14 | %%%%%%%%%%%%%% 15 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/capsuleClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%% 2 | %G. G ....% 3 | %.% % %%%%%% %.%%.% 4 | %.%o% % o% %.o%.% 5 | %.%%%.% %%% %..%.% 6 | %..... P %..%G% 7 | %%%%%%%%%%%%%%%%%%%% 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/contestClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%% 2 | %o...%........%...o% 3 | %.%%.%.%%..%%.%.%%.% 4 | %...... G GG%......% 5 | %.%.%%.%% %%%.%%.%.% 6 | %.%....% ooo%.%..%.% 7 | %.%.%%.% %% %.%.%%.% 8 | %o%......P....%....% 9 | %%%%%%%%%%%%%%%%%%%% 10 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/contoursMaze.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%% 2 | % % 3 | % % 4 | % % 5 | % % 6 | % P % 7 | % % 8 | % % 9 | % % 10 | %. % 11 | %%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/greedySearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%% 2 | %....% 3 | % %%.% 4 | % %%.% 5 | %.P .% 6 | %.%%%% 7 | %....% 8 | %%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/mediumClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%% 2 | %o...%........%....% 3 | %.%%.%.%%%%%%.%.%%.% 4 | %.%..............%.% 5 | %.%.%%.%% %%.%%.%.% 6 | %......%G G%......% 7 | %.%.%%.%%%%%%.%%.%.% 8 | %.%..............%.% 9 | %.%%.%.%%%%%%.%.%%.% 10 | %....%...P....%...o% 11 | %%%%%%%%%%%%%%%%%%%% 12 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/mediumCorners.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %. % % % %.% 3 | % % % %%%%%% %%%%%%% % % 4 | % % % % % % 5 | %%%%% %%%%% %%% %% %%%%% % %%% 6 | % % % % % % % % % 7 | % %%% % % % %%%%%%%% %%% %%% % 8 | % % %% % % % % 9 | %%% % %%%%%%% %%%% %%% % % % % 10 | % % %% % % % 11 | % % %%%%% % %%%% % %%% %%% % % 12 | % % % % % % %%% % 13 | %. %P%%%%% % %%% % .% 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/mediumDottedMaze.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % P% 3 | % %%%%%%%%%%%%%%%%%%% %%% %%%%%%%% % 4 | % %% % % %%% %%% %% ... % 5 | % %% % % % % %%%% %%%%%%%%% %% %%%%% 6 | % %% % % % % % %% %% %% ... % 7 | % %% % % % % % %%%% %%% %%%%%% % 8 | % % % % % % %% %%%%%%%% ... % 9 | % %% % % %%%%%%%% %% %% %%%%% 10 | % %% % %% %%%%%%%%% %% ... % 11 | % %%%%%% %%%%%%% %% %%%%%% % 12 | %%%%%% % %%%% %% % ... % 13 | % %%%%%% %%%%% % %% %% %%%%% 14 | % %%%%%% % %%%%% %% % 15 | % %%%%%% %%%%%%%%%%% %% %% % 16 | %%%%%%%%%% %%%%%% % 17 | %. %%%%%%%%%%%%%%%% ...... % 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/mediumMaze.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % P% 3 | % %%%%%%%%%%%%%%%%%%%%%%% %%%%%%%% % 4 | % %% % % %%%%%%% %% % 5 | % %% % % % % %%%% %%%%%%%%% %% %%%%% 6 | % %% % % % % %% %% % 7 | % %% % % % % % %%%% %%% %%%%%% % 8 | % % % % % % %% %%%%%%%% % 9 | % %% % % %%%%%%%% %% %% %%%%% 10 | % %% % %% %%%%%%%%% %% % 11 | % %%%%%% %%%%%%% %% %%%%%% % 12 | %%%%%% % %%%% %% % % 13 | % %%%%%% %%%%% % %% %% %%%%% 14 | % %%%%%% % %%%%% %% % 15 | % %%%%%% %%%%%%%%%%% %% %% % 16 | %%%%%%%%%% %%%%%% % 17 | %. %%%%%%%%%%%%%%%% % 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/mediumSafeSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %.% ....%% G %%%%%% o%%.% 3 | %.%o%%%%%%%.%%%%%%% %%%%%.% 4 | % %%%.%%%%%.%%%%%%%.%%%.%.%%%.% 5 | % ..........Po...%.........% 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/mediumScaryMaze.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % P% 3 | % %%%%%%%%%%%%%%%%%%% %%% %%%%%%%% % 4 | % %% % % %%% %%% %%GG % 5 | % %% % % % % %%%% %%%%%%%%% %% %%%%% 6 | % %% % % % % % %%GG %% % 7 | % %% % % % % % %%%%% %%% %%%%%% % 8 | % %% % % % % %% %%%%%%%%% % 9 | % %% % % %%%%%%%% %% %% %%%%% 10 | % %% % %% %%%%%%%%% %% % 11 | % %%% %% %%%%%%% %% %%%%%% % 12 | %%%%%% % % %% %% % 13 | % %%%%%% %% %% %% %% %%%%% 14 | % %%%%%% % %%%%% %% % 15 | % %%%% %%%%% %%%%%% % 16 | %%%%%%%% % %%%%%% % 17 | %. %%%%%%%%%%%%%%%% % 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/mediumSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %............%%%%%............% 3 | %%%.%...%%%.........%.%...%.%%% 4 | %...%%%.%.%%%%.%.%%%%%%.%%%...% 5 | %.%.....%......%......%.....%.% 6 | %.%%%.%%%%%.%%%%%%%.%%%.%.%%%%% 7 | %.....%........P....%...%.....% 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/minimaxClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%% 2 | %.P G% 3 | % %.%G%%% 4 | %G %%% 5 | %%%%%%%%% 6 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/oddSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%% 2 | %...%.........%%...% 3 | %.%.%.%%%%%%%%%%.%.% 4 | %..................% 5 | %%%%%%%%.%.%%%%%%%P% 6 | %%%%%%%%....... % 7 | %%%%%%%%%%%%%%%%%%%% 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/openClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%% 2 | %.. P .... .... % 3 | %.. ... ... ... ... % 4 | %.. ... ... ... ... % 5 | %.. .... .... G % 6 | %.. ... ... ... ... % 7 | %.. ... ... ... ... % 8 | %.. .... .... o% 9 | %%%%%%%%%%%%%%%%%%%%%%%%% 10 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/openMaze.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % P% 3 | % % % 4 | % % % 5 | % % % 6 | % % % 7 | % % % 8 | % % % % 9 | % % % % 10 | % % % % 11 | % % % % 12 | % % % % 13 | % % % % 14 | % % % % 15 | %%%%%%%%%%%%%% %%%%%%%%%%%%%%%%% 16 | % % % 17 | % % % 18 | % % % 19 | % % 20 | % % 21 | % % 22 | %. % 23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/openSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%% 2 | %..................% 3 | %..................% 4 | %........P.........% 5 | %..................% 6 | %..................% 7 | %%%%%%%%%%%%%%%%%%%% 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/originalClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %............%%............% 3 | %.%%%%.%%%%%.%%.%%%%%.%%%%.% 4 | %o%%%%.%%%%%.%%.%%%%%.%%%%o% 5 | %.%%%%.%%%%%.%%.%%%%%.%%%%.% 6 | %..........................% 7 | %.%%%%.%%.%%%%%%%%.%%.%%%%.% 8 | %.%%%%.%%.%%%%%%%%.%%.%%%%.% 9 | %......%%....%%....%%......% 10 | %%%%%%.%%%%% %% %%%%%.%%%%%% 11 | %%%%%%.%%%%% %% %%%%%.%%%%%% 12 | %%%%%%.% %.%%%%%% 13 | %%%%%%.% %%%% %%%% %.%%%%%% 14 | % . %G GG G% . % 15 | %%%%%%.% %%%%%%%%%% %.%%%%%% 16 | %%%%%%.% %.%%%%%% 17 | %%%%%%.% %%%%%%%%%% %.%%%%%% 18 | %............%%............% 19 | %.%%%%.%%%%%.%%.%%%%%.%%%%.% 20 | %.%%%%.%%%%%.%%.%%%%%.%%%%.% 21 | %o..%%....... .......%%..o% 22 | %%%.%%.%%.%%%%%%%%.%%.%%.%%% 23 | %%%.%%.%%.%%%%%%%%.%%.%%.%%% 24 | %......%%....%%....%%......% 25 | %.%%%%%%%%%%.%%.%%%%%%%%%%.% 26 | %.............P............% 27 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 28 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/smallClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%% 2 | %......%G G%......% 3 | %.%%...%% %%...%%.% 4 | %.%o.%........%.o%.% 5 | %.%%.%.%%%%%%.%.%%.% 6 | %........P.........% 7 | %%%%%%%%%%%%%%%%%%%% 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/smallMaze.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%% 2 | % %% % % % 3 | % %%%%%% % %%%%%% % 4 | %%%%%% P % % 5 | % % %%%%%% %% %%%%% 6 | % %%%% % % % 7 | % %%% %%% % % 8 | %%%%%%%%%% %%%%%% % 9 | %. %% % 10 | %%%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/smallSafeSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%% 2 | %.. % G % 3 | %%% %%%%% 4 | % % 5 | %%%%%%% % 6 | % % 7 | % %%%%% % 8 | % % % 9 | %%%%% % % 10 | % %o% 11 | % %%%%%%% 12 | % .% 13 | %%%%%%%.% 14 | %Po .% 15 | %%%%%%%%% 16 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/smallSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%% 2 | %. ...P .% 3 | %.%%.%%.%%.%%.%% %.% 4 | % %% %..... %.% 5 | %%%%%%%%%%%%%%%%%%%% 6 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/testClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%% 2 | % . % 3 | %.G.% 4 | % . % 5 | %. .% 6 | % % 7 | % .% 8 | % % 9 | %P .% 10 | %%%%% 11 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/testMaze.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%% 2 | %. P% 3 | %%%%%%%%%% 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/testSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%% 2 | %.P % 3 | %%% % 4 | %. % 5 | %%%%% 6 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/tinyCorners.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%% 2 | %. .% 3 | % P % 4 | % %%%% % 5 | % % % 6 | % % %%%% 7 | %.% .% 8 | %%%%%%%% 9 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/tinyMaze.lay: -------------------------------------------------------------------------------- 1 | %%%%%%% 2 | % P% 3 | % %%% % 4 | % % % 5 | %% %% 6 | %. %%%% 7 | %%%%%%% 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/tinySafeSearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%% 2 | % G %...% 3 | %%%%%%% % 4 | %Po % 5 | %.%%.%%.% 6 | %.%%....% 7 | %%%%%%%%% 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/tinySearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%% 2 | %.. ..% 3 | %%%%.%% % 4 | % P % 5 | %.%% %%.% 6 | %.%. .% 7 | %%%%%%%%% 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/trappedClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%% 2 | % P G% 3 | %G%%%%%% 4 | %.... % 5 | %%%%%%%% 6 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/trickyClassic.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%% 2 | %o...%........%...o% 3 | %.%%.%.%%..%%.%.%%.% 4 | %.%.....%..%.....%.% 5 | %.%.%%.%% %%.%%.%.% 6 | %...... GGGG%.%....% 7 | %.%....%%%%%%.%..%.% 8 | %.%....% oo%.%..%.% 9 | %.%....% %%%%.%..%.% 10 | %.%...........%..%.% 11 | %.%%.%.%%%%%%.%.%%.% 12 | %o...%...P....%...o% 13 | %%%%%%%%%%%%%%%%%%%% 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/layouts/trickySearch.lay: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%% 2 | %. ..% % 3 | %.%%.%%.%%.%%.%% % % 4 | % P % % 5 | %%%%%%%%%%%%%%%%%% % 6 | %..... % 7 | %%%%%%%%%%%%%%%%%%%% 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/projectParams.py: -------------------------------------------------------------------------------- 1 | # projectParams.py 2 | # ---------------- 3 | # Licensing Information: You are free to use or extend these projects for 4 | # educational purposes provided that (1) you do not distribute or publish 5 | # solutions, (2) you retain this notice, and (3) you provide clear 6 | # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. 7 | # 8 | # Attribution Information: The Pacman AI projects were developed at UC Berkeley. 9 | # The core projects and autograders were primarily created by John DeNero 10 | # (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu). 11 | # Student side autograding was added by Brad Miller, Nick Hay, and 12 | # Pieter Abbeel (pabbeel@cs.berkeley.edu). 13 | 14 | 15 | STUDENT_CODE_DEFAULT = 'searchAgents.py,search.py,multiAgents.py' 16 | PROJECT_TEST_CLASSES = 'search_and_gamesTestClasses.py' 17 | PROJECT_NAME = 'Project 1: Search and Games' 18 | BONUS_PIC = False 19 | -------------------------------------------------------------------------------- /old/src/pacman_demo/search.py: -------------------------------------------------------------------------------- 1 | # search.py 2 | # --------- 3 | # Licensing Information: You are free to use or extend these projects for 4 | # educational purposes provided that (1) you do not distribute or publish 5 | # solutions, (2) you retain this notice, and (3) you provide clear 6 | # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. 7 | # 8 | # Attribution Information: The Pacman AI projects were developed at UC Berkeley. 9 | # The core projects and autograders were primarily created by John DeNero 10 | # (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu). 11 | # Student side autograding was added by Brad Miller, Nick Hay, and 12 | # Pieter Abbeel (pabbeel@cs.berkeley.edu). 13 | 14 | 15 | # search.py 16 | # --------- 17 | # Licensing Information: You are free to use or extend these projects for 18 | # educational purposes provided that (1) you do not distribute or publish 19 | # solutions, (2) you retain this notice, and (3) you provide clear 20 | # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. 21 | # 22 | # Attribution Information: The Pacman AI projects were developed at UC Berkeley. 23 | # The core projects and autograders were primarily created by John DeNero 24 | # (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu). 25 | # Student side autograding was added by Brad Miller, Nick Hay, and 26 | # Pieter Abbeel (pabbeel@cs.berkeley.edu). 27 | 28 | 29 | """ 30 | In search.py, you will implement generic search algorithms which are called by 31 | Pacman agents (in searchAgents.py). 32 | """ 33 | 34 | import util 35 | import sys 36 | import copy 37 | 38 | class SearchProblem: 39 | """ 40 | This class outlines the structure of a search problem, but doesn't implement 41 | any of the methods (in object-oriented terminology: an abstract class). 42 | 43 | You do not need to change anything in this class, ever. 44 | """ 45 | 46 | def getStartState(self): 47 | """ 48 | Returns the start state for the search problem. 49 | """ 50 | util.raiseNotDefined() 51 | 52 | def goalTest(self, state): 53 | """ 54 | state: Search state 55 | 56 | Returns True if and only if the state is a valid goal state. 57 | """ 58 | util.raiseNotDefined() 59 | 60 | def getActions(self, state): 61 | """ 62 | Given a state, returns available actions. 63 | Returns a list of actions 64 | """ 65 | util.raiseNotDefined() 66 | 67 | def getResult(self, state, action): 68 | """ 69 | Given a state and an action, returns resulting state. 70 | """ 71 | util.raiseNotDefined() 72 | 73 | def getCost(self, state, action): 74 | """ 75 | Given a state and an action, returns step cost, which is the incremental cost 76 | of moving to that successor. 77 | """ 78 | util.raiseNotDefined() 79 | 80 | def getCostOfActions(self, actions): 81 | """ 82 | actions: A list of actions to take 83 | 84 | This method returns the total cost of a particular sequence of actions. 85 | The sequence must be composed of legal moves. 86 | """ 87 | util.raiseNotDefined() 88 | 89 | 90 | def tinyMazeSearch(problem): 91 | """ 92 | Returns a sequence of moves that solves tinyMaze. For any other maze, the 93 | sequence of moves will be incorrect, so only use this for tinyMaze. 94 | """ 95 | from game import Directions 96 | s = Directions.SOUTH 97 | w = Directions.WEST 98 | return [s, s, w, s, w, w, s, w] 99 | 100 | def breadthFirstSearch(problem): 101 | """ 102 | Search the shallowest nodes in the search tree first. 103 | 104 | You are not required to implement this, but you may find it useful for Q5. 105 | """ 106 | "*** YOUR CODE HERE ***" 107 | util.raiseNotDefined() 108 | 109 | def nullHeuristic(state, problem=None): 110 | """ 111 | A heuristic function estimates the cost from the current state to the nearest 112 | goal in the provided SearchProblem. This heuristic is trivial. 113 | """ 114 | return 0 115 | 116 | def iterativeDeepeningSearch(problem): 117 | """ 118 | Perform DFS with increasingly larger depth. 119 | 120 | Begin with a depth of 1 and increment depth by 1 at every step. 121 | """ 122 | "*** YOUR CODE HERE ***" 123 | util.raiseNotDefined() 124 | 125 | def aStarSearch(problem, heuristic=nullHeuristic): 126 | """Search the node that has the lowest combined cost and heuristic first.""" 127 | "*** YOUR CODE HERE ***" 128 | util.raiseNotDefined() 129 | 130 | # Abbreviations 131 | bfs = breadthFirstSearch 132 | astar = aStarSearch 133 | ids = iterativeDeepeningSearch 134 | -------------------------------------------------------------------------------- /old/src/pacman_demo/testParser.py: -------------------------------------------------------------------------------- 1 | # testParser.py 2 | # ------------- 3 | # Licensing Information: You are free to use or extend these projects for 4 | # educational purposes provided that (1) you do not distribute or publish 5 | # solutions, (2) you retain this notice, and (3) you provide clear 6 | # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. 7 | # 8 | # Attribution Information: The Pacman AI projects were developed at UC Berkeley. 9 | # The core projects and autograders were primarily created by John DeNero 10 | # (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu). 11 | # Student side autograding was added by Brad Miller, Nick Hay, and 12 | # Pieter Abbeel (pabbeel@cs.berkeley.edu). 13 | 14 | 15 | import re 16 | import sys 17 | 18 | class TestParser(object): 19 | 20 | def __init__(self, path): 21 | # save the path to the test file 22 | self.path = path 23 | 24 | def removeComments(self, rawlines): 25 | # remove any portion of a line following a '#' symbol 26 | fixed_lines = [] 27 | for l in rawlines: 28 | idx = l.find('#') 29 | if idx == -1: 30 | fixed_lines.append(l) 31 | else: 32 | fixed_lines.append(l[0:idx]) 33 | return '\n'.join(fixed_lines) 34 | 35 | def parse(self): 36 | # read in the test case and remove comments 37 | test = {} 38 | with open(self.path) as handle: 39 | raw_lines = handle.read().split('\n') 40 | 41 | test_text = self.removeComments(raw_lines) 42 | test['__raw_lines__'] = raw_lines 43 | test['path'] = self.path 44 | test['__emit__'] = [] 45 | lines = test_text.split('\n') 46 | i = 0 47 | # read a property in each loop cycle 48 | while(i < len(lines)): 49 | # skip blank lines 50 | if re.match('\A\s*\Z', lines[i]): 51 | test['__emit__'].append(("raw", raw_lines[i])) 52 | i += 1 53 | continue 54 | m = re.match('\A([^"]*?):\s*"([^"]*)"\s*\Z', lines[i]) 55 | if m: 56 | test[m.group(1)] = m.group(2) 57 | test['__emit__'].append(("oneline", m.group(1))) 58 | i += 1 59 | continue 60 | m = re.match('\A([^"]*?):\s*"""\s*\Z', lines[i]) 61 | if m: 62 | msg = [] 63 | i += 1 64 | while(not re.match('\A\s*"""\s*\Z', lines[i])): 65 | msg.append(raw_lines[i]) 66 | i += 1 67 | test[m.group(1)] = '\n'.join(msg) 68 | test['__emit__'].append(("multiline", m.group(1))) 69 | i += 1 70 | continue 71 | print 'error parsing test file: %s' % self.path 72 | sys.exit(1) 73 | return test 74 | 75 | 76 | def emitTestDict(testDict, handle): 77 | for kind, data in testDict['__emit__']: 78 | if kind == "raw": 79 | handle.write(data + "\n") 80 | elif kind == "oneline": 81 | handle.write('%s: "%s"\n' % (data, testDict[data])) 82 | elif kind == "multiline": 83 | handle.write('%s: """\n%s\n"""\n' % (data, testDict[data])) 84 | else: 85 | raise Exception("Bad __emit__") 86 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/CONFIG: -------------------------------------------------------------------------------- 1 | order: "q1 q2 q3 q4 q5 q6 q7 q8 q9" -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/CONFIG: -------------------------------------------------------------------------------- 1 | max_points: "2" 2 | class: "PassAllTestsQuestion" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/graph_backtrack.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q1/graph_backtrack.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | solution: "1:A->C 0:C->G" 5 | expanded_states: "A A D C" 6 | rev_solution: "1:A->C 0:C->G" 7 | rev_expanded_states: "A A B C" 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/graph_backtrack.test: -------------------------------------------------------------------------------- 1 | class: "GraphSearchTest" 2 | algorithm: "iterativeDeepeningSearch" 3 | 4 | diagram: """ 5 | B 6 | ^ 7 | | 8 | *A --> C --> G 9 | | 10 | V 11 | D 12 | 13 | A is the start state, G is the goal. Arrows mark 14 | possible state transitions. This tests whether 15 | you extract the sequence of actions correctly even 16 | if your search backtracks. If you fail this, your 17 | nodes are not correctly tracking the sequences of 18 | actions required to reach them. 19 | """ 20 | # The following section specifies the search problem and the solution. 21 | # The graph is specified by first the set of start states, followed by 22 | # the set of goal states, and lastly by the state transitions which are 23 | # of the form: 24 | # 25 | graph: """ 26 | start_state: A 27 | goal_states: G 28 | A 0:A->B B 1.0 29 | A 1:A->C C 2.0 30 | A 2:A->D D 4.0 31 | C 0:C->G G 8.0 32 | """ 33 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/graph_bfs_vs_dfs.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q1/graph_bfs_vs_dfs.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | solution: "1:A->G" 5 | expanded_states: "A" 6 | rev_solution: "1:A->G" 7 | rev_expanded_states: "A" 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/graph_bfs_vs_dfs.test: -------------------------------------------------------------------------------- 1 | # Graph where BFS finds the optimal solution but DFS does not 2 | class: "GraphSearchTest" 3 | algorithm: "iterativeDeepeningSearch" 4 | 5 | diagram: """ 6 | /-- B 7 | | ^ 8 | | | 9 | | *A -->[G] 10 | | | ^ 11 | | V | 12 | \-->D ----/ 13 | 14 | A is the start state, G is the goal. Arrows 15 | mark possible transitions 16 | """ 17 | # The following section specifies the search problem and the solution. 18 | # The graph is specified by first the set of start states, followed by 19 | # the set of goal states, and lastly by the state transitions which are 20 | # of the form: 21 | # 22 | graph: """ 23 | start_state: A 24 | goal_states: G 25 | A 0:A->B B 1.0 26 | A 1:A->G G 2.0 27 | A 2:A->D D 4.0 28 | B 0:B->D D 8.0 29 | D 0:D->G G 16.0 30 | """ 31 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/graph_infinite.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q1/graph_infinite.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | solution: "0:A->B 1:B->C 1:C->G" 5 | expanded_states: "A A B A B C" 6 | rev_solution: "0:A->B 1:B->C 1:C->G" 7 | rev_expanded_states: "A A B A B C" 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/graph_infinite.test: -------------------------------------------------------------------------------- 1 | # Graph where natural action choice leads to an infinite loop 2 | class: "GraphSearchTest" 3 | algorithm: "iterativeDeepeningSearch" 4 | 5 | diagram: """ 6 | B <--> C 7 | ^ /| 8 | | / | 9 | V / V 10 | *A<-/ [G] 11 | 12 | A is the start state, G is the goal. Arrows mark 13 | possible state transitions. 14 | """ 15 | # The following section specifies the search problem and the solution. 16 | # The graph is specified by first the set of start states, followed by 17 | # the set of goal states, and lastly by the state transitions which are 18 | # of the form: 19 | # 20 | graph: """ 21 | start_state: A 22 | goal_states: G 23 | A 0:A->B B 1.0 24 | B 0:B->A A 2.0 25 | B 1:B->C C 4.0 26 | C 0:C->A A 8.0 27 | C 1:C->G G 16.0 28 | C 2:C->B B 32.0 29 | """ 30 | 31 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/graph_manypaths.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q1/graph_manypaths.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | solution: "1:A->C 0:C->D 1:D->F 0:F->G" 5 | expanded_states: "A A B2 C B1 A B2 C D B1 A B2 C D E2 F" 6 | rev_solution: "1:A->C 0:C->D 1:D->F 0:F->G" 7 | rev_expanded_states: "A A B1 C B2 A B1 C D B2 A B1 C D E1 F" 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/graph_manypaths.test: -------------------------------------------------------------------------------- 1 | class: "GraphSearchTest" 2 | algorithm: "iterativeDeepeningSearch" 3 | 4 | diagram: """ 5 | B1 E1 6 | ^ \ ^ \ 7 | / V / V 8 | *A --> C --> D --> F --> [G] 9 | \ ^ \ ^ 10 | V / V / 11 | B2 E2 12 | 13 | A is the start state, G is the goal. Arrows mark 14 | possible state transitions. This graph has multiple 15 | paths to the goal, where nodes with the same state 16 | are added to the fringe multiple times before they 17 | are expanded. 18 | """ 19 | # The following section specifies the search problem and the solution. 20 | # The graph is specified by first the set of start states, followed by 21 | # the set of goal states, and lastly by the state transitions which are 22 | # of the form: 23 | # 24 | graph: """ 25 | start_state: A 26 | goal_states: G 27 | A 0:A->B1 B1 1.0 28 | A 1:A->C C 2.0 29 | A 2:A->B2 B2 4.0 30 | B1 0:B1->C C 8.0 31 | B2 0:B2->C C 16.0 32 | C 0:C->D D 32.0 33 | D 0:D->E1 E1 64.0 34 | D 1:D->F F 128.0 35 | D 2:D->E2 E2 256.0 36 | E1 0:E1->F F 512.0 37 | E2 0:E2->F F 1024.0 38 | F 0:F->G G 2048.0 39 | """ 40 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/pacman_1.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q1/pacman_1.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | # Number of nodes expanded must be with a factor of 1.0 of the numbers below. 5 | solution: """ 6 | West West West West West West West West West South South East East 7 | South South South West West West North West West West West South South 8 | South East East East East East East East South South South South South 9 | South South West West West West West West West West West West West 10 | West West West West West West South West West West West West West West 11 | West West 12 | """ 13 | expanded_nodes: "8138" 14 | rev_solution: """ 15 | South South West West West West South South East East East East South 16 | South West West West West South South East East East East South South 17 | West West West West South South East East East East South South South 18 | West West West West West West West North West West West West West West 19 | West West West West West West West West West West West South West West 20 | West West West West West West West 21 | """ 22 | rev_expanded_nodes: "8549" 23 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q1/pacman_1.test: -------------------------------------------------------------------------------- 1 | # This is a basic depth first search test 2 | class: "PacmanSearchTest" 3 | algorithm: "iterativeDeepeningSearch" 4 | 5 | # The following specifies the layout to be used 6 | layoutName: "mediumMaze" 7 | layout: """ 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | % P% 10 | % %%%%%%%%%%%%%%%%%%%%%%% %%%%%%%% % 11 | % %% % % %%%%%%% %% % 12 | % %% % % % % %%%% %%%%%%%%% %% %%%%% 13 | % %% % % % % %% %% % 14 | % %% % % % % % %%%% %%% %%%%%% % 15 | % % % % % % %% %%%%%%%% % 16 | % %% % % %%%%%%%% %% %% %%%%% 17 | % %% % %% %%%%%%%%% %% % 18 | % %%%%%% %%%%%%% %% %%%%%% % 19 | %%%%%% % %%%% %% % % 20 | % %%%%%% %%%%% % %% %% %%%%% 21 | % %%%%%% % %%%%% %% % 22 | % %%%%%% %%%%%%%%%%% %% %% % 23 | %%%%%%%%%% %%%%%% % 24 | %. %%%%%%%%%%%%%%%% % 25 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 26 | """ 27 | 28 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/CONFIG: -------------------------------------------------------------------------------- 1 | class: "PassAllTestsQuestion" 2 | max_points: "2" -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/astar_0.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q2/astar_0.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | solution: "Right Down Down" 5 | expanded_states: "A B D C G" 6 | rev_solution: "Right Down Down" 7 | rev_expanded_states: "A B D C G" 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/astar_0.test: -------------------------------------------------------------------------------- 1 | class: "GraphSearchTest" 2 | algorithm: "aStarSearch" 3 | 4 | diagram: """ 5 | C 6 | ^ 7 | | 2 8 | 2 V 4 9 | *A <----> B -----> [H] 10 | | 11 | 1.5 V 2.5 12 | G <----- D -----> E 13 | | 14 | 2 | 15 | V 16 | [F] 17 | 18 | A is the start state, F and H is the goal. Arrows mark possible state 19 | transitions. The number next to the arrow is the cost of that transition. 20 | """ 21 | # The following section specifies the search problem and the solution. 22 | # The graph is specified by first the set of start states, followed by 23 | # the set of goal states, and lastly by the state transitions which are 24 | # of the form: 25 | # 26 | graph: """ 27 | start_state: A 28 | goal_states: H F 29 | A Right B 2.0 30 | B Right H 4.0 31 | B Down D 1.0 32 | B Up C 2.0 33 | B Left A 2.0 34 | C Down B 2.0 35 | D Right E 2.5 36 | D Down F 2.0 37 | D Left G 1.5 38 | """ 39 | 40 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/astar_1_graph_heuristic.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q2/astar_1_graph_heuristic.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | solution: "0 0 2" 5 | expanded_states: "S A D C" 6 | rev_solution: "0 0 2" 7 | rev_expanded_states: "S A D C" 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/astar_1_graph_heuristic.test: -------------------------------------------------------------------------------- 1 | class: "GraphSearchTest" 2 | algorithm: "aStarSearch" 3 | 4 | diagram: """ 5 | 2 3 2 6 | S --- A --- C ---> G 7 | | \ / ^ 8 | 3 | \ 5 / 1 / 9 | | \ / / 10 | B --- D -------/ 11 | 4 5 12 | 13 | S is the start state, G is the goal. Arrows mark possible state 14 | transitions. The number next to the arrow is the cost of that transition. 15 | 16 | The heuristic value of each state is: 17 | S 6.0 18 | A 2.5 19 | B 5.25 20 | C 1.125 21 | D 1.0625 22 | G 0 23 | """ 24 | # The following section specifies the search problem and the solution. 25 | # The graph is specified by first the set of start states, followed by 26 | # the set of goal states, and lastly by the state transitions which are 27 | # of the form: 28 | # 29 | graph: """ 30 | start_state: S 31 | goal_states: G 32 | S 0 A 2.0 33 | S 1 B 3.0 34 | S 2 D 5.0 35 | A 0 C 3.0 36 | A 1 S 2.0 37 | B 0 D 4.0 38 | B 1 S 3.0 39 | C 0 A 3.0 40 | C 1 D 1.0 41 | C 2 G 2.0 42 | D 0 B 4.0 43 | D 1 C 1.0 44 | D 2 G 5.0 45 | D 3 S 5.0 46 | """ 47 | heuristic: """ 48 | S 6.0 49 | A 2.5 50 | B 5.25 51 | C 1.125 52 | D 1.0625 53 | G 0 54 | """ 55 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/astar_2_manhattan.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q2/astar_2_manhattan.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | # Number of nodes expanded must be with a factor of 1.1 of the numbers below. 5 | solution: """ 6 | West West West West West West West West West South South East East 7 | South South South West West West North West West West West South South 8 | South East East East East East East East South South South South South 9 | South South West West West West West West West West West West West 10 | West West West West West West South West West West West West West West 11 | West West 12 | """ 13 | expanded_nodes: "221" 14 | rev_solution: """ 15 | West West West West West West West West West South South East East 16 | South South South West West West North West West West West South South 17 | South East East East East East East East South South South South South 18 | South South West West West West West West West West West West West 19 | West West West West West West South West West West West West West West 20 | West West 21 | """ 22 | rev_expanded_nodes: "221" 23 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/astar_2_manhattan.test: -------------------------------------------------------------------------------- 1 | class: "PacmanSearchTest" 2 | algorithm: "aStarSearch" 3 | 4 | # The following specifies the layout to be used 5 | layoutName: "mediumMaze" 6 | layout: """ 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | % P% 9 | % %%%%%%%%%%%%%%%%%%%%%%% %%%%%%%% % 10 | % %% % % %%%%%%% %% % 11 | % %% % % % % %%%% %%%%%%%%% %% %%%%% 12 | % %% % % % % %% %% % 13 | % %% % % % % % %%%% %%% %%%%%% % 14 | % % % % % % %% %%%%%%%% % 15 | % %% % % %%%%%%%% %% %% %%%%% 16 | % %% % %% %%%%%%%%% %% % 17 | % %%%%%% %%%%%%% %% %%%%%% % 18 | %%%%%% % %%%% %% % % 19 | % %%%%%% %%%%% % %% %% %%%%% 20 | % %%%%%% % %%%%% %% % 21 | % %%%%%% %%%%%%%%%%% %% %% % 22 | %%%%%%%%%% %%%%%% % 23 | %. %%%%%%%%%%%%%%%% % 24 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 25 | """ 26 | leewayFactor: "1.1" 27 | heuristic: "manhattanHeuristic" 28 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/astar_3_goalAtDequeue.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q2/astar_3_goalAtDequeue.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | solution: "1:A->B 0:B->C 0:C->G" 5 | expanded_states: "A B C" 6 | rev_solution: "1:A->B 0:B->C 0:C->G" 7 | rev_expanded_states: "A B C" 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/astar_3_goalAtDequeue.test: -------------------------------------------------------------------------------- 1 | class: "GraphSearchTest" 2 | algorithm: "aStarSearch" 3 | 4 | diagram: """ 5 | 1 1 1 6 | *A ---> B ---> C ---> [G] 7 | | ^ 8 | | 10 | 9 | \---------------------/ 10 | 11 | A is the start state, G is the goal. Arrows mark possible state 12 | transitions. The number next to the arrow is the cost of that transition. 13 | 14 | If you fail this test case, you may be incorrectly testing if a node is a goal 15 | before adding it into the queue, instead of testing when you remove the node 16 | from the queue. See the algorithm pseudocode in lecture. 17 | """ 18 | 19 | graph: """ 20 | start_state: A 21 | goal_states: G 22 | A 0:A->G G 10.0 23 | A 1:A->B B 1.0 24 | B 0:B->C C 1.0 25 | C 0:C->G G 1.0 26 | """ 27 | # We only care about the solution, not the expansion order. 28 | exactExpansionOrder: "False" 29 | 30 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/graph_backtrack.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q2/graph_backtrack.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | solution: "1:A->C 0:C->G" 5 | expanded_states: "A B C D" 6 | rev_solution: "1:A->C 0:C->G" 7 | rev_expanded_states: "A B C D" 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/graph_backtrack.test: -------------------------------------------------------------------------------- 1 | class: "GraphSearchTest" 2 | algorithm: "aStarSearch" 3 | 4 | diagram: """ 5 | B 6 | ^ 7 | | 8 | *A --> C --> G 9 | | 10 | V 11 | D 12 | 13 | A is the start state, G is the goal. Arrows mark 14 | possible state transitions. This tests whether 15 | you extract the sequence of actions correctly even 16 | if your search backtracks. If you fail this, your 17 | nodes are not correctly tracking the sequences of 18 | actions required to reach them. 19 | """ 20 | # The following section specifies the search problem and the solution. 21 | # The graph is specified by first the set of start states, followed by 22 | # the set of goal states, and lastly by the state transitions which are 23 | # of the form: 24 | # 25 | graph: """ 26 | start_state: A 27 | goal_states: G 28 | A 0:A->B B 1.0 29 | A 1:A->C C 2.0 30 | A 2:A->D D 4.0 31 | C 0:C->G G 8.0 32 | """ 33 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/graph_manypaths.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q2/graph_manypaths.test. 2 | # This solution is designed to support both right-to-left 3 | # and left-to-right implementations. 4 | solution: "1:A->C 0:C->D 1:D->F 0:F->G" 5 | expanded_states: "A B1 C B2 D E1 F E2" 6 | rev_solution: "1:A->C 0:C->D 1:D->F 0:F->G" 7 | rev_expanded_states: "A B1 C B2 D E1 F E2" 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q2/graph_manypaths.test: -------------------------------------------------------------------------------- 1 | class: "GraphSearchTest" 2 | algorithm: "aStarSearch" 3 | 4 | diagram: """ 5 | B1 E1 6 | ^ \ ^ \ 7 | / V / V 8 | *A --> C --> D --> F --> [G] 9 | \ ^ \ ^ 10 | V / V / 11 | B2 E2 12 | 13 | A is the start state, G is the goal. Arrows mark 14 | possible state transitions. This graph has multiple 15 | paths to the goal, where nodes with the same state 16 | are added to the fringe multiple times before they 17 | are expanded. 18 | """ 19 | # The following section specifies the search problem and the solution. 20 | # The graph is specified by first the set of start states, followed by 21 | # the set of goal states, and lastly by the state transitions which are 22 | # of the form: 23 | # 24 | graph: """ 25 | start_state: A 26 | goal_states: G 27 | A 0:A->B1 B1 1.0 28 | A 1:A->C C 2.0 29 | A 2:A->B2 B2 4.0 30 | B1 0:B1->C C 8.0 31 | B2 0:B2->C C 16.0 32 | C 0:C->D D 32.0 33 | D 0:D->E1 E1 64.0 34 | D 1:D->F F 128.0 35 | D 2:D->E2 E2 256.0 36 | E1 0:E1->F F 512.0 37 | E2 0:E2->F F 1024.0 38 | F 0:F->G G 2048.0 39 | """ 40 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q3/CONFIG: -------------------------------------------------------------------------------- 1 | class: "PassAllTestsQuestion" 2 | max_points: "3" -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q3/corner_tiny_corner.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q3/corner_tiny_corner.test. 2 | solution_length: "28" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q3/corner_tiny_corner.test: -------------------------------------------------------------------------------- 1 | class: "CornerProblemTest" 2 | 3 | layoutName: "tinyCorner" 4 | layout: """ 5 | %%%%%%%% 6 | %. .% 7 | % P % 8 | % %%%% % 9 | % % % 10 | % % %%%% 11 | %.% .% 12 | %%%%%%%% 13 | """ 14 | 15 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q4/CONFIG: -------------------------------------------------------------------------------- 1 | class: "Q6PartialCreditQuestion" 2 | max_points: "3" 3 | depends: "q2" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q4/corner_sanity_1.solution: -------------------------------------------------------------------------------- 1 | # In order for a heuristic to be admissible, the value 2 | # of the heuristic must be less at each state than the 3 | # true cost of the optimal path from that state to a goal. 4 | cost: "8" 5 | path: """ 6 | North South South East East East North North 7 | """ 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q4/corner_sanity_1.test: -------------------------------------------------------------------------------- 1 | class: "CornerHeuristicSanity" 2 | points: "1" 3 | 4 | # The following specifies the layout to be used 5 | layout: """ 6 | %%%%%% 7 | %. .% 8 | %P % 9 | %. .% 10 | %%%%%% 11 | """ 12 | 13 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q4/corner_sanity_2.solution: -------------------------------------------------------------------------------- 1 | # In order for a heuristic to be admissible, the value 2 | # of the heuristic must be less at each state than the 3 | # true cost of the optimal path from that state to a goal. 4 | cost: "8" 5 | path: """ 6 | West North North East East East South South 7 | """ 8 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q4/corner_sanity_2.test: -------------------------------------------------------------------------------- 1 | class: "CornerHeuristicSanity" 2 | points: "1" 3 | 4 | # The following specifies the layout to be used 5 | layout: """ 6 | %%%%%% 7 | %. .% 8 | % %% % 9 | %.P%.% 10 | %%%%%% 11 | """ 12 | 13 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q4/corner_sanity_3.solution: -------------------------------------------------------------------------------- 1 | # In order for a heuristic to be admissible, the value 2 | # of the heuristic must be less at each state than the 3 | # true cost of the optimal path from that state to a goal. 4 | cost: "28" 5 | path: """ 6 | South South South West West West West East East East East East North 7 | North North North North West West West South South South West West 8 | North North North 9 | """ 10 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q4/corner_sanity_3.test: -------------------------------------------------------------------------------- 1 | class: "CornerHeuristicSanity" 2 | points: "1" 3 | 4 | # The following specifies the layout to be used 5 | layout: """ 6 | %%%%%%%% 7 | %.% .% 8 | % % % % 9 | % % %P % 10 | % % % 11 | %%%%% % 12 | %. .% 13 | %%%%%%%% 14 | """ 15 | 16 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q4/medium_corners.solution: -------------------------------------------------------------------------------- 1 | # This solution file specifies the length of the optimal path 2 | # as well as the thresholds on number of nodes expanded to be 3 | # used in scoring. 4 | cost: "106" 5 | path: """ 6 | North East East East East North North West West West West West West 7 | South South West West South East East North North North North North 8 | East East North North North North West West West West North North East 9 | East East East South South South South South South South South East 10 | East East East East East South South East East East East East North 11 | North East East North North East East North North East East East East 12 | South South South South East East North North East East South South 13 | South South South North North North North North North North West West 14 | North North East East North North 15 | """ 16 | thresholds: "2000 1600 1200" 17 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q4/medium_corners.test: -------------------------------------------------------------------------------- 1 | class: "CornerHeuristicPacman" 2 | 3 | # The following specifies the layout to be used 4 | layout: """ 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | %. % % % %.% 7 | % % % %%%%%% %%%%%%% % % 8 | % % % % % % 9 | %%%%% %%%%% %%% %% %%%%% % %%% 10 | % % % % % % % % % 11 | % %%% % % % %%%%%%%% %%% %%% % 12 | % % %% % % % % 13 | %%% % %%%%%%% %%%% %%% % % % % 14 | % % %% % % % 15 | % % %%%%% % %%%% % %%% %%% % % 16 | % % % % % % %%% % 17 | %. %P%%%%% % %%% % .% 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | """ 20 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/CONFIG: -------------------------------------------------------------------------------- 1 | class: "PartialCreditQuestion" 2 | max_points: "4" 3 | depends: "q2" -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_1.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_1.test. 2 | solution_cost: "0" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_1.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 1" 6 | layout: """ 7 | %%%%%% 8 | % % 9 | % % 10 | %P % 11 | %%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_10.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_10.test. 2 | solution_cost: "7" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_10.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 10" 6 | layout: """ 7 | %%%%%%%% 8 | % % 9 | %. P .% 10 | % % 11 | %%%%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_11.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_11.test. 2 | solution_cost: "8" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_11.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 11" 6 | layout: """ 7 | %%%%%%%% 8 | % % 9 | % P % 10 | %. . .% 11 | %%%%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_12.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_12.test. 2 | solution_cost: "1" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_12.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 12" 6 | layout: """ 7 | %%%%%%%% 8 | % % 9 | % P.% 10 | % % 11 | %%%%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_13.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_13.test. 2 | solution_cost: "5" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_13.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 13" 6 | layout: """ 7 | %%%%%%%% 8 | % % 9 | %P. .% 10 | % % 11 | %%%%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_14.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_14.test. 2 | solution_cost: "31" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_14.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 14" 6 | layout: """ 7 | %%%%%%%%%% 8 | % % 9 | % ...%...% 10 | % .%.%.%.% 11 | % .%.%.%.% 12 | % .%.%.%.% 13 | % .%.%.%.% 14 | % .%.%.%.% 15 | %P.%...%.% 16 | % % 17 | %%%%%%%%%% 18 | """ 19 | 20 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_15.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_15.test. 2 | solution_cost: "21" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_15.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 15" 6 | layout: """ 7 | %%% 8 | % % 9 | % % 10 | % % 11 | % % 12 | % % 13 | %.% 14 | %.% 15 | % % 16 | % % 17 | % % 18 | % % 19 | % % 20 | % % 21 | % % 22 | %.% 23 | % % 24 | %P% 25 | % % 26 | % % 27 | % % 28 | % % 29 | %.% 30 | %%% 31 | """ 32 | 33 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_16.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_16.test. 2 | solution_cost: "7" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_16.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 16" 6 | layout: """ 7 | %%%% 8 | % .% 9 | % % 10 | %P % 11 | % % 12 | % .% 13 | %%%% 14 | """ 15 | 16 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_17.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_17.test. 2 | solution_cost: "16" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_17.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 17" 6 | layout: """ 7 | %%%%%%%% 8 | %.%....% 9 | %.% %%.% 10 | %.%P%%.% 11 | %... .% 12 | %%%%%%%% 13 | """ 14 | 15 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_2.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_2.test. 2 | solution_cost: "0" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_2.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 2" 6 | layout: """ 7 | %%% 8 | % % 9 | % % 10 | % % 11 | % % 12 | % % 13 | % % 14 | % % 15 | % % 16 | % % 17 | % % 18 | % % 19 | % % 20 | % % 21 | % % 22 | % % 23 | % % 24 | %P% 25 | % % 26 | % % 27 | % % 28 | % % 29 | % % 30 | %%% 31 | """ 32 | 33 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_3.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_3.test. 2 | solution_cost: "0" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_3.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 3" 6 | layout: """ 7 | %%%% 8 | % % 9 | % % 10 | %P % 11 | % % 12 | % % 13 | %%%% 14 | """ 15 | 16 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_4.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_4.test. 2 | solution_cost: "0" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_4.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 4" 6 | layout: """ 7 | %%%%%%%% 8 | % % % 9 | % % %% % 10 | % %P%% % 11 | % % 12 | %%%%%%%% 13 | """ 14 | 15 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_5.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_5.test. 2 | solution_cost: "11" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_5.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 5" 6 | layout: """ 7 | %%%%%% 8 | %....% 9 | %....% 10 | %P...% 11 | %%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_6.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_6.test. 2 | solution_cost: "5" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_6.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 6" 6 | layout: """ 7 | %%%%%% 8 | % .% 9 | %.P..% 10 | % % 11 | %%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_7.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_7.test. 2 | solution_cost: "7" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_7.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 7" 6 | layout: """ 7 | %%%%%%% 8 | % .% 9 | %. P..% 10 | % % 11 | %%%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_8.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_8.test. 2 | solution_cost: "5" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_8.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 8" 6 | layout: """ 7 | %%%%%% 8 | % .% 9 | % .% 10 | %P .% 11 | %%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_9.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_9.test. 2 | solution_cost: "6" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_9.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicTest" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "Test 9" 6 | layout: """ 7 | %%%%%% 8 | % %. % 9 | % %%.% 10 | %P. .% 11 | %%%%%% 12 | """ 13 | 14 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_grade_tricky.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q5/food_heuristic_grade_tricky.test. 2 | # File intentionally blank. 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q5/food_heuristic_grade_tricky.test: -------------------------------------------------------------------------------- 1 | class: "HeuristicGrade" 2 | 3 | heuristic: "foodHeuristic" 4 | searchProblemClass: "FoodSearchProblem" 5 | layoutName: "trickySearch" 6 | layout: """ 7 | %%%%%%%%%%%%%%%%%%%% 8 | %. ..% % 9 | %.%%.%%.%%.%%.%% % % 10 | % P % % 11 | %%%%%%%%%%%%%%%%%% % 12 | %..... % 13 | %%%%%%%%%%%%%%%%%%%% 14 | """ 15 | # One point always, an extra point for each 16 | # threshold passed. 17 | basePoints: "1" 18 | gradingThresholds: "15000 12000 9000 7000" 19 | 20 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q6/CONFIG: -------------------------------------------------------------------------------- 1 | max_points: "3" 2 | class: "PartialCreditQuestion" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q6/grade-agent.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q6/grade-agent.test. 2 | # File intentionally blank. 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q6/grade-agent.test: -------------------------------------------------------------------------------- 1 | class: "EvalAgentTest" 2 | 3 | agentName: "ReflexAgent" 4 | layoutName: "openClassic" 5 | maxTime: "120" 6 | numGames: "10" 7 | 8 | 9 | nonTimeoutMinimum: "10" 10 | 11 | scoreThresholds: "1000" 12 | 13 | winsMinimum: "1" 14 | winsThresholds: "5 10" 15 | 16 | 17 | randomSeed: "0" 18 | ghosts: "[RandomGhost(1)]" 19 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/0-lecture-6-tree.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/0-lecture-6-tree.test. 2 | action: "Center" 3 | generated: "A B C D E F G H I max min1 min2 min3" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/0-lecture-6-tree.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "2" 4 | 5 | # Tree from lecture 6 slides 6 | diagram: """ 7 | max 8 | /-/ | \--\ 9 | / | \ 10 | / | \ 11 | min1 min2 min3 12 | /|\ /|\ /|\ 13 | / | \ / | \ / | \ 14 | A B C D E F G H I 15 | 3 12 8 5 4 6 14 1 11 16 | """ 17 | 18 | num_agents: "2" 19 | 20 | start_state: "max" 21 | win_states: "A B C D E F G H I" 22 | lose_states: "" 23 | 24 | successors: """ 25 | max Left min1 26 | max Center min2 27 | max Right min3 28 | min1 Left A 29 | min1 Center B 30 | min1 Right C 31 | min2 Left D 32 | min2 Center E 33 | min2 Right F 34 | min3 Left G 35 | min3 Center H 36 | min3 Right I 37 | """ 38 | 39 | 40 | evaluation: """ 41 | A 3.0 42 | B 12.0 43 | C 8.0 44 | D 5.0 45 | E 4.0 46 | F 6.0 47 | G 14.0 48 | H 1.0 49 | I 11.0 50 | """ 51 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/0-small-tree.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/0-small-tree.test. 2 | action: "pacLeft" 3 | generated: "A B C D deeper minLeft minRight root" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/0-small-tree.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | root 7 | / \ 8 | minLeft minRight 9 | / \ / \ 10 | A B C deeper 11 | 4 3 2 | 12 | D 13 | 1000 14 | """ 15 | num_agents: "2" 16 | 17 | start_state: "root" 18 | win_states: "A C" 19 | lose_states: "B D" 20 | 21 | successors: """ 22 | root pacLeft minLeft 23 | root pacRight minRight 24 | minLeft gLeft A 25 | minLeft gRight B 26 | minRight gLeft C 27 | minRight gRight deeper 28 | deeper pacLeft D 29 | """ 30 | 31 | evaluation: """ 32 | A 4.0 33 | B 3.0 34 | C 2.0 35 | D 1000.0 36 | """ 37 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-1-minmax.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/1-1-minmax.test. 2 | action: "Left" 3 | generated: "a b1 b2 c1 c2 cx d1 d2 d3 d4 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-1-minmax.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ | 11 | c1 c2 cx 12 | / \ / \ | 13 | d1 d2 d3 d4 dx 14 | -3 -9 10 6 -3.01 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is -3. 21 | """ 22 | num_agents: "2" 23 | 24 | start_state: "a" 25 | win_states: "d1 d2 d3 d4 dx" 26 | lose_states: "" 27 | 28 | successors: """ 29 | a Left b1 30 | a Right b2 31 | b1 Left c1 32 | b1 Right c2 33 | b2 Down cx 34 | c1 Left d1 35 | c1 Right d2 36 | c2 Left d3 37 | c2 Right d4 38 | cx Down dx 39 | """ 40 | 41 | evaluation: """ 42 | d1 -3.0 43 | d2 -9.0 44 | d3 10.0 45 | d4 6.0 46 | dx -3.01 47 | """ 48 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-2-minmax.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/1-2-minmax.test. 2 | action: "Right" 3 | generated: "a b1 b2 c1 c2 cx d1 d2 d3 d4 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-2-minmax.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ | 11 | c1 c2 cx 12 | / \ / \ | 13 | d1 d2 d3 d4 dx 14 | -3 -9 10 6 -2.99 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is -3. 21 | """ 22 | num_agents: "2" 23 | 24 | start_state: "a" 25 | win_states: "d1 d2 d3 d4 dx" 26 | lose_states: "" 27 | 28 | successors: """ 29 | a Left b1 30 | a Right b2 31 | b1 Left c1 32 | b1 Right c2 33 | b2 Down cx 34 | c1 Left d1 35 | c1 Right d2 36 | c2 Left d3 37 | c2 Right d4 38 | cx Down dx 39 | """ 40 | 41 | evaluation: """ 42 | d1 -3.0 43 | d2 -9.0 44 | d3 10.0 45 | d4 6.0 46 | dx -2.99 47 | """ 48 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-3-minmax.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/1-3-minmax.test. 2 | action: "Left" 3 | generated: "a b1 b2 c3 c4 cx d5 d6 d7 d8 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-3-minmax.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | | / \ 11 | cx c3 c4 12 | | / \ / \ 13 | dx d5 d6 d7 d8 14 | 4.01 4 -7 0 5 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b2 is 4. 21 | """ 22 | num_agents: "2" 23 | 24 | start_state: "a" 25 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8 dx" 26 | lose_states: "" 27 | 28 | successors: """ 29 | a Left b1 30 | a Right b2 31 | b1 Down cx 32 | b2 Left c3 33 | b2 Right c4 34 | c3 Left d5 35 | c3 Right d6 36 | c4 Left d7 37 | c4 Right d8 38 | cx Down dx 39 | """ 40 | 41 | evaluation: """ 42 | d5 4.0 43 | d6 -7.0 44 | d7 0.0 45 | d8 5.0 46 | dx 4.01 47 | """ 48 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-4-minmax.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/1-4-minmax.test. 2 | action: "Right" 3 | generated: "a b1 b2 c3 c4 cx d5 d6 d7 d8 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-4-minmax.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | | / \ 11 | cx c3 c4 12 | | / \ / \ 13 | dx d5 d6 d7 d8 14 | 3.99 4 -7 0 5 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b2 is 4. 21 | """ 22 | num_agents: "2" 23 | 24 | start_state: "a" 25 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8 dx" 26 | lose_states: "" 27 | 28 | successors: """ 29 | a Left b1 30 | a Right b2 31 | b1 Down cx 32 | b2 Left c3 33 | b2 Right c4 34 | c3 Left d5 35 | c3 Right d6 36 | c4 Left d7 37 | c4 Right d8 38 | cx Down dx 39 | """ 40 | 41 | evaluation: """ 42 | d5 4.0 43 | d6 -7.0 44 | d7 0.0 45 | d8 5.0 46 | dx 3.99 47 | """ 48 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-5-minmax.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/1-5-minmax.test. 2 | action: "Right" 3 | generated: "A B C D E F G H Z a b1 b2 c1 c2 cx d1 d2 d3 d4 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-5-minmax.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "4" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ | 11 | c1 c2 cx 12 | / \ / \ | 13 | d1 d2 d3 d4 dx 14 | / \ / \ / \ / \ | 15 | A B C D E F G H Z 16 | -3 13 5 9 10 3 -6 8 3.01 17 | 18 | a - max 19 | b - min 20 | c - max 21 | d - min 22 | 23 | Note the minimax value of b1 is 3. 24 | """ 25 | num_agents: "2" 26 | 27 | start_state: "a" 28 | win_states: "A B C D E F G H I J K L M N O P Z" 29 | lose_states: "" 30 | 31 | successors: """ 32 | a Left b1 33 | a Right b2 34 | b1 Left c1 35 | b1 Right c2 36 | b2 Down cx 37 | c1 Left d1 38 | c1 Right d2 39 | c2 Left d3 40 | c2 Right d4 41 | c3 Left d5 42 | c3 Right d6 43 | c4 Left d7 44 | c4 Right d8 45 | cx Down dx 46 | d1 Left A 47 | d1 Right B 48 | d2 Left C 49 | d2 Right D 50 | d3 Left E 51 | d3 Right F 52 | d4 Left G 53 | d4 Right H 54 | d5 Left I 55 | d5 Right J 56 | d6 Left K 57 | d6 Right L 58 | d7 Left M 59 | d7 Right N 60 | d8 Left O 61 | d8 Right P 62 | dx Down Z 63 | """ 64 | 65 | evaluation: """ 66 | A -3.0 67 | B 13.0 68 | C 5.0 69 | D 9.0 70 | E 10.0 71 | F 3.0 72 | G -6.0 73 | H 8.0 74 | Z 3.01 75 | """ 76 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-6-minmax.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/1-6-minmax.test. 2 | action: "Left" 3 | generated: "A B C D E F G H Z a b1 b2 c1 c2 cx d1 d2 d3 d4 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-6-minmax.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "4" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ | 11 | c1 c2 cx 12 | / \ / \ | 13 | d1 d2 d3 d4 dx 14 | / \ / \ / \ / \ | 15 | A B C D E F G H Z 16 | -3 13 5 9 10 3 -6 8 2.99 17 | 18 | a - max 19 | b - min 20 | c - max 21 | d - min 22 | 23 | Note the minimax value of b1 is 3. 24 | """ 25 | num_agents: "2" 26 | 27 | start_state: "a" 28 | win_states: "A B C D E F G H I J K L M N O P Z" 29 | lose_states: "" 30 | 31 | successors: """ 32 | a Left b1 33 | a Right b2 34 | b1 Left c1 35 | b1 Right c2 36 | b2 Down cx 37 | c1 Left d1 38 | c1 Right d2 39 | c2 Left d3 40 | c2 Right d4 41 | c3 Left d5 42 | c3 Right d6 43 | c4 Left d7 44 | c4 Right d8 45 | cx Down dx 46 | d1 Left A 47 | d1 Right B 48 | d2 Left C 49 | d2 Right D 50 | d3 Left E 51 | d3 Right F 52 | d4 Left G 53 | d4 Right H 54 | d5 Left I 55 | d5 Right J 56 | d6 Left K 57 | d6 Right L 58 | d7 Left M 59 | d7 Right N 60 | d8 Left O 61 | d8 Right P 62 | dx Down Z 63 | """ 64 | 65 | evaluation: """ 66 | A -3.0 67 | B 13.0 68 | C 5.0 69 | D 9.0 70 | E 10.0 71 | F 3.0 72 | G -6.0 73 | H 8.0 74 | Z 2.99 75 | """ 76 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-7-minmax.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/1-7-minmax.test. 2 | action: "Left" 3 | generated: "I J K L M N O P Z a b1 b2 c3 c4 cx d5 d6 d7 d8 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-7-minmax.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "4" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | | / \ 11 | cx c3 c4 12 | | / \ / \ 13 | dx d5 d6 d7 d8 14 | | / \ / \ / \ / \ 15 | Z I J K L M N O P 16 | -1.99 -1 -9 4 7 2 5 -3 -2 17 | 18 | a - max 19 | b - min 20 | c - min 21 | d - max 22 | 23 | Note that the minimax value of b2 is -2 24 | """ 25 | num_agents: "3" 26 | 27 | start_state: "a" 28 | win_states: "A B C D E F G H I J K L M N O P Z" 29 | lose_states: "" 30 | 31 | successors: """ 32 | a Left b1 33 | a Right b2 34 | b1 Down cx 35 | b2 Left c3 36 | b2 Right c4 37 | c1 Left d1 38 | c1 Right d2 39 | c2 Left d3 40 | c2 Right d4 41 | c3 Left d5 42 | c3 Right d6 43 | c4 Left d7 44 | c4 Right d8 45 | cx Down dx 46 | d1 Left A 47 | d1 Right B 48 | d2 Left C 49 | d2 Right D 50 | d3 Left E 51 | d3 Right F 52 | d4 Left G 53 | d4 Right H 54 | d5 Left I 55 | d5 Right J 56 | d6 Left K 57 | d6 Right L 58 | d7 Left M 59 | d7 Right N 60 | d8 Left O 61 | d8 Right P 62 | dx Down Z 63 | """ 64 | 65 | evaluation: """ 66 | I -1.0 67 | J -9.0 68 | K 4.0 69 | L 7.0 70 | M 2.0 71 | N 5.0 72 | O -3.0 73 | P -2.0 74 | Z -1.99 75 | """ 76 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-8-minmax.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/1-8-minmax.test. 2 | action: "Right" 3 | generated: "I J K L M N O P Z a b1 b2 c3 c4 cx d5 d6 d7 d8 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/1-8-minmax.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "4" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | | / \ 11 | cx c3 c4 12 | | / \ / \ 13 | dx d5 d6 d7 d8 14 | | / \ / \ / \ / \ 15 | Z I J K L M N O P 16 | -2.01 -1 -9 4 7 2 5 -3 -2 17 | 18 | a - max 19 | b - min 20 | c - min 21 | d - max 22 | 23 | Note that the minimax value of b2 is -2.01 24 | """ 25 | num_agents: "3" 26 | 27 | start_state: "a" 28 | win_states: "A B C D E F G H I J K L M N O P Z" 29 | lose_states: "" 30 | 31 | successors: """ 32 | a Left b1 33 | a Right b2 34 | b1 Down cx 35 | b2 Left c3 36 | b2 Right c4 37 | c1 Left d1 38 | c1 Right d2 39 | c2 Left d3 40 | c2 Right d4 41 | c3 Left d5 42 | c3 Right d6 43 | c4 Left d7 44 | c4 Right d8 45 | cx Down dx 46 | d1 Left A 47 | d1 Right B 48 | d2 Left C 49 | d2 Right D 50 | d3 Left E 51 | d3 Right F 52 | d4 Left G 53 | d4 Right H 54 | d5 Left I 55 | d5 Right J 56 | d6 Left K 57 | d6 Right L 58 | d7 Left M 59 | d7 Right N 60 | d8 Left O 61 | d8 Right P 62 | dx Down Z 63 | """ 64 | 65 | evaluation: """ 66 | I -1.0 67 | J -9.0 68 | K 4.0 69 | L 7.0 70 | M 2.0 71 | N 5.0 72 | O -3.0 73 | P -2.0 74 | Z -2.01 75 | """ 76 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-1a-vary-depth.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/2-1a-vary-depth.test. 2 | action: "Left" 3 | generated: "a b1 b2 c1 c2 cx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-1a-vary-depth.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "1" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ | 11 | -4 c1 c2 9 cx -4.01 12 | / \ / \ | 13 | d1 d2 d3 d4 dx 14 | -3 -9 10 6 -4.01 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is -3, but the depth=1 limited value is -4. 21 | The values next to c1, c2, and cx are the values of the evaluation function, not 22 | necessarily the correct minimax backup. 23 | """ 24 | num_agents: "2" 25 | 26 | start_state: "a" 27 | win_states: "d1 d2 d3 d4 dx" 28 | lose_states: "" 29 | 30 | successors: """ 31 | a Left b1 32 | a Right b2 33 | b1 Left c1 34 | b1 Right c2 35 | b2 Down cx 36 | c1 Left d1 37 | c1 Right d2 38 | c2 Left d3 39 | c2 Right d4 40 | cx Down dx 41 | """ 42 | 43 | evaluation: """ 44 | c1 -4.0 45 | c2 9.0 46 | cx -4.01 47 | d1 -3.0 48 | d2 -9.0 49 | d3 10.0 50 | d4 6.0 51 | dx -4.01 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-1b-vary-depth.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/2-1b-vary-depth.test. 2 | action: "Left" 3 | generated: "a b1 b2 c1 c2 cx d1 d2 d3 d4 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-1b-vary-depth.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "2" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ | 11 | -4 c1 c2 9 cx -4.01 12 | / \ / \ | 13 | d1 d2 d3 d4 dx 14 | -3 -9 10 6 -4.01 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is -3, but the depth=1 limited value is -4. 21 | The values next to c1, c2, and cx are the values of the evaluation function, not 22 | necessarily the correct minimax backup. 23 | """ 24 | num_agents: "2" 25 | 26 | start_state: "a" 27 | win_states: "d1 d2 d3 d4 dx" 28 | lose_states: "" 29 | 30 | successors: """ 31 | a Left b1 32 | a Right b2 33 | b1 Left c1 34 | b1 Right c2 35 | b2 Down cx 36 | c1 Left d1 37 | c1 Right d2 38 | c2 Left d3 39 | c2 Right d4 40 | cx Down dx 41 | """ 42 | 43 | evaluation: """ 44 | c1 -4.0 45 | c2 9.0 46 | cx -4.01 47 | d1 -3.0 48 | d2 -9.0 49 | d3 10.0 50 | d4 6.0 51 | dx -4.01 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-2a-vary-depth.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/2-2a-vary-depth.test. 2 | action: "Right" 3 | generated: "a b1 b2 c1 c2 cx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-2a-vary-depth.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "1" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ | 11 | -4 c1 c2 9 cx -3.99 12 | / \ / \ | 13 | d1 d2 d3 d4 dx 14 | -3 -9 10 6 -3.99 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is -3, but the depth=1 limited value is -4. 21 | The values next to c1, c2, and cx are the values of the evaluation function, not 22 | necessarily the correct minimax backup. 23 | """ 24 | num_agents: "2" 25 | 26 | start_state: "a" 27 | win_states: "d1 d2 d3 d4 dx" 28 | lose_states: "" 29 | 30 | successors: """ 31 | a Left b1 32 | a Right b2 33 | b1 Left c1 34 | b1 Right c2 35 | b2 Down cx 36 | c1 Left d1 37 | c1 Right d2 38 | c2 Left d3 39 | c2 Right d4 40 | cx Down dx 41 | """ 42 | 43 | evaluation: """ 44 | c1 -4.0 45 | c2 9.0 46 | cx -3.99 47 | d1 -3.0 48 | d2 -9.0 49 | d3 10.0 50 | d4 6.0 51 | dx -3.99 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-2b-vary-depth.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/2-2b-vary-depth.test. 2 | action: "Left" 3 | generated: "a b1 b2 c1 c2 cx d1 d2 d3 d4 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-2b-vary-depth.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "2" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ | 11 | -4 c1 c2 9 cx -3.99 12 | / \ / \ | 13 | d1 d2 d3 d4 dx 14 | -3 -9 10 6 -3.99 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is -3, but the depth=1 limited value is -4. 21 | The values next to c1, c2, and cx are the values of the evaluation function, not 22 | necessarily the correct minimax backup. 23 | """ 24 | num_agents: "2" 25 | 26 | start_state: "a" 27 | win_states: "d1 d2 d3 d4 dx" 28 | lose_states: "" 29 | 30 | successors: """ 31 | a Left b1 32 | a Right b2 33 | b1 Left c1 34 | b1 Right c2 35 | b2 Down cx 36 | c1 Left d1 37 | c1 Right d2 38 | c2 Left d3 39 | c2 Right d4 40 | cx Down dx 41 | """ 42 | 43 | evaluation: """ 44 | c1 -4.0 45 | c2 9.0 46 | cx -3.99 47 | d1 -3.0 48 | d2 -9.0 49 | d3 10.0 50 | d4 6.0 51 | dx -3.99 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-3a-vary-depth.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/2-3a-vary-depth.test. 2 | action: "Left" 3 | generated: "a b1 b2 c3 c4 cx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-3a-vary-depth.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "1" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | | / \ 11 | 5.01 cx 8 c3 c4 5 12 | | / \ / \ 13 | dx d5 d6 d7 d8 14 | 5.01 4 -7 0 5 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is 4, but the depth=1 limited value is 5. 21 | The values next to c3, c4, and cx are the values of the evaluation function, not 22 | necessarily the correct minimax backup. 23 | """ 24 | num_agents: "2" 25 | 26 | start_state: "a" 27 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8 dx" 28 | lose_states: "" 29 | 30 | successors: """ 31 | a Left b1 32 | a Right b2 33 | b1 Down cx 34 | b2 Left c3 35 | b2 Right c4 36 | c3 Left d5 37 | c3 Right d6 38 | c4 Left d7 39 | c4 Right d8 40 | cx Down dx 41 | """ 42 | 43 | evaluation: """ 44 | c3 8.0 45 | c4 5.0 46 | cx 5.01 47 | d5 4.0 48 | d6 -7.0 49 | d7 0.0 50 | d8 5.0 51 | dx 5.01 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-3b-vary-depth.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/2-3b-vary-depth.test. 2 | action: "Left" 3 | generated: "a b1 b2 c3 c4 cx d5 d6 d7 d8 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-3b-vary-depth.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "2" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | | / \ 11 | 5.01 cx 8 c3 c4 5 12 | | / \ / \ 13 | dx d5 d6 d7 d8 14 | 5.01 4 -7 0 5 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is 4, but the depth=1 limited value is 5. 21 | The values next to c3, c4, and cx are the values of the evaluation function, not 22 | necessarily the correct minimax backup. 23 | """ 24 | num_agents: "2" 25 | 26 | start_state: "a" 27 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8 dx" 28 | lose_states: "" 29 | 30 | successors: """ 31 | a Left b1 32 | a Right b2 33 | b1 Down cx 34 | b2 Left c3 35 | b2 Right c4 36 | c3 Left d5 37 | c3 Right d6 38 | c4 Left d7 39 | c4 Right d8 40 | cx Down dx 41 | """ 42 | 43 | evaluation: """ 44 | c3 8.0 45 | c4 5.0 46 | cx 5.01 47 | d5 4.0 48 | d6 -7.0 49 | d7 0.0 50 | d8 5.0 51 | dx 5.01 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-4a-vary-depth.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/2-4a-vary-depth.test. 2 | action: "Right" 3 | generated: "a b1 b2 c3 c4 cx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-4a-vary-depth.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "1" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | | / \ 11 | 4.99 cx 8 c3 c4 5 12 | | / \ / \ 13 | dx d5 d6 d7 d8 14 | 4.99 4 -7 0 5 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is 4, but the depth=1 limited value is 5. 21 | The values next to c3, c4, and cx are the values of the evaluation function, not 22 | necessarily the correct minimax backup. 23 | """ 24 | num_agents: "2" 25 | 26 | start_state: "a" 27 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8 dx" 28 | lose_states: "" 29 | 30 | successors: """ 31 | a Left b1 32 | a Right b2 33 | b1 Down cx 34 | b2 Left c3 35 | b2 Right c4 36 | c3 Left d5 37 | c3 Right d6 38 | c4 Left d7 39 | c4 Right d8 40 | cx Down dx 41 | """ 42 | 43 | evaluation: """ 44 | c3 8.0 45 | c4 5.0 46 | cx 4.99 47 | d5 4.0 48 | d6 -7.0 49 | d7 0.0 50 | d8 5.0 51 | dx 4.99 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-4b-vary-depth.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/2-4b-vary-depth.test. 2 | action: "Left" 3 | generated: "a b1 b2 c3 c4 cx d5 d6 d7 d8 dx" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-4b-vary-depth.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "2" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | | / \ 11 | 4.99 cx 8 c3 c4 5 12 | | / \ / \ 13 | dx d5 d6 d7 d8 14 | 4.99 4 -7 0 5 15 | 16 | a - max 17 | b - min 18 | c - max 19 | 20 | Note that the minimax value of b1 is 4, but the depth=1 limited value is 5. 21 | The values next to c3, c4, and cx are the values of the evaluation function, not 22 | necessarily the correct minimax backup. 23 | """ 24 | num_agents: "2" 25 | 26 | start_state: "a" 27 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8 dx" 28 | lose_states: "" 29 | 30 | successors: """ 31 | a Left b1 32 | a Right b2 33 | b1 Down cx 34 | b2 Left c3 35 | b2 Right c4 36 | c3 Left d5 37 | c3 Right d6 38 | c4 Left d7 39 | c4 Right d8 40 | cx Down dx 41 | """ 42 | 43 | evaluation: """ 44 | c3 8.0 45 | c4 5.0 46 | cx 4.99 47 | d5 4.0 48 | d6 -7.0 49 | d7 0.0 50 | d8 5.0 51 | dx 4.99 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-one-ghost-3level.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/2-one-ghost-3level.test. 2 | action: "Left" 3 | generated: "a b1 b2 c1 c2 c3 c4 d1 d2 d3 d4 d5 d6 d7 d8" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/2-one-ghost-3level.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ / \ 11 | c1 c2 c3 c4 12 | / \ / \ / \ / \ 13 | d1 d2 d3 d4 d5 d6 d7 d8 14 | 3 9 10 6 4 7 0 5 15 | 16 | a - max 17 | b - min 18 | c - max 19 | """ 20 | num_agents: "2" 21 | 22 | start_state: "a" 23 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8" 24 | lose_states: "" 25 | 26 | successors: """ 27 | a Left b1 28 | a Right b2 29 | b1 Left c1 30 | b1 Right c2 31 | b2 Left c3 32 | b2 Right c4 33 | c1 Left d1 34 | c1 Right d2 35 | c2 Left d3 36 | c2 Right d4 37 | c3 Left d5 38 | c3 Right d6 39 | c4 Left d7 40 | c4 Right d8 41 | """ 42 | 43 | evaluation: """ 44 | d1 3.0 45 | d2 9.0 46 | d3 10.0 47 | d4 6.0 48 | d5 4.0 49 | d6 7.0 50 | d7 0.0 51 | d8 5.0 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/3-one-ghost-4level.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/3-one-ghost-4level.test. 2 | action: "Left" 3 | generated: "A B C D E F G H I J K L M N O P a b1 b2 c1 c2 c3 c4 d1 d2 d3 d4 d5 d6 d7 d8" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/3-one-ghost-4level.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "4" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ / \ 11 | c1 c2 c3 c4 12 | / \ / \ / \ / \ 13 | d1 d2 d3 d4 d5 d6 d7 d8 14 | / \ / \ / \ / \ / \ / \ / \ / \ 15 | A B C D E F G H I J K L M N O P 16 | 3 13 5 9 10 11 6 8 1 0 4 7 12 15 2 14 17 | 18 | a - max 19 | b - min 20 | c - max 21 | d - min 22 | """ 23 | num_agents: "2" 24 | 25 | start_state: "a" 26 | win_states: "A B C D E F G H I J K L M N O P" 27 | lose_states: "" 28 | 29 | successors: """ 30 | a Left b1 31 | a Right b2 32 | b1 Left c1 33 | b1 Right c2 34 | b2 Left c3 35 | b2 Right c4 36 | c1 Left d1 37 | c1 Right d2 38 | c2 Left d3 39 | c2 Right d4 40 | c3 Left d5 41 | c3 Right d6 42 | c4 Left d7 43 | c4 Right d8 44 | d1 Left A 45 | d1 Right B 46 | d2 Left C 47 | d2 Right D 48 | d3 Left E 49 | d3 Right F 50 | d4 Left G 51 | d4 Right H 52 | d5 Left I 53 | d5 Right J 54 | d6 Left K 55 | d6 Right L 56 | d7 Left M 57 | d7 Right N 58 | d8 Left O 59 | d8 Right P 60 | """ 61 | 62 | evaluation: """ 63 | A 3.0 64 | B 13.0 65 | C 5.0 66 | D 9.0 67 | E 10.0 68 | F 11.0 69 | G 6.0 70 | H 8.0 71 | I 1.0 72 | J 0.0 73 | K 4.0 74 | L 7.0 75 | M 12.0 76 | N 15.0 77 | O 2.0 78 | P 14.0 79 | """ 80 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/4-two-ghosts-3level.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/4-two-ghosts-3level.test. 2 | action: "Left" 3 | generated: "a b1 b2 c1 c2 c3 c4 d1 d2 d3 d4 d5 d6 d7 d8" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/4-two-ghosts-3level.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ / \ 11 | c1 c2 c3 c4 12 | / \ / \ / \ / \ 13 | d1 d2 d3 d4 d5 d6 d7 d8 14 | 3 9 10 6 4 7 0 5 15 | 16 | a - max 17 | b - min 18 | c - min 19 | """ 20 | num_agents: "3" 21 | 22 | start_state: "a" 23 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8" 24 | lose_states: "" 25 | 26 | successors: """ 27 | a Left b1 28 | a Right b2 29 | b1 Left c1 30 | b1 Right c2 31 | b2 Left c3 32 | b2 Right c4 33 | c1 Left d1 34 | c1 Right d2 35 | c2 Left d3 36 | c2 Right d4 37 | c3 Left d5 38 | c3 Right d6 39 | c4 Left d7 40 | c4 Right d8 41 | """ 42 | 43 | evaluation: """ 44 | d1 3.0 45 | d2 9.0 46 | d3 10.0 47 | d4 6.0 48 | d5 4.0 49 | d6 7.0 50 | d7 0.0 51 | d8 5.0 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/5-two-ghosts-4level.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/5-two-ghosts-4level.test. 2 | action: "Left" 3 | generated: "A B C D E F G H I J K L M N O P a b1 b2 c1 c2 c3 c4 d1 d2 d3 d4 d5 d6 d7 d8" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/5-two-ghosts-4level.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "4" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ / \ 11 | c1 c2 c3 c4 12 | / \ / \ / \ / \ 13 | d1 d2 d3 d4 d5 d6 d7 d8 14 | / \ / \ / \ / \ / \ / \ / \ / \ 15 | A B C D E F G H I J K L M N O P 16 | 3 13 5 9 10 11 6 8 1 0 4 7 12 15 2 14 17 | 18 | a - max 19 | b - min 20 | c - min 21 | d - max 22 | """ 23 | num_agents: "3" 24 | 25 | start_state: "a" 26 | win_states: "A B C D E F G H I J K L M N O P" 27 | lose_states: "" 28 | 29 | successors: """ 30 | a Left b1 31 | a Right b2 32 | b1 Left c1 33 | b1 Right c2 34 | b2 Left c3 35 | b2 Right c4 36 | c1 Left d1 37 | c1 Right d2 38 | c2 Left d3 39 | c2 Right d4 40 | c3 Left d5 41 | c3 Right d6 42 | c4 Left d7 43 | c4 Right d8 44 | d1 Left A 45 | d1 Right B 46 | d2 Left C 47 | d2 Right D 48 | d3 Left E 49 | d3 Right F 50 | d4 Left G 51 | d4 Right H 52 | d5 Left I 53 | d5 Right J 54 | d6 Left K 55 | d6 Right L 56 | d7 Left M 57 | d7 Right N 58 | d8 Left O 59 | d8 Right P 60 | """ 61 | 62 | evaluation: """ 63 | A 3.0 64 | B 13.0 65 | C 5.0 66 | D 9.0 67 | E 10.0 68 | F 11.0 69 | G 6.0 70 | H 8.0 71 | I 1.0 72 | J 0.0 73 | K 4.0 74 | L 7.0 75 | M 12.0 76 | N 15.0 77 | O 2.0 78 | P 14.0 79 | """ 80 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/6-tied-root.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q7/6-tied-root.test. 2 | action: "Left" 3 | generated: "A B C max min1 min2" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/6-tied-root.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "MinimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | max 7 | / \ 8 | min1 min2 9 | | / \ 10 | A B C 11 | 10 10 0 12 | """ 13 | num_agents: "2" 14 | 15 | start_state: "max" 16 | win_states: "A B" 17 | lose_states: "C" 18 | 19 | successors: """ 20 | max Left min1 21 | max Right min2 22 | min1 Down A 23 | min2 Left B 24 | min2 Right C 25 | """ 26 | 27 | evaluation: """ 28 | A 10.0 29 | B 10.0 30 | C 0.0 31 | """ 32 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/7-pacman-game.test: -------------------------------------------------------------------------------- 1 | class: "PacmanGameTreeTest" 2 | alg: "MinimaxAgent" 3 | seed: "0" 4 | depth: "2" 5 | max_points: "4" 6 | 7 | # The following specifies the layout to be used 8 | layoutName: "smallClassic" 9 | layout: """ 10 | %%%%%%%%%%%%%%%%%%%% 11 | %......%G G%......% 12 | %.%%...%% %%...%%.% 13 | %.%o.%........%.o%.% 14 | %.%%.%.%%%%%%.%.%%.% 15 | %........P.........% 16 | %%%%%%%%%%%%%%%%%%%% 17 | """ 18 | 19 | 20 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q7/CONFIG: -------------------------------------------------------------------------------- 1 | max_points: "2" 2 | class: "PassAllTestsQuestion" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/0-expectimax1.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q8/0-expectimax1.test. 2 | action: "Left" 3 | generated: "A B C D E F G H I exp1 exp2 exp3 max" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/0-expectimax1.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "ExpectimaxAgent" 3 | depth: "2" 4 | 5 | # Tree adapted from lecture 6 slides 6 | diagram: """ 7 | max 8 | /-/ | \--\ 9 | / | \ 10 | / | \ 11 | exp1 exp2 exp3 12 | /|\ /|\ /|\ 13 | / | \ / | \ / | \ 14 | A B C D E F G H I 15 | 3 12 8 2 4 6 14 5 2 16 | """ 17 | num_agents: "2" 18 | 19 | start_state: "max" 20 | win_states: "A B C D E F G H I" 21 | lose_states: "" 22 | 23 | successors: """ 24 | max Left exp1 25 | max Center exp2 26 | max Right exp3 27 | exp1 Left A 28 | exp1 Center B 29 | exp1 Right C 30 | exp2 Left D 31 | exp2 Center E 32 | exp2 Right F 33 | exp3 Left G 34 | exp3 Center H 35 | exp3 Right I 36 | """ 37 | 38 | evaluation: """ 39 | A 3.0 40 | B 12.0 41 | C 8.0 42 | D 2.0 43 | E 4.0 44 | F 6.0 45 | G 14.0 46 | H 5.0 47 | I 2.0 48 | """ 49 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/1-expectimax2.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q8/1-expectimax2.test. 2 | action: "Left" 3 | generated: "A B C D E F G H I exp1 exp2 exp3 max" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/1-expectimax2.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "ExpectimaxAgent" 3 | depth: "2" 4 | 5 | # Tree from lecture 7 slides 6 | diagram: """ 7 | max 8 | /-/ | \--\ 9 | / | \ 10 | / | \ 11 | exp1 exp2 exp3 12 | /|\ /|\ /|\ 13 | / | \ / | \ / | \ 14 | A B C D E F G H I 15 | 3 12 9 2 4 6 15 6 0 16 | """ 17 | num_agents: "2" 18 | 19 | start_state: "max" 20 | win_states: "A B C D E F G H I" 21 | lose_states: "" 22 | 23 | successors: """ 24 | max Left exp1 25 | max Center exp2 26 | max Right exp3 27 | exp1 Left A 28 | exp1 Center B 29 | exp1 Right C 30 | exp2 Left D 31 | exp2 Center E 32 | exp2 Right F 33 | exp3 Left G 34 | exp3 Center H 35 | exp3 Right I 36 | """ 37 | 38 | evaluation: """ 39 | A 3.0 40 | B 12.0 41 | C 9.0 42 | D 2.0 43 | E 4.0 44 | F 6.0 45 | G 15.0 46 | H 6.0 47 | I 0.0 48 | """ 49 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/2-one-ghost-3level.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q8/2-one-ghost-3level.test. 2 | action: "Left" 3 | generated: "a b1 b2 c1 c2 c3 c4 d1 d2 d3 d4 d5 d6 d7 d8" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/2-one-ghost-3level.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "ExpectimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ / \ 11 | c1 c2 c3 c4 12 | / \ / \ / \ / \ 13 | d1 d2 d3 d4 d5 d6 d7 d8 14 | 3 9 10 6 4 7 0 5 15 | 16 | a - max 17 | b - exp 18 | c - max 19 | """ 20 | num_agents: "2" 21 | 22 | start_state: "a" 23 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8" 24 | lose_states: "" 25 | 26 | successors: """ 27 | a Left b1 28 | a Right b2 29 | b1 Left c1 30 | b1 Right c2 31 | b2 Left c3 32 | b2 Right c4 33 | c1 Left d1 34 | c1 Right d2 35 | c2 Left d3 36 | c2 Right d4 37 | c3 Left d5 38 | c3 Right d6 39 | c4 Left d7 40 | c4 Right d8 41 | """ 42 | 43 | evaluation: """ 44 | d1 3.0 45 | d2 9.0 46 | d3 10.0 47 | d4 6.0 48 | d5 4.0 49 | d6 7.0 50 | d7 0.0 51 | d8 5.0 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/3-one-ghost-4level.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q8/3-one-ghost-4level.test. 2 | action: "Right" 3 | generated: "A B C D E F G H I J K L M N O P a b1 b2 c1 c2 c3 c4 d1 d2 d3 d4 d5 d6 d7 d8" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/3-one-ghost-4level.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "ExpectimaxAgent" 3 | depth: "4" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ / \ 11 | c1 c2 c3 c4 12 | / \ / \ / \ / \ 13 | d1 d2 d3 d4 d5 d6 d7 d8 14 | / \ / \ / \ / \ / \ / \ / \ / \ 15 | A B C D E F G H I J K L M N O P 16 | 3 13 5 9 10 11 6 8 1 0 4 7 12 15 2 14 17 | 18 | a - max 19 | b - exp 20 | c - max 21 | d - exp 22 | """ 23 | num_agents: "2" 24 | 25 | start_state: "a" 26 | win_states: "A B C D E F G H I J K L M N O P" 27 | lose_states: "" 28 | 29 | successors: """ 30 | a Left b1 31 | a Right b2 32 | b1 Left c1 33 | b1 Right c2 34 | b2 Left c3 35 | b2 Right c4 36 | c1 Left d1 37 | c1 Right d2 38 | c2 Left d3 39 | c2 Right d4 40 | c3 Left d5 41 | c3 Right d6 42 | c4 Left d7 43 | c4 Right d8 44 | d1 Left A 45 | d1 Right B 46 | d2 Left C 47 | d2 Right D 48 | d3 Left E 49 | d3 Right F 50 | d4 Left G 51 | d4 Right H 52 | d5 Left I 53 | d5 Right J 54 | d6 Left K 55 | d6 Right L 56 | d7 Left M 57 | d7 Right N 58 | d8 Left O 59 | d8 Right P 60 | """ 61 | 62 | evaluation: """ 63 | A 3.0 64 | B 13.0 65 | C 5.0 66 | D 9.0 67 | E 10.0 68 | F 11.0 69 | G 6.0 70 | H 8.0 71 | I 1.0 72 | J 0.0 73 | K 4.0 74 | L 7.0 75 | M 12.0 76 | N 15.0 77 | O 2.0 78 | P 14.0 79 | """ 80 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/4-two-ghosts-3level.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q8/4-two-ghosts-3level.test. 2 | action: "Left" 3 | generated: "a b1 b2 c1 c2 c3 c4 d1 d2 d3 d4 d5 d6 d7 d8" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/4-two-ghosts-3level.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "ExpectimaxAgent" 3 | depth: "3" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ / \ 11 | c1 c2 c3 c4 12 | / \ / \ / \ / \ 13 | d1 d2 d3 d4 d5 d6 d7 d8 14 | 3 9 10 6 4 7 0 5 15 | 16 | a - max 17 | b - exp 18 | c - exp 19 | """ 20 | num_agents: "3" 21 | 22 | start_state: "a" 23 | win_states: "d1 d2 d3 d4 d5 d6 d7 d8" 24 | lose_states: "" 25 | 26 | successors: """ 27 | a Left b1 28 | a Right b2 29 | b1 Left c1 30 | b1 Right c2 31 | b2 Left c3 32 | b2 Right c4 33 | c1 Left d1 34 | c1 Right d2 35 | c2 Left d3 36 | c2 Right d4 37 | c3 Left d5 38 | c3 Right d6 39 | c4 Left d7 40 | c4 Right d8 41 | """ 42 | 43 | evaluation: """ 44 | d1 3.0 45 | d2 9.0 46 | d3 10.0 47 | d4 6.0 48 | d5 4.0 49 | d6 7.0 50 | d7 0.0 51 | d8 5.0 52 | """ 53 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/5-two-ghosts-4level.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q8/5-two-ghosts-4level.test. 2 | action: "Left" 3 | generated: "A B C D E F G H I J K L M N O P a b1 b2 c1 c2 c3 c4 d1 d2 d3 d4 d5 d6 d7 d8" 4 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/5-two-ghosts-4level.test: -------------------------------------------------------------------------------- 1 | class: "GraphGameTreeTest" 2 | alg: "ExpectimaxAgent" 3 | depth: "4" 4 | 5 | diagram: """ 6 | /-----a------\ 7 | / \ 8 | / \ 9 | b1 b2 10 | / \ / \ 11 | c1 c2 c3 c4 12 | / \ / \ / \ / \ 13 | d1 d2 d3 d4 d5 d6 d7 d8 14 | / \ / \ / \ / \ / \ / \ / \ / \ 15 | A B C D E F G H I J K L M N O P 16 | 3 13 5 9 10 11 6 8 1 0 4 7 12 15 2 14 17 | 18 | a - max 19 | b - exp 20 | c - exp 21 | d - max 22 | """ 23 | num_agents: "3" 24 | 25 | start_state: "a" 26 | win_states: "A B C D E F G H I J K L M N O P" 27 | lose_states: "" 28 | 29 | successors: """ 30 | a Left b1 31 | a Right b2 32 | b1 Left c1 33 | b1 Right c2 34 | b2 Left c3 35 | b2 Right c4 36 | c1 Left d1 37 | c1 Right d2 38 | c2 Left d3 39 | c2 Right d4 40 | c3 Left d5 41 | c3 Right d6 42 | c4 Left d7 43 | c4 Right d8 44 | d1 Left A 45 | d1 Right B 46 | d2 Left C 47 | d2 Right D 48 | d3 Left E 49 | d3 Right F 50 | d4 Left G 51 | d4 Right H 52 | d5 Left I 53 | d5 Right J 54 | d6 Left K 55 | d6 Right L 56 | d7 Left M 57 | d7 Right N 58 | d8 Left O 59 | d8 Right P 60 | """ 61 | 62 | evaluation: """ 63 | A 3.0 64 | B 13.0 65 | C 5.0 66 | D 9.0 67 | E 10.0 68 | F 11.0 69 | G 6.0 70 | H 8.0 71 | I 1.0 72 | J 0.0 73 | K 4.0 74 | L 7.0 75 | M 12.0 76 | N 15.0 77 | O 2.0 78 | P 14.0 79 | """ 80 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/6-pacman-game.test: -------------------------------------------------------------------------------- 1 | class: "PacmanGameTreeTest" 2 | alg: "ExpectimaxAgent" 3 | seed: "0" 4 | depth: "2" 5 | max_points: "4" 6 | 7 | # The following specifies the layout to be used 8 | layoutName: "smallClassic" 9 | layout: """ 10 | %%%%%%%%%%%%%%%%%%%% 11 | %......%G G%......% 12 | %.%%...%% %%...%%.% 13 | %.%o.%........%.o%.% 14 | %.%%.%.%%%%%%.%.%%.% 15 | %........P.........% 16 | %%%%%%%%%%%%%%%%%%%% 17 | """ 18 | 19 | 20 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q8/CONFIG: -------------------------------------------------------------------------------- 1 | max_points: "2" 2 | class: "PassAllTestsQuestion" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q9/CONFIG: -------------------------------------------------------------------------------- 1 | max_points: "4" 2 | class: "PartialCreditQuestion" 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q9/grade-agent.solution: -------------------------------------------------------------------------------- 1 | # This is the solution file for test_cases/q9/grade-agent.test. 2 | # File intentionally blank. 3 | -------------------------------------------------------------------------------- /old/src/pacman_demo/test_cases/q9/grade-agent.test: -------------------------------------------------------------------------------- 1 | class: "EvalAgentTest" 2 | 3 | agentName: "ExpectimaxAgent" 4 | agentArgs: "evalFn=better" 5 | layoutName: "smallClassic" 6 | maxTime: "120" 7 | numGames: "10" 8 | 9 | nonTimeoutMinimum: "0" 10 | nonTimeoutThresholds: "10" 11 | 12 | scoreThresholds: "1000" 13 | 14 | winsThresholds: "5 10" 15 | 16 | randomSeed: "0" 17 | ghosts: "[RandomGhost(1)]" 18 | -------------------------------------------------------------------------------- /old/src/pacman_demo/textDisplay.py: -------------------------------------------------------------------------------- 1 | # textDisplay.py 2 | # -------------- 3 | # Licensing Information: You are free to use or extend these projects for 4 | # educational purposes provided that (1) you do not distribute or publish 5 | # solutions, (2) you retain this notice, and (3) you provide clear 6 | # attribution to UC Berkeley, including a link to http://ai.berkeley.edu. 7 | # 8 | # Attribution Information: The Pacman AI projects were developed at UC Berkeley. 9 | # The core projects and autograders were primarily created by John DeNero 10 | # (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu). 11 | # Student side autograding was added by Brad Miller, Nick Hay, and 12 | # Pieter Abbeel (pabbeel@cs.berkeley.edu). 13 | 14 | 15 | import time 16 | try: 17 | import pacman 18 | except: 19 | pass 20 | 21 | DRAW_EVERY = 1 22 | SLEEP_TIME = 0 # This can be overwritten by __init__ 23 | DISPLAY_MOVES = False 24 | QUIET = False # Supresses output 25 | 26 | class NullGraphics: 27 | def initialize(self, state, isBlue = False): 28 | pass 29 | 30 | def update(self, state): 31 | pass 32 | 33 | def checkNullDisplay(self): 34 | return True 35 | 36 | def pause(self): 37 | time.sleep(SLEEP_TIME) 38 | 39 | def draw(self, state): 40 | print state 41 | 42 | def updateDistributions(self, dist): 43 | pass 44 | 45 | def finish(self): 46 | pass 47 | 48 | class PacmanGraphics: 49 | def __init__(self, speed=None): 50 | if speed != None: 51 | global SLEEP_TIME 52 | SLEEP_TIME = speed 53 | 54 | def initialize(self, state, isBlue = False): 55 | self.draw(state) 56 | self.pause() 57 | self.turn = 0 58 | self.agentCounter = 0 59 | 60 | def update(self, state): 61 | numAgents = len(state.agentStates) 62 | self.agentCounter = (self.agentCounter + 1) % numAgents 63 | if self.agentCounter == 0: 64 | self.turn += 1 65 | if DISPLAY_MOVES: 66 | ghosts = [pacman.nearestPoint(state.getGhostPosition(i)) for i in range(1, numAgents)] 67 | print "%4d) P: %-8s" % (self.turn, str(pacman.nearestPoint(state.getPacmanPosition()))),'| Score: %-5d' % state.score,'| Ghosts:', ghosts 68 | if self.turn % DRAW_EVERY == 0: 69 | self.draw(state) 70 | self.pause() 71 | if state._win or state._lose: 72 | self.draw(state) 73 | 74 | def pause(self): 75 | time.sleep(SLEEP_TIME) 76 | 77 | def draw(self, state): 78 | print state 79 | 80 | def finish(self): 81 | pass 82 | -------------------------------------------------------------------------------- /old/src/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlberkeley/openbrain/5dabc229324a1e4b1603b6b5cd32635b748dcc35/old/src/utils/__init__.py -------------------------------------------------------------------------------- /old/src/utils/ubigraph.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import xmlrpc.client 4 | 5 | def default_node_props(): 6 | return { 7 | 'color': "#999999", 8 | 'shape': "sphere"} 9 | 10 | 11 | class Ubigraph: 12 | def __init__(self, adjacency, 13 | server_url='http://192.168.168.33:20738/RPC2', 14 | node_prop=default_node_props()): 15 | """ 16 | Initializes the Ubigraph connection. 17 | :param adjacency: 18 | :param server_url: 19 | :param node_prop: 20 | """ 21 | print("Connecting to UbiGraph at {}".format(server_url)) 22 | 23 | server = xmlrpc.client.ServerProxy(server_url) 24 | self.G = server.ubigraph 25 | self.G.clear() 26 | 27 | print("Connected and cleared.") 28 | 29 | self.nodes = [None for n in range(adjacency.shape[0])] 30 | self.edges = [] 31 | self.node_props = [] 32 | self.num_edges = 0 33 | 34 | self.build_graph(adjacency, node_prop) 35 | 36 | print("Constructed {} nodes and {} edges." 37 | .format(len(self.nodes), self.num_edges)) 38 | 39 | def build_graph(self, adjacency, node_property): 40 | for r, row in enumerate(adjacency): 41 | self.edges += [[None for cell in row]] 42 | for c, cell in enumerate(row): 43 | 44 | if not self.nodes[c]: 45 | self.nodes[c] = self.make_node(node_property) 46 | if not self.nodes[r]: 47 | self.nodes[r] = self.make_node(node_property) 48 | 49 | if cell != 0: 50 | self.edges[r][c] = self.make_edge(self.nodes[c], self.nodes[r]) 51 | self.num_edges += 1 52 | 53 | 54 | def make_node(self, node_property): 55 | """ 56 | Makes a new vertex. 57 | :param node_property: The properties of the vertex. 58 | :return: 59 | """ 60 | # Try except because Ubigraph is old as hell! 61 | try: n = self.G.new_vertex() 62 | except: pass 63 | for prop, val in node_property.items(): 64 | try: self.G.set_vertex_attribute(n, prop, val) 65 | except: return make_node(node_property) 66 | return n 67 | 68 | def make_edge(self, a, b): 69 | """ 70 | Makes an edge from a to be. 71 | :param a: 72 | :param b: 73 | :return: 74 | """ 75 | try: e = self.G.new_edge(a, b) 76 | except: return self.G.new_edge(a,b) 77 | 78 | try: self.G.set_edge_attribute(e, "arrow", "true") 79 | except: return self.G.new_edge(a,b) 80 | 81 | try: self.G.set_edge_attribute(e, "spline", "false") 82 | except: return self.G.new_edge(a,b) 83 | return e 84 | 85 | def set_properties(self, props, nodes): 86 | for node in nodes: 87 | for prop, val in props.items(): 88 | try: self.G.set_vertex_attribute(self.nodes[node], prop, val) 89 | except: pass 90 | 91 | 92 | 93 | --------------------------------------------------------------------------------