mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Animation for reworked beta2
This commit is contained in:
parent
94c121bcf7
commit
427ad698fe
3 changed files with 1421 additions and 816 deletions
|
@ -1827,8 +1827,8 @@ class AskAboutUnknownProbabilities(Scene):
|
||||||
|
|
||||||
def show_many_coins(self, n_rows, n_cols):
|
def show_many_coins(self, n_rows, n_cols):
|
||||||
coin_choices = VGroup(
|
coin_choices = VGroup(
|
||||||
get_coin(BLUE_E, "H"),
|
get_coin("H"),
|
||||||
get_coin(RED_E, "T"),
|
get_coin("T"),
|
||||||
)
|
)
|
||||||
coin_choices.set_stroke(width=0)
|
coin_choices.set_stroke(width=0)
|
||||||
coins = VGroup(*[
|
coins = VGroup(*[
|
||||||
|
@ -1873,10 +1873,10 @@ class AskProbabilityOfCoins(Scene):
|
||||||
condition = VGroup(
|
condition = VGroup(
|
||||||
TextMobject("If you've seen"),
|
TextMobject("If you've seen"),
|
||||||
Integer(80, color=BLUE_C),
|
Integer(80, color=BLUE_C),
|
||||||
get_coin(BLUE_E, "H").set_height(0.5),
|
get_coin("H").set_height(0.5),
|
||||||
TextMobject("and"),
|
TextMobject("and"),
|
||||||
Integer(20, color=RED_C),
|
Integer(20, color=RED_C),
|
||||||
get_coin(RED_E, "T").set_height(0.5),
|
get_coin("T").set_height(0.5),
|
||||||
)
|
)
|
||||||
condition.arrange(RIGHT)
|
condition.arrange(RIGHT)
|
||||||
condition.to_edge(UP)
|
condition.to_edge(UP)
|
||||||
|
@ -1886,7 +1886,7 @@ class AskProbabilityOfCoins(Scene):
|
||||||
"\\text{What is }",
|
"\\text{What is }",
|
||||||
"P(", "00", ")", "?"
|
"P(", "00", ")", "?"
|
||||||
)
|
)
|
||||||
coin = get_coin(BLUE_E, "H")
|
coin = get_coin("H")
|
||||||
coin.replace(question.get_part_by_tex("00"))
|
coin.replace(question.get_part_by_tex("00"))
|
||||||
question.replace_submobject(
|
question.replace_submobject(
|
||||||
question.index_of_part_by_tex("00"),
|
question.index_of_part_by_tex("00"),
|
||||||
|
@ -1899,10 +1899,7 @@ class AskProbabilityOfCoins(Scene):
|
||||||
random.shuffle(values)
|
random.shuffle(values)
|
||||||
|
|
||||||
coins = VGroup(*[
|
coins = VGroup(*[
|
||||||
get_coin(
|
get_coin(symbol)
|
||||||
BLUE_E if symbol == "H" else RED_E,
|
|
||||||
symbol
|
|
||||||
)
|
|
||||||
for symbol in values
|
for symbol in values
|
||||||
])
|
])
|
||||||
coins.arrange_in_grid(10, 10, buff=MED_SMALL_BUFF)
|
coins.arrange_in_grid(10, 10, buff=MED_SMALL_BUFF)
|
||||||
|
@ -3265,8 +3262,8 @@ class StateIndependence(Scene):
|
||||||
class IllustrateBinomialSetupWithCoins(Scene):
|
class IllustrateBinomialSetupWithCoins(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
coins = [
|
coins = [
|
||||||
get_coin(BLUE_E, "H"),
|
get_coin("H"),
|
||||||
get_coin(RED_E, "T"),
|
get_coin("T"),
|
||||||
]
|
]
|
||||||
|
|
||||||
coin_row = VGroup()
|
coin_row = VGroup()
|
||||||
|
@ -3289,7 +3286,7 @@ class IllustrateBinomialSetupWithCoins(Scene):
|
||||||
"k": GREEN,
|
"k": GREEN,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
heads = get_coin(BLUE_E, "H")
|
heads = get_coin("H")
|
||||||
template = prob_label.get_part_by_tex("00")
|
template = prob_label.get_part_by_tex("00")
|
||||||
heads.replace(template)
|
heads.replace(template)
|
||||||
prob_label.replace_submobject(
|
prob_label.replace_submobject(
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5,6 +5,11 @@ import scipy.stats
|
||||||
CMARK_TEX = "\\text{\\ding{51}}"
|
CMARK_TEX = "\\text{\\ding{51}}"
|
||||||
XMARK_TEX = "\\text{\\ding{55}}"
|
XMARK_TEX = "\\text{\\ding{55}}"
|
||||||
|
|
||||||
|
COIN_COLOR_MAP = {
|
||||||
|
"H": BLUE_E,
|
||||||
|
"T": RED_E,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Histogram(Group):
|
class Histogram(Group):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
@ -171,29 +176,6 @@ def get_random_process(choices, shuffle_time=2, total_time=3, change_rate=0.05,
|
||||||
return container
|
return container
|
||||||
|
|
||||||
|
|
||||||
def get_coin(color, symbol):
|
|
||||||
coin = VGroup()
|
|
||||||
circ = Circle()
|
|
||||||
circ.set_fill(color, 1)
|
|
||||||
circ.set_stroke(WHITE, 1)
|
|
||||||
circ.set_height(1)
|
|
||||||
label = TextMobject(symbol)
|
|
||||||
label.set_height(0.5 * circ.get_height())
|
|
||||||
label.move_to(circ)
|
|
||||||
coin.add(circ, label)
|
|
||||||
coin.symbol = symbol
|
|
||||||
coin.lock_triangulation()
|
|
||||||
return coin
|
|
||||||
|
|
||||||
|
|
||||||
def get_random_coin(**kwargs):
|
|
||||||
coins = VGroup(
|
|
||||||
get_coin(BLUE_E, "H"),
|
|
||||||
get_coin(RED_E, "T"),
|
|
||||||
)
|
|
||||||
return get_random_process(coins, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def get_die_faces():
|
def get_die_faces():
|
||||||
dot = Dot()
|
dot = Dot()
|
||||||
dot.set_width(0.15)
|
dot.set_width(0.15)
|
||||||
|
@ -242,6 +224,69 @@ def get_random_card(height=1, **kwargs):
|
||||||
return get_random_process(cards, **kwargs)
|
return get_random_process(cards, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
# Coins
|
||||||
|
def get_coin(symbol, color=None):
|
||||||
|
if color is None:
|
||||||
|
color = COIN_COLOR_MAP.get(symbol, GREY_E)
|
||||||
|
coin = VGroup()
|
||||||
|
circ = Circle()
|
||||||
|
circ.set_fill(color, 1)
|
||||||
|
circ.set_stroke(WHITE, 1)
|
||||||
|
circ.set_height(1)
|
||||||
|
label = TextMobject(symbol)
|
||||||
|
label.set_height(0.5 * circ.get_height())
|
||||||
|
label.move_to(circ)
|
||||||
|
coin.add(circ, label)
|
||||||
|
coin.symbol = symbol
|
||||||
|
coin.lock_triangulation()
|
||||||
|
return coin
|
||||||
|
|
||||||
|
|
||||||
|
def get_random_coin(**kwargs):
|
||||||
|
return get_random_process([get_coin("H"), get_coin("T")], **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def get_prob_coin_label(symbol="H", color=None, p=0.5, num_decimal_places=2):
|
||||||
|
label = TexMobject("P", "(", "00", ")", "=",)
|
||||||
|
coin = get_coin(symbol, color)
|
||||||
|
template = label.get_part_by_tex("00")
|
||||||
|
coin.replace(template)
|
||||||
|
label.replace_submobject(label.index_of_part(template), coin)
|
||||||
|
rhs = DecimalNumber(p, num_decimal_places=num_decimal_places)
|
||||||
|
rhs.next_to(label, RIGHT, buff=MED_SMALL_BUFF)
|
||||||
|
label.add(rhs)
|
||||||
|
return label
|
||||||
|
|
||||||
|
|
||||||
|
def get_q_box(mob):
|
||||||
|
box = SurroundingRectangle(mob)
|
||||||
|
box.set_stroke(WHITE, 1)
|
||||||
|
box.set_fill(GREY_E, 1)
|
||||||
|
q_marks = TexMobject("???")
|
||||||
|
max_width = 0.8 * box.get_width()
|
||||||
|
max_height = 0.8 * box.get_height()
|
||||||
|
|
||||||
|
if q_marks.get_width() > max_width:
|
||||||
|
q_marks.set_width(max_width)
|
||||||
|
|
||||||
|
if q_marks.get_height() > max_height:
|
||||||
|
q_marks.set_height(max_height)
|
||||||
|
|
||||||
|
q_marks.move_to(box)
|
||||||
|
box.add(q_marks)
|
||||||
|
return box
|
||||||
|
|
||||||
|
|
||||||
|
def get_coin_grid(bools, height=6):
|
||||||
|
coins = VGroup(*[
|
||||||
|
get_coin("H" if heads else "T")
|
||||||
|
for heads in bools
|
||||||
|
])
|
||||||
|
coins.arrange_in_grid()
|
||||||
|
coins.set_height(height)
|
||||||
|
return coins
|
||||||
|
|
||||||
|
|
||||||
def get_prob_positive_experience_label(include_equals=False,
|
def get_prob_positive_experience_label(include_equals=False,
|
||||||
include_decimal=False,
|
include_decimal=False,
|
||||||
include_q_mark=False):
|
include_q_mark=False):
|
||||||
|
@ -325,6 +370,25 @@ def get_beta_dist_axes(y_max=20, y_unit=2, label_y=False, **kwargs):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def scaled_pdf_axes(scale_factor=3.5):
|
||||||
|
axes = get_beta_dist_axes(
|
||||||
|
label_y=True,
|
||||||
|
y_unit=1,
|
||||||
|
)
|
||||||
|
axes.y_axis.numbers.set_submobjects([
|
||||||
|
*axes.y_axis.numbers[:5],
|
||||||
|
*axes.y_axis.numbers[4::5]
|
||||||
|
])
|
||||||
|
sf = scale_factor
|
||||||
|
axes.y_axis.stretch(sf, 1, about_point=axes.c2p(0, 0))
|
||||||
|
for number in axes.y_axis.numbers:
|
||||||
|
number.stretch(1 / sf, 1)
|
||||||
|
axes.y_axis_label.to_edge(LEFT)
|
||||||
|
axes.y_axis_label.add_background_rectangle(opacity=1)
|
||||||
|
axes.set_stroke(background=True)
|
||||||
|
return axes
|
||||||
|
|
||||||
|
|
||||||
def get_beta_graph(axes, n_plus, n_minus, **kwargs):
|
def get_beta_graph(axes, n_plus, n_minus, **kwargs):
|
||||||
dist = scipy.stats.beta(n_plus + 1, n_minus + 1)
|
dist = scipy.stats.beta(n_plus + 1, n_minus + 1)
|
||||||
graph = axes.get_graph(dist.pdf, **kwargs)
|
graph = axes.get_graph(dist.pdf, **kwargs)
|
||||||
|
|
Loading…
Add table
Reference in a new issue