Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Math 480 - Grading for Homework 3:
Due Friday, April 22, 2016 by 6pm
Your grading will be automatically collected.
HOMEWORK TOTAL: 50 POINTS
GRADING GUIDELINES
- Go through your gradee's homework worksheet and assign a score to each question. Please state an individual questions assigned score in a cell below it, and leave a few words comment.
- State the total score you've assigned for the homework at the top of the worksheet. Put
TOTAL: X/50
in a cell on its own, where X is the total score for this homework. - The idea is to provide constructive feedback for your gradee. Please attempt to be fair in your grading, and make sure your comments are professional.
- For visibility, I recommend any text you add be colored red. You're welcome to copy any of red html text below and paste it in, suitably edited, if you so desire.
Problem 1: Standard deviation
a. Write a straightforward Python function (not using anything special from numpy or Sage) to compute the standard deviation of a list of numbers.
b. Compare the speed of your program when given as input v = range(1000)
, v = range(10000)
and v = range(100000)
with the speed of standard deviation on that input as implemented in: numpy, R, and stats.TimeSeries. Use %timeit.
c. Do a and b again, but for an implementation of mysd using Cython (you do not have to use any special features of Cython).
20 Points Total
Part A (2 points total)
Test that their function behaves the same way as the standard deviation function built into sage.
Award:
- 2 points if they did not use anything special outside of vanila Python
- 1
Part B (9 points total, 3 points per part)
Award:
- 3 points
- 2 points
Part C (9 points total, 3 points per part)
Award:
- 3 points if they
- 2 points if they
- 1 point if they.
- 0 points for anything else
Problem 2: Which approach
Imagine you're an a tenure-track academic researcher. To do some key research, you need to implement code to compute a function , and use it to evaluate .
You can implement this code in two ways:
STRATEGY 1: Work fulltime for one month implementing and debugging a very fast algorithm in C, so that actually computing only takes hour on your laptop.
STRATEGY 2: Spend about 3 hours writing a non-optimized Python program (that calls some other slow code), then let your code run on a cluster for 1 month (running the program costs $2K in grant money).
Come up with a creative (but serious) argument in favor of each of the above strategies.
(How this will be graded: (a) you may lose points for mistakes in English spelling and grammar, (b) you must have put real thought into the problem.)
Problem 3:
Given a rough order of magnitude estimate for how long each of the following should take:
Doing a Google search for
math software
(just the time that Google reports it having taken).A server in Seattle pinging a server in California (both with optimal network connections).
A server in Seattle pinging a server in Japan (both with optimal network connections).
Adding together 1 million double precision floating point numbers using pure Python.
Adding together 1 million double precision floating point numbers using Cython (or C) with type declarations.
Computing the determinant of a 100x100 matrix whose entries are random single-digit integers (using Sage). No rounding errors.
1 million separate writes of random numbers to an SSD disk. By "separate write" we mean that you flush the write to disk every time. You can lookup specs for number of IO operations per second for some common SSD's by searching on Google.
Problem 4: Techniques used by projects
Track down projects that use various tools that we discussed this week.
Question 1
source: https://github.com/cython/cython/wiki/projects
Sage - Call useful methods at Cython speed (ex. Fast Hashable Class http://doc.sagemath.org/html/en/reference/misc/sage/misc/fast_methods.html)
Crux
Plasticity
GIPSY
PyYAML
These projects use Cython to get the functionality of Python and the speed of C (faster than pure Python)
Question 2
SciPy (https://www.scipy.org/)
PyTables (http://www.pytables.org/)
Pathomx (http://pathomx.org/)
NeuralTalk (https://github.com/karpathy/neuraltalk)
Numpy is used for data collection of generic data that can be seamlessly utilized with many different data structures (source: http://www.numpy.org/)
Question 3
Numbas (https://github.com/numbas/Numbas)
numbagg (https://github.com/shoyer/numbagg)
numbavec (https://github.com/mvsaha/numbavec)
Numba is used to run mathematical processes faster than pure Python can.
Problem 5:
Write a simple naive function using a for loop to compute , the sum of the first integers. Do not use the formula . Use %timeit and/or %time to see how long your function takes when and .
Ensure that the numbers are of type Python int in part 1 (rather than Sage's Integers). How much does that improve the timings?
Use Numba to try to speed up your Python function and time it (put %python at the top of any cell in which you use numba). Does Numba help?
Compile the exact same function using Cython and time it.
Add Cython type declarations, so assume that everything is
cdef long
, and compile it.Do 1-5 above again, but using the formula instead of a for loop.