Exemple #1
0
    def show_proportionality_to_dx_squared(self):
        ddf = self.ddf.copy()
        ddf.generate_target()
        ddf.target.next_to(self.ddf, UP, LARGE_BUFF)
        rhs = TexMobject(
            "\\approx", "(\\text{Some constant})", "(dx)^2"
        )
        rhs.scale(0.8)
        rhs.next_to(ddf.target, RIGHT)

        example_dx = TexMobject(
            "dx = 0.01 \\Rightarrow (dx)^2 = 0.0001"
        )
        example_dx.scale(0.8)
        example_dx.to_corner(UP+RIGHT)

        self.play(MoveToTarget(ddf))
        self.play(Write(rhs))
        self.dither()
        self.play(Write(example_dx))
        self.dither(2)
        self.play(FadeOut(example_dx))

        self.ddf = ddf
        self.dx_squared = rhs.get_part_by_tex("dx")
Exemple #2
0
    def show_proportionality_to_dx_squared(self):
        ddf = self.ddf.copy()
        ddf.generate_target()
        ddf.target.next_to(self.ddf, UP, LARGE_BUFF)
        rhs = TexMobject(
            "\\approx", "(\\text{Some constant})", "(dx)^2"
        )
        rhs.scale(0.8)
        rhs.next_to(ddf.target, RIGHT)

        example_dx = TexMobject(
            "dx = 0.01 \\Rightarrow (dx)^2 = 0.0001"
        )
        example_dx.scale(0.8)
        example_dx.to_corner(UP+RIGHT)

        self.play(MoveToTarget(ddf))
        self.play(Write(rhs))
        self.wait()
        self.play(Write(example_dx))
        self.wait(2)
        self.play(FadeOut(example_dx))

        self.ddf = ddf
        self.dx_squared = rhs.get_part_by_tex("dx")
Exemple #3
0
    def show_example_approximation(self):
        approx_at_x, approx_at_point = [
            TexMobject(
                "\\cos(", s, ")", "\\approx",
                "1 - \\frac{1}{2}", "(", s, ")", "^2"
            ).next_to(self.get_students(), UP, 2)
            for s in "x", "0.1",
        ]
        approx_rhs = TexMobject("=", "0.995")
        approx_rhs.next_to(approx_at_point, RIGHT)
        real_result = TexMobject(
            "\\cos(", "0.1", ")", "=", 
            "%.7f"%np.cos(0.1)
        )
        real_result.shift(
            approx_rhs.get_part_by_tex("=").get_center() -\
            real_result.get_part_by_tex("=").get_center()
        )
        for mob in approx_at_point, real_result:
            mob.highlight_by_tex("0.1", YELLOW)
        real_result.set_fill(opacity = 0)

        self.play(
            Write(approx_at_x, run_time = 2),
            self.teacher.change_mode, "raise_right_hand"
        )
        self.dither(2)
        self.play(ReplacementTransform(
            approx_at_x, approx_at_point,
        ))
        self.dither()
        self.play(Write(approx_rhs))
        self.dither(2)
        self.play(
            real_result.shift, 1.5*DOWN,
            real_result.set_fill, None, 1,
        )
        self.change_student_modes(*["hooray"]*3)
        self.dither(2)
        self.change_student_modes(
            *["plain"]*3,
            added_anims = map(FadeOut, [
                approx_at_point, approx_rhs, real_result
            ]),
            look_at_arg = approx_at_x
        )
