FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/animation/bayes_update.py at master · feisuo/matplotlib · GitHub
feisuo
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
animation
/
bayes_update.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (39 loc) · 1.43 KB
Breadcrumbs
matplotlib
/
examples
/
animation
/
bayes_update.py
Copy path
File metadata and controls
47 lines (39 loc) · 1.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# update a distribution based on new data.
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
import
scipy
.
stats
as
ss
from
matplotlib
.
animation
import
FuncAnimation
class
UpdateDist
(
object
):
def
__init__
(
self
,
ax
,
prob
=
0.5
):
self
.
success
=
0
self
.
prob
=
prob
self
.
line
,
=
ax
.
plot
([], [],
'k-'
)
self
.
x
=
np
.
linspace
(
0
,
1
,
200
)
self
.
ax
=
ax
# Set up plot parameters
self
.
ax
.
set_xlim
(
0
,
1
)
self
.
ax
.
set_ylim
(
0
,
15
)
self
.
ax
.
grid
(
True
)
# This vertical line represents the theoretical value, to
# which the plotted distribution should converge.
self
.
ax
.
axvline
(
prob
,
linestyle
=
'--'
,
color
=
'black'
)
def
init
(
self
):
self
.
success
=
0
self
.
line
.
set_data
([], [])
return
self
.
line
,
def
__call__
(
self
,
i
):
# This way the plot can continuously run and we just keep
# watching new realizations of the process
if
i
==
0
:
return
self
.
init
()
# Choose success based on exceed a threshold with a uniform pick
if
np
.
random
.
rand
(
1
,)
<
self
.
prob
:
self
.
success
+=
1
y
=
ss
.
beta
.
pdf
(
self
.
x
,
self
.
success
+
1
, (
i
-
self
.
success
)
+
1
)
self
.
line
.
set_data
(
self
.
x
,
y
)
return
self
.
line
,
fig
,
ax
=
plt
.
subplots
()
ud
=
UpdateDist
(
ax
,
prob
=
0.7
)
anim
=
FuncAnimation
(
fig
,
ud
,
frames
=
np
.
arange
(
100
),
init_func
=
ud
.
init
,
interval
=
100
,
blit
=
True
)
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL