Chapter 8: Gradients

Topics: gradient vector, gradients + matrix/vector operations, gradient descent, convexity, positive definite matrices

Problems below are collected from past exams; each links back to its full exam. Solutions are in the dropdowns.

Problems


FA25 MT2 · Problem 6: Quadratus Formulus 14 pts

From FA25 MT2

Let \(\displaystyle f(\vec x) = \frac{1}{2} \vec x^T S \vec x - \vec b^T \vec x\), where \(S\) is a symmetric \(n \times n\) matrix and \(\vec b \in \mathbb{R}^n\).

a)

4 pts Find \(\nabla f(\vec x)\), the gradient of \(f(\vec x)\). Show your work, and \(\boxed{\text{circle}}\) your final answer, which should be an expression in terms of \(\vec x\), \(S\), \(\vec b\), and/or constants. Hint: There’s no need to re-prove gradient rules from class.

Solution
$$ \begin{align*} \nabla f(\vec x) &= \nabla_{\vec x}\left(\frac{1}{2} \vec x^T S \vec x\right) - \nabla_{\vec x}\left(\vec b^T \vec x\right) \\\\ &= \frac{1}{2}(2S \vec x) - \vec b \\\\ &= \boxed{S\vec x - \vec b} \end{align*} $$
b)

2 pts True or False: As long as \(S\) is invertible, if \(\nabla f(\vec a) = \vec 0\), then \(\vec a\) is a global minimum of \(f(\vec x)\).

True False
Solution
True False

In general, this is false. Even if \(S\) is invertible, \(\nabla f(\vec a) = \vec 0\) could mean that \(\vec a\) is at a local maxima, local minima, or saddle point.

For example, let \(\vec x = \begin{bmatrix} x \\ y \end{bmatrix}\), \(\vec b = \begin{bmatrix} 0 \\ 0 \end{bmatrix}\), and \(S = \begin{bmatrix} 2 & 0 \\ 0 & -2 \end{bmatrix}\), which is an invertible matrix. Then,

$$ f(\vec x) = \frac{1}{2} \begin{bmatrix} x & y \end{bmatrix} \begin{bmatrix} 2 & 0 \\\\ 0 & -2 \end{bmatrix} \begin{bmatrix} x \\\\ y \end{bmatrix} - \begin{bmatrix} 0 \\\\ 0 \end{bmatrix} \cdot \begin{bmatrix} x \\\\ y \end{bmatrix} = x^2 - y^2 $$

but \(f(\vec x) = x^2 - y^2\) has no global minimum, since you can make \(f(\vec x)\) arbitrarily negative by setting \(x = 0\) and \(y = -\text{large number}\).

c)

2 pts True or False: As long as all of the components of \(S\) are positive real numbers, if

\(\nabla f(\vec a) = \vec 0\), then \(\vec a\) is a global minimum of \(f(\vec x)\).

True False
Solution
True False

This is also false. Even if all of the components of \(S\) are positive real numbers, \(f(\vec x)\) may not have a global minimum. As we saw later in the semester, the convexity of \(f\) has to do with whether or not \(S\) is positive semidefinite. But, this was not a concept we knew about on the midterm, so the problem is answerable without that concept.

Instead, the way to think through this is through counterexamples. For example, let \(\vec x = \begin{bmatrix} x \\ y \end{bmatrix}\), \(\vec b = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\), and \(S = \begin{bmatrix} 2 & 4 \\ 4 & 8 \end{bmatrix}\), which is a symmetric matrix with all positive real components. Then,

$$ f(\vec x) = \frac{1}{2} \begin{bmatrix} x & y \end{bmatrix} \begin{bmatrix} 2 & 4 \\\\ 4 & 8 \end{bmatrix} \begin{bmatrix} x \\\\ y \end{bmatrix} - \begin{bmatrix} 1 \\\\ 0 \end{bmatrix} \cdot \begin{bmatrix} x \\\\ y \end{bmatrix} = x^2 + 4xy + 4y^2 - x = (x + 2y)^2 - x $$

\(f(\vec x)\) has no global minimum, since you can keep decreasing the output by picking a really large positive value of \(x\) and set \(y = -\frac{x}{2}\), which makes

$$ f(\vec x) = (x + 2 \cdot -\frac{x}{2})^2 - x = 0 - x = -x $$
d)

6 pts We’d like to use gradient descent to minimize \(f(\vec x)\). Suppose \(S = \begin{bmatrix} 2 & 0 \\ 0 & 6 \end{bmatrix}\), \(\vec b = \begin{bmatrix} 1 \\ -4 \end{bmatrix}\), and we use a learning rate of \(\alpha = 1\). After one iteration of gradient descent, we have \(\vec x^{(1)} = \begin{bmatrix} - 2 \\ -4 \end{bmatrix}\). What was our initial guess, \(\vec x^{(0)}\)? Show your work, and \(\boxed{\text{circle}}\) your final answer, which should be a vector with two entries and no variables.

