using MLDatasets
# training images
size(MNIST().features)
(28, 28, 60000)
Due Oct 13 @ 11:59pm
Submit a PDF (scanned/photographed from handwritten solutions, or converted from RMarkdown or Jupyter Notebook or Quarto) to Gradescope in BruinLearn.
Use the Cauchy-Schwarz inequality to prove that \[ - \frac{1}{\sqrt{n}} \|\mathbf{x}\| \le \frac{1}{n} \sum_{i=1}^n x_i \le \frac{1}{\sqrt{n}} \|\mathbf{x}\| \] for any \(\mathbf{x} \in \mathbb{R}^n\). In other words, \(-\operatorname{rms}(\mathbf{x}) \le \operatorname{avg}(\mathbf{x}) \le \operatorname{rms}(\mathbf{x})\).
What are the conditions on \(\mathbf{x}\) to have equality in the upper bound? When do we have equality in the lower bound?
Use the Cauchy-Schwartz inequality to prove that \[ \frac{1}{n} \sum_{i=1}^n x_i \ge \left( \frac{1}{n} \sum_{i=1}^n \frac{1}{x_i} \right)^{-1} \] for any \(\mathbf{x} \in \mathbb{R}^n\) with positive entries \(x_i\).
The left hand side is called the arithmetic mean (AM) and the right hand side is called the harmonic mean (HM). You may wonder what can be a practical use of such a simple inequality. See this paper, which uses the AM-GM inequality to derive a class of optimization algorithms for geometric and signomial programming.
Show the norm property \[ \|\mathbf{A} \mathbf{B}\| \le \|\mathbf{A}\| \|\mathbf{B}\| \] for the Frobenius norm. Hint: Cauchy-Schwartz inequality.
BV exercise 6.14 is a special case of this result.
Read BV Chapter 4.
BV exercise 4.1.
(Optional) Implement the \(k\)-means algorithm (BV Algorithm 4.1) and apply to the 60,000 MNIST training images with \(k=20\). Can we reproduce the Figures 4.7-4.9 in BV textbook? For Julia users, you can start with the following code.
using MLDatasets
# training images
size(MNIST().features)
(28, 28, 60000)
# vec each image into a 784-vector
= reshape(MNIST().features, (28 * 28, 60000)) X
784×60000 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0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