Problem Set 1 (61 points)

Important information

  1. We provide signatures of the functions that you have to implement. Make sure you follow the signatures defined, otherwise your coding solutions will not be graded.

  2. Please submit the single Jupyter Notebook file, where only Python and Markdown/$\\LaTeX$ are used. Any hand-written solutions inserted by photos or in any other way are prohibitive and will not be graded. If you will have any questions about using Markdown, ask them!

  3. The works will be checked for plagiarism. The score will be divided by the number of similar works.

Problem 1 (18 pts)

Problem 1.0 (Matrix norms) (8 pts)

  1. For any norm $\|\cdot\|$ in finite dimentional space $\mathbb{C}^{N}$ we define dual norm $\|x\|^{'} = \sup\left\{\left|y^{\star} x\right|:\left\|y\right\|=1\right\}$, where ${\cdot}^{\star}$ denotes transpose complex-conjugate vector.

Problem 1.1 (Matrix norms) (10 pts)

  1. Let $U \in \mathbb{R}^{n \times r}$ be an $n \times r$ matrix with orthonormal columns $U^{\top} U = I_r$. Let $V$ be an $m \times r$ matrix.

Problem 1.2 (Unitary and orthogonal matrices) (4 pts)

Problem 2 (15 pts)

  1. We define approximate $\epsilon-$rank of matrix $A$ as $\text{rank}_{\epsilon}A = \min \left\{\text{rank}(X): \left\|A-X\right\|_{\max}\leq \epsilon\right\}$.

Problem 3 (Molecules) (16 pts)

We have in our posession a database with molecules. Each molecule has five atoms A, B, C, D, E located in the same plane $x, y$.

The coordinates of the molecules was collected by an automatic system that processed "pictures" from the electronic microscope. As a result, some of the samples differs by unkonwn rotation in $2D$ space. Your task is to normalize this database to find distinct molecules.

What you should do:

Problem 4 (Disentangled representation) (12 pts)

Brief intro

The main component of GAN is Generator network. Generator is such model that takes as input random vector and produces an image. In this task, we will work with the already pre-trained generator $G$. Here are a few things you need to know about this model:

1.   Model input: batch of random vectors $z\sim N(0,1)$ with normally distributed values of size (Batch_Size,100). Here, Batch_Size is a number of images we want to generate 2.   Model output: $\mathrm{images} = G(z)$ - batch of images with size (Batch_Size,3,64,64). Here 3 - defines number of image channels (3 for RGB images), 64, 64 - width and height. 3.   Model structure: generator is a set of sequentially appplied functions. Each function input is the output of the previous one. In other words, $G(z) = f_N(f_{N-1}...f_1(f_0(z)))$. $N$ - defines number of functions in generator.

Disentanglement

The good property of GAN is that generator input space has a set of meaningful directions - moving input vector along this directions produce interpretable changes in image. For example, we can change a Pose, Age, Expression or even add eyeglasses. You can read more about it on resource. The main question is how to find such good directions. This problem is called disentanglement.

Problem discription

We are going to find meaningful directions using SVD applied over the Jacobian matrix of some hidden output with respect to model input. i-th hidden output of generator model is defined by formula $G_{i}(z) = f_i(f_{i-1}...f_1(f_0(z))))$, where $i < N$. So, the task could be splitted on four main parts:

1. (4 pts)   Write the function Get_Hidden_Output, which reproduces formula $G_{i}(z) = f_i(f_{i-1}...f_1(f_0(z))))$ 2. (3 pts)   Calculate jacobian matrix $J$ of generator $G$ for several i values. For each of them:

   Calculate the jacobian matrix with respect to $z$: $\frac{\partial G(z)}{\partial z}$   Reshape jacobian matrix to have the size (Batch_Size * Hidden_Output_Size,100)

3. (3 pts)  Apply SVD to jacobian matrix ($J = U @ S @ V.T$) from previous step

4. (2 pts)  Take several directions from matrix $V$ (particular columns), and run visualization code (already written for you). Leave a comment on what you got (how found directions affect image)

Attention!!!

1.  Please run the code on google colab to fulfil packages requirements 2.  Jacobian matrix computation may take more than 20 minutes! 3.  Use GPU runtime to accelerate computations

Prerequisites

Generator network visualization

Perform experiments

Define the function that returns the output of any generator function for given input z and generator function index (4 pts)

Define the function that calculates the jacobian matrix based on given input z and generator function index (use the function which you implemented earlier) (3 pts)

Calculate SVD and visualize singular values for several generator function indexes (2-3 indexes are enough). Based on singular value plots, decide what generator function is more useful for disentangled representation search and why, leave a comment.(3 pts)

Choose some directions from matrix V (some columns) corresponding to chosen generator function index (based on previous step). Run visualization code. Which image attributes affects chosen directions? (2 pts)