0% found this document useful (0 votes)
13 views15 pages

Ass1 Solns

Uploaded by

ceadamtan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views15 pages

Ass1 Solns

Uploaded by

ceadamtan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Homework Assignment 1

Due: Friday, September 20, 2024, 11:59 p.m. Mountain time


Total marks: 25

Policies:
For all multiple-choice questions, note that multiple correct answers may exist. However, selecting
an incorrect option will cancel out a correct one. For example, if you select two answers, one
correct and one incorrect, you will receive zero points for that question. Similarly, if the number
of incorrect answers selected exceeds the correct ones, your score for that question will be zero.
Please note that it is not possible to receive negative marks.
While the syllabus initially indicated the need to submit a paragraph explaining the use of AI or
other resources in your assignments, this requirement no longer applies as we are now utilizing
eClass quizzes instead of handwritten submissions. Therefore, you are not required to submit any
explanation regarding the tools or resources (such as online tools or AI) used in completing this
quiz.
This PDF version of the questions has been provided for your convenience should you wish to print
them and work offline.
Only answers submitted through the eClass quiz system will be graded. Please do not
submit a written copy of your responses.

Question 1. [1 mark]
Is the following True or False. (R2 ) × R is a set.

Solution:
True. A Cartesian product is always a set. It is defined as (R2 ) × R = {((x1 , x2 ), y)|x1 , x2 , y ∈ R},
which is a set of tuples where each tuple has an element from R2 and an element from R.

Question 2. [1 mark]
Is the following True or False. (((1, 2), 3), ((1/2, 1/3), 1/4)) is a tuple.

Solution:
True. Since parentheses are used at the outermost level, this is a tuple. It doesn’t matter what the
elements of the tuple are; as long as they are enclosed in parentheses, it is a tuple. It is also clear
that it is not an open interval, since an open interval would have exactly two elements and would
be written as (a, b) where a ∈ R, b ∈ R, and a < b.

Question 3. [1 mark]
Is the following True or False. A tuple can have duplicates.

Solution:
True. Tuples are ordered collections of elements, and they can contain duplicates.

Question 4. [1 mark]
Which of the following is an element of N4 ?

1/15
Fall 2024 CMPUT 267: Basics of Machine Learning

a. (1, 2, 3, 4)

b. (1, 2, 3)

c. (1, 2, 3, 4, 5)

d. (1, 2, 3, π)

Solution:
The correct answer is:

• a. (1, 2, 3, 4)

Explanation:
N4 represents the set of all 4-tuples where each element is a natural number (N).

a. (1, 2, 3, 4): Correct. This is a 4-tuple of natural numbers.

b. (1, 2, 3): Incorrect. This is a 3-tuple, not a 4-tuple.

c. (1, 2, 3, 4, 5): Incorrect. This is a 5-tuple, not a 4-tuple.

d. (1, 2, 3, π): Incorrect. π is not a natural number.

Question 5. [1 mark]
Which of the following is an element of X × Y where X = R3 and Y = R?

a. (1, 2, 3)

b. ((1, 2, 3), (1, 2, 3))

c. ((1, 2, 3), 4)

d. (1, (2, 3, 4))

Solution:
The correct answer is:

• c. ((1, 2, 3), 4)

Explanation:
An element of X × Y is an ordered pair (x, y) where x ∈ R3 and y ∈ R.

a. (1, 2, 3): Incorrect. This is a single 3-tuple in R3 , not an ordered pair.

b. ((1, 2, 3), (1, 2, 3)): Incorrect. Both elements are in R3 ; the second should be in R.

c. ((1, 2, 3), 4): Correct. The first element is in R3 and the second is in R.

d. (1, (2, 3, 4)): Incorrect. The first element is in R, but it should be in R3 .

2/15
Fall 2024 CMPUT 267: Basics of Machine Learning

Question 6. [1 mark]
Let D = ((x1 , y1 ), . . . , (xn , yn )) where xi ∈ Rd and yi ∈ {0, 1} for all i ∈ {1, . . . , n}. Then, how
would you write the set of all possible D?

