# BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

# 计算机代写｜COMP3670 Assignment 4 – PCA & Dimensionality Reduction

### 计算机代写｜COMP3670 Assignment 4 – PCA & Dimensionality Reduction

PROGRAMMING SECTION

For all of the following, program the solution yourself. Don’t just call a library function that does the whole question for you, or you’ll get zero (no, that doesn’t mean you can’t use any library functions, but it does mean that you have to show you understand how to compute the answer yourself).

All written answers should be between 50 and 500 words. If you can describe all the necessary information in 50 words, that’s better. However, you’ll only be graded on whether you describe the necessary ideas.

TASK 0.1: You know the drill. Import Numpy and PyPlot.

In [1]:

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D #This is for 3d scatter plots.

import math

import random

import os

import scipy

from matplotlib.pyplot import imread

from PIL import Image

np.random.seed(13579201)

Let’s understand the settings of datasets.

We provide you with 3 pedestrian image folders, ‘train’, ‘gallery’, and ‘val_query’. There are 199 images in ‘train’ which are used to compute the eigen pedestrians and build the projection matrix. ‘Gallery’ contains 90 images which belong to 15 different pedestrians. ‘Val_query’ has 3 images of 3 pedestrians. If two images’ file name have same first four digits, then these two images belong to same pedestrian.

In [ ]:

width = 64

height = 128

dimension = (height, width, 3)

images = []

filename = []

for file in os.listdir(“./train”):

if file.endswith(“.jpg”):

im = imread(“./train/” + file)

im = im.flatten() # flatten im into a vector

images.append(im)

filename.append(file)

A_pp = np.stack(images).T # build a matrix where each column is a flattened image print(A_pp.shape)

plt.imshow(A_pp[:, 0].reshape(dimension))

plt.show()

TASK 1.1: Let be a matrix of data. Each column of is a sample of data (1 example for instance). The rows of are thus the features (dimensions) of each of these samples. Complete the function , for which:

𝑄𝑖,: = 𝐴_𝑝𝑝𝑖,: − 𝜇𝑖

…where 𝜇𝑖=1/𝑚∑𝑗 𝑝𝑝𝑖?

𝐴𝑖,: =𝑄𝑖,:/||𝑄𝑖,:||∞

𝐴 ∈ ℝ𝐷×N

𝑄𝑖,: is the row of 𝑄.

HINT:

If the norm is 0, divide by 1 instead.

In [ ]:

def preprocess(A_pp):

# YOUR CODE HERE

A, Q_norms, A_means = preprocess(A_pp)

print(A)

print(Q_norms)

print(A_means.shape)