In this lab you will familiarize yourself with pyro, a tool for controlling both simulated and physical robots, that is written in python. All of the source code for pyro is located at /usr/local/pyrobot/. Feel free to go check out any aspect that interests you. Pyro includes many machine learning tools, such as neural networks, which we will explore this week. To begin, run update81 to copy some starting point files into your home directory (cs81/labs/1/).
I have provided three examples of simple neural networks for solving the logic problems and, or, and xor. Open one of these files in an editor and read through the code. Then execute it in python. Notice that only two layers of units are necessary to solve and and or, but three layers of units are necessary to solve xor.
% python -i and.pyThis will execute the code and then leave you in the python interpreter. Do the following to see the weights:
>>> n.getWeights("input", "output")Do the following to see the bias of a particular node:
>>> n["output"].weight[0]
%pyrobot -s PyrobotSimulator -w Tutorial.py -r PyrobotRobot60000 -b wallFollow.pyThe -s flag specifies which simulator you would like to use. Each simulator has a number of different worlds, which are specified by the -w flag. The simulator can control multiple robots simultaneously. Each robot has a name specified by the -r flag. Finally the robot is controlled by a brain, which is specified by the -b flag.
This will open two windows: one the pyro control window and the other the simulator window. In the simulator window, select the "View" menu and choose "Trail", to see the robot's path. In the pyro window, push the "Run" button to start the robot. Every 500 steps the program will report the average distance of the robot from the wall on its left side. We will use data collected from a program running a controller like this to train a neural network.
To quit, first press the "Stop" button in the pyro window. Then, in the pyro window, go to the "File" menu and select "Exit". If the pyro window fails to close, then in a terminal window do: killall -9 pyrobot.
%pyrobot -s PyrobotSimulator -w Tutorial.py -r PyrobotRobot60000 -b collectData.pyWhen you see a message that the data collection is done. Stop the robot and exit from pyro. You should now have two files called sensorInputs.dat and motorOutputs.dat saved in your directory.
%python trainNetwork.pyThis will take several minutes to complete. It will execute 1000 epochs of training on the collected data. Watch the error and percent correct during training. Does error consistently go down? Does percent correct consistently go up? After training is complete, you will have a new file in your directory called wallFollow.wts containing the weights and biases of the most successful version of the trained neural network.
%pyrobot -s PyrobotSimulator -w Tutorial.py -r PyrobotRobot60000 -b testNetwork.pyBe sure to "View" the robot's "Trail" in the simulator window before pressing the "Run" button in the pyro window. How does the neural network controlled robot perform compared to the hand-coded teacher program? In what ways does the neural network controlled robot behave differently from the teacher?