a. ((Rd ) × {0, 1})n

b. (X × Y)n where X = Rd and Y = {0, 1}

c. {(z1 , . . . , zn ) | zi ∈ Rd × R, i ∈ {1, . . . , n}}

d. {((x1 , y1 ), . . . , (xn , yn )) | xi ∈ R, yi ∈ {0, 1}, i ∈ {1, . . . , n}}

Solution:
The correct answers are:

• a. ((Rd ) × {0, 1})n

• b. (X × Y)n where X = Rd and Y = {0, 1}

Explanation:
We need to represent all sequences D of n pairs (xi , yi ) with xi ∈ Rd and yi ∈ {0, 1}.

a. ((Rd ) × {0, 1})n : Correct. This set includes all n-tuples of pairs (xi , yi ) where xi ∈ Rd and
yi ∈ {0, 1}.

b. (X × Y)n where X = Rd and Y = {0, 1}: Correct. This is equivalent to option a., using
variable names.

c. {(z1 , . . . , zn ) | zi ∈ Rd × R, i ∈ {1, . . . , n}}: Incorrect. Here, yi can be any real number, but
it should be restricted to {0, 1}.

d. {((x1 , y1 ), . . . , (xn , yn )) | xi ∈ R, yi ∈ {0, 1}, i ∈ {1, . . . , n}}: Incorrect. This specifies xi ∈ R


instead of Rd .

Question 7. [1 mark]
Suppose you wanted to keep information of houses being sold. You decide to use two features to
represent each house and to keep track of the price (an element of [0, ∞)) it was sold at. The
first feature was the number of rooms (a natural number), the second feature was age (an element
of [0, ∞)). How would you write the set of all possible houses that are represented in this way?
Elements of this set should look like ((x1 , x2 ), y) where x1 represents the number of rooms, x2
represents the age, and y represents the price.

a. (N × [0, ∞)) × [0, ∞)

b. N × [0, ∞) × [0, ∞)

c. (N × [0, ∞)) × N

d. R2 × [0, ∞)

3/15
Fall 2024 CMPUT 267: Basics of Machine Learning

Solution:
The correct answers are:

• a. (N × [0, ∞)) × [0, ∞)

Explanation:
Each house is represented as ((x1 , x2 ), y) where:

• x1 ∈ N (number of rooms)

• x2 ∈ [0, ∞) (age)

• y ∈ [0, ∞) (price)

a. (N × [0, ∞)) × [0, ∞): Correct. It matches the required structure.

b. N × [0, ∞) × [0, ∞): Incorrect. An element of this set would look like (x1 , x2 , y), not
((x1 , x2 ), y).

c. (N × [0, ∞)) × N: Incorrect. The price y should be in [0, ∞), not N.

d. R2 × [0, ∞): Incorrect. The number of rooms x1 should be in N, not R.

Question 8. [1 mark]
Let f : (R3 ) × (R3 ) → Y be such that f (x, w) = x> w, where x, w are vectors. If x = (1, 4, 2)> and
w = (1, 2, 3)> , then what is f (x, w)?

Solution:
The correct answer is:

• 15

Explanation:
To find f (x, w), we compute the dot product of x and w:

f (x, w) = x> w = (1)(1) + (4)(2) + (2)(3) = 1 + 8 + 6 = 15


Therefore, f (x) = 15.

Question 9. [1 mark]
Let f : R → Y be such that f (x) = 4 + x2 . What is the range of f , and what is a valid codomain
Y?

a. The range of f is [4, ∞), and a valid codomain is R.

b. The range of f is [0, ∞), and a valid codomain is [0, ∞).

c. The range of f is [4, ∞), and a valid codomain is [4, ∞).

d. The range of f is R, and a valid codomain is R.

4/15
Fall 2024 CMPUT 267: Basics of Machine Learning

Solution:
The correct answers are:

• a. The range of f is [4, ∞), and a valid codomain is R.

• c. The range of f is [4, ∞), and a valid codomain is [4, ∞).

