mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 14:03:59 +08:00
Preliminary end of bayes followup video
This commit is contained in:
@ -320,7 +320,6 @@ class LaggedStart(Animation):
|
||||
anim.update(alpha)
|
||||
return self
|
||||
|
||||
|
||||
class DelayByOrder(Animation):
|
||||
"""
|
||||
Modifier of animation.
|
||||
|
126
eop/bayes.py
126
eop/bayes.py
@ -214,7 +214,7 @@ class IntroducePokerHand(PiCreatureScene, SampleSpaceScene):
|
||||
you, her = self.you, self.her
|
||||
equation = TexMobject(
|
||||
"{ {10 \\choose 2}", "\\over", "{45 \\choose 2} }",
|
||||
"=", "{1 \\over 22}", "\\approx", "4.5\\%"
|
||||
"=", "{45 \\over 990}", "\\approx", "4.5\\%"
|
||||
)
|
||||
equation.next_to(self.community_cards, UP, buff = LARGE_BUFF)
|
||||
percentage = equation.get_part_by_tex("4.5")
|
||||
@ -486,6 +486,8 @@ class UpdatePokerPrior(SampleSpaceScene):
|
||||
"cash_string" : "\\$\\$\\$",
|
||||
}
|
||||
def construct(self):
|
||||
self.force_skipping()
|
||||
|
||||
self.add_sample_space()
|
||||
self.add_top_conditionals()
|
||||
self.react_to_top_conditionals()
|
||||
@ -497,7 +499,11 @@ 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()
|
||||
@ -874,6 +880,8 @@ class UpdatePokerPrior(SampleSpaceScene):
|
||||
her.shift(DOWN)
|
||||
her.glasses = SunGlasses(her)
|
||||
post_rects = self.post_rects
|
||||
posterior = VGroup(post_rects.braces, post_rects.labels)
|
||||
prior_rects = self.get_prior_rectangles()
|
||||
risk_averse_words = TextMobject(
|
||||
"Suppose risk \\\\ averse \\dots"
|
||||
)
|
||||
@ -886,7 +894,7 @@ class UpdatePokerPrior(SampleSpaceScene):
|
||||
for x in range(3)
|
||||
])
|
||||
arrows.arrange_submobjects(DOWN)
|
||||
arrows.next_to(post_rects[1], RIGHT, SMALL_BUFF)
|
||||
arrows.next_to(prior_rects[1], RIGHT, SMALL_BUFF)
|
||||
|
||||
self.dither(2)
|
||||
self.play(*map(FadeIn, [her, her.glasses]))
|
||||
@ -895,11 +903,18 @@ class UpdatePokerPrior(SampleSpaceScene):
|
||||
self.dither()
|
||||
self.play(ShowCreation(arrows))
|
||||
self.play(
|
||||
*self.get_conditional_change_anims(1, 0.1, post_rects),
|
||||
*it.chain(
|
||||
self.get_conditional_change_anims(1, 0.1, post_rects),
|
||||
[Animation(arrows)]
|
||||
),
|
||||
run_time = 3
|
||||
)
|
||||
self.play(FadeOut(arrows))
|
||||
self.dither(3)
|
||||
self.dither(2)
|
||||
post_surrounding_rect = SurroundingRectangle(posterior)
|
||||
self.play(ShowCreation(post_surrounding_rect))
|
||||
self.play(FadeOut(post_surrounding_rect))
|
||||
self.dither()
|
||||
self.play(
|
||||
FadeOut(risk_averse_words),
|
||||
*self.get_conditional_change_anims(1, 0.3, post_rects),
|
||||
@ -1140,7 +1155,7 @@ class BayesRuleInMemory(Scene):
|
||||
|
||||
class NextVideoWrapper(TeacherStudentsScene):
|
||||
CONFIG = {
|
||||
"title" : "Next chapter: Bayesian networks"
|
||||
"title" : "Upcoming chapter: Bayesian networks"
|
||||
}
|
||||
def construct(self):
|
||||
title = TextMobject(self.title)
|
||||
@ -1164,6 +1179,107 @@ class NextVideoWrapper(TeacherStudentsScene):
|
||||
self.play(Animation(screen))
|
||||
self.dither(5)
|
||||
|
||||
class BayesianNetworkPreview(Scene):
|
||||
def construct(self):
|
||||
self.add_network()
|
||||
self.show_propogation(self.network.nodes[0])
|
||||
self.show_propogation(self.network.nodes[-1])
|
||||
|
||||
def add_network(self):
|
||||
radius = MED_SMALL_BUFF
|
||||
node = Circle(color = WHITE, radius = radius)
|
||||
node.shift(2*DOWN)
|
||||
nodes = VGroup(*[
|
||||
node.copy().shift(x*RIGHT + y*UP)
|
||||
for x, y in [
|
||||
(-1, 0),
|
||||
(1, 0),
|
||||
(-2, 2),
|
||||
(0, 2),
|
||||
(2, 2),
|
||||
(-2, 4),
|
||||
(0, 4),
|
||||
]
|
||||
])
|
||||
for node in nodes:
|
||||
node.children = VGroup()
|
||||
node.parents = VGroup()
|
||||
node.outgoing_edges = VGroup()
|
||||
edge_index_pairs = [
|
||||
(2, 0),
|
||||
(3, 0),
|
||||
(3, 1),
|
||||
(4, 1),
|
||||
(5, 2),
|
||||
(6, 3),
|
||||
]
|
||||
edges = VGroup()
|
||||
for i1, i2 in edge_index_pairs:
|
||||
n1, n2 = nodes[i1], nodes[i2]
|
||||
edge = Arrow(
|
||||
n1.get_center(),
|
||||
n2.get_center(),
|
||||
buff = radius,
|
||||
color = WHITE,
|
||||
)
|
||||
n1.outgoing_edges.add(edge)
|
||||
edges.add(edge)
|
||||
n1.children.add(n2)
|
||||
n2.parents.add(n1)
|
||||
|
||||
network = VGroup(nodes, edges)
|
||||
network.nodes = nodes
|
||||
network.edges = edges
|
||||
self.add(network)
|
||||
self.network = network
|
||||
|
||||
def show_propogation(self, node):
|
||||
self.set_network_fills()
|
||||
all_ghosts = VGroup()
|
||||
curr_nodes = [node]
|
||||
covered_nodes = set()
|
||||
self.play(GrowFromCenter(node.fill))
|
||||
self.remove(node.fill)
|
||||
while curr_nodes:
|
||||
next_nodes = set([])
|
||||
anims = []
|
||||
for node in curr_nodes:
|
||||
node.ghost = node.fill.copy().fade()
|
||||
self.add(node.ghost)
|
||||
all_ghosts.add(node.ghost)
|
||||
connected_nodes = filter(
|
||||
lambda n : n not in covered_nodes,
|
||||
it.chain(node.children, node.parents)
|
||||
)
|
||||
for next_node in connected_nodes:
|
||||
if next_node in covered_nodes:
|
||||
continue
|
||||
next_nodes.add(next_node)
|
||||
anims.append(Transform(
|
||||
node.fill.copy(), next_node.fill,
|
||||
remover = True
|
||||
))
|
||||
if len(connected_nodes) == 0:
|
||||
anims.append(FadeOut(node.fill))
|
||||
if anims:
|
||||
self.play(*anims)
|
||||
covered_nodes.update(curr_nodes)
|
||||
curr_nodes = list(next_nodes)
|
||||
self.dither()
|
||||
self.play(FadeOut(all_ghosts))
|
||||
|
||||
|
||||
def set_network_fills(self):
|
||||
for node in self.network.nodes:
|
||||
node.fill = self.get_fill(node)
|
||||
|
||||
|
||||
def get_fill(self, node):
|
||||
fill = node.copy()
|
||||
fill.set_fill(YELLOW, 1)
|
||||
fill.set_stroke(width = 0)
|
||||
return fill
|
||||
|
||||
class GeneralizeBayesRule(SampleSpaceScene):
|
||||
def construct(self):
|
||||
self.add_sample_space()
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -123,8 +123,12 @@ class TexMobject(SVGMobject):
|
||||
num_submobs = len(sub_tex_mob.submobjects)
|
||||
new_index = curr_index + num_submobs
|
||||
if num_submobs == 0:
|
||||
if len(self) > curr_index:
|
||||
last_submob_index = curr_index
|
||||
else:
|
||||
last_submob_index = -1
|
||||
sub_tex_mob.submobjects = [VectorizedPoint(
|
||||
self.submobjects[curr_index].get_right()
|
||||
self.submobjects[last_submob_index].get_right()
|
||||
)]
|
||||
else:
|
||||
sub_tex_mob.submobjects = self.submobjects[curr_index:new_index]
|
||||
|
@ -1776,7 +1776,7 @@ class TheoryHeavy(TeacherStudentsScene):
|
||||
self.student_says(
|
||||
"Too much theory!",
|
||||
target_mode = "angry",
|
||||
write_kwargs = {"run_time" : 2},
|
||||
content_introduction_kwargs = {"run_time" : 2},
|
||||
)
|
||||
self.dither()
|
||||
student = self.get_students()[1]
|
||||
|
@ -315,7 +315,8 @@ class PiCreatureBubbleIntroduction(AnimationGroup):
|
||||
"bubble_creation_class" : ShowCreation,
|
||||
"bubble_creation_kwargs" : {},
|
||||
"bubble_kwargs" : {},
|
||||
"write_kwargs" : {},
|
||||
"content_introduction_class" : Write,
|
||||
"content_introduction_kwargs" : {},
|
||||
"look_at_arg" : None,
|
||||
}
|
||||
def __init__(self, pi_creature, *content, **kwargs):
|
||||
@ -335,9 +336,11 @@ class PiCreatureBubbleIntroduction(AnimationGroup):
|
||||
bubble_creation = self.bubble_creation_class(
|
||||
bubble, **self.bubble_creation_kwargs
|
||||
)
|
||||
writing = Write(bubble.content, **self.write_kwargs)
|
||||
content_introduction = self.content_introduction_class(
|
||||
bubble.content, **self.content_introduction_kwargs
|
||||
)
|
||||
AnimationGroup.__init__(
|
||||
self, change_mode, bubble_creation, writing,
|
||||
self, change_mode, bubble_creation, content_introduction,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user