Docsity

Least-Squares Problems: Finding Distance to a Line and Solving Linear Equations, Slides of Logic

Toggle sidebar
bg1
EE263 Prof. S. Boyd
Oct. 27 – 28 or Oct. 28 – 29, 2006.
Midterm exam solutions
1. Point of closest convergence of a set of lines. We have mlines in Rn, described as
Li={pi+tvi|t∈R}, i = 1,...,m,
where pi∈Rn, and vi∈Rn, with kvik= 1, for i= 1,...,m. We define the distance
of a point z∈Rnto a line Las
dist(z, L) = min{kz−uk | u∈ L}.
(In other words, dist(z, L) gives the closest distance between the point zand the line
L.)
We seek a point z⋆∈Rnthat minimizes the sum of the squares of the distances to the
lines, m
X
i=1
dist(z, Li)2.
The point z⋆that minimizes this quantity is called the point of closest convergence.
(a) Explain how to find the point of closest convergence, given the lines (i.e., given
p1,...,pmand v1,...,vm). If your method works provided some condition holds
(such as some matrix being full rank), say so. If you can relate this condition to
a simple one involving the lines, please do so.
(b) Find the point z⋆of closest convergence for the lines with data given in the Matlab
file line_conv_data.m. This file contains n×mmatrices Pand Vwhose columns
are the vectors p1,...,pm, and v1,...,vm, respectively. The file also contains
commands to plot the lines and the point of closest convergence (once you have
found it). Please include this plot with your solution.
Solution.
(a) There are several ways to solve this problem. Our first solution starts by working
out an explicit expression for dist(z, Li). To find this distance we need to solve
the simple least-squares problem of minimizing kz−pi−tvik2over t∈R. The
optimal tis given by t⋆=vT
i(z−pi), so we have
dist(z, Li) = kz−pi−t⋆vik=k(I−vivT
i)(z−pi)k.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Least-Squares Problems: Finding Distance to a Line and Solving Linear Equations and more Slides Logic in PDF only on Docsity!

EE263 Prof. S. Boyd Oct. 27 – 28 or Oct. 28 – 29, 2006.

Midterm exam solutions

  1. Point of closest convergence of a set of lines. We have m lines in Rn, described as

Li = {pi + tvi | t ∈ R}, i = 1,... , m,

where pi ∈ Rn, and vi ∈ Rn, with ‖vi‖ = 1, for i = 1,... , m. We define the distance of a point z ∈ Rn^ to a line L as

dist(z, L) = min{‖z − u‖ | u ∈ L}.

(In other words, dist(z, L) gives the closest distance between the point z and the line L.) We seek a point z⋆^ ∈ Rn^ that minimizes the sum of the squares of the distances to the lines, ∑m

i=

dist(z, Li)^2.

The point z⋆^ that minimizes this quantity is called the point of closest convergence.

(a) Explain how to find the point of closest convergence, given the lines (i.e., given p 1 ,... , pm and v 1 ,... , vm). If your method works provided some condition holds (such as some matrix being full rank), say so. If you can relate this condition to a simple one involving the lines, please do so. (b) Find the point z⋆^ of closest convergence for the lines with data given in the Matlab file line_conv_data.m. This file contains n × m matrices P and V whose columns are the vectors p 1 ,... , pm, and v 1 ,... , vm, respectively. The file also contains commands to plot the lines and the point of closest convergence (once you have found it). Please include this plot with your solution.

Solution.

(a) There are several ways to solve this problem. Our first solution starts by working out an explicit expression for dist(z, Li). To find this distance we need to solve the simple least-squares problem of minimizing ‖z − pi − tvi‖^2 over t ∈ R. The optimal t is given by t⋆^ = vTi (z − pi), so we have

dist(z, Li) = ‖z − pi − t⋆vi‖ = ‖(I − viviT )(z − pi)‖.

This makes sense: we recognize I − viviT as projection onto the orthogonal com- plement of the line through the origin in the direction vi, i.e., projection onto the plane with normal vector vi.

We can now set up our problem as a standard least-squares problem. We define

A =

  

I − v 1 vT 1 .. . I − vmvmT

   ,^ b^ =

  

(I − v 1 v 1 T )p 1 .. . (I − vmvTm)pm

   ,

so we can write (^) m ∑ i=

dist(z, Li)^2 = ‖Az − b‖^2.

Now we can solve the problem, assuming A is full rank (we’ll come back to this). The solution is

