Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Small fixes to Bayes videos

Grant Sandersonda1751b7c5c4
diff --git a/eop/bayes.py b/eop/bayes.py
index 930bbc405..95d37e97b 100644
--- a/eop/bayes.py
+++ b/eop/bayes.py
@@ -486,8 +486,6 @@ class UpdatePokerPrior(SampleSpaceScene):
"cash_string" : "\\$\\$\\$",
}
def construct(self):
- self.force_skipping()
-
self.add_sample_space()
self.add_top_conditionals()
self.react_to_top_conditionals()
@@ -499,11 +497,7 @@ class UpdatePokerPrior(SampleSpaceScene):
self.reshape_rectangles()
self.compare_prior_to_posterior()
self.preview_tweaks()
-
- self.revert_to_original_skipping_status()
self.tweak_non_flush_case()
- return
-
self.tweak_flush_case()
self.tweak_prior()
self.compute_posterior()
@@ -1910,10 +1904,21 @@ class MusicExample(SampleSpaceScene, PiCreatureScene):
ratio.get_top(), rhs[1].get_bottom(), **arrow_kwargs
)
+ prior_rects = self.get_prior_rectangles()
+
self.play(
ShowCreation(to_ratio_arrow),
FadeIn(ratio)
)
+ self.dither(2)
+ for mob in prior_rects, prior_rects[0]:
+ self.play(
+ mob.highlight, YELLOW,
+ Animation(self.products),
+ rate_func = there_and_back,
+ run_time = 2
+ )
+ self.dither()
self.dither()
self.play(ShowCreation(to_rhs_arrow))
self.play(Write(rhs, run_time = 1))
@@ -1925,19 +1930,18 @@ class MusicExample(SampleSpaceScene, PiCreatureScene):
def intuition_of_positive_feedback(self):
friends = self.friends
prior_num = self.sample_space.horizontal_parts.labels[0][-1]
+ prior_num_ghost = prior_num.copy().set_fill(opacity = 0.5)
post_num = self.post_rhs[-1]
prior_rect = SurroundingRectangle(prior_num)
post_rect = SurroundingRectangle(post_num)
- dot = Dot(prior_rect.get_center())
- dot.set_fill(WHITE, 0.5)
self.play(ShowCreation(prior_rect))
- self.play(
- dot.move_to, post_rect,
- dot.set_fill, None, 0,
+ self.play(Transform(
+ prior_num_ghost, post_num,
+ remover = True,
path_arc = -np.pi/6,
run_time = 2,
- )
+ ))
self.play(ShowCreation(post_rect))
self.dither(2)
for mode, time in ("shruggie", 2), ("hesitant", 0):
diff --git a/eop/bayes_footnote.py b/eop/bayes_footnote.py
index e167c61ea..a1bb0919f 100644
--- a/eop/bayes_footnote.py
+++ b/eop/bayes_footnote.py
@@ -32,10 +32,20 @@ from eop.bayes import IntroducePokerHand
SICKLY_GREEN = "#9BBD37"
+
+class BayesClassicExampleOpeningQuote(OpeningQuote):
+ CONFIG = {
+ "quote" : [
+ "",
+ ],
+ "author" : "",
+ }
+
class Introduction(TeacherStudentsScene):
def construct(self):
self.hold_up_example()
self.write_counter_intuitive()
+ self.comment_on_crazy_results()
self.put_it_first()
self.swap_example_order()
self.other_culprit()
@@ -98,14 +108,32 @@ class Introduction(TeacherStudentsScene):
self.bayes_to_intuition = group
+ def comment_on_crazy_results(self):
+ disease_group = VGroup(self.example, self.bayes_to_intuition)
+ disease_group.save_state()
+
+ self.teacher_says(
+ "Who doesn't love \\\\ crazy results?",
+ target_mode = "hooray",
+ added_anims = [disease_group.to_corner, UP+LEFT]
+ )
+ self.dither(2)
+
+ self.disease_group = disease_group
+
def put_it_first(self):
poker_example = self.get_poker_example()
music_example = self.get_music_example()
- disease_group = VGroup(
- self.example, self.bayes_to_intuition
- )
+ disease_group = self.disease_group
- self.play(disease_group.to_edge, LEFT)
+ self.play(
+ disease_group.restore,
+ disease_group.to_edge, LEFT,
+ RemovePiCreatureBubble(
+ self.teacher,
+ target_mode = "hesitant"
+ )
+ )
self.change_student_modes(
*["pondering"]*3,
look_at_arg = disease_group
@@ -394,6 +422,14 @@ class ReceivePositiveResults(TestScene):
self.play(randy.change, "sad", accuracy)
self.dither(2)
+class AskAboutRephrasingQuestion(TeacherStudentsScene):
+ def construct(self):
+ self.teacher_says(
+ "What if we rephrased \\\\ the question?",
+ run_time = 1
+ )
+ self.dither(3)
+
class RephraseQuestion(Scene):
def construct(self):
words = VGroup(*map(TextMobject, [
@@ -442,26 +478,19 @@ class RephraseQuestion(Scene):
class TryUnitSquareVisual(SampleSpaceScene):
def construct(self):
sample_space = self.get_sample_space()
- sample_space.divide_horizontally(0.1)
- for part in sample_space.horizontal_parts:
- part.set_stroke(part.get_fill_color(), width = 3)
- initial_labels, final_labels = [
- VGroup(
- TexMobject("P(\\text{Disease})", s1),
- TexMobject("P(\\text{Not disease})", s2),
- ).scale(0.7)
- for s1, s2 in ("", ""), ("= 0.001", "= 0.999")
- ]
- sample_space.get_side_braces_and_labels(initial_labels)
- sample_space.add_braces_and_labels()
+ self.add_prior_division()
+ self.add(sample_space)
+ self.add_conditional_divisions()
+ prior_label = sample_space.horizontal_parts.labels[0]
+ final_labels = self.final_labels
hard_to_see = TextMobject("Hard to see")
hard_to_see.scale(0.7)
- hard_to_see.next_to(sample_space.full_space, UP)
+ hard_to_see.next_to(prior_label, UP)
hard_to_see.to_edge(UP)
- arrow = Arrow(hard_to_see, sample_space.full_space)
+ hard_to_see.highlight(YELLOW)
+ arrow = Arrow(hard_to_see, prior_label)
- self.add(sample_space)
self.dither()
anims = self.get_division_change_animations(
sample_space, sample_space.horizontal_parts,
@@ -475,6 +504,57 @@ class TryUnitSquareVisual(SampleSpaceScene):
)
self.dither(2)
+ def add_prior_division(self):
+ sample_space = self.sample_space
+ sample_space.divide_horizontally(0.1)
+ initial_labels, final_labels = [
+ VGroup(
+ TexMobject("P(\\text{Disease})", s1),
+ TexMobject("P(\\text{Not disease})", s2),
+ ).scale(0.7)
+ for s1, s2 in ("", ""), ("= 0.001", "= 0.999")
+ ]
+ sample_space.get_side_braces_and_labels(initial_labels)
+ sample_space.add_braces_and_labels()
+
+ self.final_labels = final_labels
+
+ def add_conditional_divisions(self):
+ sample_space = self.sample_space
+ top_part, bottom_part = sample_space.horizontal_parts
+
+ top_brace = Brace(top_part, UP)
+ top_label = TexMobject(
+ "P(", "+", "|", "\\text{Disease}", ")", "=", "1"
+ )
+ top_label.scale(0.7)
+ top_label.next_to(top_brace, UP)
+ top_label.highlight_by_tex("+", GREEN)
+
+ self.play(GrowFromCenter(top_brace))
+ self.play(FadeIn(top_label))
+ self.dither()
+
+ bottom_part.divide_vertically(
+ 0.95, colors = [BLUE_E, YELLOW_E]
+ )
+ bottom_label = TexMobject(
+ "P(", "+", "|", "\\text{Not disease}", ")", "=", "1"
+ )
+ bottom_label.scale(0.7)
+ bottom_label.highlight_by_tex("+", GREEN)
+ braces, labels = bottom_part.get_bottom_braces_and_labels(
+ [bottom_label]
+ )
+ bottom_brace = braces[0]
+
+ self.play(
+ FadeIn(bottom_part.vertical_parts),
+ GrowFromCenter(bottom_brace),
+ )
+ self.play(FadeIn(bottom_label))
+ self.dither()
+
class ShowRestrictedSpace(Scene):
CONFIG = {
"n_rows" : 25,