Exemple #4
0
    def write_second_derivative(self):
        ddf_over_dx_squared = TexMobject(
            "{d(df)", "\\over", "(dx)^2}"
        )
        ddf_over_dx_squared.scale(0.8)
        ddf_over_dx_squared.move_to(self.ddf, RIGHT)
        ddf_over_dx_squared.highlight_by_tex("df", self.ddf.get_color())
        parens = VGroup(
            ddf_over_dx_squared[0][1],
            ddf_over_dx_squared[0][4],
            ddf_over_dx_squared[2][0],
            ddf_over_dx_squared[2][3],
        )

        right_shifter = ddf_over_dx_squared[0][0]
        left_shifter = ddf_over_dx_squared[2][4]

        exp_two = TexMobject("2")
        exp_two.highlight(self.ddf.get_color())
        exp_two.scale(0.5)
        exp_two.move_to(right_shifter.get_corner(UP+RIGHT), LEFT)
        exp_two.shift(MED_SMALL_BUFF*RIGHT)
        pre_exp_two = VGroup(ddf_over_dx_squared[0][2])

        self.play(
            Write(ddf_over_dx_squared.get_part_by_tex("over")),
            *[
                ReplacementTransform(
                    mob, 
                    ddf_over_dx_squared.get_part_by_tex(tex),
                    path_arc = -np.pi/2,                    
                )
                for mob, tex in (self.ddf, "df"), (self.dx_squared, "dx")
            ]
        )
        self.wait(2)
        self.play(FadeOut(parens))
        self.play(
            left_shifter.shift, 0.2*LEFT,
            right_shifter.shift, 0.2*RIGHT,
            ReplacementTransform(pre_exp_two, exp_two),
            ddf_over_dx_squared.get_part_by_tex("over").scale_in_place, 0.8
        )
        self.wait(2)
Exemple #5
0
    def write_second_derivative(self):
        ddf_over_dx_squared = TexMobject(
            "{d(df)", "\\over", "(dx)^2}"
        )
        ddf_over_dx_squared.scale(0.8)
        ddf_over_dx_squared.move_to(self.ddf, RIGHT)
        ddf_over_dx_squared.highlight_by_tex("df", self.ddf.get_color())
        parens = VGroup(
            ddf_over_dx_squared[0][1],
            ddf_over_dx_squared[0][4],
            ddf_over_dx_squared[2][0],
            ddf_over_dx_squared[2][3],
        )

        right_shifter = ddf_over_dx_squared[0][0]
        left_shifter = ddf_over_dx_squared[2][4]

        exp_two = TexMobject("2")
        exp_two.highlight(self.ddf.get_color())
        exp_two.scale(0.5)
        exp_two.move_to(right_shifter.get_corner(UP+RIGHT), LEFT)
        exp_two.shift(MED_SMALL_BUFF*RIGHT)
        pre_exp_two = VGroup(ddf_over_dx_squared[0][2])

        self.play(
            Write(ddf_over_dx_squared.get_part_by_tex("over")),
            *[
                ReplacementTransform(
                    mob, 
                    ddf_over_dx_squared.get_part_by_tex(tex),
                    path_arc = -np.pi/2,                    
                )
                for mob, tex in (self.ddf, "df"), (self.dx_squared, "dx")
            ]
        )
        self.dither(2)
        self.play(FadeOut(parens))
        self.play(
            left_shifter.shift, 0.2*LEFT,
            right_shifter.shift, 0.2*RIGHT,
            ReplacementTransform(pre_exp_two, exp_two),
            ddf_over_dx_squared.get_part_by_tex("over").scale_in_place, 0.8
        )
        self.dither(2)
    def construct(self):
        plane_prob = TexMobject("P(\\text{Dying in a }", "\\text{plane}",
                                "\\text{ crash})", "\\approx", "1/",
                                "11{,}000{,}000")
        plane_prob.highlight_by_tex("plane", BLUE)
        car_prob = TexMobject("P(\\text{Dying in a }", "\\text{car}",
                              "\\text{ crash})", "\\approx", "1/", "5{,}000")
        car_prob.highlight_by_tex("car", YELLOW)
        plane_prob.shift(UP)
        car_prob.shift(
            plane_prob.get_part_by_tex("approx").get_center() -\
            car_prob.get_part_by_tex("approx").get_center() +\
            DOWN
        )

        self.play(Write(plane_prob))
        self.dither(2)
        self.play(ReplacementTransform(plane_prob.copy(), car_prob))
        self.dither(2)