Explanation:
f (x) = 4 + x2 is a quadratic function that achieves a minimum value of 4 when x = 0 and increases
without bound as |x| increases. Therefore, the range is [4, ∞).

a. Correct. R includes the range [4, ∞).

b. Incorrect. The range starts at 4, not 0.

c. Correct. Setting the codomain to [4, ∞) precisely matches the range.

d. Incorrect. While R is a valid codomain, the range is not all of R; it is restricted to [4, ∞).

Question 10. [1 mark]


A polynomial of degree 3 or less is a function that looks like f (x) = a0 + a1 x + a2 x2 + a3 x3 , where
a0 , a1 , a2 , a3 ∈ R are considered to be fixed constants (i.e., they are not variables of the function f ).
Which of the following is a set of all functions that have domain R and are polynomials of degree
3 or less?

a. {f : R → R | f (x) = a0 + a1 x + a2 x2 + a3 x3 and a0 , a1 , a2 , a3 ∈ R}

b. {f : R → R | f (x) = a0 + a1 x + a2 x2 + a3 x3 and a0 , a1 , a2 , a3 ∈ N}

c. {f : R → R | f (x) = a0 + a1 x + a2 x2 and a0 , a1 , a2 ∈ R}

d. {f : R → R | f (x) = a0 + a1 x + a2 x2 + a3 x3 + a4 x4 and a0 , a1 , a2 , a3 , a4 ∈ R}

Solution:
The correct answer is:

• a. {f : R → R | f (x) = a0 + a1 x + a2 x2 + a3 x3 , a0 , a1 , a2 , a3 ∈ R}

Explanation:

a. Correct. This set precisely defines all real polynomials of degree up to 3.

b. Incorrect. This set has coefficients as only natural numbers, whereas the definition restricts
coefficients to R.

c. Incorrect. This set only includes polynomials of degree up to 2.

d. Incorrect. This set includes polynomials of degree up to 4, which exceeds the specified degree.

5/15
Fall 2024 CMPUT 267: Basics of Machine Learning

Question 11. [1 mark]


Which of the following is a function

A : (R × R)n → {f | f : R → R and f (x) = xw, w ∈ R}

where n = 2?

a. A((a, b), (c, d)) = f (x) = ax + b

b. A((a, b), (c, d)) = f (x) = cx

c. A((a, b), (c, d)) = f (x) = ax + d


ab+cd
d. A((a, b), (c, d)) = f (x) = a2 +b2
x

Solution:
The correct answers are:

• b. A((a, b), (c, d)) = f (x) = cx

Explanation:
The function A should map input tuples to functions of the form f (x) = xw, where w ∈ R.

a. Incorrect. f (x) = ax + b includes a constant term b, which does not fit the required form
f (x) = xw.

b. Correct. f (x) = cx matches the form with w = c.

c. Incorrect. f (x) = ax + d includes a constant term d, which does not fit the required form.
ab+cd
d. Incorrect. f (x) = a2 +b2
x is undefined when a = 0 and b = 0.

Question 12. [1 mark]


Let f (x, w) = xw where x, w ∈ R. What is the partial derivative of f (x, w) with respect to w?

a. x

b. w

c. x + w

d. 1

Solution:
The correct answer is:

• a. x

6/15
Fall 2024 CMPUT 267: Basics of Machine Learning

Explanation:
The function f (x, w) = xw is a linear function in w. To find the partial derivative of f with respect
to w, we treat x as a constant:

∂f ∂
= (xw) = x
∂w ∂w
Therefore, the partial derivative is x.

a. x: Correct. The partial derivative of xw with respect to w is x.

b. w: Incorrect. This would be the partial derivative if the function were 21 w2 .

c. x + w: Incorrect. This suggests adding x and w, which is not applicable here.

d. 1: Incorrect. This would be the partial derivative if the function were w.

Question 13. [1 mark]


Let `(ŷ, y) = (ŷ − y)2 where ŷ, y ∈ R. What is the partial derivative of `(ŷ, y) with respect to ŷ?

a. 2(ŷ − y)

b. (ŷ − y)

c. 2ŷ

d. −2y

