001 package aima.test.learningtest; 002 003 import java.util.Arrays; 004 import java.util.List; 005 006 import junit.framework.TestCase; 007 import aima.learning.reinforcement.QTable; 008 009 /** 010 * @author Ravi Mohan 011 * 012 */ 013 014 public class QTableTest extends TestCase { 015 016 private QTable<String, String> qt; 017 018 @Override 019 public void setUp() { 020 // simple qlearning example from 021 // http://people.revoledu.com/kardi/tutorial/ReinforcementLearning/index.html 022 List<String> states = Arrays.asList(new String[] { "A", "B", "C", "D", 023 "E", "F" }); 024 List<String> actions = Arrays.asList(new String[] { "toA", "toB", 025 "toC", "toD", "toE", "toF" }); 026 qt = new QTable<String, String>(actions); 027 } 028 029 public void testInitialSetup() { 030 assertEquals(0.0, qt.getQValue("A", "toB")); 031 assertEquals(0.0, qt.getQValue("F", "toF")); 032 033 } 034 035 public void testQUpDate() { 036 assertEquals(0.0, qt.getQValue("B", "toF")); 037 038 qt.upDateQ("B", "toF", "B", 1.0, 100, 0.8); 039 assertEquals(100.0, qt.getQValue("B", "toF")); 040 041 qt.upDateQ("D", "toB", "B", 1.0, 0, 0.8); 042 assertEquals(80.0, qt.getQValue("D", "toB")); 043 044 qt.upDateQ("A", "toB", "B", 1.0, 0, 0.8); 045 assertEquals(80.0, qt.getQValue("A", "toB")); 046 047 qt.upDateQ("A", "toD", "D", 1.0, 0, 0.8); 048 assertEquals(64.0, qt.getQValue("A", "toD")); 049 } 050 051 }