Files
Alec Helbling 63427be139 Added ability to pass layer_args dictionary to each forward pass, which allows
for arguments to be passed through to each neural network layer when running a neural
network forward pass.
2022-04-25 16:28:11 -04:00

37 lines
1.1 KiB
Python

from manim import *
import random
from manim_ml.neural_network.layers.parent_layers import VGroupNeuralNetworkLayer
class VectorLayer(VGroupNeuralNetworkLayer):
"""Shows a vector"""
def __init__(self, num_values, value_func=lambda: random.uniform(0, 1),
**kwargs):
super().__init__(**kwargs)
self.num_values = num_values
self.value_func = value_func
# Make the vector
self.vector_label = self.make_vector()
self.add(self.vector_label)
def make_vector(self):
"""Makes the vector"""
if False:
# TODO install Latex
values = np.array([self.value_func() for i in range(self.num_values)])
values = values[None, :].T
vector = Matrix(values)
vector_label = Text(f"[{self.value_func():.2f}]")
vector_label.scale(0.3)
return vector_label
def make_forward_pass_animation(self, layer_args={}, **kwargs):
return AnimationGroup()
@override_animation(Create)
def _create_override(self):
"""Create animation"""
return Write(self.vector_label)