Solution:
The correct answer is:

• a. 2(ŷ − y)

Explanation:
Given `(ŷ, y) = (ŷ − y)2 , the partial derivative with respect to ŷ is:

∂`
= 2(ŷ − y)
∂ ŷ

a. 2(ŷ − y): Correct.

b. (ŷ − y): Incorrect. Missing the factor of 2 from the power rule.

c. 2ŷ: Incorrect. This would be the partial derivative if y were zero.

d. −2y: Incorrect. This ignores the ŷ term.

Question 14. [1 mark]


Let `(ŷ, y) = (ŷ − y)2 where ŷ, y ∈ R. Let f (x, w) = xw where x, w ∈ R. What is the partial
derivative of `(f (x, w), y) with respect to w?

7/15
Fall 2024 CMPUT 267: Basics of Machine Learning

a. 2x(xw − y)
b. 2(xw − y)
c. x
d. 2xw

Solution:
The correct answer is:
• a. 2x(xw − y)
Explanation:
First, express `(f (x, w), y):

`(f (x, w), y) = (xw − y)2


To find the partial derivative with respect to w:


`(f (x, w), y) = 2(xw − y) · x = 2x(xw − y)
∂w
a. 2x(xw − y): Correct. Applies the chain rule correctly.
b. 2(xw − y): Incorrect. Missing the multiplication by x.
c. x: Incorrect. This is the partial derivative of f (x, w) with respect to w, not of `.
d. 2xw: Incorrect. This ignores the y term and the product rule.

Question 15. [1 mark]


If X = {1, 2, 3}, what is 13 x∈X x?
P

Solution:
The correct answer is:
• 2
Explanation:
First, compute the sum:
X
x=1+2+3=6
x∈X
Then,
1X 6
x= =2
3 3
x∈X

Question 16. [1 mark]


If X = (x1 , . . . , xn ), how would you write the sum over all x ∈ X ?

8/15
Fall 2024 CMPUT 267: Basics of Machine Learning

Pn
a. i=1 xi
Q
b. x∈X x
R
c. X x dx
P
d. x∈X x

Solution:
The correct answers are:
Pn
• a. i=1 xi

• d.
P
x∈X x

Explanation:
When X = {x1 , . . . , xn }, the sum over all x ∈ X is written as:

X n
X
x1 + x2 + · · · + xn = x= xi
x∈X i=1

Pn
a. i=1 xi : Correct.
Q
b. x∈X x: Incorrect. This represents the product, not the sum.
R
c. X x dx: Incorrect. This represents an integral, which is not applicable for finite sums.
P
d. x∈X x: Correct.

Question 17. [1 mark]


Let X = (x1 , . . . , xn ). Let f (x, w) = xw where x, w ∈ R. How would you write the sum of f (x, w)
over all x ∈ X ?
Pn
a. i=1 xi w

b. w ni=1 xi
P

Pn
c. x=1 w

d. w ni=1 xi
Q

Solution:
The correct answers are:
Pn
• a. i=1 xi w
Pn
• b. w i=1 xi

9/15
Fall 2024 CMPUT 267: Basics of Machine Learning

Explanation:
The sum of f (x, w) = xw over all x ∈ X is:

X n
X n
X
f (x, w) = xi w = w xi
x∈X i=1 i=1

Thus, both expressions ni=1 xi w and w ni=1 xi are correct.


P P

Pn
a. i=1 xi w: Correct. Direct substitution of f (xi , w).
Pn
b. w i=1 xi : Correct. Factor w out of the sum.
Pn
c. x=1 w: Incorrect. This sums w n times, ignoring xi .
Qn
d. w i=1 xi : Incorrect. This represents w multiplied by the product of all xi , not the sum.

Question 18. [1 mark]


Let D = ((x1 , y1 ), . . . , (xn , yn )). Let `(ŷ, y) = (ŷ − y)2 where ŷ, y ∈ R. Let f (x, w) = xw where
x, w ∈ R. How would you write the sum of `(f (x, w), y) over all (x, y) ∈ D?
Pn 2
a. i=1 (ŷi − yi )
Pn 2
b. i=1 (xi w − yi )
Pn
c. i=1 xi wyi
Qn
d. i=1 (xi w − yi )2