z⋆^ = (AT^ A)−^1 AT^ b =

( mI −

∑^ m

i=

viviT

)− (^1) m ∑

i=

(pi − vivTi pi).

Finally, let’s look at the conditions under which A is not full rank. Each n × n block of A, i.e., I − vivTi , has rank exactly n − 1, with nullspace span(vi). So unless all the vi are aligned (i.e., vi = vj or vi = −vj for all i, j), A is full rank. Geometrically, this means that the lines are all parallel. So we can say that A above is full rank, unless all the lines are parallel.

Here is another solution of the problem (or really, a variation on the solution given above). If we define

C =

   

−v 1 0 · · · 0 I 0 −v 2 · · · 0 I .. .

. I

0 0 · · · −vm I

   

, d =

  

p 1 .. . pm

   ,^ u^ =

   

t 1 .. . tm z

   

we have (^) m ∑

i=

dist(z, Li)^2 = (^) tmin 1 ,...,tm ‖Cu − d‖,

and

min z

∑m i=

dist(z, Li)^2 = min u ‖Cu − d‖.

In the last expression, we are optimizing over the line parameters ti and the point z at the same time.

Therefore, assuming C is full rank, we have

z⋆^ =

[ 0 0 0 I

] (CT^ C)−^1 CT^ d,

which expands to the same solution we have above. And of course, C is full rank if and only if A is, which occurs exactly when the lines are not all parallel.

−20−20 −15 −10 −5 0 5 10 15 20

−

−

−

0

5

10

15

20

Figure 1: Point of closest convergence.

  1. Estimating direction and amplitude of a light beam. A light beam with (nonnegative) amplitude a comes from a direction d ∈ R^3 , where ‖d‖ = 1. (This means the beam travels in the direction −d.) The beam falls on m ≥ 3 photodetectors, each of which generates a scalar signal that depends on the beam amplitude and direction, and the direction in which the photodetector is pointed. Specifically, photodetector i generates an output signal pi, with pi = aα cos θi + vi, where θi is the angle between the beam direction d and the outward normal vector qi of the surface of the ith photodetector, and α is the photodetector sensitivity. You can interpret qi ∈ R^3 , which we assume has norm one, as the direction the ith photodetector is pointed. We assume that |θi| < 90 ◦, i.e., the beam illuminates the top of the photodetectors. The numbers vi are small measurement errors. You are given the photodetector direction vectors q 1 ,... , qm ∈ R^3 , the photodetector sensitivity α, and the noisy photodetector outputs, p 1 ,... , pm ∈ R. Your job is to estimate the beam direction d ∈ R^3 (which is a unit vector), and a, the beam amplitude. To describe unit vectors q 1 ,... , qm and d in R^3 we will use azimuth and elevation, defined as follows:

q =

 

cos φ cos θ cos φ sin θ sin φ

 .

Here φ is the elevation (which will be between 0◦^ and 90◦, since all unit vectors in this problem have positive 3rd component, i.e., point upward). The azimuth angle θ, which varies from 0◦^ to 360◦, gives the direction in the plane spanned by the first and second coordinates. If q = e 3 (i.e., the direction is directly up), the azimuth is undefined.

(a) Explain how to do this, using a method or methods from this class. The simpler the method the better. If some matrix (or matrices) needs to be full rank for your method to work, say so. (b) Carry out your method on the data given in beam_estim_data.m. This mfile defines p, the vector of photodetector outputs, a vector det_az, which gives the azimuth angles of the photodetector directions, and a vector det_el, which gives the elevation angles of the photodetector directions. Note that both of these are given in degrees, not radians. Give your final estimate of the beam amplitude a and beam direction d (in azimuth and elevation, in degrees).

Solution.

(a) Since cos θi = qTi d/(‖qi‖‖d‖) = qTi d (using ‖qi‖ = ‖d‖ = 1), we have

pi = aαqTi d + vi.

In this equation we are given pi, α, and qi; we are to estimate a ∈ R and d ∈ R^3 , using the given information that vi is small. At first glance it looks like a nonlinear problem, since two of the variables we need to estimate, a and d, are multiplied together in this formula. But a little thought reveals that things are actually much simpler. Let’s define x ∈ R^3 as x = ad. We can just as well work with x since given any nonzero x ∈ R^3 , we have a = ‖x‖ and d = x/‖x‖. (Conversely, given any a and d, we have x = ad by definition.) We can therefore express the problem in terms of the variable x as