Solution

The gradient update rule is \(\vec x^{(t+1)} = \vec x^{(t)} - \alpha \nabla f(\vec x^{(t)})\). Plugging in \(\alpha = 1\) and \(t = 0\) simplifies our problem to

$$ \begin{align*} \vec x^{(1)} &= \vec x^{(0)}-\alpha \nabla f(\vec x^{(0)}) \\\\&= \vec x^{(0)}-(S\vec x^{(0)}-\vec b) \\\\&= \vec x^{(0)}-S\vec x^{(0)}+\vec b \end{align*} $$

Now, all we need to do is substitute our known vector \(\vec x^{(1)} = \begin{bmatrix} - 2 \\ -4 \end{bmatrix}\) and matrix \(S\) into the above equation and solve for \(\vec x^{(0)}\).

$$ \begin{align*} \\\\\begin{bmatrix} - 2 \\\\ -4 \end{bmatrix}&= \vec x^{(0)}-\begin{bmatrix} 2 & 0 \\\\ 0 & 6 \end{bmatrix}\vec x^{(0)}+\begin{bmatrix} 1 \\\\ -4 \end{bmatrix} \\\\\begin{bmatrix} - 3 \\\\ 0 \end{bmatrix}&= \vec x^{(0)}-\begin{bmatrix} 2 & 0 \\\\ 0 & 6 \end{bmatrix}\vec x^{(0)} \\\\\begin{bmatrix} - 3 \\\\ 0 \end{bmatrix}&= \vec x^{(0)}-\begin{bmatrix} 2x^{(0)}_1 \\\\ 6x^{(0)}_2 \end{bmatrix} \\\\\begin{bmatrix} - 3 \\\\ 0 \end{bmatrix}&= \begin{bmatrix} -x^{(0)}_1 \\\\ -5x^{(0)}_2 \end{bmatrix} \\\\ x^{(0)}_1=3 &, \: x^{(0)}_2 = 0 \end{align*} $$

So, our initial guess was

$$ \boxed{\vec x^{(0)}=\begin{bmatrix}3 \\\\ 0 \end{bmatrix}} $$

FA25 MT2 · Problem 7: Complexity 10 pts

From FA25 MT2

Suppose \(f: \mathbb{R} \to \mathbb{R}\) is a convex function.

a)

4 pts Find scalars \(a\) and \(b\) such that \(f(3) \leq a f(2) + b f(6)\). Show your work and \(\boxed{\text{circle}}\) your final answer, which should be a pair of scalars.

Solution

Recall the definition of convexity (which is relevant, since \(f\) is told to us to be convex):

$$ f((1-t) x + ty) \leq (1-t) f(x) + t f(y) $$

Matching the right-side of the inequality above to the right-side of the inequality given, we see that \(a = 1-t\) and \(b = t\).

So, our job is to find \(1-t\) and \(t\) such that

$$ 3 = (1-t) \cdot 2 + t \cdot 6 $$

i.e. \(\textbf{to write 3 as a linear combination of 2 and 6}\).

$$ 3 = (1 - t) \cdot 2 + t \cdot 6 = 2 - 2t + 6t = 2 + 4t \implies t = \frac{3 - 2}{4} = \frac{1}{4} $$

So, \(\boxed{a = \frac{3}{4}, b = \frac{1}{4}}\).

b)

6 pts Using the result from part a), prove that \(f(3) + f(5) \leq f(2) + f(6)\).

Solution

In part a), we proved

$$ f(3) \leq \frac{3}{4} f(2) + \frac{1}{4} f(6) $$

Since there’s an \(f(5)\) in the left side of expression we want to prove, we need to find an inequality for \(f(5)\) in terms of \(f(2)\) and \(f(6)\).

Trying to match the pattern, let \(t = \frac{3}{4}\), and keep \(x = 2\) and \(y = 6\). Where did \(t = \frac{3}{4}\) come from? You could have found it from solving \((1-t) \cdot 2 + t \cdot 6 = 5\), or by guessing/observing that no other value of \(t\) would eventually allow us to add the two inequalities together to get \(f(2) + f(6)\) on the right.

$$ \begin{align*} f((1-t)x + ty) &\leq (1-t)f(x) + t f(y) \\\\ f\left( (1-\frac{3}{4}) \cdot 2 + \frac{3}{4} \cdot 6 \right) &\leq (1-\frac{3}{4}) f(2) + \frac{3}{4} f(6) \\\\ f(5) &\leq \frac{1}{4} f(2) + \frac{3}{4} f(6) \end{align*} $$