Exemple #7
0
    def get_expression(self, base):
        expression = TexMobject(
            "{d(", "%d^"%base, "t", ")", "\\over \\,", "dt}",
            "=", "%d^"%base, "t", "(%.4f\\dots)"%np.log(base),
        )
        expression.highlight_by_tex("t", YELLOW)
        expression.highlight_by_tex("dt", GREEN)
        expression.highlight_by_tex("\\dots", BLUE)

        brace = Brace(expression.get_part_by_tex("\\dots"), UP)
        brace_text = brace.get_text("$\\ln(%d)$"%base)
        for mob in brace, brace_text:
            mob.set_fill(opacity = 0)

        expression.add(brace, brace_text)
        return expression
Exemple #8
0
    def take_third_derivative_of_cubic(self):
        polynomial = self.polynomial
        plus_cubic_term = TexMobject("+\\,", "c_3", "x^3")
        plus_cubic_term.next_to(polynomial, RIGHT)
        plus_cubic_term.to_edge(RIGHT, buff = LARGE_BUFF)
        plus_cubic_term.highlight_by_tex("c_3", self.colors[3])
        plus_cubic_copy = plus_cubic_term.copy()

        polynomial.generate_target()
        polynomial.target.next_to(plus_cubic_term, LEFT)

        self.play(FocusOn(polynomial))
        self.play(
            MoveToTarget(polynomial),
            GrowFromCenter(plus_cubic_term)
        )
        self.dither()

        brace = Brace(polynomial.quadratic_part, DOWN)
        third_derivative = TexMobject(
            "\\frac{d^3 P}{dx^3}(x) = ", "0"
        )
        third_derivative.shift(
            brace.get_bottom() + MED_SMALL_BUFF*DOWN -\
            third_derivative.get_part_by_tex("0").get_top()
        )        

        self.play(Write(third_derivative[0]))
        self.play(GrowFromCenter(brace))
        self.play(ReplacementTransform(
            polynomial.quadratic_part.copy(),
            VGroup(third_derivative[1])
        ))
        self.dither(2)
        self.play(plus_cubic_copy.next_to, third_derivative, RIGHT)
        derivative_term = self.take_derivatives_of_monomial(
            VGroup(*plus_cubic_copy[1:])
        )
        third_derivative.add(derivative_term)

        self.polynomial_third_derivative = third_derivative
Exemple #9
0
    def get_expression(self, base):
        expression = TexMobject(
            "{d(",
            "%d^" % base,
            "t",
            ")",
            "\\over \\,",
            "dt}",
            "=",
            "%d^" % base,
            "t",
            "(%.4f\\dots)" % np.log(base),
        )
        expression.highlight_by_tex("t", YELLOW)
        expression.highlight_by_tex("dt", GREEN)
        expression.highlight_by_tex("\\dots", BLUE)

        brace = Brace(expression.get_part_by_tex("\\dots"), UP)
        brace_text = brace.get_text("$\\ln(%d)$" % base)
        for mob in brace, brace_text:
            mob.set_fill(opacity=0)

        expression.add(brace, brace_text)
        return expression
    def construct(self):
        scale_factor = 0.7
        sick = "\\text{sick}"
        positive = "\\text{positive}"
        formula = TexMobject("P(", sick, "\\,|\\,", positive, ")", "=",
                             "{\\quad P(", sick, "\\text{ and }", positive,
                             ") \\quad", "\\over", "P(", positive, ")}", "=",
                             "{1/1{,}000", "\\over", "1/1{,}000", "+",
                             "(999/1{,}000)(0.01)}")
        formula.scale(scale_factor)
        formula.next_to(self.pi_creatures, UP, LARGE_BUFF)
        formula.shift_onto_screen(buff=MED_LARGE_BUFF)
        equals_group = formula.get_parts_by_tex("=")
        equals_indices = [
            formula.index_of_part(equals) for equals in equals_group
        ]

        lhs = VGroup(*formula[:equals_indices[0]])
        initial_formula = VGroup(*formula[:equals_indices[1]])
        initial_formula.save_state()
        initial_formula.shift(3 * RIGHT)

        over = formula.get_part_by_tex("\\over")
        num_start_index = equals_indices[0] + 1
        num_end_index = formula.index_of_part(over)
        numerator = VGroup(*formula[num_start_index:num_end_index])
        numerator_rect = SurroundingRectangle(numerator)

        alt_numerator = TexMobject("P(", sick, ")", "P(", positive, "\\,|\\,",
                                   sick, ")")
        alt_numerator.scale(scale_factor)
        alt_numerator.move_to(numerator)

        number_fraction = VGroup(*formula[equals_indices[-1]:])

        rhs = TexMobject("\\approx 0.09")
        rhs.scale(scale_factor)
        rhs.move_to(equals_group[-1], LEFT)
        rhs.highlight(YELLOW)

        for mob in formula, alt_numerator:
            mob.highlight_by_tex(sick, SICKLY_GREEN)
            mob.highlight_by_tex(positive, YELLOW)

        #Ask question
        self.student_says("What does the \\\\ formula look like here?")
        self.play(self.teacher.change, "happy")
        self.dither()
        self.play(
            Write(lhs),
            RemovePiCreatureBubble(
                self.students[1],
                target_mode="pondering",
            ),
            self.teacher.change,
            "raise_right_hand",
            self.students[0].change,
            "pondering",
            self.students[2].change,
            "pondering",
        )
        self.dither()

        #Show initial formula
        lhs_copy = lhs.copy()
        self.play(
            LaggedStart(FadeIn, initial_formula, lag_ratio=0.7),
            Animation(lhs_copy, remover=True),
        )
        self.dither(2)
        self.play(ShowCreation(numerator_rect))
        self.play(FadeOut(numerator_rect))
        self.dither()
        self.play(Transform(numerator, alt_numerator))
        initial_formula.add(*numerator)
        formula.add(*numerator)
        self.dither(3)

        #Show number_fraction
        self.play(initial_formula.move_to, initial_formula.saved_state,
                  FadeIn(VGroup(*number_fraction[:3])))
        self.dither(2)
        self.play(
            LaggedStart(FadeIn,
                        VGroup(*number_fraction[3:]),
                        run_time=3,
                        lag_ratio=0.7))
        self.dither(2)

        #Show rhs
        self.play(formula.shift, UP)
        self.play(Write(rhs))
        self.change_student_modes(*["happy"] * 3)
        self.look_at(rhs)
        self.dither(2)
