Quiz 3

For Penn State student, access quiz here

import ipywidgets as widgets

Question 1

Is \(f(x)=e^x\)  a convex function?

Question 2

Consider the uniform distribution \(\mathcal X\) on \([-a,a]\) for some number \(a>0\). What are the expectation and variance of \(\mathcal X\)

Question 3

Suppose you flip a fair icon 3 times. Let \(\chi\) be the number of heads. Calculate the expectation of \(\chi ^2 \)

Question 4

Consider the function \(f(x,y,z)=yz+e^{xyz}\). At the point

\( \begin{pmatrix} x\\ y\\ z \end{pmatrix} = \begin{pmatrix} 0\\ 1\\ 2 \end{pmatrix} \)

find the direction along which the function decreases most rapidly.

Question 5

Consider \(f(x,y)=2x^2+2y^2.\) Given initial guess

\( \begin{pmatrix} x^0\\ y^0 \end{pmatrix} = \begin{pmatrix} 2\\ 3 \end{pmatrix} \)

\(\eta =1/8\)

compute two steps of the gradient  descent method for \(f(x,y)\)

Question 6

What is output of the following code?

class test:
        def _ _init_ _(self, a):
               self.a=a
        def display(self):
               print(self.a)
obj = test()
obj.display()
  File "<ipython-input-2-c152c3ed665a>", line 2
    def _ _init_ _(self, a):
    ^
SyntaxError: invalid character in identifier

Question 7

If we use “import Course’’ in Python, what is “Course”?

Question 8

What is the output of the following code:

print('{}\n/{}'.format(1,2))

Question 9

How to define stochastic gradient descent method with learing rate=1 after:

import torch.optim
import torch.nn as nn
my_model=nn.Linear(784,10)

Queation 10

For MNIST dataset, if we would like to use full gradient descent method, how should we define the trainloader?