Let’s add this to our previous inequality.

$$ \begin{align*} f(3) + f(5) &\leq \frac{3}{4} f(2) + \frac{1}{4} f(6) + \frac{1}{4} f(2) + \frac{3}{4} f(6) \\\\ f(3) + f(5) &\leq f(2) + f(6) \end{align*} $$

as required!


FA25 Final · Problem 6 4 pts MT2 Redemption

From FA25 Final

Suppose \(A\) and \(B\) are both (not necessarily symmetric!) \(n \times n\) matrices. Which of the following is \(\nabla f(\vec x)\), the gradient of

$$ f(\vec x) = (A \vec x)^T (B \vec x) $$
\(2AB \vec x\) \(A^TB \vec x\) \(2A^TB \vec x\) \(2B^TA \vec x\) \((A^TB + B^TA) \vec x\) \((A^TB - B^TA) \vec x\)
Solution
\(2AB \vec x\) \(A^TB \vec x\) \(2A^TB \vec x\) \(2B^TA \vec x\) \((A^TB + B^TA) \vec x\) \((A^TB - B^TA) \vec x\)

We can rewrite the function as

$$ f(\vec x) = (A\vec x)^T(B\vec x) = \vec x^T A^T B \vec x $$

If \(M\) is any matrix, then

$$ \nabla(\vec x^T M \vec x) = (M + M^T)\vec x $$

Here, \(M = A^TB\), so

$$ \nabla f(\vec x) = \left(A^TB + (A^TB)^T\right)\vec x = \boxed{(A^TB + B^TA)\vec x} $$

FA25 Final · Problem 7 6 pts MT2 Redemption

From FA25 Final

Consider the function \(f: \mathbb{R} \to \mathbb{R}\) graphed below.

image

Note that \(f\) is a piecewise linear function, with slopes of \(0\), \(4\), and \(-4\). The slope changes at the following values of \(x\): \(-6, -5, -2, -1, 1, 2, 5, 6\).

Suppose we want to minimize \(f(x)\) using gradient descent. There are several values of \(x\) such that \(f\) is not differentiable at \(x\); if any of our guesses \(x^{(0)}, x^{(1)}, x^{(2)}, \ldots\) ever evaluate to one of these values, we say that gradient descent crashes.

a)

2 pts True or False: \(f(x)\) is convex on the domain \(x \in [-9, 9]\).

True False
Solution
True False

This is false. In order for a function to be convex, it must be the case that we can draw a line segment between any two points on the function and the line segment never passes below the function, but this is not the case for this \(f\). For example, connect \((-3, 1)\) to \((-1, -3)\); the line segment is entirely beneath the function.

b)

4 pts Suppose we choose a learning rate/step size of \(\alpha = 0.1\).

Among the options below, which value of \(x^{(0)}\) will allow gradient descent to converge to the global minimum of \(f(x)\) without crashing?

If multiple values of \(x^{(0)}\) are possible, select the value that converges the quickest (i.e. in the fewest number of iterations).

\(1.4\) \(1.6\) \(1.8\) \(1.9\) \(2.0\)
Solution
\(1.4\) \(1.6\) \(1.8\) \(1.9\) \(2.0\)

When \(x\) is between \(1\) and \(2\), the slope is 4, so with learning rate \(\alpha = 0.1\), gradient descent updates by

$$ x^{(t+1)} = x^{(t)} - 0.1(4) = x^{(t)} - 0.4 $$

Now, let’s check the options:

  • \(1.4 \to 1.0\), so gradient descent crashes at the nondifferentiable point \(x=1\).

  • \(1.6 \to 1.2 \to 0.8\), so it reaches the flat global-minimum region without crashing.

  • \(1.8 \to 1.4 \to 1.0\), so it crashes.

  • \(1.9 \to 1.5 \to 1.1 \to 0.7\), so it also works, but it takes more iterations than starting at 1.6.

  • Starting at \(2.0\) crashes immediately, because \(f\) is not differentiable there.

Therefore, the correct choice is \(\boxed{1.6}\).


WN26 MT2 · Problem 7 10 pts

From WN26 MT2

a)

6 pts Suppose \(A\) is a \(4 \times 4\) matrix and \(\vec x \in \mathbb{R}^4\). Furthermore, suppose that the gradient of the function \(f(\vec x) = \vec x^T A \vec x\) is given by

$$ \nabla f(\vec x) = \begin{bmatrix} 2x_1 \\\\ -15 x_2 \\\\ 10 x_3 \\\\ x_4 \end{bmatrix} $$