Exemple #11
0
class IntroScene(PiCreatureScene):

    CONFIG = {
        "rect_height": 0.2,
        "duration": 1.0,
        "eq_spacing": 3 * MED_LARGE_BUFF
    }

    def construct(self):

        randy = self.get_primary_pi_creature()
        randy.scale(0.7).to_corner(DOWN + RIGHT)

        self.build_up_euler_sum()
        self.build_up_sum_on_number_line()
        self.show_pi_answer()
        self.other_pi_formulas()
        self.refocus_on_euler_sum()

    def build_up_euler_sum(self):

        self.euler_sum = TexMobject("1",
                                    "+",
                                    "{1 \\over 4}",
                                    "+",
                                    "{1 \\over 9}",
                                    "+",
                                    "{1 \\over 16}",
                                    "+",
                                    "{1 \\over 25}",
                                    "+",
                                    "\\cdots",
                                    "=",
                                    arg_separator=" \\, ")

        self.euler_sum.to_edge(UP)
        self.euler_sum.shift(2 * LEFT)

        terms = [1. / n**2 for n in range(1, 6)]
        partial_results_values = np.cumsum(terms)

        self.play(FadeIn(self.euler_sum[0], run_time=self.duration))

        equals_sign = self.euler_sum.get_part_by_tex("=")

        self.partial_sum_decimal = DecimalNumber(partial_results_values[1],
                                                 num_decimal_points=2)
        self.partial_sum_decimal.next_to(equals_sign, RIGHT)

        for i in range(4):

            FadeIn(self.partial_sum_decimal, run_time=self.duration)

            if i == 0:

                self.play(
                    FadeIn(self.euler_sum[1], run_time=self.duration),
                    FadeIn(self.euler_sum[2], run_time=self.duration),
                    FadeIn(equals_sign, run_time=self.duration),
                    FadeIn(self.partial_sum_decimal, run_time=self.duration))

            else:
                self.play(
                    FadeIn(self.euler_sum[2 * i + 1], run_time=self.duration),
                    FadeIn(self.euler_sum[2 * i + 2], run_time=self.duration),
                    ChangeDecimalToValue(self.partial_sum_decimal,
                                         partial_results_values[i + 1],
                                         run_time=self.duration,
                                         num_decimal_points=6,
                                         show_ellipsis=True,
                                         position_update_func=lambda m: m.
                                         next_to(equals_sign, RIGHT)))

            self.wait()

        self.q_marks = TextMobject("???").highlight(LIGHT_COLOR)
        self.q_marks.move_to(self.partial_sum_decimal)

        self.play(
            FadeIn(self.euler_sum[-3], run_time=self.duration),  # +
            FadeIn(self.euler_sum[-2], run_time=self.duration),  # ...
            ReplacementTransform(self.partial_sum_decimal, self.q_marks))

    def build_up_sum_on_number_line(self):

        self.number_line = NumberLine(
            x_min=0,
            color=WHITE,
            number_at_center=1,
            stroke_width=1,
            numbers_with_elongated_ticks=[0, 1, 2, 3],
            numbers_to_show=np.arange(0, 5),
            unit_size=5,
            tick_frequency=0.2,
            line_to_number_buff=MED_LARGE_BUFF)

        self.number_line_labels = self.number_line.get_number_mobjects()
        self.add(self.number_line, self.number_line_labels)
        self.wait()

        # create slabs for series terms

        max_n = 10

        terms = [0] + [1. / (n**2) for n in range(1, max_n + 1)]
        series_terms = np.cumsum(terms)
        lines = VGroup()
        self.rects = VGroup()
        slab_colors = [YELLOW, BLUE] * (max_n / 2)

        for t1, t2, color in zip(series_terms, series_terms[1:], slab_colors):
            line = Line(*map(self.number_line.number_to_point, [t1, t2]))
            rect = Rectangle()
            rect.stroke_width = 0
            rect.fill_opacity = 1
            rect.highlight(color)
            rect.stretch_to_fit_height(self.rect_height, )
            rect.stretch_to_fit_width(line.get_width())
            rect.move_to(line)

            self.rects.add(rect)
            lines.add(line)

        #self.rects.radial_gradient_highlight(ORIGIN, 5, YELLOW, BLUE)

        for i in range(5):
            self.play(
                GrowFromPoint(self.rects[i],
                              self.euler_sum[2 * i].get_center(),
                              run_time=self.duration))

        for i in range(5, max_n):
            self.play(
                GrowFromPoint(self.rects[i],
                              self.euler_sum[10].get_center(),
                              run_time=self.duration))

    def show_pi_answer(self):

        self.pi_answer = TexMobject("{\\pi^2 \\over 6}").highlight(YELLOW)
        self.pi_answer.move_to(self.partial_sum_decimal)
        self.pi_answer.next_to(self.euler_sum[-1],
                               RIGHT,
                               submobject_to_align=self.pi_answer[-2])
        self.play(ReplacementTransform(self.q_marks, self.pi_answer))

    def other_pi_formulas(self):

        self.play(FadeOut(self.rects), FadeOut(self.number_line_labels),
                  FadeOut(self.number_line))

        self.leibniz_sum = TexMobject(
            "1-{1\\over 3}+{1\\over 5}-{1\\over 7}+{1\\over 9}-\\cdots", "=",
            "{\\pi \\over 4}")

        self.wallis_product = TexMobject(
            "{2\\over 1} \\cdot {2\\over 3} \\cdot {4\\over 3} \\cdot {4\\over 5}"
            + "\\cdot {6\\over 5} \\cdot {6\\over 7} \\cdots", "=",
            "{\\pi \\over 2}")

        self.leibniz_sum.next_to(
            self.euler_sum.get_part_by_tex("="),
            DOWN,
            buff=self.eq_spacing,
            submobject_to_align=self.leibniz_sum.get_part_by_tex("="))

        self.wallis_product.next_to(
            self.leibniz_sum.get_part_by_tex("="),
            DOWN,
            buff=self.eq_spacing,
            submobject_to_align=self.wallis_product.get_part_by_tex("="))

        self.play(Write(self.leibniz_sum))
        self.play(Write(self.wallis_product))

    def refocus_on_euler_sum(self):

        self.euler_sum.add(self.pi_answer)

        self.play(
            FadeOut(self.leibniz_sum), FadeOut(self.wallis_product),
            ApplyMethod(self.euler_sum.shift,
                        ORIGIN + 2 * UP - self.euler_sum.get_center()))

        # focus on pi squared
        pi_squared = self.euler_sum.get_part_by_tex("\\pi")[-3]
        self.play(ScaleInPlace(pi_squared, 2, rate_func=wiggle))

        # Morty thinks of a circle

        q_circle = Circle(stroke_color=YELLOW,
                          fill_color=YELLOW,
                          fill_opacity=0.5,
                          radius=0.4,
                          stroke_width=10.0)
        q_mark = TexMobject("?")
        q_mark.next_to(q_circle)

        thought = Group(q_circle, q_mark)
        q_mark.scale_to_fit_height(0.8 * q_circle.get_height())
        self.pi_creature_thinks(thought,
                                target_mode="confused",
                                bubble_kwargs={
                                    "height": 2,
                                    "width": 3
                                })

        self.wait()
