






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







EE364a: Convex Optimization I S. Boyd March 14–15, 15–16, or 16–17, 2019
This is a 24 hour take-home final. Please turn it in at Bytes Cafe in the Packard building, 24 hours after you pick it up.
You may use any books, notes, or computer programs, but you may not discuss the exam with anyone until 9:30AM March 17, after everyone has finished the exam. The only exception is that you can ask us for clarification, via the course staff email address or private Piazza post. We’ve tried pretty hard to make the exam unambiguous and clear, so we’re unlikely to say much.
Please make a copy of your exam, or scan it, before handing it in.
Please attach the cover page to the front of your exam. Assemble your solutions in order (problem 1, problem 2, problem 3,... ), starting a new page for each problem. Put everything associated with each problem (e.g., text, code, plots) together; do not attach code or plots for all problems at the end of the final.
We will deduct points from long, needlessly complex solutions, even if they are correct. Our solutions are not long, so if you find that your solution to a problem goes on and on for many pages, you should try to figure out a simpler one. We expect neat, legible exams from everyone, including those enrolled Cr/N.
When a problem involves computation you must give all of the following: a clear discussion and justification of exactly what you did, the source code that produces the result, and the final numerical results or plots.
Files containing problem data can be found in the usual place,
http://www.stanford.edu/~boyd/cvxbook/cvxbook_additional_exercises/
Please respect the honor code. Although we allow you to work on homework assignments in small groups, you cannot discuss the final with anyone, at least until everyone has taken it.
All problems have equal weight. Some are (quite) straightforward. Others, not so much.
Be sure you are using the most recent version of CVX, CVXPY, or Convex.jl. Check your email often during the exam, just in case we need to send out an important announcement.
Some problems involve applications. But you do not need to know anything about the problem area to solve the problem; the problem statement contains everything you need.
Some of the data files generate random data (with a fixed seed), which are not necessarily the same for Matlab, Python, and Julia.
λkt k!
, k = 0, 1 ,... ,
with parameter λt ≥ 0, t = 1,... , 24. (For λt = 0, k = 0 events occur with probability one.) Here t denotes the hour, with t = 1 corresponding to the hour from midnight to 1AM, and t = 24 the hour between 11PM and midnight. (This is the periodic Poisson distribution in the title.) The parameter λt is the expected value of the number of events that occur in hour t; it can be thought of as the rate of occurence of the events in hour t. Over one day we observe the numbers of events N 1 ,... , N 24.
(a) Maximum likelihood estimate of parameters. What is the maximum likelihood es- timate of the parameters λ 1 ,... , λ 24? Hint. There is a simple analytical solution. You should consider the cases Nt > 0 and Nt = 0 separately. (b) Regularized maximum likelihood estimate of parameters. In many applications it is reasonable to assume that λt varies smoothly over the day; for example, the rate of occurence of events for 3PM–4PM is not too different from the rate of occurence for 4PM–5PM. To obtain a smooth estimate of λt we maximize the log likelihood minus the regularization term
ρ
t=
(λt+1 − λt)^2 + (λ 1 − λ 24 )^2
where ρ ≥ 0. Explain how to find the values λ 1 ,... , λ 24 using convex optimization. If you change variables, explain. (c) What happens as ρ → ∞? You can give a very short answer, with an informal argument. Hint. As in part (a), there is a simple analytical solution. (d) Numerical example. Over one day, we observe
N = (0, 4 , 2 , 2 , 3 , 0 , 4 , 5 , 6 , 6 , 4 , 1 , 4 , 4 , 0 , 1 , 3 , 4 , 2 , 0 , 3 , 2 , 0 , 1).
Find the regularized maximum likelihood parameters for ρ ∈ { 0. 1 , 1 , 10 , 100 } using CVX*, and plot λt versus t for each value of ρ. (e) Choosing the hyper-parameter value by out-of-sample test. One way to choose the value of ρ is to see which of the models found in part (d) has the highest log likelihood on a test set, i.e., another day’s data, that was not used to create the model. For each of the 4 values of the parameters you estimated in part (d), evaluate the log likelihood of another day’s number of events,
N test^ = (0, 1 , 3 , 2 , 3 , 1 , 4 , 5 , 3 , 1 , 4 , 3 , 5 , 5 , 2 , 1 , 1 , 1 , 2 , 0 , 1 , 2 , 1 , 0).
Which hyper-parameter value ρ would you choose?
pld^ = pgrid^ + pbatt^ + ppv.
(This is called the power balance constraint. The lefthand side is the load power, and the righthand side is the sum of the power coming from the grid, the battery, and the PV array.) All powers are given in kW. The battery state of charge is given by q ∈ R^96. It must satisfy 0 ≤ qi ≤ Q for all i, where Q is the battery capacity (in kWh). The battery dynamics are
qi+1 = qi − (1/4)pbatt i , i = 1,... , 95 , q 1 = q 96 − (1/4)pbatt 96.
(The last equation means that we seek a periodic operation of the microgrid.) The battery power must satisfy −C ≤ pbatt i ≤ D for all i, where C and D are (positive) known maximum charge and maximum discharge rates. When we buy power (i.e., pgrid i ≥ 0) we pay for it at the rate of Rbuy i (in $/kWh). When we sell power to the grid (i.e., pgrid i < 0) we are paid for it at the rate of Rsell i. These (positive) prices vary with time period, and are known. The total cost of the grid power (in $) is
(1/4)
Rbuy
pgrid
Rsell
pgrid
where (pgrid)+ = max{pgrid, 0 } and (pgrid)− = max{−pgrid, 0 } (elementwise). You can assume that Rbuy i > Rsell i > 0, i.e., in every period, you pay at a higher rate to consume power from the grid than you are paid when you send power back into the grid. The data for the problem are
pld, ppv, Q, C, D, Rbuy, Rsell.
(a) Explain how to find the powers and battery state of charge that minimize the total cost of the grid power. Carry out your method using the data given in microgrid_data.*. Report the optimal cost of the grid power. Plot pgrid, pload, ppv, pbatt, and q versus i. Note. For CVXPY, you might need to spec- ify solver=cvx.ECOS when you call the solve() method.
(b) Price and payments. Let ν ∈ R^96 denote the optimal dual variable associated with the power balance constraint. The vector 4ν can be interpreted as the (time-varying) price of electricity at the microgrid, and is called the locational marginal price (LMP). The LMP is in $/kWh, and is generally positive; the factor 4 converts between 15 minute power intervals and per kWh prices. Find and plot the LMP, along with the grid buy and sell prices, versus i. Make a very brief comment comparing the LMP prices with the buy and sell grid prices. Hint. Depending on how you express the power balance constraint, your software might return −ν instead of ν. Feel free to use − 4 ν instead of ν, or to switch the left-hand and righ-hand sides of your power balance constraint. (c) The LMPs can be used as a system for payments among the load, the PV array, the battery, and the grid. The load pays νT^ pld; the PV array is paid νT^ ppv; the battery is paid νT^ pbatt; and the grid is paid νT^ pgrid. Note carefully the directions of these payments. Also note that the battery and grid, whose powers can have either sign, can be paid in some time intervals and pay in others. Use this pricing scheme to calculate the LMP payments made by the load, and to the PV array, the battery, and the grid. If all goes well, these payments will balance, i.e., the load will pay an amount equal to the sum of the others.
When you execute the script that contains the data, it will create plots showing the various powers and prices versus time. Your are welcome to use these as templates for plotting your results. You are very welcome to look inside the script to see how the data is generated.
Remark. (Not needed to solve the problem.) The given data is approximately consis- tent with a group of ten houses, a common or pooled PV array of around 100 panels, and two Tesla Powerwall batteries.
(a) Sum of squares of 2-norms.
t=0 ‖ut‖
2
t=0 ‖ut‖^2. (c) Max of 2-norms. maxt=0,...,T − 1 ‖ut‖ 2. (d) Sum of 1-norms.
t=0 ‖ut‖^1. In some applications this is an approximation of the fuel use.
For each objective, plot (the components of) optimal input, as well as ‖ut‖ 2 , versus t. Make a very brief comment on each plot of optimal control inputs, explaining why you might expect what happened.
N∑ − 1
i=
d(p(i), p(i+1))
where d is a distance function.
(a) Euclidean morphing. What is the solution when the distance function is the sum of squares, dsq(u, v) = ‖u − v‖^22? The solution is simple; you can just give it without justification. (b) Hellinger morphing. Now we use the Hellinger distance function
dhel(u, v) =
∑^ n
i=
ui −
vi)^2.
Explain how to solve the Hellinger morphing problem using convex optimization. (c) Kolmogorov morphing. Now we use the Kolmogorov distance function
dkol(u, v) = max i=1,...,n
∑^ i
j=
uj −
∑^ i
j=
vj
which is the `∞ distance between the respective cumulative distributions (using the order of the outcomes). Explain how to solve the Kolmogorov morphing problem using convex optimization. (d) Find the Euclidean, Hellinger, and Kolmogorov morphings for N = 10, n = 100. Use q and r provided in morphing_data.*. Plot each p(i)^ versus n. Produce one figure for each choice of distance function. Note. In Python and Julia, you should use the ECOS solver.
N l^ =
i=
gi, N s^ =
∑^ n
i=L+
gi.
When N l^ > 0 (N l^ < 0), we say that we have had a long term capital gain (loss), and similary for short term gain. These two net gains determine the total tax liability. The long and short term net gains are taxed at two different rates, ρl^ and ρs, respectively, which satisfy 0 < ρl^ < ρs. The simplest case is when both net gains are nonnegative, in which case the tax is ρlN l^ + ρsN s. Another simple case occurs when both net gains are nonpositive, in which case the tax is zero. In the case when one of the net gains is positive and the other is negative, you are allowed to use the net loss in one to offset the net gain in the other, up to the value of the net gain. Specifically, if N l^ < 0 (you have a long term loss), the tax is ρs(N s^ + N l)+; if N s^ < 0 (you have a short term loss), the tax is ρl(N s^ +N l)+. (Here (u)+ = max{u, 0 }.) Note that you have zero tax liability if N s^ + N l^ ≤ 0, i.e., your total long and short net gains is less than or equal to zero. Apology. Sorry this sounds complicated. In fact, this is a highly simplified version of the way taxes really work. Hint. The tax liability is neither a convex nor quasiconvex function of the long and short term net gains N l^ and N s.
(a) Explain how to find s that minimizes the tax liability, subject to the constraints listed above, using convex optimization. Your solution can involve solving a mod- est number of convex problems. (b) Suppose you want to raise C = 2300 dollars from n = 10 tax lots, and the cost
basis and values of each lot are given by
b = (400, 80 , 400 , 200 , 400 , 400 , 80 , 400 , 100 , 500), v = (500, 100 , 500 , 200 , 700 , 300 , 120 , 300 , 150 , 600).
Carry out your method on this data with L = 4, ρl = 0.2, and ρs = 0.3. Give optimal values of si, and the optimal value of the tax liability. Compare this to the tax liability when you liquidate all tax lots proportionally, i.e., s = (C/ 1 T^ v)v.