Find one possible matrix \(A\). Your answer should be a \(4 \times 4\) matrix with no variables.

\(A = \_\_\_\_\_\_\)

Solution

Recall that for

$$ f(\vec x) = \vec x^T A \vec x, $$

the gradient is

$$ \nabla f(\vec x) = (A + A^T)\vec x $$

We want

$$ (A + A^T)\vec x = \begin{bmatrix} 2x_1 \\\\ -15x_2 \\\\ 10x_3 \\\\ x_4 \end{bmatrix} $$

One easy way to make this happen is to choose \(A\) to be diagonal and symmetric. Then \(A + A^T = 2A\), so we want

$$ \begin{align*} 2A &= \begin{bmatrix} 2 & 0 & 0 & 0 \\\\ 0 & -15 & 0 & 0 \\\\ 0 & 0 & 10 & 0 \\\\ 0 & 0 & 0 & 1 \end{bmatrix} \end{align*} $$

Thus, one possible choice is

$$ A = \begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & -15/2 & 0 & 0 \\\\ 0 & 0 & 5 & 0 \\\\ 0 & 0 & 0 & 1/2 \end{bmatrix} $$
b)

4 pts Suppose \(A\) is an \(n \times n\) matrix, \(\vec b \in \mathbb{R}^n\), and that \(g: \mathbb{R}^n \to \mathbb{R}\) is defined by

$$ g(\vec x) = (\vec b^T A \vec x)^2 $$

Which of the following is \(\nabla g(\vec x)\), the gradient of \(g(\vec x)\)?

\(2 A^T \vec b\)

\((\vec b^T A \vec x) A^T \vec b\)

\(2 (\vec b^T A \vec x) \vec b\)

\(2 (\vec b^T A \vec x) A^T \vec b\)

\(2 (\vec b^T A \vec x) A^T \vec x\)

None of the above

Solution

None of the above

Let

$$ f(\vec x) = \vec b^T A \vec x = (A^T \vec b)^T \vec x = (A^T \vec b) \cdot \vec x $$

Then

$$ g(\vec x) = (g(\vec x))^2 $$

The gradient of \(f(\vec x)\) can be computed using the dot product “big three” rule, which tells us that

$$ \nabla f(\vec x) = A^T \vec b $$

Applying the chain rule,

$$ \begin{align*} \nabla g(\vec x) &= 2 f(\vec x) \nabla f(\vec x) \\\\ &= 2 (\vec b^T A \vec x) A^T \vec b \end{align*} $$

WN26 MT2 · Problem 8 11 pts

From WN26 MT2

Let \(\vec x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\). Consider the function

$$ f(\vec x) = (x_1 + x_2 - 4)^2 $$
a)

3 pts Fill in the blanks: The set of all vectors \(\vec x^{\ast}\) that minimize \(f(\vec x)\) form a __(i)__ in \(\mathbb{R}^2\). This set __(ii)__ a subspace of \(\mathbb{R}^2\).

  1. point line plane
  2. is not is
    Solution
    is not is

    We have

    $$ f(\vec x) = (x_1 + x_2 - 4)^2 $$

    so the minimum value is 0, which happens exactly when

    $$ x_1 + x_2 - 4 = 0 \iff x_1 + x_2 = 4 $$

    The equation

    $$ x_1 + x_2 = 4 $$

    describes a line in \(\mathbb{R}^2\).

    This line is not a subspace, because it does not pass through the origin. For example,

    $$ \begin{bmatrix} 0 \\\\ 0 \end{bmatrix} $$

    is not a minimizer. Therefore, this set is not a subspace.

b)

8 pts Suppose we use gradient descent to minimize \(f(\vec x)\) using an initial guess of \(\vec x^{(0)} = \begin{bmatrix} 1 \\ 1 \end{bmatrix}\).

Find the learning rate/step size \(\alpha\) that will cause gradient descent to converge to a global minimum of \(f(\vec x)\) in one iteration, i.e. such that \(\vec x^{(1)}\) is a minimizer of \(f(\vec x)\).

Show your work in the space provided, and write your final answer in the bottom-right corner of the box. Your answer should be a number with no variables.

$$ \alpha = \_\_\_\_\_\_ $$
Solution

First, we need to compute the gradient of \(f(\vec x)\):

$$ f(\vec x) = (x_1 + x_2 - 4)^2 \quad \Longrightarrow \quad \nabla f(\vec x) = \begin{bmatrix} 2(x_1 + x_2 - 4) \\\\ 2(x_1 + x_2 - 4) \end{bmatrix} $$

At

$$ \vec x^{(0)} = \begin{bmatrix} 1 \\\\ 1 \end{bmatrix} $$