Exemple #12
0
    def construct(self):
        clunky_deriv = TexMobject(
            "{d", "\\big(", "{df", "\\over", "dx}", "\\big)",
            "\\over", "dx }"
        )
        over_index = clunky_deriv.index_of_part(
            clunky_deriv.get_parts_by_tex("\\over")[1]
        )
        numerator = VGroup(*clunky_deriv[:over_index])
        denominator = VGroup(*clunky_deriv[over_index+1:])


        rp = clunky_deriv.get_part_by_tex("(")
        lp = clunky_deriv.get_part_by_tex(")")
        dfs, overs, dxs = map(clunky_deriv.get_parts_by_tex, [
            "df", "over", "dx"
        ])
        df_over_dx = VGroup(dfs[0], overs[0], dxs[0])
        d = clunky_deriv.get_part_by_tex("d")
        d_over_dx = VGroup(d, overs[1], dxs[1])

        d2f_over_dx2 = TexMobject("{d^2 f", "\\over", "dx", "^2}")
        d2f_over_dx2.highlight_by_tex("dx", YELLOW)

        for mob in clunky_deriv, d2f_over_dx2:
            mob.next_to(self.teacher, UP+LEFT)

        for mob in numerator, denominator:
            circle = Circle(color = YELLOW)
            circle.replace(mob, stretch = True)
            circle.scale_in_place(1.3)
            mob.circle = circle
        dx_to_zero = TexMobject("dx \\to 0")
        dx_to_zero.highlight(YELLOW)
        dx_to_zero.next_to(clunky_deriv, UP+LEFT)

        self.student_says(
            "What's that notation?",
            target_mode = "raise_left_hand"
        )
        self.change_student_modes("confused", "raise_left_hand", "confused")
        self.play(
            FadeIn(
                clunky_deriv,
                run_time = 2,
                submobject_mode = "lagged_start"
            ),
            RemovePiCreatureBubble(self.get_students()[1]),
            self.teacher.change_mode, "raise_right_hand"
        )
        self.wait()
        self.play(ShowCreation(numerator.circle))
        self.wait()
        self.play(ReplacementTransform(
            numerator.circle,
            denominator.circle,
        ))
        self.wait()
        self.play(
            FadeOut(denominator.circle),
            Write(dx_to_zero),
            dxs.highlight, YELLOW
        )
        self.wait()
        self.play(
            FadeOut(dx_to_zero),
            *[ApplyMethod(pi.change, "plain") for pi in self.get_pi_creatures()]
        )
        self.play(
            df_over_dx.scale, dxs[1].get_height()/dxs[0].get_height(),
            df_over_dx.move_to, d_over_dx, RIGHT,
            FadeOut(VGroup(lp, rp)),
            d_over_dx.shift, 0.8*LEFT + 0.05*UP,
        )
        self.wait()
        self.play(*[
            ReplacementTransform(
                group,
                VGroup(d2f_over_dx2.get_part_by_tex(tex))
            )
            for group, tex in [
                (VGroup(d, dfs[0]), "d^2"),
                (overs, "over"),
                (dxs, "dx"),
                (VGroup(dxs[1].copy()), "^2}"),
            ]
        ])
        self.wait(2)
        self.student_says(
            "How does one... \\\\ read that?",
            student_index = 0,
        )
        self.play(self.teacher.change, "happy")
        self.wait(2)