p = α

  

q 1 T .. . qTm

   x^ +^ v^ =^ αQx^ +^ v,

where p = (p 1 ,... , pm), v = (v 1 ,... , vm), and Q is the matrix with rows qTi. Now we can get a reasonable guess of x using least-squares. Assuming Q is full rank, we have the least-squares estimate

xˆ = (1/α)(QT^ Q)−^1 QT^ p.

We then form estimates of a and d using ˆa = ‖ˆx‖, dˆ = ˆx/‖xˆ‖. The matrix Q is full rank (i.e., rank 3), if and only if the vectors {q 1 ,... , qm} span R^3. In other words, we cannot have all photodetectors pointing in a common plane. (b) The following code solves the problem for the given data.

  1. Minimum energy input with way-point constraints. We consider a vehicle that moves in R^2 due to an applied force input. We will use a discrete-time model, with time index k = 1, 2 ,.. .; time index k corresponds to time t = kh, where h > 0 is the sample interval. The position at time index k is denoted by p(k) ∈ R^2 , and the velocity by v(k) ∈ R^2 , for k = 1,... , K + 1. These are related by the equations

p(k + 1) = p(k) + hv(k), v(k + 1) = (1 − α)v(k) + (h/m)f (k), k = 1,... , K,

where f (k) ∈ R^2 is the force applied to the vehicle at time index k, m > 0 is the vehicle mass, and α ∈ (0, 1) models drag on the vehicle: In the absence of any other force, the vehicle velocity decreases by the factor 1 − α in each time index. (These formulas are approximations of more accurate formulas that we will see soon, but for the purposes of this problem, we consider them exact.) The vehicle starts at the origin, at rest, i.e., we have p(1) = 0, v(1) = 0. (We take k = 1 as the initial time, to simplify indexing.) The problem is to find forces f (1),... , f (K) ∈ R^2 that minimize the cost function

J =

∑^ K

k=

‖f (k)‖^2 ,

subject to way-point constraints

p(ki) = wi, i = 1,... , M,

where ki are integers between 1 and K. (These state that at the time ti = hki, the vehicle must pass through the location wi ∈ R^2 .) Note that there is no requirement on the vehicle velocity at the way-points.

(a) Explain how to solve this problem, given all the problem data (i.e., h, α, m, K, the way-points w 1 ,... , wM , and the way-point indices k 1 ,... , kM ). (b) Carry out your method on the specific problem instance with data h = 0.1, m = 1, α = 0.1, K = 100, and the M = 4 way-points

w 1 =

[ 2 2

] , w 2 =

[ − 2 3

] , w 3 =

[ 4 − 3

] , w 4 =

[ − 4 − 2

] ,

with way-point indices k 1 = 10, k 2 = 30, k 3 = 40, and k 4 = 80. Give the optimal value of J. Plot f 1 (k) and f 2 (k) versus k, using subplot(211); plot(f(1,:)); subplot(212); plot(f(2,:)); We assume here that f is a 2 × K matrix, with columns f (1),... , f (K). Plot the vehicle trajectory, using plot(p(1,:),p(2,:)). Here p is a 2 × (K + 1) matrix with columns p(1),... , p(K + 1).

(a) The equations of motion can be written as the discrete-time linear dynamical system x(k + 1) = Ax(k) + Bf (k), p(k) = Cx(k), x(1) = 0, where

x(k) =

[ p(k) v(k)

] , A =

[ I hI 0 (1 − α)I

] , B =

[ 0 (h/m)I

] , C = [ I 0 ].

We can solve these state equations to get x(k) in terms of the input forces f (1),... , f (k − 1):

x(k) = [ Ak−^2 B Ak−^3 B · · · B ]

   

f (1) f (2) .. . f (k − 1)

   

The position of the vehicle at way-point index ki is therefore

p(ki) = Cx(ki) = C[ Aki−^2 B Aki−^3 B · · · B ]

   

f (1) f (2) .. . f (ki − 1)

   

We can write the way-point constraint p(ki) = wki as

wi = C[ Aki−^2 B Aki−^3 B · · · B 0 · · · 0 ]

  

f (1) .. . f (K)

   ,

or equivalently , wi = Giu, where

u =

  

f (1) .. . f (K)

   ∈^ R

2 K , G

i =^ C[^ Aki−^2 B^ Aki−^3 B^ · · ·^ B^0 · · ·^ 0 ]^ ∈^ R

