Quiz 1¶
For Penn State student, access quiz here
import ipywidgets as widgets
Question 1¶
Consider three sets
and \(A_3=\{(x,y)\in R^2:(x-\frac{3}{2})^2+y^2\le \frac{1}{4}\}\)
Which two sets are linearly separable ?
Show answer
Answer: \(A_1\),\(A_3\) are linearly separable
Question 2¶
Consider three sets \(A_1,A_2,A_3\subset R^d\), and three sentences listed below
-A: \(A_1,A_2,A_3\) are all-vs-one linearly separable.
-B: \(A_1,A_2,A_3\) are linearly separable.
-C: \(A_1,A_2,A_3\) are pairwise linearly separable.
Which sentence implies other sentence ?
Show answer
Answer: A implies B; C implies B
Question 3¶
Let
Compute the eigenvalues and corresponding eigenvectors of \(A\). Write out solution
Show answer
Question 4¶
Determine the global minimizer and the global minimum of the function \(f(x,y)=e^{(x-2)^2+y^2+2x^2+2xy+2(y-4)^2+4y-16x} \)
Show answer
Minimizer (3,1), Minimum 1.
Question 5¶
Let
Compute the Hessian matrix of the multivariable function \(f(\boldsymbol x)=\frac{1}{2} \boldsymbol x^TA \boldsymbol x.\)
Show answer
\(\frac{1}{2}(A+A^T)\)
Question 6¶
To define
what Python code should you use ?
Show answer
A = torch.tensor([[1,2,3],[4,5,6],[7,8,9]])
Question 8¶
What is the output of the following code:
salary = 8000
def printSalary(salary):
if salary < 10000:
salary = 10000
else:
print("Salary:", salary)
printSalary(salary)
print("Salary:", salary)
Salary: 8000
Show answer
Salary: 8000
Question 9¶
What are the outputs of the following code?
str = "pynative"
print (str[1:3])
yn
Show answer
yn
Question 10¶
What are the outputs of the following code?
def my_sort(nums):
count=0
for i in range(len(nums)-1):
for j in range(i+1,len(nums)):
if nums[j] > nums[i]:
count = count+1
num_temp = nums[j]
nums[j] = nums[i]
nums[i] = num_temp
print('The number of swap operation is',count)
return nums
list_of_nums = [5, 1, 2, 8, 4]
print(my_sort(list_of_nums))
The number of swap operation is 6
[8, 5, 4, 2, 1]
Show answer
The number of swap operations is 6
[8, 5, 4, 2, 1]