Homework 4

  1. Get the timing comparison code from line 41 of notebook 6 to run, i.e. the one containing the code starting:

    # %%prun
    for m in m_array:
        for n in n_array:
             if m >= n:   
              x = np.random.uniform(-10,10,n)
          ...
  2. Fit a line \(y = \beta_0 + \beta_1 x\) to the data points \((0, 1), (1, 2), (2, 2), (3, 4)\).

    1. Write down the normal (matrix) equations for this linear regression problem.
    2. Solve the normal equations.
    3. What are the predicted values (sometimes called the fitted vector)?
    4. Find the residual vector (i.e. the error between the actual and observed values).
    5. Verify that the residual is orthogonal to the column space of the initial matrix.
    6. Interpret the slope and intercept.
  3. Use QR factorization to solve the least-squares problem from the previous problem.

    1. Compute \(A =QR\).
    2. Solve \(R \hat \beta = Q^T y\).
    3. Compare with the normal-equation solution.
    4. Explain why QR is often preferred computationally.
  4. Create a synthetic matrix using smooth functions, for example \(A_{i, j} = \sin(x_i) \cos(y_j) + 0.5 \cos(2x_i) \sin(y_j)\).

    1. Compute the SVD.
    2. Plot singular values.
    3. Construct rank-\(1\), rank-\(2\), rank-\(5\), and rank-\(10\) approximations.
    4. Compare approximation errors.
  5. If you pick two unit vectors at random in \(\mathbb{R^n}\) we expect their inner product to be small. Given a specific method of picking vectors, can you get an estimate for \(v_1 \cdot v_2\) in terms of \(n\)? Here are three ways of making this question precise. For each method, what do you need to know about sums / sums of squares of the random variables? Can you actually get an estimate in terms of \(n\)?

    1. Each coordinate of each vector is chosen independently from the uniform distribution on \([0, 1]\), and then the vectors are normalized to have length \(1\).

    2. Each coordinate of each vector is chosen independently from the normal distribution \(N(0, 1)\), and then the vectors are normalized to have length \(1\).

    3. Each vector is chosen uniformly from the unit sphere \(S^{n-1} \subset \mathbb{R}^n\).