2 × 2 K .

Using notation

w =

  

w 1 .. . wM

   ,^ G^ =

  

G 1

GM

   ,

and noting that J = ‖u‖^2 , the problem becomes

minimize ‖u‖^2 subject to Gu = w.

−10 0 10 20 30 40 50 60 70 80 90 100

−

0

5

10

15

20

−15 0 10 20 30 40 50 60 70 80 90 100

−

−

0

5

10

k

k

f^1

f^2

Figure 2: f versus k.

% simulating the system p = zeros(2,K+1); v = zeros(2,K+1); for i=1:K p(:,i+1) = p(:,i) + hv(:,i); v(:,i+1) = (1-alpha)v(:,i) + h*f(:,i)/m; end

% Optimal value of J J = norm(u)^

figure; plot(p(1,:),p(2,:)); hold on ps = [w1 w2 w3 w4]; plot(ps(1,:),ps(2,:),’*’);

Figure (2) shows the minimum norm input forces. We see that for k ≥ 80, the optimal force is zero. This makes perfect sense: for k ≥ 80, the force f (k) does not affect the vehicle position at any of the way-points, so using any force on the vehicle for k ≥ 80 just increases the cost J.

−6−6 −4 −2 0 2 4 6

−

−

0

2

4

6

x

y

Figure 3: Trajectory in R^2.

The optimal value of J is found to be 4770.5.

Figure (3) shows the resulting trajectory.

Each gate has a delay di, which is given by

di = βi + γiC iload /xi,

where βi and γi are positive constants, and C iload is the load capacitance of gate i. Note that the gate delay di is always larger than βi, which can be intepreted as the minimum possible delay of gate i, achieved only in the limit as the gate scale factor becomes large.

The load capacitance of gate i is given by

C iload = C iext +

∑

j∈FO(i)

C jin ,

where C iext is a positive constant that accounts for the capacitance of the interconnect wires and external circuitry.

We will follow a simple design method, which assigns an equal delay T to all gates in the circuit, i.e., we have di = T , where T > 0 is given. For a given value of T , there may or may not exist a feasible design (i.e., a choice of the xi, with 1 ≤ xi ≤ xmax) that yields di = T for i = 1,... , n. We can assume, of course, that T > maxi βi, i.e., T is larger than the largest minimum delay of the gates.

Finally, we get to the problem.

(a) Explain how to find a design x⋆^ ∈ Rn^ that minimizes T , subject to a given area constraint A ≤ Amax. You can assume the fanout lists, and all constants in the problem description are known; your job is to find the scale factors xi. Be sure to explain how you determine if the design problem is feasible, i.e., whether or not there is an x that gives di = T , with 1 ≤ xi ≤ xmax, and A ≤ Amax. Your method can involve any of the methods or concepts we have seen so far in the course. It can also involve a simple search procedure, e.g., trying (many) different values of T over a range. Note: this problem concerns the general case, and not the simple example shown above. (b) Carry out your method on the particular circuit with data given in the file gate_sizing_data.m. The fan-out lists are given as an n × n matrix F, with i, j entry one if j ∈ FO(i), and zero otherwise. In other words, the ith row of F gives the fanout of gate i. The jth entry in the ith row is 1 if gate j is in the fan-out of gate i, and 0 otherwise.

Comments and hints.

  • You do not need to know anything about digital circuits; everything you need to know is stated above.
  • Yes, this problem does belong on the EE263 midterm.

Solution.

(a) We define the fanout matrix F as Fij = 1, if j ∈ FO(i), and Fij = 0 otherwise. The matrix F is strictly upper triangular, since FO(i) ⊆ {i + 1,... , n}. Using the formulas given above, and di = T , we have

T = di

= βi + γi

C iload xi

= βi + γi

C iext +

∑ j∈FO(i) C in j xi

= βi + γi

C iext +

∑ j∈FO(i) αj^ xj xi

Multiplying by xi we get the equivalent equations

T xi = βixi + γi

 C iext + ∑

j∈FO(i)

αj xj

  (^) ,

which we can express in matrix form as

T x = diag(β)x + diag(γ)Cext^ + diag(γ)F diag(α)x.

Defining K = diag(β) + diag(γ)F diag(α), we can write the equations as

(T I − K)x = diag(γ)Cext,

a set of n linear equations in n unknowns. So this problem really does belong in EE263, after all. For choices of T for which T I − K is nonsingular, there is only one solution of this set of linear equations,

