Skip to content

Commit

Permalink
add week 3
Browse files Browse the repository at this point in the history
  • Loading branch information
nvti committed Feb 20, 2020
1 parent 24f3799 commit 6ba57e4
Show file tree
Hide file tree
Showing 18 changed files with 2,182,675 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Week 01/Python review session/python-review-demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import numpy as np

def power_iteration(A, tolerance=1e-7):
b_old = np.random.rand(A.shape[1])
b = np.random.rand(A.shape[1])
num_iterations = 0
while num_iterations == 0 or np.linalg.norm(b_old - b) > tolerance:
b_old = np.copy(b)
b = np.dot(A, b)
b_norm = np.linalg.norm(b)
b /= b_norm
num_iterations += 1
return np.dot(A, b), b, num_iterations

def main():
A = np.array([[.5, .4], [.2, .8]])
ab, b, number_iterations = power_iteration(A)

eig1 = ab[0] / b[0]
eig2 = ab[1] / b[1]
assert(np.abs((eig1 - eig2) / eig2) < 1e-5)

b /= b[1]

print(eig1, b, number_iterations)

if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions Week 03/Assignment 3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Assignment 3

- [Handout](http://web.stanford.edu/class/cs224n/assignments/a3.pdf)
2 changes: 2 additions & 0 deletions Week 03/Assignment 3/collect_submission.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rm -f assignment3.zip
zip -r assignment3.zip *.py ./data ./utils
Loading

0 comments on commit 6ba57e4

Please sign in to comment.