Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Refactor of layer activations in nn

Grant Sanderson8a5d63917f10
diff --git a/nn/part1.py b/nn/part1.py
index 1e311db48..c187115ec 100644
--- a/nn/part1.py
+++ b/nn/part1.py
@@ -214,6 +214,10 @@ class NetworkMobject(VGroup):
def get_active_layer(self, layer_index, activation_vector):
layer = self.layers[layer_index].deepcopy()
+ self.activate_layer(layer)
+ return layer
+
+ def activate_layer(self, layer, activation_vector):
n_neurons = len(layer.neurons)
av = activation_vector
def arr_to_num(arr):
@@ -241,6 +245,11 @@ class NetworkMobject(VGroup):
)
return layer
+ def activate_layers(self, input_vector):
+ activations = self.neural_network.get_activation_of_all_layers(input_vector)
+ for activation, layer in zip(activations, self.layers):
+ self.activate_layer(layer, activation)
+
def deactivate_layers(self):
all_neurons = VGroup(*it.chain(*[
layer.neurons