## Description

Background

TAs: Rongye Shi, Sida Gao, Rawal Khirodkar, George Xu

START HERE: Instructions

• Late Submission Policy: See the late submission policy here: http://www.cs.cmu. edu/~mgormley/courses/10601bd-f18/about.html#6-general-policies

• Submitting your work:

– Autolab: You will submit your code for programming questions on the homework to Autolab (https://autolab.andrew.cmu.edu/). After uploading your code, our grading scripts will autograde your assignment by running your program on a virtual machine (VM). The software installed on the VM is identical to that on linux.andrew.cmu.edu, so you should check that your code runs correctly there. If developing locally, check that the version number of the programming language environment and versions of permitted libraries match those on linux.andrew.cmu.edu. (Octave users: Please make sure you do not use any Matlab-specific libraries in your code that might make it fail against our tests.) You have a total of 10 Autolab submissions. Use them wisely. In order to not waste Autolab submissions, we recommend debugging your implementation on your local machine (or the linux servers) and making sure your code is running correctly first before any Autolab submission. The above is true for future assignments, but this one allows unlimited submissions.

• Materials: Download from autolab the tar file (“Download handout”). The tar file will contain all the data that you will need in order to complete this assignment.

For multiple choice or select all that apply questions, shade in the box or circle in the template document corresponding to the correct answer(s) for each of the questions. For LATEXusers, use and for shaded boxes and circles, and don’t change anything else.

1 Hello, Autolab! [38 Points]

1.1 Introduction

The goal of this assignement is to ensure that you:

1. Have a way to edit and test your code (i.e. a text editor and compiler/interpreter)

2. Are familiar with submitting to Autolab

3. Are familiar with file I/O and standard output in the language of your choice

1.2 Reading from a file [30pts]

In reverse.{py|m|java|cpp}, implement a program that reads in the lines of a file, then writes them in reverse order to an output file. Specifically, your program should take two command line arguments: the name of the input file and the name of the output file. It should read the lines of the input file and write them to the output file from last to first, separated by “ ”. You should assume that the input file has unix-style line breaks. (Windows uses “ ” to indicate a new line. Unix uses only “ ”.)

For example, if the file input.txt contained the stream

#pineapples #pinstripes #pinwheelofdoom #pinsir

which is commonly displayed as

#pineapples

#pinstripes

#pinwheelofdoom

#pinsir

depending on your language of choice, one of the following:

• python reverse.py input.txt output.txt

• octave -qH reverse.m input.txt output.txt

• javac reverse.java; java reverse input.txt output.txt

• g++ reverse.cpp; ./a.out input.txt output.txt

should write the following to output.txt

#pinsir #pinwheelofdoom #pinstripes #pineapples

which is displayed as

#pinsir

#pinwheelofdoom

#pinstripes

#pineapples

Note to Octave users: Please be sure that reverse.m is a script that gets its arguments from the command line rather than a function.

1.3 Test Code on linux.andrew.cmu.edu Machines

Before submitting to Autolab on this and every future assignment, you should check that it behaves correctly when run on the linux.andrew.cmu.edu machines, since they mirror the software installed on the Autolab virtual machines (VMs). These instructions assume you are working on a unix based operating system (e.g. Linux, Mac OS) – if you are using Windows you can install cygwin (https://www.cygwin.com/) which provides a unix-like environment. (Of course, you are also welcome to develop your code directly on these same servers.)

Follow the three stpes below. Here we assume your code and the example.txt file are located in a subdirectory ./reverse/.

1. Copy your code to the linux server:

rsync -a ./reverse/ <Your Andrew ID>@linux.andrew.cmu.edu:~/reverse/

2. Log into the linux server:

ssh <Your Andrew ID>@linux.andrew.cmu.edu

3. Change directories to where you just copied the code:

cd ~/reverse/

4. Run the code with one of the below:

• python reverse.py example.txt output.txt

• octave -qH reverse.m example.txt output.txt

• javac reverse.java; java reverse example.txt output.txt • g++ -g -std=c++11 reverse.cpp; ./a.out example.txt output.txt

5. Check that it was properly reversed:

cat output.txt

1.4 Autolab Submission [8pts]

You must submit a .tar file named reverse.tar containing reverse.{py|m|java|cpp}. You can create that file by running:

tar -cvf reverse.tar reverse.{py|m|java|cpp} from the directory containing your code.

Some additional tips: DO NOT compress your files; you are just creating a tarball. Do not use tar -czvf. DO NOT put the above files in a folder and then tar the folder. Autolab is case sensitive, so observe that all your files should be named in lowercase. You must submit this file to the corresponding homework link on Autolab.

Python3 Users: Please include a blank file called python3.txt (case-sensitive) in your tar submission and we will execute your submitted program using Python 3 instead of Python

2.7. If the file is not present, we will default to running your code with Python 2.7.

Instructions for Specific Problem Types

For “Select One” questions, please fill in the appropriate bubble completely:

Select One: Who taught this course?

Matt Gormley

# Marie Curie # Noam Chomsky

Select One: Who taught this course?

Matt Gormley # Marie Curie

@ @ Noam Chomsky

For “Select all that apply” questions, please fill in all appropriate squares completely:

Select all that apply: Which are scientists?

Stephen Hawking

Albert Einstein

Isaac Newton

I don’t know

Select all that apply: Which are scientists?

Stephen Hawking

Albert Einstein Isaac Newton

@@ I don’t know

Fill in the blank: What is the course number?

10-601 10-S7601S

2 Prerequisite Practice[62 Points]

In this section, you will work through a number of problems covering probability, statistics, calculus, linear algebra, geometry, and computer science.

2.1 Probability and Statistics [30pts]

Use the following data to answer questions 1-4. Consider data created by flipping a

coin five times S = [1, 1, 0, 1, 1] , where 1 denotes that the coin turned up heads and 0 denotes that it turned up tails.

1. [2pt] The sample mean for this data is:

Select one:

1

2. [2pt] The (uncorrected) sample variance for this data is:

Select one:

3. [2pt] With reference to the previous question, what is the probability of observing this data, assuming it was generated by flipping a coin X with an unequal probability of heads (1) and tails (0), where now the distribution is P(X = 1) = 0.75, P(X = 0) =

0.25?

Select one:

4. Note that the probability of this data sample would be greater if the value of P(X = 1) was not 0.5, but instead some other value. What is the value that maximizes the probability of the sample S?

Select one:

1

5. [2pt] State true or false. For events A and B,

P(A ∩ B) = P(A) + P(B) − P(A ∪ B)

Select one:

True

False

6. [2pt] State true or false. For events A and B,

P(A1 ∩ A2 ∩ A3) = P(A3|A2 ∩ A1)P(A2|A1)P(A1)

Select one:

True

False

Use the following information to answer questions 7-8. Whether your car is

P(R) = 0.4

P(W|R) = 0.8

P(W|¬R) = 0.2

7. What is the probability of P(¬R)? (Here ¬R reads: no rain last night)

0.1

0.4

0.9

0.6

8. [2pt] Using the same probabilities as the previous question, what is the probability that your car is wet in the morning?

Select one:

0.64

0.56

0.44

0.4

Use the following information to answer questions 9-10. Consider the follow-

ing joint probability table where both X and Y are binary variables:

X Y Probability

0 0 0.1

0 1 0.2

1 0 0.4

1 1 0.3

9. [2pt] Using the same table, what is P(X = 1|Y = 1)?

Select one:

10. What is P(Y = 0)?

0.2

0.6

0.5

0.3

Use the following information to answer questions 11-13. Let X be a random

variable and the expected value of X is E[X] = 1 and the variance of X is V ar[X] = 1.

11. [2pt] What is E[6X]?

Select one:

1

3

6

36

12. [2pt] What is V ar[3X]?

Select one:

1

3

6

9

13. [2pt] What is V ar[2X + 3]?

Select one:

3

4

5

7

14. What is the mean, variance and entropy of a Bernoulli (p) random variable?

p,p(1 − p),−(1 − p)log(1 − p) − plog(p) p(1 − p),p,−(1 − p)log(1 − p) − plog(p) p,−(1 − p)log(1 − p) − plog(p),p(1 − p)

The entropy of a Bernoulli variable is not defined.

15. [2pt] Please match the probability density function of the random variable X to its corresponding distribution name.

(a) prob(X=x) =

(b) prob(X=x) = λe−λx when x ≥ 0; 0 otherwise

(c) prob(X=x) =

(d) prob(X=x) = when a ≤ x ≤ b; 0 otherwise

(e) prob(X=x) = px(1 − p)1−x

Multivariate Gaussian:

Exponential:

Uniform:

Bernoulli:

Binomial:

2.2 CS Foundations [10pts]

1. [2pt] If f(n) = ln(n) and g(n) = log3(n) which of the following are true?

Select one:

f(n) = O(g(n)) g(n) = O(f(n))

Both

Neither

2. [2pt] If f(n) = n10 and g(n) = 10n which of the following are true?

Select one:

f(n) = O(g(n)) g(n) = O(f(n))

Both

Neither

Figure 1: Britian’s Royal Family

3. [2pt] Using the tree shown above, how many nodes would depth-first-search visit in finding Mia Tindall (including her node)? Assuming we search left-to-right and topdown.

Select one:

3

12

15

18

Figure 2: A Binary Tree with indexed nodes

4. [2pt] Shown above is a Binary Tree with indexed nodes. Assume root node is node 1. What is the node-visit order of DFS and BFS of the above Binary Tree?

A depth-first search (DFS) traversal of a binary tree starts with visiting the root node, and recursively searches down the left subtree (i.e., the tree rooted at the left node) before going to search the right subtree (i.e., the tree rooted at the right node) until the traversal is done.

Note: Alternatively, we can also look right subtree before left subtree too, for the question please consider left to right order!

A breath-first search (BFS) traversal of a binary tree visits every node (assuming a left-to-right order) on a level (with the same distance to the root) before going to a lower level until the traversal is done.

The node-visit order of DFS is:

The node-visit order of BFS is:

5. [2pt] Fill in the blanks in the pseudo code for key search using recursive depth-first search (DFS) traversal.

class TreeNode:

def __init__(self, val): self.val = val self.leftNode = None self.rightNode = None

# the left/right node is denoted as node.leftNode/node.rightNode

# left/right node are of type TreeNode

# the value of the node is denoted as node.val

# recursive DFS to search for the node with value key in a binary tree # the left node is assumed to be searched before the right node

def find_val(node, key):

if node is None:

return None

if (1)____________________________: return node

else:

result = (2)___________________________

if result is None:

result = (3)___________________________ return (4)___________________________

2.3 Calculus [8pts]

1. [2pt] Find the derivative of y with respect to x, where y = 2×3 + x − 5

Select one:

6×2

6×2 − 5

6×2 + 1

6×2 + x − 5

2. [2pt] Evaluate the derivative of y with respect to x, where at x = 1.

3. [2pt] Find the partial derivative of y with respect to x, where y = 3xcos(z)e−x

Select one:

3cos(z)e−x(1 − x)

3cos(z)e−x

3cos(z)e−x(1 + x)

−3sin(z)e−x

4. [2pt] If you take the derivative of −x2 − 4x − 3 set the derivative to 0 and solve for x you will find:

Select one: a minimum a maximum a minimum or a maximum

None of the above

2.4 Vectors and Matrices [8pts]

1. [2pt] Consider the matrix X and the vectors y and z below: X= y= z=

What is the inner product of the vectors y and z? (this is also sometimes called the dot product) Select one:

2. [2pt] Using the same values for X, y, and z as above, what is the product of Xy?

Select one:

3. [2pt] For the matrices and What is the product

AB?

Select one:

13

13

4 11

−14

−4

5

9

−2

20 −6

3 −20 9

2

19

−14

−5

4. [2pt] True or False, The matrix A from the previous question has an inverse?

Select one:

True

False

2.5 Geometry [6pts]

1. [2pt] What relationship does the vector w share with the line wTx + b = 0? (assume x and w are both two dimensional column vectors, and wT indicates the transpose of the column vector w.)

Select one:

parallel orthogonal depends on the value of b

2. [2pt] With reference to the above question, select the statement which best explains why w and wTx + b = 0 share the above relationship.

Select one:

The inner product wT(x0 − x00), where x0 and x00 are two points on the line wTx + b = 0, is 0

The inner product wT(x0 − x00), where x0 and x00 are two points on the line wTx + b = 0, is 1

The inner product wT(x0 − x00), where x0 and x00 are two points on the line wTx + b = 0, is (b1 − b2)

3. [2pt] What is the distance from the origin to the line wTx + b = 0? (λ is some constant)

Select one:

Collaboration Questions Please answer the following:

1. Did you receive any help whatsoever from anyone in solving this assignment?

Yes / No.

• If you answered ‘yes’, give full details:

• (e.g. “Jane Doe explained to me what is asked in Question 3.4”)

2. Did you give any help whatsoever to anyone in solving this assignment?

Yes / No.

• If you answered ‘yes’, give full details:

• (e.g. “I pointed Joe Smith to section 2.3 since he didn’t know how to proceed with Question 2”)

3. Did you find or come across code that implements any part of this assignment ? Yes / No. (See below policy on “found code”)

• If you answered ‘yes’, give full details:

• (book & page, URL & location within the page, etc.).

## Reviews

There are no reviews yet.