we have

$$ x_1^{(0)} + x_2^{(0)} - 4 = 1 + 1 - 4 = -2 $$

so

$$ \nabla f(\vec x^{(0)}) = \begin{bmatrix} -4 \\\\ -4 \end{bmatrix} $$

One gradient descent step gives

$$ \begin{align*} \vec x^{(1)} &= \vec x^{(0)} - \alpha \nabla f(\vec x^{(0)}) \\\\ &= \begin{bmatrix} 1 \\\\ 1 \end{bmatrix} - \alpha \begin{bmatrix} -4 \\\\ -4 \end{bmatrix} \\\\ &= \begin{bmatrix} 1 + 4\alpha \\\\ 1 + 4\alpha \end{bmatrix} \end{align*} $$

We want \(\vec x^{(1)}\) to be a minimizer, so it must satisfy

$$ x_1^{(1)} + x_2^{(1)} = 4 $$

That gives

$$ \begin{align*} (1 + 4\alpha) + (1 + 4\alpha) &= 4 \\\\ 2 + 8\alpha &= 4 \\\\ 8\alpha &= 2 \\\\ \alpha &= \frac{1}{4} \end{align*} $$

WN26 Final · Problem 8 9 pts MT2 Redemption

From WN26 Final

Consider the function \(g: \mathbb{R}^3 \to \mathbb{R}\). We’d like to minimize \(g\) using gradient descent.

a)

(6 pts) Suppose two separate runs of gradient descent are started from the same initial guess \(\vec x^{(0)}\), but with different learning rates (step sizes), \(\alpha\).

If \(\alpha = 1/2\), then \(\vec x^{(1)} = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}\), and if \(\alpha = 1/4\), then \(\vec x^{(1)} = \begin{bmatrix} 2 \\ 3 \\ 2 \end{bmatrix}\).

Find \(\nabla g(\vec x^{(0)})\), the gradient of \(g\) at \(\vec x^{(0)}\). Show your work, and write your final answer in the box provided. Your answer should be a vector with no variables.

$$ \nabla g(\vec x^{(0)}) = \_\_\_\_\_\_ $$
Solution

Let \(\vec d = \nabla g(\vec x^{(0)})\). The gradient descent update rule is

$$ \vec x^{(1)} = \vec x^{(0)} - \alpha \nabla g(\vec x^{(0)}) $$

The two runs give

$$ \begin{bmatrix} 1\\\\ 1\\\\ 1 \end{bmatrix} = \vec x^{(0)} - \frac{1}{2}\nabla g(\vec x^{(0)}) $$

and

$$ \begin{bmatrix} 2\\\\ 3\\\\ 2 \end{bmatrix} = \vec x^{(0)} - \frac{1}{4}\nabla g(\vec x^{(0)}) $$

Subtracting the second equation from the first eliminates \(\vec x^{(0)}\):

$$ \begin{bmatrix} -1\\\\ -2\\\\ -1 \end{bmatrix} = -\frac{1}{4}\nabla g(\vec x^{(0)}) $$

So

$$ \nabla g(\vec x^{(0)}) = \boxed{ \begin{bmatrix} 4\\\\ 8\\\\ 4 \end{bmatrix}} $$

Now let \(\vec x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\), and consider the function \(f: \mathbb{R}^2 \to \mathbb{R}\) defined by

$$ f(\vec x) = (x_1 + 2x_2 - 6)^2 + \lVert \vec x \rVert^2 $$
b)

3 pts Suppose

$$ \nabla f(\vec x) = M \begin{bmatrix} x_1\\\\ x_2\\\\ 1 \end{bmatrix} $$

for some \(2 \times 3\) matrix \(M\). Which of the following matrices is \(M\)?

\(\begin{bmatrix} 2 & 2 & -6 \\ 2 & 5 & -12 \end{bmatrix}\) \(\begin{bmatrix} 4 & 2 & -12 \\ 2 & 10 & -24 \end{bmatrix}\) \(\begin{bmatrix} 4 & 4 & -12 \\ 4 & 10 & -24 \end{bmatrix}\) \(\begin{bmatrix} 4 & 4 & 12 \\ 4 & 10 & 24 \end{bmatrix}\) \(\begin{bmatrix} 4 & 4 & -12 \\ 2 & 6 & -12 \end{bmatrix}\)
Solution

\(\begin{bmatrix} 4 & 4 & -12 \\ 2 & 6 & -12 \end{bmatrix}\)

We have

$$ f(\vec x) = (x_1 + 2x_2 - 6)^2 + \lVert \vec x \rVert^2 $$

Using the chain rule,

