Students may discuss homework exercises with one another. However, sharing, copying, or providing any part of a completed homework solution or code is an infraction of the University’s rules on Academic Integrity. Any violation will be punished as severely as possible. Final submissions must be uploaded to Gradescope using entry code XE3YJ6 (course ID 1370811). No email or hard copy will be accepted. For late submission policy and grading rubrics, please refer to the course website.
You are only required to complete five of the six questions. You may choose any five.
You are required to submit the rendered file
HWx_yourNetID.pdf. For example,
HW01_rqzhu.pdf. Please note that this must be a
.pdf file. .html format
cannot be accepted since they may not be readable in
Gradescope. All proofs must be typed in LaTeX format. Make all of your
R code chunks visible for grading.
Include your Name and NetID in the report.
If you use this file or the example homework .Rmd
file as a template, be sure to remove this instruction
section.
On random seed and reproducibility: You should
use R version \(\geq
4.0.0\). This will ensure your random seed generation is the same
as everyone else. Please note that updating the R version
may require you to reinstall all of your packages. In the markdown file,
set seed properly so that the results can be
reproduced.
For some questions, there will be restrictions on what packages/functions you can use. Please read the requirements carefully. As long as the question does not specify such restrictions, you can use anything.
Using AI tools: You must provide a brief statement describing any use of AI tools in your homework. You remain responsible for the reasoning, code, interpretation, and correctness of your submission.
Let \(x,y \in \mathbb{R}^p\).
\[ k_1(x,y) = (x^T y)^2 \]
Expand \(k_1(x,y)\) and show that it can be written as
\[ k_1(x,y) = \langle \Phi_1(x), \Phi_1(y) \rangle \]
for some feature mapping \(\Phi_1\) containing second-order terms of \(x\).
\[ k_2(x,y) = (x^T y + 1)^2 \]
Using your result from part (a), find a feature mapping \(\Phi_2\) such that
\[ k_2(x,y) = \langle \Phi_2(x), \Phi_2(y) \rangle \]
Explain how this feature mapping contains second-order terms, first-order terms, and an intercept term.
Let \(\mathcal{X}\) be a set and \(\mathcal{F}\) be a Hilbert space. \(\Phi\) is a map from \(\mathcal{X}\) to \(\mathcal{F}\). If we define a kernel function \(k(\cdot, \cdot)\) as \[ k(x, x') = \langle \Phi(x), \Phi(x') \rangle_{\mathcal{F}}, \quad \forall x, x' \in \mathcal{X}, \] show that \(k\) is a positive definite kernel (Hint: use definition).
Suppose \(k_1\) and \(k_2\) are two positive definite kernels on \(\mathcal{X}\). Show that the kernel \(k = k_1 + k_2\) is also a positive definite kernel.
Let \(\mathcal{X}=\mathbb{R}\) and \(\sigma>0\). Consider the kernel \[ k(x, x') = \mathbf{1}\left\{ |x-x'| < \sigma \right\}. \] Is this a positive definite kernel on \(\mathbb{R}\)? If yes, prove it. If no, give a counterexample.
Show that if a reproducing kernel \(k(\cdot, \cdot)\) exists for a Hilbert space \(\mathcal{H} \subseteq \mathbb{R}^{\mathcal{X}}\), then it is unique. Hint: you may consider assuming that there are two different kernel functions \(k_1\) and \(k_2\) for \(\mathcal{H}\), and then show that the Hilbert norm of their difference \(\|k_1(\cdot, x) - k_2(\cdot, x)\|_{\mathcal{H}}\) is zero for any \(x \in \mathcal{X}\). To do that, expand this equation and use properties of a Hilbert space and the reproducing property.
Let \(\Omega\) be a set, and let \(\phi: \Omega \to \mathbb{R}\) be a fixed, non-zero function. Define a kernel function as \(K(x, y) =\phi(x)\phi(y)\).
Describe the resulting RKHS \(\mathcal{H}_{K}\).
For a function \(f\) in this space, find its norm \(\lVert f \rVert_K\).
Load an image from the ElemStatLearn package. This
package has been archived, so you will need to find a way to install it.
The first image in the zip.train dataset is a handwritten
digit 6 with resolution \(16
\times 16\). “Blow it up” to \(48
\times 48\) by replicating each pixel into a \(3 \times 3\) block. The original and
enlarged images look the same, but they have different dimensions.
# Handwritten Digit Recognition Data
library(ElemStatLearn)
data(zip.train)
# plot two images
par(mfrow=c(1,2), mar=c(0,0,1,0))
# look at the first sample
img16 <- zip2image(zip.train, 1)
## [1] "digit 6 taken"
image(img16, col=gray(256:0/256), zlim=c(-1,1),
xlab="", ylab="", axes=FALSE)
# change the resolution of this image to 48 x 48
img48 <- img16[rep(1:16, each=3), rep(1:16, each=3)]
# plot the enlarged image
image(img48, col=gray(256:0/256), zlim=c(-1,1),
xlab="", ylab="", axes=FALSE)
Although the enlarged image is larger, it is still pixelated. Treat the two image coordinates as covariates and use two-dimensional kernel ridge regression to obtain smoothed gray-scale values. Use the original \(16 \times 16\) pixels as the \(n=256\) training observations, and predict the image on a \(48 \times 48\) grid. Scale both image coordinates to \([0,1]\).
For this question, you should:
solve() rather than forming a matrix inverse: \[
\widehat{\boldsymbol\alpha}
= (\mathbf K+n\lambda\mathbf I)^{-1}\mathbf y,
\qquad
\widehat{\mathbf y}_*=\mathbf K_*\widehat{\boldsymbol\alpha}.
\]Load the mixture.example dataset from the
ElemStatLearn package. Let \(X_1,
\ldots, X_n\) denote observations from one of the two classes.
The population kernel mean embedding is
\[ \mu_P(\cdot)=\mathbb{E}_P[k(\cdot,X)]. \]
For the bounded Gaussian kernel used below, this expectation is well-defined. The empirical kernel mean embedding is
\[ \widehat{\mu}_P(x) = \frac{1}{n}\sum_{i=1}^n k(x, X_i). \]
Use the Gaussian kernel
\[ k(x,x') = \exp\left( -\frac{\|x-x'\|^2}{2\sigma^2} \right). \]
\[ \langle f, \mu_P \rangle_{\mathcal{H}} = \mathbb{E}_P[f(X)]. \]
mixture.example$x
and the labels in mixture.example$y, separately compute the
empirical kernel mean embeddings for observations with \(y=0\) and \(y=1\). Write the kernel function and the
empirical kernel mean embedding calculation yourself instead of using an
existing kernel package.Evaluate each empirical kernel mean embedding over the
two-dimensional grid given by mixture.example$px1 and
mixture.example$px2.
[5 pts] For each bandwidth considered in part (d), visualize the
two empirical kernel mean embeddings using contour(),
image(), or another suitable plotting function. Use
comparable plotting scales for the two classes.
[5 pts] Try at least two reasonable values of \(\sigma\). Briefly describe how changing the bandwidth affects the empirical kernel mean embeddings.