mlech26l / ncps

PyTorch and TensorFlow implementation of NCP, LTC, and CfC wired neural models
https://www.nature.com/articles/s42256-020-00237-3
Apache License 2.0
1.86k stars 298 forks source link

How to check the output of each LTC neuron in the model prediction? #11

Closed xiao-hua-sheng closed 3 years ago

mlech26l commented 3 years ago

Have a look at the example script

xiao-hua-sheng commented 3 years ago

Thank you very much

xiao-hua-sheng commented 3 years ago

Hidden states of first example tf.Tensor( [[ 0. 0. 0. 0. 0. 0.

          1. 0.
          1. 0.
  1. ] [-0.06407283 0.20069316 -0.2614325 0.14638339 0.00264633 0.20453362 -0.01128791 -0.19888248 0.15739349 0.04569557 0.18099542 -0.09539916 0.09582035 0.28807268 0.01978978 -0.34735638 0.13532008 0.22435933 0.25046283] [-0.04526144 0.28720087 -0.2964695 0.2107636 0.0264671 0.32190132 0.00938952 -0.22504494 0.19405863 0.05282384 0.27799672 -0.11116944 0.1054275 0.3238275 0.02104725 -0.4447802 0.13771126 0.24910215 0.29687914] [-0.02482559 0.344334 -0.3109218 0.24100298 0.0296307 0.3725669 0.01553136 -0.2284677 0.2013689 0.05535388 0.324138 -0.11083744 0.11014516 0.3286453 0.02050293 -0.47931242 0.13570514 0.2508992 0.3033786 ] [-0.01719125 0.37525403 -0.31596306 0.25437585 0.02981876 0.39145947 0.01552579 -0.22913907 0.20308894 0.05694852 0.34463295 -0.11135554 0.11028657 0.330946 0.0208799 -0.49009064 0.1359781 0.25026476 0.30331942] [-0.01681967 0.39091298 -0.31834745 0.259629 0.02879347 0.39825392 0.01470497 -0.2292255 0.20327553 0.05607554 0.3545323 -0.11123699 0.11556265 0.33062014 0.02190676 -0.4917807 0.1363711 0.2512049 0.30334663]], shape=(6, 19), dtype=float32) I get the hidden state of the single-step RNN model,but I can't confirm which are interneurons, which are command neurons, which are motor neurons?The definition is as follows:

wiring1 = kncp.wirings.NCP( inter_neurons=12,
command_neurons=6, motor_neurons=1,
sensory_fanout=4,
inter_fanout=4,
recurrent_command_synapses=4, motor_fanin=6,
)

mlech26l commented 3 years ago

The Wiring class has a method get_type_of_neuron, which can be used to query the type of each neuron from its index (allowing you to define custom wirings with new types of neurons).

I have updated the example to show how to use the method.