Exemple #13
0
    def construct(self):
        self.setup_axes()
        func_graph = self.get_graph(
            self.function,
            self.function_color,
        )
        approx_graphs = [
            self.get_graph(
                taylor_approximation(self.function, n),
                self.approximation_color
            )
            for n in self.order_sequence
        ]

        near_text = TextMobject(
            "Near %s $= %d$"%(
                self.x_axis_label, self.center_point
            )
        )
        near_text.to_corner(UP + RIGHT)
        near_text.add_background_rectangle()
        equation = TexMobject(
            self.function_tex, 
            "\\approx",
            *self.approximation_terms
        )
        equation.next_to(near_text, DOWN, MED_LARGE_BUFF)
        equation.to_edge(RIGHT)
        near_text.next_to(equation, UP, MED_LARGE_BUFF)
        equation.highlight_by_tex(
            self.function_tex, self.function_color,
            substring = False
        )
        approx_terms = VGroup(*[
            equation.get_part_by_tex(tex, substring = False)
            for tex in self.approximation_terms
        ])
        approx_terms.set_fill(
            self.approximation_color,
            opacity = 0,
        )
        equation.add_background_rectangle()

        approx_graph = VectorizedPoint(
            self.input_to_graph_point(self.center_point, func_graph)
        )

        self.play(
            ShowCreation(func_graph, run_time = 2),
            Animation(equation),
            Animation(near_text),
        )
        for graph, term in zip(approx_graphs, approx_terms):
            self.play(
                Transform(approx_graph, graph, run_time = 2),
                Animation(equation),
                Animation(near_text),
                term.set_fill, None, 1,
            )
            self.dither()
        self.dither(2)
