예제 #1
0
def get_training_image_group(train_in, train_out):
    image = MNistMobject(train_in)
    image.scale_to_fit_height(1)
    arrow = Vector(RIGHT, color=BLUE, buff=0)
    output = np.argmax(train_out)
    output_tex = TexMobject(str(output)).scale(1.5)
    result = Group(image, arrow, output_tex)
    result.arrange_submobjects(RIGHT)
    result.to_edge(UP)
    return result
예제 #2
0
    def construct(self):
        #self.force_skipping()

        self.fruit_num = 101
        apples = Group(*(Apple() for _ in xrange(self.fruit_num)))
        apples.arrange_submobjects(buff=0.5)
        apples.to_edge(LEFT, buff=2.5)

        pears = Group(*(Pear() for _ in xrange(self.fruit_num)))
        for apple, pear in zip(apples, pears):
            pear.move_to(apple)

        apples.shift(1.5 * UP)
        pears.shift(1.5 * DOWN)

        apple_numbers = number_submobjects(apples, direction=UP)
        pear_numbers = number_submobjects(pears, direction=DOWN)

        self.play(ShowCreation(apples), Write(apple_numbers))
        self.play(ShowCreation(pears), Write(pear_numbers))
        #self.dither()
        apples.submobjects.reverse()
        pears.submobjects.reverse()
        apple_numbers.submobjects.reverse()
        pear_numbers.submobjects.reverse()

        apples_ori = apples.copy()
        pears_ori = pears.copy()
        apple_numbers_ori = apple_numbers.copy()
        pear_numbers_ori = pear_numbers.copy()

        apples_persp = apples.copy()
        pears_persp = pears.copy()
        apple_numbers_persp = apple_numbers.copy()
        pear_numbers_persp = pear_numbers.copy()

        self.camera_distance = 12.0
        self.camera_point = apples[-1].get_center() * X_MASK
        vanishing_point = self.camera_point + self.camera_distance * RIGHT

        self.darken(apples_persp)
        self.darken(pears_persp)
        self.darken(apple_numbers_persp)
        self.darken(pear_numbers_persp)

        # perspective shift of numbers
        self.apply_perspective(apples_persp, objectwise=True)
        self.apply_perspective(pears_persp, objectwise=True)
        self.apply_perspective(apple_numbers_persp, objectwise=False)
        self.apply_perspective(pear_numbers_persp, objectwise=False)

        self.play(
            ReplacementTransform(apples, apples_persp),
            ReplacementTransform(pears, pears_persp),
            ReplacementTransform(apple_numbers, apple_numbers_persp),
            ReplacementTransform(pear_numbers, pear_numbers_persp),
        )
        apples = apples_persp
        pears = pears_persp
        apple_numbers = apple_numbers_persp
        pear_numbers = pear_numbers_persp

        #self.dither()

        matching = make_ordinal_matching(
            Ordinal(*apples[1:]),
            Ordinal(*pears[1:]),
        )
        self.darken(matching)
        self.play(ShowCreation(matching))
        self.dither()
        matching_straight = matching.copy()

        # Extra apple
        self.show_extra_fruit(apples, apples_ori, apple_numbers,
                              apple_numbers_ori, matching, apples[:-1],
                              pears[1:], matching_straight)

        # Extra pear
        self.show_extra_fruit(pears, pears_ori, pear_numbers, pear_numbers_ori,
                              matching, apples[1:], pears[:-1],
                              matching_straight)
        self.dither()

        self.play(Transform(matching, matching_straight))

        definition = TextMobject("Definition:", "$|A| = |B|$")
        definition.to_edge(UP)
        self.play(Write(definition[0]))

        apple_box, apple_label = self.pack_into_box(apples, apple_numbers, UP,
                                                    'A', RED, matching, apples,
                                                    pears)
        #self.dither()

        pear_box, pear_label = self.pack_into_box(pears, pear_numbers, DOWN,
                                                  'B', YELLOW, matching,
                                                  apples, pears)
        #self.dither()

        self.move_labels_to_definition(apple_label, pear_label, definition[1])

        finite_pears = VGroup(*pears_ori[-3:])
        finite_pears.move_to(pear_box)
        pears_dest = VGroup(*[pears[0].copy() for _ in range(len(pears) - 3)])
        pears_dest.fade(0)
        pears_dest.add(*finite_pears.submobjects)

        self.play(
            Uncreate(matching),
            FadeOut(definition[1]),
        )
        self.play(Transform(pears, pears_dest), )
        self.remove(pears)
        self.add(finite_pears)
        finite_pears.submobjects.reverse()
        pears = finite_pears

        #self.dither()

        def attempt(i0, i1, i2, remove=True):
            apple_indices = i0, i1, i2
            matching = get_matching(
                pears,
                Group(*(apples.submobjects[-1 - i] for i in apple_indices)))
            self.play(ShowCreation(matching), submobject_mode="all_at_once")
            #self.dither()
            if remove: self.remove(matching)
            else: return matching

        attempt(5, 8, 12)
        attempt(0, 10, 19)
        matching = attempt(7, 1, 0, remove=False)

        def2 = TextMobject(":", "$|A|>|B|$")
        def2.shift(definition[0][-1].get_center() - def2[0].get_center())

        self.move_labels_to_definition(apple_label, pear_label, def2[1])
        self.dither()