$$ \nabla f(\vec x) = 2(x_1+2x_2-6) \begin{bmatrix} 1\\\\ 2 \end{bmatrix} + 2\vec x $$

We applied the chain rule above by writing \(\left( x_1 + 2x_2 - 6 \right)^2 = (\begin{bmatrix} 1 \\ 2 \end{bmatrix} \cdot \vec x - 6)^2\). If this feels foreign, we can instead take partial derivatives with respect to \(x_1\) and \(x_2\) separately.

$$ \frac{\partial f}{\partial x_1} = 2(x_1 + 2x_2 - 6) \cdot 1 + 2x_1 = 4x_1 + 4x_2 - 12 $$
$$ \frac{\partial f}{\partial x_2} = 2(x_1 + 2x_2 - 6) \cdot 2 + 2x_2 = 4x_1 + 10x_2 - 24 $$

Either way, \(\nabla f(\vec x)\) simplifies to

$$ \nabla f(\vec x) = \begin{bmatrix} 2(x_1+2x_2-6)+2x_1\\\\ 4(x_1+2x_2-6)+2x_2 \end{bmatrix} = \begin{bmatrix} 4x_1+4x_2-12\\\\ 4x_1+10x_2-24 \end{bmatrix} = \begin{bmatrix} 4 & 4 & -12\\\\ 4 & 10 & -24 \end{bmatrix} \begin{bmatrix} x_1 \\\\ x_2 \\\\ 1 \end{bmatrix} $$

So,

$$ M = \boxed{ \begin{bmatrix} 4 & 4 & -12\\\\ 4 & 10 & -24 \end{bmatrix}} $$

SP26 MT2 · Problem 6 12 pts

From SP26 MT2

Suppose \(A\) is an \(n \times d\) matrix and \(\vec x \in \mathbb{R}^d\). Consider the function \(f: \mathbb{R}^d \to \mathbb{R}\) given by

$$ f(\vec x) = \left\|A\vec x\right\| $$
a)

2 pts True or False: \(f(\vec x)\) is a linear transformation.

True False
Solution
True False

This is false. Recall, a linear transformation must satisfy \(f(c \vec x) = c f(\vec x)\) for any scalar \(c\). But, suppose we pick \(n = d = 1\), and let \(A = [1]\) (here we’re thinking of a \(1 \times 1\) matrix as a scalar). Then, \(f(x)\) is just the absolute value of the scalar \(x\).

$$ f(x) = |x| $$

But, \(f(-2) = 2\) is not the same as \(-2 f(1) = -2\). So, this \(f(x)\) is not a linear transformation, and thus in general \(f(\vec x) = \lVert A \vec x \rVert\) is not a linear transformation.

Another way to think about why \(f(\vec x)\) is not linear is to use the fact that \(\lVert A \vec x \rVert^2 = \vec x^T A^T A \vec x\):

$$ f(\vec x) = \sqrt{\vec x^T A^T A \vec x} $$

\(f(\vec x)\) is the square root of a quadratic form, which is not linear.

b)

10 pts Find \(\nabla f(\vec x)\). Assume that \(A \vec x \neq \vec 0\). Show your work, and write your final answer in the bottom-right corner of the box. Your answer should be an expression in terms of \(A\), \(\vec x\), and/or constants. Hint: Start by taking the gradient of \(\lVert A \vec x \rVert^2\), then apply the chain rule.

$$ \nabla f(\vec x) = \_\_\_\_\_\_ $$
Solution

As the hint suggests, let’s start by writing

$$ \left\|A\vec x\right\|^2 = (A\vec x)^T(A\vec x) = \vec x^T A^T A \vec x $$

Using the quadratic-form gradient rule,

$$ \nabla \left\|A\vec x\right\|^2 = 2A^TA\vec x $$

Now,

$$ f(\vec x) = \left\|A\vec x\right\| = \sqrt{\left\|A\vec x\right\|^2} $$

The chain rule from Chapter 8.2 states that if \(f(\vec x) = h(g(\vec x))\), where \(h: \mathbb{R} \to \mathbb{R}\) and \(g: \mathbb{R}^d \to \mathbb{R}\) are both differentiable, then \(\nabla f(\vec x) = h’(g(\vec x)) \nabla g(\vec x)\).

Here, \(h(x) = \sqrt{x}\) (so \(h’(x) = \displaystyle \frac{1}{2\sqrt{x}}\)) and \(g(\vec x) = \left|A\vec x\right|^2\), so

$$ \nabla f(\vec x) = \frac{1}{2\sqrt{\left\|A\vec x\right\|^2}} \left( 2A^TA\vec x \right) = \frac{A^TA\vec x}{\left\|A\vec x\right\|} $$

SP26 MT2 · Problem 7 15 pts

