Tuesday, March 31, 2020

NN --> BT


I have started sketching more seriously on ideas for converting a neural network output to a solid behavior tree (BT). For reference, here is the GitHub repo I'm working in https://github.com/marcus1337/BTMaker. The repo is a bad brew of different GitHub repos + the new code that I am making (in the /src folder). So, it might be hard to try it for yourself. In short it uses "BehaviorTree.CPP", my NEAT project and some non-official boost plugin "Levenshtein-distance".

Anyways the number of output nodes from the NN can be adjusted before the code starts. My idea so far is to use 2 output nodes per BT node. The first of 2 output nodes classify which type of node it is, I.e. None, Action, Interior or Condition. The 2nd output node then maps to an integer between [0, #nodes] telling which node implementation from an array should be used. By assuming that all nodes’ positions in the BT go from left to right, I will just define the outputs position from left to right iteratively. I will let the root node always be a sequence (interior) node to make things easier. Next I will iterate all output nodes one at a time, if it is an interior node I "step into it" and continue from there. If not, I just add the node to the rightmost position possible given the currently selected interior node. However, a special case is if the node is a condition, then it will be placed 1 step to the left of whatever the current position is, and if that means breaking out of the currently selected interior node, then so be it. Finally, I let an evaluation function check if it is a valid BT, if not I will probably just trash it completely and give the NN a bad reward value. Each time a node has the "none" value, that means to pop out of the current interior to whatever the parent is, one step to the right. This means that if the last output node is an interior node, then the produced tree won’t be valid. I plan to call a tree finished once "none" is called while the root node is selected. Ideally one would not want to have too many output nodes in a NN, or too few nodes when classifying something. I feel like this plan to create a BT from a NN makes decent compromises between having a rational amount of output nodes with the fact that I will need to classify the output. So instead of using 4 output nodes per classification I will try with only 1.

For initial tests I wish to just train a network with a bias to output any valid BT structure and see if it can do so consistently. Naturally I will use my NEAT implementation to give rewards to networks that produce valid BTs and eliminate bad networks.

No comments:

Post a Comment