Student: Harry Potter (ID# 123456789)
"Harry Potter"
"123456789"
CPSC 406 — Homework 7
Exercise 1. Projection onto a halfspace
A nonzero n-vector $a$ and a scalar $\beta$ define the halfspace
$$H^{-}_{a,β}=\{x∈\Re^n\mid ⟨a,x⟩≤β\}.$$
(Part a). Derive an explicit expression for the projection of an arbitrary n-vector b onto $H^-_{a,β}$.
$$\mbox{proj}_{H^-_{a,β}}(b) = \begin{cases} blah & \mbox{if $...$}\\ blah & \mbox{if $...$} \end{cases}$$
(Part b.) Implement your solution above by completing the following function.
(Part c.) Verify numerically with a few examples that your projection code is correct.
Exercise 2. Alternating projection method
The function projsplx
, defined in the Helper Function Section below, computes the projection of any n-vector onto the probability simplex $\{x\in\Re^n\mid \sum_j^nx_j=1,\ x≥0\}$. The cell below shows the result of the projection of a vector b
onto the simplex.
0.0
0.0
1.0
Now suppose that we wish to compute the projection onto the intersection of the probability simplex and an arbitrary halfspace. Can you do this using the projection function proj_halfspace
, which you implemented above, and proj_simplex
?
Yes, you can, using the Projection Onto Convex Sets algorithm, which iteratively projects onto each convex set. The algorithm is simple, and involves the following iteration:
$$x_{k+1}=P_1(P_2(x_k)),$$
where $P_1$ and $P_2$ are projection operators onto the first and second sets. Implement this algorithm for generic projection operators $P_1$ and $P_2$. Exit the loop when $\|x_{k+1}-x_k\|≤ϵ\|x_0\|$ for some positive tolerance $\epsilon$.
Note that this method can in some situations take many iterations.
(Part a.) Complete the following function.
(Part b). Test your implementationo f proj_intersection
on a small problem that aims to find the projection of a vector onto the intersection of the unit probability simplex and a halfspace. Verify that the answer is correct.
Warning
Make sure that your test problem is feasible – i.e., that the intersection isn't empty.
Exercise 3. Projected gradient method.
(Part a). The function below is meant to minimize a simple quadratic function $\frac12 x^T Qx$ over a convex set $C$. Complete the implementation. Use a fixed step size equal to $1/L$, where $L$ is the Lipschitz constant of the gradient.
(Part b). Use the function pgrad
to obtain the minimum-risk portfolio from a set of assets with returns r
and covariances Σ
, computed here:
The plot below shows the error in the optimality of the iterations, as measured by
$$\|x_{k+1}-x_k\|.$$
UndefVarError: min_risk_itn_errors not defined
- top-level scope@Local: 1
(Part c). Use the function efficient_portfolio
to compute an optimal portfolio with expected return of 10%.
syntax: invalid identifier name "..."
UndefVarError: xp1_itn_errors not defined
- top-level scope@Local: 1