\documentclass[10pt]{article}
\usepackage{amssymb,amsmath,float}
\usepackage{epsfig}
\usepackage{bm} % Added for bold greek letters (beta)

\newcommand{\comment}[1]{}
\newcommand{\beq}{\begin{equation}}
\newcommand{\eeq}{\end{equation}}
\newcommand{\beqa}{\begin{eqnarray}}
\newcommand{\eeqa}{\end{eqnarray}}
\newcommand{\bit}{\begin{itemize}\setlength{\itemsep}{0cm}\setlength{\topsep}{0cm}}
\newcommand{\eit}{\end{itemize}}
\newcommand{\benum}{\begin{enumerate}\setlength{\itemsep}{0cm}\setlength{\parsep
}{0cm}}
\newcommand{\eenum}{\end{enumerate}}
\newcommand{\bprogram}{\begin{tabbing}mm\=mm\=mm\=mm\= \kill\\}
\newcommand{\eprogram}{\end{tabbing}}

% math mode commands from template
\newcommand{\calB}{\mathcal{B}}
\newcommand{\calF}{\mathcal{F}}
\newcommand{\bigOO}{{\cal O}}
\newcommand{\bbone}{{\mathbf 1}}
\newcommand {\argmax}[2]{\mbox{\raisebox{-1.7ex}{$\stackrel{\textstyle{\rm #1}}{\scriptstyle #2}$}}\,}
\newcommand{\dataset}{{\cal D}}
\newcommand{\rrr}{{\mathbb R}}
\newcommand{\fracpartial}[2]{\frac{\partial #1}{\partial #2}}

\newcommand{\setxx}[1]{\{x\,|\,{#1} \}}
\newcommand{\tilDD}{\tilde{\dataset}}
\newcommand{\tilN}{\tilde{n}}
\newcommand{\tilx}{\tilde{x}}
\newcommand{\hatl}{\hat{l}}
\newcommand{\haty}{\hat{y}}
\newcommand{\llogit}{L_{logit}}
\newcommand{\biasss}{\operatorname{bias}}

% Additional macros required for the assignment content
\newcommand{\RR}{\rrr}
\newcommand{\zero}{\mathbf{0}}
\newcommand{\one}{\mathbf{1}}
\newcommand{\wv}{\boldsymbol{\beta}} % Vector beta
\newcommand{\xv}{\mathbf{x}}
\newcommand{\yv}{\mathbf{y}}
\newcommand{\ans}[1]{{\color{orange}\textsf{Ans}: #1}}

\begin{document}
\setlength{\parindent}{0em}
\setlength{\parskip}{1.3em}

\begin{large}
\centerline{CS 480/680 Assignment 2}  % assignment number here

\centerline{Released Jan 22, 2026}       % out date here
\end{large}

\centerline{\large \copyright Marina Meil\u{a}}
\centerline{\large mmp@stat.washington.edu}

\vspace{2em}

{\bf Problem 1 -- Least Squares}

Let $x_1,x_2,\ldots x_n$ be real numbers, and define by $g(z)$ the function
\[
g(z)\;=\;\sum_{i=1}^n(x_i-z)^2
\]
\benum
    \item Show that the minimum of $g$ is attained for
    \[
    z^*\;=\;\frac{1}{n}\sum_{i=1}^n x_i
    \]
    [Hint: Take the derivative of $g$ w.r.t. $z$ and solve the equation $g'(z)=0$.]
    
    \item What is the value $g(z^*)$?
\eenum

\vspace{2em}
{\bf Problem 2 -- Linear regression interpretation}

{\em No proofs required for this problem}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.8\linewidth]{fig_toy_linreg_resid.png}
    % \caption{Enter Caption}
    % \label{fig:placeholder}
\end{figure}

The figure above shows $n=20$ data points and a linear regression line $f(x)=\beta_0+\beta_1x$ estimated by Maximum Likelihood from these data. Answer based on the figure (approximative values to 1 decimal point OK).

\benum
    \item What are the numerical values of $\beta_{0,1}$?

    \item What is the residual for data point with $x^i\approx 0.1$ ?

    \item What is the predicted value $f(x=0.85)$?

    \item True or false: $\sum_{i=1}^n(y^i-f(x^i))=0$ for any data set? (where $f$ retrained on this data set by Maximum Likelihood) 
\eenum

\vspace{2em}
{\bf Problem 3 -- Regression Implementation}

Recall that ridge regression refers to
\beq
  \min_{\wv\in \RR^d} ~ \overbrace{\underbrace{\tfrac{1}{2n} \|X \wv - \yv\|_2^2}_{\mbox{error}} + \lambda \|\wv\|_2^2}^{\mbox{loss}}, \label{eq:regression}
\eeq
where $X \in \RR^{n \times d}$ and $\yv \in \RR^n$ are the given dataset and $\lambda \geq 0$ is the regularization hyperparameter.
If $\lambda = 0$, then this is the standard linear regression problem.
Observe the distinction between the error (which does not include the regularization term) and the loss (which does).

\benum
  \item Show that ridge regression can be rewritten as a non-regularized linear regression problem.
  That is, prove (\ref{eq:regression}) is equivalent to 
\beq
  \min_{\wv\in \RR^d} ~ \tfrac{1}{2n} \left\|\begin{bmatrix}
X \\
    \sqrt{2\lambda n}I_d 
    \end{bmatrix} \wv  - \begin{bmatrix}\yv \\ \zero_d\end{bmatrix}\right\|_2^2 , 
\eeq
where $I_d$ is the $d$-dimensional identity matrix, and $\zero_k$ is the zero column vector in $k$ dimensions.

\item Show that the derivative of (\ref{eq:regression}) is
\beq
\frac{\partial}{\partial\wv} =  \tfrac1n X^\top (X\wv - \yv) + 2 \lambda \wv
\eeq

  \item Implement ridge regression using the closed form solution for linear regression as derived in lecture. 
    You may find the function \texttt{numpy.linalg.solve} useful.

\eenum

\end{document}