| Tutorial on using the Q-learning framework |
|
Applying the QCON Framework to your project requires just a few steps: 1. Download the jar file and add it as a library to your project. In these boxes I'll refer to the QWanderBot example, which is available as an applet and whose source code can be also downloaded . 2. Create a class extending the framework class: pl.elsy.qconf.Perception. See wanderbot.brain.MyPerception class. 3. In this class implement required methods:
In updateInputValues() WanderBot observes 9 points in front of him (marked with blue dots in the applet): protected void updateInputValues() { for (int d = 1; d <= 3; d++) { for (int a = -1; a <= 1; a++) { double xPerc = xPerc(d, a); double yPerc = yPerc(d, a); setNextValue(player.getWorld().pointInObstacle(xPerc,yPerc) ? 5: -5); } } } The getReward() method is simplier - it returns 0.1 if the agent moves forward, -0.5 if a collision occurred and 0.0 otherwise: public double getReward() { if(player.movingForwardWell()) return 0.1; if(player.collides()) return -0.2; return 0.0; } 4. Think what actions the agent can perform. For each action create one separate class extending pl.elsy.qconf.Action. Here we've got 3 classes: MoveForward, TurnLeft and TurnRight, all placed in the wanderbot.brain.actions package. 5. In these classes implement required method:
Each Action class has its own execute() method. These are respectively: public int execute() { //MoveForward return player.moveForward(Player.STEP_SIZE); } public int execute() { //TurnLeft player.turn(-Player.TURNING_ANGLE); return 1; } public int execute() { //TurnRight player.turn(Player.TURNING_ANGLE); return 1; } 6. In you agent's class add a field - instance of pl.elsy.qconf.Brain. Initialize it in the agent's constructor with the following arguments:
The Player constructor In our example looks like this: public Player(World world) { this.world = world; r = 10; Action actionArray[] = new Action[3]; actionArray[MOVE_FORWARD] = new MoveForward(this); actionArray[TURN_LEFT] = new TurnLeft(this); actionArray[TURN_RIGHT] = new TurnRight(this); perception = new MyPerception(this); brain = new Brain(perception, actionArray); brain.setAlpha(0.2); // the lines below only set specific Q-learning parameters instead of default ones brain.setGamma(0.9); brain.setLambda(0.8); brain.setUseBoltzmann(true); brain.setTemperature(0.02); } 7. In the main loop of the program, where the player decides what to do, include the following lines: ...myPerception.perceive(); brain.count(); brain.executeAction(); ... In our example it is almost the same. See Player.count() method. 8. That's all. Now, just check, whether everything goes well. Good luck! If you have any questions or comments, please let me know , so I could improve the framework.
Only registered users can write comments. Powered by AkoComment 2.0! |
||
| < Prev | Next > |
|---|



