jmbejara / comp-econ-sp18

Main Course Repository for Computational Methods in Economics (Econ 21410, Spring 2018)
16 stars 23 forks source link

Cant figure out what is wrong with my compression #9

Closed alykhanb96 closed 6 years ago

alykhanb96 commented 6 years ago

Wrote this code to compress:

def compress(n):
  newU = u[0:768, 0:n]
  newV = v[0:n, 0:1024]
  u_n= newU
  v_n= newV
  s_n= np.eye(n, dtype=float) * np.diag(s[0:n])

Each time i run it I run it this way:

compress(500)
pre = np.matmul(u_n, s_n)
face_compressed_500= np.matmul(pre, v_n)
plt.imshow(face_compressed_500, cmap=plt.cm.gray)

compress(300)
pre = np.matmul(u_n, s_n)
face_compressed_300= np.matmul(pre, v_n)
plt.imshow(face_compressed_300, cmap=plt.cm.gray)

But i get the exact same picture, furthermore my storage size is only 200 apart

alykhanb96 commented 6 years ago

@jmbejara can you take a look at this if you have a moment. Thanks so much

jmbejara commented 6 years ago

It seems like the main point is that you're not returning anything from your compress function. The variables you define in the function disappear when the function finishes. To understand this, take some time to go through the discussion here: https://github.com/jmbejara/comp-econ-sp18/issues/2

Some other points:

Let me know if this makes sense. Be sure to stop by the office hours at 1:45 as well. Hope this helps!