Exemple #14
0
    def construct(self):
        clunky_deriv = TexMobject(
            "{d", "\\big(", "{df", "\\over", "dx}", "\\big)",
            "\\over", "dx }"
        )
        over_index = clunky_deriv.index_of_part(
            clunky_deriv.get_parts_by_tex("\\over")[1]
        )
        numerator = VGroup(*clunky_deriv[:over_index])
        denominator = VGroup(*clunky_deriv[over_index+1:])


        rp = clunky_deriv.get_part_by_tex("(")
        lp = clunky_deriv.get_part_by_tex(")")
        dfs, overs, dxs = map(clunky_deriv.get_parts_by_tex, [
            "df", "over", "dx"
        ])
        df_over_dx = VGroup(dfs[0], overs[0], dxs[0])
        d = clunky_deriv.get_part_by_tex("d")
        d_over_dx = VGroup(d, overs[1], dxs[1])

        d2f_over_dx2 = TexMobject("{d^2 f", "\\over", "dx", "^2}")
        d2f_over_dx2.highlight_by_tex("dx", YELLOW)

        for mob in clunky_deriv, d2f_over_dx2:
            mob.next_to(self.teacher, UP+LEFT)

        for mob in numerator, denominator:
            circle = Circle(color = YELLOW)
            circle.replace(mob, stretch = True)
            circle.scale_in_place(1.3)
            mob.circle = circle
        dx_to_zero = TexMobject("dx \\to 0")
        dx_to_zero.highlight(YELLOW)
        dx_to_zero.next_to(clunky_deriv, UP+LEFT)

        self.student_says(
            "What's that notation?",
            target_mode = "raise_left_hand"
        )
        self.change_student_modes("confused", "raise_left_hand", "confused")
        self.play(
            FadeIn(
                clunky_deriv,
                run_time = 2,
                submobject_mode = "lagged_start"
            ),
            RemovePiCreatureBubble(self.get_students()[1]),
            self.teacher.change_mode, "raise_right_hand"
        )
        self.dither()
        self.play(ShowCreation(numerator.circle))
        self.dither()
        self.play(ReplacementTransform(
            numerator.circle,
            denominator.circle,
        ))
        self.dither()
        self.play(
            FadeOut(denominator.circle),
            Write(dx_to_zero),
            dxs.highlight, YELLOW
        )
        self.dither()
        self.play(
            FadeOut(dx_to_zero),
            *[ApplyMethod(pi.change, "plain") for pi in self.get_pi_creatures()]
        )
        self.play(
            df_over_dx.scale, dxs[1].get_height()/dxs[0].get_height(),
            df_over_dx.move_to, d_over_dx, RIGHT,
            FadeOut(VGroup(lp, rp)),
            d_over_dx.shift, 0.8*LEFT + 0.05*UP,
        )
        self.dither()
        self.play(*[
            ReplacementTransform(
                group,
                VGroup(d2f_over_dx2.get_part_by_tex(tex))
            )
            for group, tex in [
                (VGroup(d, dfs[0]), "d^2"),
                (overs, "over"),
                (dxs, "dx"),
                (VGroup(dxs[1].copy()), "^2}"),
            ]
        ])
        self.dither(2)
        self.student_says(
            "How does one... \\\\ read that?",
            student_index = 0,
        )
        self.play(self.teacher.change, "happy")
        self.dither(2)
Exemple #15
0
    def reminder_of_weights_and_bias(self):
        neuron = self.neuron
        layer0 = self.network_mob.layers[0]
        active_layer0 = self.network_mob.get_active_layer(
            0, np.random.random(len(layer0.neurons)))
        prev_neurons = layer0.neurons

        weights = 4 * (np.random.random(len(neuron.edges_in)) - 0.5)
        weighted_edges = VGroup(*[
            edge.copy().set_stroke(color=GREEN if w > 0 else RED, width=abs(w))
            for w, edge in zip(weights, neuron.edges_in)
        ])

        formula = TexMobject("=", "\\sigma(", "w_1", "a_1", "+", "w_2", "a_2",
                             "+", "\\cdots", "+", "w_n", "a_n", "+", "b", ")")
        w_labels = formula.get_parts_by_tex("w_")
        a_labels = formula.get_parts_by_tex("a_")
        b = formula.get_part_by_tex("b")
        sigma = VGroup(
            formula.get_part_by_tex("\\sigma"),
            formula.get_part_by_tex(")"),
        )
        symbols = VGroup(
            *[formula.get_parts_by_tex(tex) for tex in "=", "+", "dots"])

        w_labels.highlight(GREEN)
        b.highlight(BLUE)
        sigma.highlight(YELLOW)
        # formula.to_edge(UP)
        formula.next_to(neuron, RIGHT)

        weights_word = TextMobject("Weights")
        weights_word.next_to(neuron.edges_in, RIGHT, aligned_edge=UP)
        weights_word.highlight(GREEN)
        weights_arrow = Arrow(weights_word.get_bottom(),
                              neuron.edges_in[0].get_center(),
                              color=GREEN)

        alt_weights_arrows = VGroup(*[
            Arrow(weights_word.get_bottom(), w_label.get_top(), color=GREEN)
            for w_label in w_labels
        ])

        bias_word = TextMobject("Bias")
        bias_arrow = Vector(DOWN, color=BLUE)
        bias_arrow.next_to(b, UP, SMALL_BUFF)
        bias_word.next_to(bias_arrow, UP, SMALL_BUFF)
        bias_word.highlight(BLUE)

        self.revert_to_original_skipping_status()
        self.play(Transform(layer0, active_layer0),
                  FadeIn(a_labels),
                  FadeIn(symbols),
                  run_time=2,
                  submobject_mode="lagged_start")
        self.play(
            Write(weights_word),
            GrowArrow(weights_arrow),
            Transform(neuron.edges_in, weighted_edges),
            run_time=1,
        )
        self.dither()
        self.play(
            ReplacementTransform(
                weighted_edges.copy(),
                w_labels,
            ), ReplacementTransform(VGroup(weights_arrow), alt_weights_arrows))
        self.dither()
        self.play(Write(b),
                  Write(bias_word),
                  GrowArrow(bias_arrow),
                  run_time=1)
        self.play(Write(sigma))
        self.dither(2)