EvolvingBehavior  0.2.0
 
Loading...
Searching...
No Matches
Experiment Results: Saving, Loading, Evaluating

Once you have set up your experiment, you may want to save the results, load them and resume the experiment, or evaluate and use the behavior trees.

Ending the Experiment

The experiment will end after the specified number of trials (generations) from the LifeCycle Actor. You can also interrupt the experiment early by stopping the game, and you can then load and resume it later if you wish.

You can set a specific Map to load when the experiment ends, as well as the map to load to restart the level when each individual Trial ends, in the LifeCycle component.

Note that, if you stop an experiment in the middle of a Trial, that partly-completed Trial will not be saved.

Saving and Loading the Experiment In Progress

After testing every generation (a single trial), the experiment will automatically save its state. If you stop running the experiment and then start it again, it will automatically load and pick up at the beginning of the next generation/trial.

The settings for saving and loading an experiment in LifeCycle.

In the LifeCycle Actor, you can change properties to affect the saving and loading:

Slot Name: Changes the name of the save file to use for saving and loading.

User Index: If you want to save multiple experiments into the same file, you can change this number to switch between them.

By changing these to new values, you can switch which experiment you are loading and saving to, or start a totally new experiment while keeping your old ones available.

You can also delete the currently-specified save file by clicking "Delete Current Save." (The save files are placed in the "Saved/SaveGames" folder if you want to manually delete them, copy them, etc.)

Saving and Examining Behavior Trees

Each behavior tree evolved to populate each trial will be saved in a folder corresponding to the Trial Number (the number of generations that have been generated so far).

You can find all of these saved trees listed by ID in the /Content/EvolvingBehavior/Trial<num>/ folder in the Asset Browser or on disk.

The filename also indicates the Fitness of the tree, to help you sort through them.

Thus, the full filename for a specific behavior tree is: <fitness>-Tree-<id>.asset

You can load these behavior trees in the Unreal Editor as you would any other Behavior Tree asset, though they will be shown with an automatically-generated layout that may not exactly match your preferred placement of the nodes. You may need to manually drag nodes around to look at the tree with your preferred layout.

You can also manually edit these behavior trees, and you can use these behavior trees as static assets on any NPC, by dragging them into the Behavior Tree property for the AI Controller. Essentially, they work just like hand-crafted behavior trees.

You may note that the first time you open the Behavior Tree, it shows as having unsaved changes. This is due to the Editor needing to generate the initial, automatic layout of the nodes. You can safely save the layout without affecting the basic workings of the tree.

If you open a behavior tree immediately after it is generated, you may find that you get an error saying that the tree cannot be fully saved. This is because the tree has not yet been fully loaded in the editor. You can either restart the editor or manually tell the asset to fully load, after which you should be able to save it normally.

Fitness Logs

You can find the logs of fitness for every generated individual in the trial in the "EvolvingBehavior-FitnessStats" folder inside the "Saved" directory.

These logs are stored as .csv files, with the rows corresponding to each generation of a single population. The .csv is named after the population name from the EvolutionControlActor.

Note that, if you run the experiment with the same experiment ID again, it will continue appending to the .csv. So remember to change your experiment ID or delete/move the FitnessStats files to avoid mixing results from several runs. (The Grid Search actor separates its experiment IDs automatically, if you want to automate this.)

To, for example, create a graph of average fitness over time, you could open the .csv in a spreadsheet editor (such as LibreOffice Calc or Excel), and use =AVERAGE() to average each row into a new column. Then, graph the new average column's values. If the experiment is working well, generally, average fitness will increase in later generations (though it may jitter, stall, or drop temporarily, or eventually plateau and even decline slightly when it runs out of new improvements to find).

If you are not seeing improvement over time, you may want to restart the experiment multiple times with different random initial populations, tweak your fitness functions, change which behavior tree nodes are available or generatable, and/or tune various parameters for mutation rates, elitism, etc.

Additional Logs and Information

You can also find additional information (such as errors and warnings) about the experiment as it is in progress or after it has completed by examining the log files.

The "Output Log" (in Window->Developer->Output Log) contains the relevant log messages. You can also find this log as a text file on disk under your project's directory at "Saved/Logs/". Look for messages with the LogEvolvingBehavior and LogEvolvingBehaviorError categories to find information about the agents and fitnesses, and about errors or problems with the settings, respectively. If you find that agents are not evolving, or the experiment does not seem to be working, these logs are the first place to check for problems. They are also another way to see representations of the behavior trees and their fitnesses without opening each file.

Next Steps

Next Page: Tuning Parameters.