In this lab you will familiarize yourself a python library called conx for creating and experimenting with neural networks that is part of pyrobot.
You will go over an extended example demonstrating how you collect
data for a robot task, train a neural network, and then test the
resulting weights on the robot. You will then create a robot with a
neural network brain and train it to do phototaxis (moving in response
One method for teaching a neural network to control a robot is called offline training and involves the following steps. First write a robot controller. Then use this controller to collect data to be used to train a neural network. Next train a neural network with the collected data. Finally use the trained network to control the robot and test its performance.
Let's use this approach to train a neural network brain for a robot to do wall following.
pyrobot -s PyrobotSimulator -w Tutorial.py -r PyrobotRobot60000 -b wallFollow.pyRecall that the -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 pyrobot 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 pyrobot window, push the Run button to start the robot. Every 200 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.
Recall that to quit, you first press the Stop button in the pyrobot window to suspend the brain. Then go to the Robot menu and select Unload Robot. Finally, go to the File menu and select Exit. If the pyrobot window fails to close, then in a terminal window do: killall -9 pyrobot.
Note that all data used with a neural network must be scaled to match the range of the activation function. In our case, all data must be scaled between 0 and 1.
To run the data collection program do:
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 pyrobot. You should now have two files called sensorInputs.dat and motorTargets.dat saved in your directory. Open these files and look at the data. Each line represents one training example. We will train a neural network to map the given inputs to the given targets.
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. You will also have a log file showing the progress of learning throughout training.
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 pyrobot 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?
You will go through the same series of steps as above, but this time using your own hand-coded program for teaching a robot to orient and approach a light source.
You should use the Braitenberg.py world as the basis for
your task. When collecting data be sure to start the robot from many
different initial conditions (with the light straight ahead, to the
right, to the left, behind the robot). You can use
the Simulation device, which is discussed in
the pyrobot overview, to programmatically
reposition the robot after it has successfully reached the light
Put all of the files you created in the cs81/labs/1 directory. In the SUMMARY file provided, describe what your teacher program does, how you trained the network, and your results.
When you are done, run handin81 to turn in your completed lab work.