Skip to article content

Neural Networks

Back to Article
Pre-requisite Review
Download Article

Pre-requisite Review

all three files inside the upload dropbox

Problem 1: Factorial

(20 marks)

The factorial of a non-negative integer n , denoted by n!n!, is the product of all positive integers less than or equal to n . The factorial of n also equals the product of n with the next smaller factorial:

n!=n×(n1)×(n2)×(n3)××3×2×1=n×(n1)!n ! = n × ( n − 1 ) × ( n − 2 ) × ( n − 3 ) × ⋯ × 3 × 2 × 1 = n × ( n − 1 ) !

For example, 5!=5×4!=5×4×3×2×1=120.5 ! = 5 × 4 ! = 5 × 4 × 3 × 2 × 1 = 120. The value of 0! is 1, according to the convention for an empty product.

Write a recursive C function to compute factorial of a natural number n. It should pass the test_factorial function 10 times. test_factorial function is given.

C programmers: download and edit the file test_factorial_template.c .

Rename the file to test_factorial.c. Complete the function and submit the file as a separate file to Gradescope autograder.

Problem 2: Prime numbers

(20 marks)

A natural number (1, 2, 3, 4, 5, 6, etc.) is called a prime number (or a prime) if it is greater than 1 and cannot be written as the product of two smaller natural numbers.

Write a C function to calculate if a number is prime. Return 1 if it is prime and 0 if it is not a prime. If the number is not a prime number, then a factor exists. Return the factor as through a pointer.

C programmers: Download and edit the file test_prime_template.c. Complete the function and submit the file as a separate file to gradescope.

Rename the file to test_prime.c. Complete the function and submit the file as a separate file to Gradescope autograder.

Problem 3: Structures

(20 marks)

2.a. Write a C data structure named struct date that capture year, month and days of a date.

2.b. Also write a function greg_is_leap_year that determines whether an year is a leap year.

2.c. Also write a function date_greg_days that count the total number of days since 0001-01-01 AD.

C programmers: Download and edit the file test_date_template.c. Complete the function and submit the file as a separate file to gradescope.

Rename the file to test_date.c. Complete the function and submit the file as a separate file to Gradescope autograder.

Problem 4: Probability and statistics

(25 marks)

Resources: Khan Academy

  1. Write the definitions of a Random Variable, Expectation, and Variance. (5 marks)

  2. What is the difference between Expectation and a sample mean? When do they converge? (5 marks)

  1. What is the difference between Probability density function, a Probability mass function and Cumulative distribution function. (5 marks)

  2. Prove that for any Random Variable XX, the variance V(X)=E[X2]E[X]2V(X) = E[X^2] - E[X]^2, where E[X]E[X] denotes the expectation of XX. (5 marks)

  3. Prove that E[X2]>0E[X^2] > 0 (5 marks)

Problem 5: Multivariable Calculus

(20 marks)

Resources: Khan academy

  1. Find the mininimum point the function f(x)=x26x+33f(x) = x^2 - 6x + 33 using calculus. Write the property of derivatives that made you reach the answer? (10 marks)

  2. Find the mininimum point the function f(x,y)=x26x+y28xxy+33f(x, y) = x^2 - 6x + y^2 - 8x - xy + 33 using calculus. Write the property of derivatives that made you reach the answer? (10 marks)

Problem 6: Linear Algebra

(50 marks)

Please review Linear Algebra concepts and notations from here and answer the following questions (all answers are in the pdf).

Other resources: Gilbert Strang lectures

  1. (2 marks) In matrix notation defined in the linked document, when I say a matrix is n×mn \times m (alternatively the matrix is in the set Rn×m\mathbb{R}^{n \times m}, does the n refer to the number of rows or the number of columns .

  2. (5 marks) Let the matrix AR4×2A \in \mathbb{R}^{4 \times 2} and BR2×3B \in \mathbb{R}^{2 \times 3} be defined as

    A:=[12357111317],B:=[192329313741]A := \begin{bmatrix} 1 & 2 \\ 3 & 5 \\ 7 & 11 \\ 13 & 17 \\ \end{bmatrix}, \\ B := \begin{bmatrix} 19 & 23 & 29 \\ 31 & 37 & 41 \\ \end{bmatrix} \\

    Is the matrix multiplication ABAB valid? Make up an example of matrix BB when matrix multiplication ABAB would not have been valid. Find out the matrix multiplication C=ABC = AB by hand. Write down all the steps to show which numbers get multiplied by which numbers.

  3. Given two matrices AA of size m×nm \times n and BB of size p×qp \times q, when is the matrix multiplication ABAB valid? When is the matrix multiplication BABA valid? When is the addition A+BA + B valid? (5 marks)

  4. What is the transpose of a matrix? If a matrix AA has the shape n×mn \times m, what is the shape of matrix AA^\top (3 marks).

  5. Define dot product for two vectors? How to test when two given vectors are perpendicular? Assume you have two n-dimensional vectors a=[a1,a2,,an]\vec{a} = [a_1, a_2, \dots, a_n] and b=[b1,b2,,bn]\vec{b} = [b_1, b_2, \dots, b_n]. Denote dot product as, ab\vec{a} \cdot \vec{b}? (5 marks)

  6. Denote the above vectors as column matrices. Define the following n×1n \times 1 matrices with the vector components.

    a=[a1a2an],b=[b1b2bn]\mathbf{a} = \begin{bmatrix} a_1 \\ a_2 \\ \vdots \\ a_n \end{bmatrix},\\ \mathbf{b} = \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_n \end{bmatrix}

    Use matrix operation like matrix transpose and matrix multiplication to write vector dot product (5 marks).

  7. Define cross product for two vectors? How to test when two vectors are parallel to other? (5 marks)

  8. How to can you find the magnitude of a vector? What is a unit vector? (5 marks)

  9. What is a square matrix (0 marks)?

  10. What are the column vectors and row vectors of a matrix? How can you write matrix multiplication in terms of row vectors and column vectors of a matrix (5 marks)?

  11. Suppose you are given a n×nn \times n square matrix called UU. All it’s nn columns vectors are unit vectors and every pair of the unit vectors are perpendicular to each other. Find out the product UUU^\top U . What is the name of given to such matrices whose column vectors are unit vectors and are perpendicular to each other? (10 marks).