Solution:
The correct answer is:
Pn
• b. i=1 (xi w − yi )
2

Explanation:
Given D = ((x1 , y1 ), . . . , (xn , yn )), the sum is:

X n
X n
X
2
`(f (x, w), y) = ( xi w −yi ) = (xi w − yi )2
|{z}
(x,y)∈D i=1 f (x ,w) i=1
i

Pn
a. i=1 (ŷi − yi )2 : Incorrect. ŷi is not defined in this context.
Pn
b. i=1 (xi w − yi )2 : Correct. Direct substitution of f (xi , w).
Pn
c. i=1 xi wyi : Incorrect. This represents a different operation, not the squared loss.
Qn
d. i=1 (xi w − yi )2 : Incorrect. This represents the product of squared losses, not the sum.

Question 19. [1 mark]


Let L(z1 , . . . , zn ) = n1 ni=1 zi where zi ∈ R for all i ∈ {1, . . . , n}. Let `(ŷ, y) = (ŷ − y)2 where ŷ, y ∈
P
R. Let f (x, w) = xw where x, w ∈ R. What is the partial derivative of L(`(f (x1 , w), y1 ), . . . , `(f (xn , w), yn ))
with respect to w?

10/15
Fall 2024 CMPUT 267: Basics of Machine Learning

2 Pn
a. n i=1 xi (xi w − yi )
Pn
b. i=1 xi (xi w − yi )
1 Pn
c. n i=1 2(xi w − yi )
Pn
d. 2 i=1 xi w

Solution:
The correct answer is:
• a. n2 ni=1 xi (xi w − yi )
P