x = (T I − K)−^1 diag(γ)Cext.

If this x happens to satisfy 1 ≤ xi ≤ xmax, and A = aT^ x ≤ Amax, then it is a feasible design. Our job, then, is to find the smallest T for which this occurs. If it occurs for no T , then the problem is infeasible. Let’s analyze the issue of singularity of T I −K. The matrix K is upper triangular, with diagonal elements βi. So T I − K is upper triangular, with diagonal elements T − βi. But these are all positive, by our assumption. So the matrix T I − K is nonsingular.

(^02) 2.5 3 3.5 4 4.5 5 5.5 6

1

2

3

4

(^02) 2.5 3 3.5 4 4.5 5 5.5 6

50

100

150

(^02) 2.5 3 3.5 4 4.5 5 5.5 6

100

200

300

400

500

T

max

xi i^

min

xi i

A

Figure 4: maxi xi, mini xi, and A versus T.

plot(Trange,Area) xlabel(’T’) ylabel(’A’) axis([2 6 0 500]) line([2,6],[400,400],’Color’,’r’) grid on

The output of the code is

T= 2.

Figure 4 shows how the minimum and maximum gate sizes, and the total area, vary with T , with the blue lines showing the limits. This shows that the feasible designs correspond to 2. 5194 ≤ T ≤ 5 .088.

A few more comments about this problem:

  • Since the matrix T I − K is upper triangular, we can solve for x very, very quickly. In fact, if we use sparse matrix operations, we can easily compute x very quickly (seconds or less) for a problem with n = 10^5 gates or more. You didn’t need to know this; we’re just pointing it out for fun.
  • The plots above show that as T increases, all of gate sizes decrease. This implies that mini xi, maxi xi, and A all decrease as T increases. This means you can use a more efficient bisection search to find the optimal T. Again, you didn’t need to know this; we’re just pointing it out.

Solution. Let bi be the ith column of B.

R(B) ⊆ R(A) ⇔ every column of B is in the range of A ⇔ there exists a vector zi such that bi = Azi ⇔ there exists a matrix Z ∈ Rn×n^ such that B = AZ ⇔ rank([ A B ]) = rank(A). (1)

This shows that statements a, e and i are equivalent.

N (A) ⊆ N (B) ⇔ N (A)⊥^ ⊇ N (B)⊥ ⇔ R(BT^ ) ⊆ R(AT^ ) ⇔ there exists a matrix Y˜ ∈ Rn×n^ such that BT^ = AT^ Y˜ ⇔ there exists a matrix Y ∈ Rn×n^ such that B = Y A ⇔ rank([ AT^ BT^ ]) = rank(AT^ )

⇔ rank(

[ A B

] ) = rank(A). (2)

This shows that statements b, g and k are equivalent.

R(A) ⊆ N (B) ⇔ for all z ∈ Rn, B(Az) = 0 ⇔ BA = 0. (3)

This shows that statements d and h are equivalent.

R(A) ⊥ N (BT^ ) ⇔ R(A) ⊆ N (BT^ )⊥ ⇔ R(A) ⊆ R(B) ⇔ rank([ A B ]) = rank(B). (4)

This shows that statements f and j are equivalent.

None of these groups of statements is equivalent to any other, or to c. This is demon- strated by the following counterexamples.

Take

A =

[ 1 0 0 0

] , B =

[ 0 0 1 0

] .

Since AB = 0 but BA 6 = 0, then group (3) and statement c are not equivalent. Furthermore since

rank(

[ A B

] ) = rank(A) = rank(B) = 1

but rank([A B]) = 2, groups (2) and (1) are not equivalent. Groups (2) and (4) are not either.

When A = B 6 = 0, N (A) = N (B) but AB = BA = A^2 6 = 0. Hence groups (2) and (3) are not equivalent. Group (2) and statement c are not equivalent either.

Take

A = I, B =

[ 0 0 1 0

] .

Since rank([AB]) = rank(A) = 2 but rank(B) = 1, groups (1) and (4) are not equivalent. Furthermore since BA 6 = 0 groups (1) and (3) are not equivalent. Since AB 6 = 0, group (1) and statement c aren’t either.

In a similar fashion, taking

A =

[ 0 0 1 0

] , B = I,

shows that groups (3) and (4) are not equivalent and that statement c and group (4) aren’t either.

Thus, the final answer is a, e, i b, g, k c d, h f, j.