@@ -7,7 +7,7 @@ const LINE_COLOR_NEGATIVE = Color.blueviolet
77
88const ACTIVATION_COLOR_POSITIVE = Color .white
99const ACTIVATION_COLOR_INACTIVE = Color .black
10- const ACTIVATION_COLOR_NEGATIVE = Color .blue
10+ const ACTIVATION_COLOR_NEGATIVE = Color .blue # would appear in 1st layer
1111
1212var lines = []
1313
@@ -17,28 +17,32 @@ onready var identifier: ColorRect = $"%identifier"
1717
1818func visualize_network (network : Network ) -> void :
1919 # generate a framework
20+ var sep = 0
21+ for i in network .sizes :
22+ if i > sep :
23+ sep = i
24+ layer_container .set ("custom_constants/separation" , max (10 , sep * 2 ))
2025 for x in network .sizes .size ():
2126 var layer = _generate_layer ()
2227 for _y in range (network .sizes [x ]):
2328 _generate_node (layer )
2429 # now set weights
2530 yield (get_tree (), "idle_frame" )
26- lines = update_weights (network )
31+ update_weights (network )
2732 # warning-ignore:return_value_discarded
2833 network .connect ("activation_changed" , self , "_update_activations" )
29- update ()
3034
3135
3236func update_weights (network : Network ):
33- var lines_array = []
37+ lines . clear ()
3438 for layer_number in network .weights .size ():
3539 for current_node_idx in network .weights [layer_number ].size ():
3640 for prev_node_idx in network .weights [layer_number ][current_node_idx ].size ():
3741 var from = get_activation_node (layer_number , prev_node_idx )
3842 var to = get_activation_node (layer_number + 1 , current_node_idx )
3943 var weight = network .weights [layer_number ][current_node_idx ][prev_node_idx ]
40- lines_array .append ([from , to , weight ])
41- return lines_array
44+ lines .append ([from , to , weight ])
45+ update ()
4246
4347
4448func get_activation_node (layer_idx , node_idx ) -> TextureRect :
@@ -53,10 +57,13 @@ func _update_activations(layer_idx, activations: Array):
5357 var color = ACTIVATION_COLOR_POSITIVE
5458 if activation < 0 :
5559 color = ACTIVATION_COLOR_NEGATIVE
56- color .a = abs (activation )
57- if activation == 0 :
60+ if is_equal_approx (activation , 0 ):
5861 color = ACTIVATION_COLOR_INACTIVE
62+ else :
63+ color .a = abs (activation )
64+
5965 layer .get_child (node_idx ).modulate = color
66+ update ()
6067
6168
6269func _generate_layer () -> Node :
@@ -79,4 +86,4 @@ func _draw() -> void:
7986 var color := LINE_COLOR_POSITIVE
8087 if line [2 ] < 0 :
8188 color = LINE_COLOR_NEGATIVE
82- draw_line (start , end , color , abs (line [2 ]) * SCALE )
89+ draw_line (start , end , color , abs (line [2 ]) * SCALE * 2 )
0 commit comments