In [ ]:
# To train call 'neat_train.py' with arguments.
!python neat_train.py -h

In [ ]:
# Train using default NEAT parameters on cart-pole swing-up with a small population and few generations
!cat p/quickTest.json
!python neat_train.py -p p/quickTest.json

In [ ]:
# -- View stats of a completed run
# Rows:
# 0 - Fitness evaluations used
# 1 - Median fitness of population
# 2 - Max fitness of population
# 3 - Top fitness every achieved
# 4 - Median number of nodes of individuals in population
# 5 - Median number of connections of individuals in population
from matplotlib import pyplot as plt
import numpy as np
stats = np.loadtxt('demo/swingup/test_stats.out', delimiter=',')
fig, ax = plt.subplots()
x = stats[:,0]
y = stats[:,[1,2,3]]
plt.plot(y)
plt.legend(['Median Fitness','Max Fitness','Best Fitness'])
plt.xlabel('Evaluations')
plt.ylabel('Fitness')

In [ ]:
# -- View Topology of Network
# Lighter color connections are connected to earlier layers (NOT weight strength)
import vis as nv
nv.viewInd('demo/swingup/test_best.out','swingup')

In [ ]:
# -- View Behavior of Network
!python neat_test.py -p p/swingup.json -i demo/swingup/test_best.out --view True

In [ ]:
# -- Compare Replicates
# Run several experiments 
#  for i in {0..10}; do python neat_train.py -p p/swingup.json -n 96 -o tanh_$i; done
#  for i in {0..10}; do python neat_train.py -p p/swing_allAct.json -n 96 -o allAct_$i; done
#
# View results as median and quartiles
#
import vis as nv
experiment_1 = 'demo/swingup/tanh'
experiment_2 = 'demo/swingup/allAct'
_,_,bestRun = nv.viewReps([experiment_1,experiment_2],label=['Tanh Only','All Activation Functions'],\
                           title='Best Fitness Found with Uniform or Diverse Activations',getBest=True)