From b9822db5bf7980b42155f8560581d9edd3616933 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 24 May 2019 15:04:45 -0700 Subject: [PATCH 1/6] Changed thumbnail of nn1 --- old_projects/nn/network.py | 2 +- old_projects/nn/part1.py | 47 ++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/old_projects/nn/network.py b/old_projects/nn/network.py index 37ff3209..08ca0ce6 100644 --- a/old_projects/nn/network.py +++ b/old_projects/nn/network.py @@ -20,7 +20,7 @@ import random import numpy as np from PIL import Image from nn.mnist_loader import load_data_wrapper -from utils.space_ops import get_norm +# from utils.space_ops import get_norm NN_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) # PRETRAINED_DATA_FILE = os.path.join(NN_DIRECTORY, "pretrained_weights_and_biases_80") diff --git a/old_projects/nn/part1.py b/old_projects/nn/part1.py index 81c5ca4e..cf228d20 100644 --- a/old_projects/nn/part1.py +++ b/old_projects/nn/part1.py @@ -2964,7 +2964,7 @@ class BiasForInactiviyWords(Scene): self.play(Write(words)) self.wait(3) -class ContinualEdgeUpdate(ContinualAnimation): +class ContinualEdgeUpdate(VGroup): CONFIG = { "max_stroke_width" : 3, "stroke_width_exp" : 7, @@ -2972,7 +2972,8 @@ class ContinualEdgeUpdate(ContinualAnimation): "colors" : [GREEN, GREEN, GREEN, RED], } def __init__(self, network_mob, **kwargs): - digest_config(self, kwargs) + VGroup.__init__(self, **kwargs) + self.internal_time = 0 n_cycles = self.n_cycles edges = VGroup(*it.chain(*network_mob.edge_groups)) self.move_to_targets = [] @@ -2990,11 +2991,14 @@ class ContinualEdgeUpdate(ContinualAnimation): edge.generate_target() edge.target.set_stroke(edge.colors[0], edge.widths[0]) - self.move_to_targets.append(MoveToTarget(edge)) + edge.become(edge.target) + self.move_to_targets.append(edge) self.edges = edges - ContinualAnimation.__init__(self, edges, **kwargs) + self.add(edges) + self.add_updater(lambda m, dt: self.update_edges(dt)) - def update_mobject(self, dt): + def update_edges(self, dt): + self.internal_time += dt if self.internal_time < 1: alpha = smooth(self.internal_time) for move_to_target in self.move_to_targets: @@ -4559,8 +4563,9 @@ class ShowAmplify(PiCreatureScene): class Thumbnail(NetworkScene): CONFIG = { "network_mob_config" : { - 'neuron_stroke_color' : WHITE - } + 'neuron_stroke_color' : WHITE, + 'layer_to_layer_buff': 1.25, + }, } def construct(self): network_mob = self.network_mob @@ -4568,6 +4573,23 @@ class Thumbnail(NetworkScene): for layer in network_mob.layers: layer.neurons.set_stroke(width = 5) + network_mob.set_height(5) + network_mob.to_edge(DOWN) + network_mob.to_edge(LEFT, buff=1) + + subtitle = TextMobject( + "From the\\\\", + "ground up\\\\", + ) + # subtitle.arrange( + # DOWN, + # buff=0.25, + # aligned_edge=LEFT, + # ) + subtitle.set_color(YELLOW) + subtitle.set_height(2.75) + subtitle.next_to(network_mob, RIGHT, buff=MED_LARGE_BUFF) + edge_update = ContinualEdgeUpdate( network_mob, max_stroke_width = 10, @@ -4576,7 +4598,18 @@ class Thumbnail(NetworkScene): edge_update.internal_time = 3 edge_update.update(0) + for mob in network_mob.family_members_with_points(): + if mob.get_stroke_width() < 2: + mob.set_stroke(width=2) + + + title = TextMobject("Neural Networks") + title.scale(3) + title.to_edge(UP) + self.add(network_mob) + self.add(subtitle) + self.add(title) From bf8f517b496b8f733b3b5942407ee3282fc18b6d Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 24 May 2019 15:05:20 -0700 Subject: [PATCH 2/6] Changed SceneFileWriter.get_default_file_name --- manimlib/scene/scene_file_writer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.py index a6aaa721..c385483f 100644 --- a/manimlib/scene/scene_file_writer.py +++ b/manimlib/scene/scene_file_writer.py @@ -34,6 +34,7 @@ class SceneFileWriter(object): # TODO, address this in extract_scene et. al. "file_name": None, "output_directory": None, + "file_name": None, } def __init__(self, scene, **kwargs): @@ -80,7 +81,10 @@ class SceneFileWriter(object): return scene_module.replace(".", os.path.sep) def get_default_file_name(self): - return self.scene.__class__.__name__ + if self.file_name is None: + return self.scene.__class__.__name__ + else: + return self.file_name def get_movie_directory(self): pixel_height = self.scene.camera.pixel_height From c4449fdfb82f4d284e90eefd8fd058df4f94b9ba Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 24 May 2019 15:06:10 -0700 Subject: [PATCH 3/6] Small tweaks to Fourier series animations --- active_projects/ode/part2/fourier_series.py | 60 ++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/active_projects/ode/part2/fourier_series.py b/active_projects/ode/part2/fourier_series.py index 2638a7c8..3d822b00 100644 --- a/active_projects/ode/part2/fourier_series.py +++ b/active_projects/ode/part2/fourier_series.py @@ -313,12 +313,7 @@ class FourierOfPiSymbol(FourierCirclesScene): coefs = self.get_coefficients_of_path(path) circles = self.get_circles(coefficients=coefs) - for k, circle in zip(it.count(1), circles): - circle.set_stroke(width=max( - 1 / np.sqrt(k), - 1, - )) - + self.set_decreasing_stroke_widths(circles) # approx_path = self.get_circle_end_path(circles) drawn_path = self.get_drawn_path(circles) if self.start_drawn: @@ -329,6 +324,14 @@ class FourierOfPiSymbol(FourierCirclesScene): self.add(drawn_path) self.wait(self.run_time) + def set_decreasing_stroke_widths(self, circles): + for k, circle in zip(it.count(1), circles): + circle.set_stroke(width=max( + 1 / np.sqrt(k), + 1, + )) + return circles + def get_path(self): tex_mob = TexMobject(self.tex) tex_mob.set_height(6) @@ -338,6 +341,51 @@ class FourierOfPiSymbol(FourierCirclesScene): return path +class FourierOfName(FourierOfPiSymbol): + CONFIG = { + "n_circles": 100, + "name_color": WHITE, + "name_text": "Abc", + "time_per_symbol": 5, + "slow_factor": 1 / 5, + } + + def construct(self): + name = TextMobject(self.name_text) + max_width = FRAME_WIDTH - 2 + max_height = FRAME_HEIGHT - 2 + name.set_width(max_width) + if name.get_height() > max_height: + name.set_height(max_height) + + circles = VGroup(VectorizedPoint()) + for path in name.family_members_with_points(): + for subpath in path.get_subpaths(): + sp_mob = VMobject() + sp_mob.set_points(subpath) + coefs = self.get_coefficients_of_path(sp_mob) + new_circles = self.get_circles( + coefficients=coefs + ) + self.set_decreasing_stroke_widths(new_circles) + drawn_path = self.get_drawn_path(new_circles) + drawn_path.clear_updaters() + drawn_path.set_stroke(self.name_color, 3) + + new_circles.suspend_updating() + self.play(ReplacementTransform(circles, new_circles)) + new_circles.resume_updating() + circles = new_circles + self.play( + ShowCreation(drawn_path), + rate_func=linear, + run_time=self.time_per_symbol + ) + circles.suspend_updating() + self.play(FadeOut(circles)) + self.wait(3) + + class FourierOfPiSymbol5(FourierOfPiSymbol): CONFIG = { "n_circles": 5, From 2d3493c3d5a539f8c9a268ead1080e4613583732 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 24 May 2019 15:06:52 -0700 Subject: [PATCH 4/6] Fourier series name animations --- active_projects/ode/name_animations.py | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 active_projects/ode/name_animations.py diff --git a/active_projects/ode/name_animations.py b/active_projects/ode/name_animations.py new file mode 100644 index 00000000..83effea7 --- /dev/null +++ b/active_projects/ode/name_animations.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +from big_ol_pile_of_manim_imports import * +from active_projects.ode.part2.fourier_series import FourierOfName + +name_color_pairs = [ + +] + +circle_counts = [ + # 10, + # 25, + 100, +] + +if __name__ == "__main__": + for name, color in name_color_pairs: + for n_circles in circle_counts: + try: + first_name = name.split(" ")[0] + scene = FourierOfName( + name_text=name, + name_color=color, + n_circles=n_circles, + file_writer_config={ + "write_to_movie": True, + "output_directory": os.path.join( + "patron_fourier_names", + first_name, + ), + "file_name": "{}_Fouierified_{}_Separate_paths".format( + first_name, + n_circles + ), + }, + camera_config={ + "frame_rate": 24, + }, + ) + except: + pass From 91b3abae4a4d8967f0e5531a67341f5e5a5a6559 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 24 May 2019 15:08:02 -0700 Subject: [PATCH 5/6] Change big_ol_pile_of_imports to manimlib.imports --- name_animations.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 name_animations.py diff --git a/name_animations.py b/name_animations.py new file mode 100644 index 00000000..b96c00e9 --- /dev/null +++ b/name_animations.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +from manimlib.imports import * +from active_projects.ode.part2.fourier_series import FourierOfName + +name_color_pairs = [ + +] + +circle_counts = [ + # 10, + # 25, + 100, +] + +if __name__ == "__main__": + for name, color in name_color_pairs: + for n_circles in circle_counts: + try: + first_name = name.split(" ")[0] + scene = FourierOfName( + name_text=name, + name_color=color, + n_circles=n_circles, + file_writer_config={ + "write_to_movie": True, + "output_directory": os.path.join( + "patron_fourier_names", + first_name, + ), + "file_name": "{}_Fouierified_{}_Separate_paths".format( + first_name, + n_circles + ), + }, + camera_config={ + "frame_rate": 24, + }, + ) + except: + pass From ce866e822247d73c68d47703dea62fee5d063df7 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 24 May 2019 15:09:53 -0700 Subject: [PATCH 6/6] Removed duplicate name_animations.py --- active_projects/ode/name_animations.py | 2 +- name_animations.py | 40 -------------------------- 2 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 name_animations.py diff --git a/active_projects/ode/name_animations.py b/active_projects/ode/name_animations.py index 83effea7..b96c00e9 100644 --- a/active_projects/ode/name_animations.py +++ b/active_projects/ode/name_animations.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from big_ol_pile_of_manim_imports import * +from manimlib.imports import * from active_projects.ode.part2.fourier_series import FourierOfName name_color_pairs = [ diff --git a/name_animations.py b/name_animations.py deleted file mode 100644 index b96c00e9..00000000 --- a/name_animations.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python -from manimlib.imports import * -from active_projects.ode.part2.fourier_series import FourierOfName - -name_color_pairs = [ - -] - -circle_counts = [ - # 10, - # 25, - 100, -] - -if __name__ == "__main__": - for name, color in name_color_pairs: - for n_circles in circle_counts: - try: - first_name = name.split(" ")[0] - scene = FourierOfName( - name_text=name, - name_color=color, - n_circles=n_circles, - file_writer_config={ - "write_to_movie": True, - "output_directory": os.path.join( - "patron_fourier_names", - first_name, - ), - "file_name": "{}_Fouierified_{}_Separate_paths".format( - first_name, - n_circles - ), - }, - camera_config={ - "frame_rate": 24, - }, - ) - except: - pass