Algorithms: Decision Trees for AIFighter

The math here is mostly taken from Russell and Norvig, the quintessential AI book.

For AIFighter, the AIs must learn from the player’s actions how to fight.  There are two types of primitives, actions and conditions.  Actions are available moves character (AI or human alike) can perform, like Swing Sword or Move Towards OpponentConditionals are statements about the world (like Opponent just targeted me with Bow) that might inform an AI unit which action to take.  During the training phase, the AI builds a table which has each action that the player took and the existing conditionals at the time of that action.

After the training phase (ignoring for now the “questioning” phase) the AI must create a decision tree for the data.  This is the learning phase.  The decision tree basically is a series of tests (like “Am I currently being attacked with a sword”) where the leaf node of the tree is an action to perform.  The decision tree is a compact and human understandable way of mapping conditions to actions.

In the execution phase, the AI simply consults its table to see what to do.  Of course, while one AI is in its execution phase, the opposite player’s AI is in its training phase.

To calculate the decision tree, we try to find conditionals that split our data to maximize the information gain.  For example, the AI would prefer to first test a conditional that always leads to a certain action in every piece of training data rather than a conditional that gives no information on which action to take.  The information in this case is equal to the sum over all i of -P(vi)logP(vi), where P(vi) is the probability that we should take the ith action.  The remainder for a particular conditional is the sum of each of its cases, where a case is equal to the information of the samples in the case multiplied by the percentage of all samples that are in that case.  Finally, the information gain for a particular condition is the information of the total problem minus the remainder for that case.  To determine the best condition to split on, we recursively find the condition with the greatest information gain.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*