CS335 – Assignment 0 Solved

$ 29.99
Category:

Description

The objective of this lab assignment is to familiarize you with the numpy and matplotlib libraries in python.
1 Problem on Probability
1.1 Theoretical Problems
(a) Let X ∼ FX be a random variable with given CDF FX. Let there be another random variable Y ∼ Unif[0,1]. Express X in terms of Y and prove your result. (1.5 Marks)
(b) Let X be an exponential distribution with parameter λ. Using the above result, obtain X in terms of Y . (0.5 Marks)
1.2 Programming
Let X be from the exponential distribution with λ = 1.0. Complete the function modify uniform in the file probability.py to generate samples of this variable using only the numpy.random.uniform function. (1 Mark)
2 Vectorization
In this problem you will implement a function to compute the pair-wise L2 similarity between each pair of points in a set.
Let X ∈ Rn×d where n is the number of points in the the set and d is the number of dimensions of the basis if the points, the L2 similarity between two points x and y is defined as

(a) Obtain a vector expression for d(x,y) when x,y ∈Rd (1 Mark)
1
(b) Complete the function pairwise similarity looped in the file similarity.py to obtain this matrix K using for loops. (0.5 Marks)
The above O(n2d) solution doesn’t scale well. However, numpy provides a powerful mechanism called vectorization which can speed up this process drastically.
(c) Complete the function pairwise similarity vec in the file similarity.py to obtain K in a vectorized manner. Refer to the comments in the function for an approach to this problem. (2 Marks)
(d) Run the file similarity.py for multiple values of d and n using the command
$ python3 similarity . py −−dim <d> −−num <n>
How do you expect time taken for the vectorized and looped functions to grow with dimension and number of samples? Plot 4 graphs showing the time vs dimension and time vs number of samples for the two functions and include these in your answers file. Pick 5 values between 0 − 1000 for both n and d for your plot, while keeping the other variable constant. (0.5 Mark)
3 Probability and simulation
You are given a special coin for which probability of getting a head is 0.75 and probability of getting a Tail is 0.25. You are told to keep flipping the coin till you get two consecutive heads. What is the expected number of flips that you have to make?
(a) Compute the expected value analytically. (2 Marks)
Collate all the theoretical solutions into ONE pdf file named answers.pdf. Add the graphs from Problems 2 and 3 as well. Submit this file along with the python files simulation.py, probability.py and similarity.py, zip them in a folder named <roll no> assignment 0.zip. The starter folder is present in the files uploaded with the assignment.
2

Reviews

There are no reviews yet.

Be the first to review “CS335 – Assignment 0 Solved”

Your email address will not be published. Required fields are marked *