From SP26 MT2

Let \(\vec x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\). Consider the function \(f: \mathbb{R}^2 \to \mathbb{R}\) given by

$$ f(\vec x) = c x_1^2 + d x_2^2 $$

where \(c\) and \(d\) are constants. We’d like to use gradient descent to minimize \(f(\vec x)\). For some values of \(c\) and \(d\), and some initial guess \(\vec x^{(0)}\) and learning rate/step size \(\alpha\), we find that

$$ \vec x^{(1)} = \begin{bmatrix} 4 \\\\ 1 \end{bmatrix}, \qquad \nabla f(\vec x^{(1)}) = \begin{bmatrix} 6 \\\\ -2 \end{bmatrix}, \qquad \vec x^{(2)} = \begin{bmatrix} 2.8 \\\\ 1.4 \end{bmatrix} $$
a)

5 pts Find the value of \(\alpha\). Show your work, and write your final answer in the bottom-right corner of the box. Your answer should be a number with no variables.

$$ \alpha = \_\_\_\_\_\_ $$
Solution

Gradient descent uses the update

$$ \vec x^{(2)} = \vec x^{(1)} - \alpha \nabla f(\vec x^{(1)}) $$

Substituting the given values,

$$ \begin{bmatrix} 2.8 \\\\ 1.4 \end{bmatrix} = \begin{bmatrix} 4 \\\\ 1 \end{bmatrix} - \alpha \begin{bmatrix} 6 \\\\ -2 \end{bmatrix} = \begin{bmatrix} 4 - 6\alpha \\\\ 1 + 2\alpha \end{bmatrix} $$

Using either component,

$$ \begin{align*} 4 - 6\alpha &= 2.8 \\\\ 6\alpha &= 1.2 \\\\ \alpha &= \frac{1}{5} \end{align*} $$
b)

5 pts Find the value of \(d\) (not \(c\)). Show your work, and write your final answer in the bottom-right corner of the boxes. Your answer should be a number with no variables.

$$ d = \_\_\_\_\_\_ $$
Solution

The gradient of

$$ f(\vec x) = cx_1^2 + dx_2^2 $$

is

$$ \nabla f(\vec x) = \begin{bmatrix} 2cx_1 \\\\ 2dx_2 \end{bmatrix} $$

At \(\vec x^{(1)} = \begin{bmatrix} 4 \\ 1 \end{bmatrix}\), we’re told that

$$ \nabla f(\vec x^{(1)}) = \begin{bmatrix} 6 \\\\ -2 \end{bmatrix} $$

Using the second component (because we’re only asked for \(d\)),

$$ \begin{align*} 2d(1) &= -2 \\\\ d &= -1 \end{align*} $$
c)

5 pts Your friend claims that gradient descent always converges to a minimum because each iteration moves in the direction of steepest decrease. Based on the information in this problem, is your friend correct? State “yes” or “no”, and briefly explain your reasoning.

Solution

No. From part b), \(d=-1\), so

$$ f(\vec x) = cx_1^2 - x_2^2 $$

This function does not have a minimum, because we can make \(f(\vec x)\) arbitrarily negative by making \(|x_2|\) arbitrarily large. So, in this problem, gradient descent cannot converge to a minimum.


SP26 Final · Problem 9 9 pts MT2 Redemption

From SP26 Final

Let \(\vec a \in \mathbb{R}^2\) and let

$$ f(\vec x) = \log(\vec a \cdot \vec x) $$

for all vectors \(\vec x\) such that \(\vec a \cdot \vec x > 0\); if \(\vec a \cdot \vec x \leq 0\), then \(f(\vec x)\) is undefined. Suppose that

$$ \nabla f\left(\begin{bmatrix}2\\\\1\end{bmatrix}\right) = \begin{bmatrix}1/5\\\\3/5\end{bmatrix} $$
a)

3 pts Which of the following could be \(\vec a\)? Select all that apply.

\(\begin{bmatrix}3\\1\end{bmatrix}\) \(\begin{bmatrix}1\\3\end{bmatrix}\) \(\begin{bmatrix}-1\\-3\end{bmatrix}\) \(\begin{bmatrix}1\\2\end{bmatrix}\) \(\begin{bmatrix}5\\3\end{bmatrix}\) \(\begin{bmatrix}2\\6\end{bmatrix}\)
Solution

\(\begin{bmatrix}2\\6\end{bmatrix}\)

Let

$$ g(\vec{x})=\vec{a}\cdot\vec{x}=a_1x_1+a_2x_2 \qquad\text{and}\qquad h(u)=\log(u) $$

Then \(f(\vec{x})=h(g(\vec{x}))\). Using the chain rule from Chapter 8.2,

