Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLE Visualization Q3 #47

Closed
alykhanb96 opened this issue May 7, 2018 · 1 comment
Closed

MLE Visualization Q3 #47

alykhanb96 opened this issue May 7, 2018 · 1 comment
Labels

Comments

@alykhanb96
Copy link

Been stuck on Q3 for a while. The error I get says that plt.plot cant take a generator.

def pdf(x):
a = (1/(x0.5 (2np.pi)**(1/2))) math.exp(-1* ((math.log10(x) - 11)2)/(2 (0.5*2)))
return a

grid = np.linspace(0, 150000, num= 150000)

#fig, ax = plt.subplots(figsize=(10, 6))
#ax.hist(obs, bins=40, normed=True)
new = map(pdf, grid)
plt.plot(grid, new, 'k-', linewidth=2)
plt.show()

@jmbejara
Copy link
Owner

jmbejara commented May 7, 2018

Hi Aly. Here are some suggestions:

  • Don't use map. Use vectorization using numpy as we discussed. (numpy's 'ufuncs')
  • Try simplifying the problem to understand the error. You'll see that new is a generator and not a list.

Compare

def pdf(x):
    a = x**2
    return a

grid = np.linspace(-5, 5, num= 20)
new = map(pdf, grid)
plt.plot(grid, new, 'k-', linewidth=2)
plt.show()

with

def pdf(x):
   a = x**2
   return a

grid = np.linspace(-5, 5, num= 20)
new = list(map(pdf, grid))
plt.plot(grid, new, 'k-', linewidth=2)
plt.show()

After running new = map(pdf, grid), you'll see this:

image

  • Don't use math.exp or math.log. Use np.exp and np.log. This will help you so that you don't have to use map.

Let me know if this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants