38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
# ### Homework 4
|
|
#
|
|
# David Allemang. STOR 881.001.FA25.
|
|
|
|
# #### 1. Flat subspace
|
|
#
|
|
# Show the set of flat vectors $F = \{ \alpha \vec 1 : \alpha \in \mathbb R\}$ is a subspace of $\mathbb R^d$. (Where $\vec 1$ is the vector where all coefficients are $1$).
|
|
#
|
|
# Proof.
|
|
#
|
|
# Show that $F$ is closed under linear combination. Given flat vectors $\vec u = \alpha \vec 1$ and $\vec v = \beta \vec 1$, and scalars $a$, $b$, show that $a \vec u + b \vec v \in F$.
|
|
#
|
|
# $$\begin{align*}
|
|
# a \vec u + b \vec v &= a \alpha \vec 1 + b \beta \vec 1 \\
|
|
# &= (a \alpha + b \beta) \vec 1 \\
|
|
# &= \gamma \vec 1 \\
|
|
# \end{align*}$$
|
|
|
|
# #### 2. Projection onto flat subspace.
|
|
#
|
|
# Show that the projection of a $d$-dimensional vector onto the space of flat vectors is the flat vector whose common entry is the mean of entries of the original vector.
|
|
#
|
|
# Define the projection operator which projects $\vec x$ onto the line spanned by $\vec y$: $$P(\vec x, \vec y) = \frac{\langle \vec x, \vec y\rangle}{\langle \vec y, \vec y\rangle} \vec y$$
|
|
#
|
|
# Proof.
|
|
#
|
|
# The flat vector subspace is rank 1, spanned by any of its vectors. Pick $\vec 1$ as the basis element for easy arithmetic and consider the projection of an arbitrary vector $\vec x$ onto the line spanned by $\vec 1$:
|
|
#
|
|
# $$\begin{align*}
|
|
# P(\vec x, \vec 1) &= \frac{\langle \vec x, \vec 1\rangle}{\langle \vec 1, \vec 1\rangle} \vec 1 \\
|
|
# &= \frac{\sum_{i=1}^d x_i \cdot 1}{\sum_{i=1}^d 1 \cdot 1} \vec 1 \\
|
|
# &= \left (\frac 1 d \sum_{i=1}^d x_i \right) \vec 1 \\
|
|
# &= \mu \vec 1
|
|
# \end{align*}$$
|