$$ \nabla f(\vec{x}) = h'(g(\vec{x}))\nabla g(\vec{x}) $$

Now,

$$ h'(u)=\frac{1}{u} \qquad\text{and}\qquad \nabla g(\vec{x})= \begin{bmatrix}a_1\\\\a_2\end{bmatrix} =\vec{a} $$

so

$$ \nabla f(\vec{x}) = h'(\vec a \cdot \vec x) \nabla g(\vec{x}) = \frac{\vec{a}}{\vec{a}\cdot\vec{x}} $$

At \(\vec{x}=\begin{bmatrix}2\\1\end{bmatrix}\), this becomes

$$ \frac{\vec{a}}{2a_1+a_2} = \begin{bmatrix}1/5\\\\3/5\end{bmatrix} $$

Since \(f\) is defined at \(\begin{bmatrix}2\\1\end{bmatrix}\), this must mean that \(\vec a \cdot \vec x\), which is equal to \(2a_1 + a_2\), is positive. Multiplying both sides by this positive denominator gives

$$ \vec{a} = (2a_1+a_2) \begin{bmatrix}1/5\\\\3/5\end{bmatrix} = \frac{2a_1+a_2}{5} \begin{bmatrix}1\\\\3\end{bmatrix} $$

This says \(\vec{a}\) must be a positive scalar multiple of \(\begin{bmatrix}1\\3\end{bmatrix}\). Among the answer choices, the vectors with that form are \(\begin{bmatrix}1\\3\end{bmatrix}\) and \(\begin{bmatrix}2\\6\end{bmatrix}\).

Another way to approach this would be to take the equation

$$ \frac{\vec a}{2a_1+a_2} = \begin{bmatrix}1/5\\\\3/5\end{bmatrix} $$

from above, and realize the expression on the right is also equal to \(\frac{1}{2a_1+a_2} \begin{bmatrix}a_1\\a_2\end{bmatrix}\), which allows us to set up a system of equations directly for \(a_1\) and \(a_2\):

$$ \begin{align*} \frac{a_1}{2a_1+a_2} &= 1/5 \\\\ \frac{a_2}{2a_1+a_2} &= 3/5 \end{align*} $$

Both equations say the same thing: \(a_2 = 3a_1\), i.e. that \(a_2\) must be triple \(a_1\), so \(\vec a\) is a scalar multiple of \(\begin{bmatrix}1\\3\end{bmatrix}\). But, don’t forget the added constraint that \(2a_1 + a_2\) must be positive.

b)

4 pts Suppose we use gradient descent to minimize \(f(\vec x)\) using an initial guess of \(\vec x^{(0)} = \begin{bmatrix} 2 \\ 1 \end{bmatrix}\) and a learning rate of \(\alpha = 1/2\). Find \(\vec x^{(1)}\). Show your work, and write your answer in the box provided. Your answer should be a vector with no variables.

$$ \vec x^{(1)} = \_\_\_\_\_\_ $$
Solution

The gradient descent update from Chapter 8.3 is

$$ \vec{x}^{(1)} = \vec{x}^{(0)}-\alpha\nabla f(\vec{x}^{(0)}) $$

Here, \(\vec{x}^{(0)}=\begin{bmatrix}2\\1\end{bmatrix}\), \(\alpha=1/2\), and \(\nabla f(\vec{x}^{(0)})=\begin{bmatrix}1/5\\3/5\end{bmatrix}\). So,

$$ \vec{x}^{(1)} = \begin{bmatrix}2\\\\1\end{bmatrix} - \frac{1}{2}\begin{bmatrix}1/5\\\\3/5\end{bmatrix} = \begin{bmatrix}2\\\\1\end{bmatrix} - \begin{bmatrix}1/10\\\\3/10\end{bmatrix} = \begin{bmatrix}19/10\\\\7/10\end{bmatrix} $$
c)

2 pts This part is unrelated to the previous parts.

Suppose \(g: \mathbb{R} \to \mathbb{R}\). True or false: if \(g\) has a global minimum and no local maxima, it must be convex.

True False
Solution
True False

This is false. For instance, consider

$$ g(x)=x^4+x^3 $$

This function has a global minimum, since \(g(x)\to\infty\) as \(x\to\infty\) and as \(x\to-\infty\). Also,

$$ g'(x)=4x^3+3x^2=x^2(4x+3) $$

The derivative only changes sign at \(x=-3/4\), where it changes from negative to positive, so \(g\) has a local minimum and no local maxima. But,

$$ g''(x)=12x^2+6x $$

which is negative for some \(x\) values, for instance \(x=-1/4\). So \(g\) is not convex. See Chapter 8.5 for the convexity condition.

image