-
Notifications
You must be signed in to change notification settings - Fork 4
/
a20200512_20.py
77 lines (61 loc) · 2 KB
/
a20200512_20.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from manimlib.imports import *
import numpy as np
class a20200512_20(GraphScene):
CONFIG = {
"y_max" : 1.2,
"y_min" : 0,
"x_min" : -16,
"x_max" : 16,
"graph_origin": [0,-3,0]
}
def construct(self):
self.setup_axes()
g = lambda x : 1/(1+np.exp(-x))
gg = self.get_graph(g)
self.add(gg)
fx = lambda x: 1/(1+np.exp(-x.get_value()))
x_value = ValueTracker(0)
fx_value = ValueTracker(fx(x_value))
x_tex = DecimalNumber(x_value.get_value()).add_updater(lambda v: v.set_value(x_value.get_value()))
fx_tex = DecimalNumber(fx_value.get_value(), num_decimal_places = 10).add_updater(lambda v: v.set_value(fx(x_value)))
# TeX labels definition
x_label = Tex("x = ")
fx_label = Tex("f(x) = ")
# Grouping of labels and numbers
group = VGroup(x_tex,fx_tex,x_label,fx_label).scale(1)
VGroup(x_tex, fx_tex).arrange_submobjects(DOWN)
# Align labels and numbers
x_label.next_to(x_tex,LEFT, buff=0.3,)
fx_label.next_to(fx_tex,LEFT, buff=0.3,)
pt = Dot().add_updater(
lambda v: v.move_to( self.coords_to_point ( x_value.get_value(), fx(x_value) ) )
)
self.add(pt)
self.add(group.to_edge(UL, buff=1))
self.wait()
self.play(
x_value.set_value,15,
rate_func=linear,
run_time=5
)
self.wait()
self.play(
x_value.set_value,-15,
rate_func=linear,
run_time=5
)
self.wait()
self.play(
x_value.set_value,0,
rate_func=linear,
run_time=5
)
self.wait()
string = r"""
f(x) = {{1} \over {1 + e^{-x}}}
"""
string = string.split()
f_1 = Tex(*string)
f_1.to_edge(LEFT, buff=1)
self.play(Write(f_1))
self.wait()