Explanation:
First, express L(`(f (x1 , w), y1 ), . . . , `(f (xn , w), yn )):
n n
1X 1X
L= `(f (xi , w), yi ) = (xi w − yi )2
n n
i=1 i=1
To find the partial derivative with respect to w:
n n
∂L 1X 2X
= 2(xi w − yi ) · xi = xi (xi w − yi )
∂w n n
i=1 i=1

2 Pn 1
a. n i=1 xi (xi w − yi ): Correct. Applies the chain rule and factor of n.
Pn 2
b. i=1 xi (xi w − yi ): Incorrect. Missing the factor n.
1 Pn
c. n i=1 2(xi w − yi ): Incorrect. Missing multiplication by xi .
Pn
d. 2 i=1 xi w: Incorrect. This does not account for the yi terms.

Question 20. [1 mark]


Let f (x, y) = xy where x, y ∈ R. What is
X
f (x, y)
y∈Y

where Y = {1, 2, 3}?

a. 6x

b. 6

c. 6y

d. x

Solution:
The correct answer is:

11/15
Fall 2024 CMPUT 267: Basics of Machine Learning

• a. 6x

Explanation:
We are asked to compute the sum:
X X
f (x, y) = xy
y∈Y y∈{1,2,3}

Substituting the values of y from the set Y:


X
xy = x × 1 + x × 2 + x × 3 = x + 2x + 3x = 6x
y∈{1,2,3}

Thus, the sum is 6x, which corresponds to option a.

a. 6x: Correct. As shown above, the sum evaluates to 6x.

b. 6: Incorrect. This would be the sum if x = 1, but x is a variable and not necessarily equal
to 1.

c. 6y: Incorrect. The sum results in 6x, not 6y. y is a variable within the summation and does
not factor out.

d. x: Incorrect. This would be the case if the sum had only one term, but there are three
terms being summed.

Question 21. [1 mark]


Let f (x, y) = xy where x, y ∈ R. What is
 
Z X Z X
f (x, y) dx =  f (x, y) dx
X y∈Y X y∈Y

where Y = {1, 2, 3} and X = [0, 5]?

Solution:
The correct answer is:

• a. 75

Explanation:
First, compute the sum inside the integral:
X X
f (x, y) = xy = x × 1 + x × 2 + x × 3 = x + 2x + 3x = 6x
y∈Y y∈{1,2,3}

Now, substitute this back into the integral:


Z X Z 5
f (x, y) dx = 6x dx
X y∈Y 0

12/15
Fall 2024 CMPUT 267: Basics of Machine Learning

Evaluate the integral:


5 5 5
x2
Z Z   
25
6x dx = 6 × x dx = 6 × =6× −0 = 6 × 12.5 = 75
0 0 2 0 2

Thus, the integral evaluates to 75, which corresponds to option a.

Question 22. [1 mark]


Let f (x, y) = xy where x, y ∈ R. What is
Z
f (x, y) dy
Y

where Y = [1, 3]?

a. 4x

b. 6x

c. 2x

d. x

Solution:
The correct answer is:

• a. 4x

Explanation:
Compute the integral: Z Z 3
f (x, y) dy = xy dy
Y 1
Since x is treated as a constant with respect to y, factor it out of the integral:
Z 3 Z 3
xy dy = x y dy
1 1

Evaluate the integral of y:


3 3
y2
Z 
9 1
y dy = = − =4
1 2 1 2 2
Multiply by x:
x × 4 = 4x
Thus, the integral evaluates to 4x, which corresponds to option a.

a. 4x: Correct. As calculated above.

b. 6x: Incorrect. Overestimation of the integral’s value.

c. 2x: Incorrect. Underestimation of the integral’s value.

13/15
Fall 2024 CMPUT 267: Basics of Machine Learning

d. x: Incorrect. Incorrect calculation of the integral.

Question 23. [1 mark]


Let f (x, y) = xy where x, y ∈ R. What is
Z Z Z Z 
f (x, y) dy dx = f (x, y) dy dx
X Y X Y

where Y = [1, 3] and X = [0, 5]?

Solution:
The correct answer is:
• a. 50
Explanation:
First, compute the inner integral:
3 3 3
y2
Z Z Z   
9 1
f (x, y) dy = xy dy = x y dy = x =x − = x × 4 = 4x
Y 1 1 2 1 2 2

Now, substitute this back into the outer integral:


Z Z Z 5
f (x, y) dy dx = 4x dx
X Y 0

Evaluate the outer integral:


5 5 5
x2
Z Z   
25
4x dx = 4 × x dx = 4 × =4× −0 = 4 × 12.5 = 50
0 0 2 0 2

Thus, the double integral evaluates to 50, which corresponds to option a.

Question 24. [1 mark]


Let X be a discrete random variable uniformly distributed with outcome space X = {3, 5, 7, 9}.
The probability mass function (pmf) of X is given by p(x) = 41 for each x ∈ X . What is the
probability of the event that X is either 5 or 9?

Solution:
The correct answer is:
• b. 1
2

Explanation:
Since X is uniformly distributed over {3, 5, 7, 9}, each outcome has an equal probability of 14 .
The event X is either 5 or 9 is represented as the set {5, 9}. Therefore,
1 1 1
P(X ∈ {5, 9}) = p(5) + p(9) = + =
4 4 2
Thus, the probability is 12 , which corresponds to option b.

14/15
Fall 2024 CMPUT 267: Basics of Machine Learning

Question 25. [1 mark]


Let Y be a continuous random variable uniformly distributed with outcome space Y = [2, 10]. The
probability density function (pdf) of Y is given by p(y) = 18 for y ∈ [2, 10]. What is the probability
of the event that Y lies between 4 and 7?

Solution:
The correct answer is:

• b. 3
8

Explanation:
For a continuous uniform distribution over [a, b], the probability that Y lies between c and d (where
a ≤ c < d ≤ b) is calculated as:
Z d
P(c ≤ Y ≤ d) = p(y) dy = p(y) × (d − c)
c
Given:

a=2
b = 10
1
p(y) =
8
c=4
d=7

Calculating the probability:


1 1 3
P(4 ≤ Y ≤ 7) = × (7 − 4) = × 3 =
8 8 8
Thus, the correct probability is 38 , which corresponds to option b.

15/15

You might also like