Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: math480-2016
Views: 2158

Problem 3: (numpy)

  1. Generate a random vector of integers between 0 and 10 (inclusive) of length 100. (hint: np.bincount)

  2. Which number appears most often?

# Solution Z = np.random.randint(0, 10, size = 100) np.bincount(Z).argmax()
3
%md ### Problem 4 (numpy) For two different types of random matrices with size 1000x1000 (e.g. rand, randn): - Multiply the matrix with its own transpose: $B = A^T * A$ - Then compute the eigenvalues of that resulting matrix $B$ and plot a histogram via matplotlib. Guess what each the distributions of eigenvalues looks like. (Compare with the distribution of the random sampling routines.) * random matrices: http://docs.scipy.org/doc/numpy/reference/routines.random.html * linear algebra: http://docs.scipy.org/doc/numpy/reference/routines.linalg.html e.g. `np.random.beta(.1, 5, size=(1000, 1000))`

Problem 4 (numpy)

  1. For different types of random matrices with size 1000x1000 (e.g. rand, randn)

  2. Multiply the matrix with its own transpose: B=ATAB = A^T * A

  3. Then compute the eigenvalues of that resulting matrix BB and plot a histogram via matplotlib!

Guess, what each the distributions of eigenvalues looks like! (Compare with the distribution of the random sampling routines)

# Solution %python A = np.random.beta(.1, 5, size=(1000, 1000)) A = A.T * A Aev = np.linalg.eigvals(A) plt.hist(Aev) plt.show()
(array([ 17., 57., 135., 226., 270., 168., 89., 32., 5., 1.]), array([-0.31629052, -0.24057083, -0.16485113, -0.08913143, -0.01341173, 0.06230796, 0.13802766, 0.21374736, 0.28946706, 0.36518675, 0.44090645]), <a list of 10 Patch objects>)
%md ### Problem 5: (scipy) 1. create two random vectors with normal distribution 1. use a T-test to check, if they significantly differ * http://docs.scipy.org/doc/scipy/reference/tutorial/stats.html

Problem 5: (scipy)

  1. create two random vectors with normal distribution

  2. use a T-test to check, if they significantly differ

# Solution

Problem 6: (scipy)

The family of BFGS optimization algorithms is very well known.

Optimize a two dimensional function over a constraint box using it!

  1. choose one from this list of classical optimization functions: https://en.wikipedia.org/wiki/Test_functions_for_optimization

  2. express the mathematical equation in terms of numpy vectors

  3. minimize in the box [10,10]2[-10, 10]^2 using the l-bfgs-b algorithm from scipy.

    question: what happens, when you do not specify the gradients?

# Solution