forked from NeuromatchAcademy/course-content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyplots.py
71 lines (55 loc) · 2.59 KB
/
myplots.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
#!/usr/bin/env python
# coding: utf-8
import time # import time
import numpy as np # import numpy
import scipy as sp # import scipy
import math # import basic math functions
import random # import basic random number generator functions
import matplotlib.pyplot as plt # import matplotlib
from IPython import display
def my_plot(x, auditory=None, visual=None, posterior_pointwise=None):
"""
Plots normalized Gaussian distributions and posterior
DO NOT EDIT THIS FUNCTION !!!
Args:
x (numpy array of floats): points at which the likelihood has been evaluated
auditory (numpy array of floats): normalized probabilities for auditory likelihood evaluated at each `x`
visual (numpy array of floats): normalized probabilities for visual likelihood evaluated at each `x`
posterior (numpy array of floats): normalized probabilities for the posterior evaluated at each `x`
Returns:
Nothing.
"""
if auditory is None:
auditory = np.zeros_like(x)
if visual is None:
visual = np.zeros_like(x)
if posterior_pointwise is None:
posterior_pointwise = np.zeros_like(x)
plt.plot(x, auditory, '-r', LineWidth=2, label='Auditory')
plt.plot(x, visual, '-b', LineWidth=2, label='Visual')
plt.plot(x, posterior_pointwise, '-g', LineWidth=2, label='Posterior')
plt.legend()
plt.ylabel('Probability')
plt.xlabel('Orientation (Degrees)')
def my_dynamic_plot(x, auditory, visual, posterior_pointwise):
"""
DO NOT EDIT THIS FUNCTION !!!
Plots the auditory, visual and posterior distributions and update the figure every .2 seconds
Args:
x (numpy array of floats): points at which the likelihood has been evaluated
auditory (numpy array of floats): normalized probabilities for auditory likelihood evaluated at each `x`
visual (numpy array of floats): normalized probabilities for visual likelihood evaluated at each `x`
posterior (numpy array of floats): normalized probabilities for the posterior evaluated at each `x`
Returns:
Nothing
"""
plt.clf()
plt.plot(x, auditory, '-r', LineWidth=2, label='Auditory')
plt.plot(x, visual, '-b', LineWidth=2, label='Visual')
plt.plot(x, posterior_pointwise, '-g', LineWidth=2, label='Posterior')
plt.ylabel('Probability')
plt.xlabel('Orientation (Degrees)')
plt.legend()
display.clear_output(wait=True)
display.display(plt.gcf())
time.sleep(0.2)