Custom Homework

Data Compression

Week1-Programming

Write a matlab function with the following signature:


      function ret = prog(varargin)
      % Your implementation here.
      end
    
    
The function takes an arbitrary number of arguments and returns their sum. You must name the function 'prog' and you must put it in a file named 'prog.m'. Submit this file to Gradescope.

NOTE: This assignment is meant to be very simple and will take you through the paces of automated grading of a programming assignment.

Week2-Programming

Losslessly compress the bouncing ball data genarated with the following MATLAB function


      function pos = bouncingballpos(timestep, nsteps, delay)
      % position - the position of the ball over time
      % NOTE: quantization to 8-bits
      if nargin < 3
      delay = 0;
      end
      pos = uint8(round(255*2*abs(rem(linspace(0, timestep * nsteps, nsteps),1)-1/2)));
      end
    
    
You must name the function 'prog' and you must put it in a file named 'prog.m'. The file should implement a function called like this:

      function out = prog(in, mode)
      % Your implementation here.
      end
    
    

If 'mode' is zero, the progam should perform the encoder function, i.e. it should interpret the input 'in' as the sequence of positions of the bouncing ball, quantized to 8 bits, as if produced by the function 'bouncingballpos' with some arguments.

If 'mode' is non-zero, the program should interpret the decoder function, i.e. the input 'in' should be understood as the previously encoded data (obtained with 'mode' set to 0). In this mode 'prog' should reproduce the original ball position.

It is required that


	assert( all( prog(prog(x, 0),1) == x ) )
      
never fails, as long as $x$ is an 'uint8' array with not more than 1 million entries.

Furthermore, the compression ratio for good data should be as big as possible:


	compression_ratio = length(x)./ length(prog(x, 0))
      
should be as large as possible when produced in this way:

	x = bouncingballpos(timestep, nsteps, delay)
      
The values of 'timestep', 'nsteps' and 'delay' will be randomized scalars of class 'double', with reasonable values.

The leaderboard will be ordered according to the value of 'compression_ratio'.

Suggestions

Start your project by copying the files in the folder BouncingBall . This folder can be submitted as is, as a Zip file. That is, it is a reference implementation of the code. However, I created a Zip file that only includes the functions that are called by prog (directly or indirectly).

The folder implements simple unit testing, a methodology of testing small units of functionality. MATLAB automates running tests. The files that start with the word 'test' (e.g. 'testbouncing.m', 'testroundtrip.m') are unit test files. They can be run in one shot as follows:


	runtests
      
You should create your own test files and rerun all tests in this manner often. Note the reports of failures and successes. Work out the bugs until there are no failures.

In test driven development you write tests before you write your functions. The function stubs get then created, so that the code does not fail for the trivial reason of a function not having been implemented.

Week3-Programming

Develop a (binary) Huffman code which is optimal for encoding the Shakespeare play Coriolanus, as presented in the file coriolanus.txt in the LectureNotes folder.

The procedure is explained on this documentation page:

https://www.mathworks.com/help/comm/ref/huffmanenco.html

The autograder for this assignment will expect several functions implemented in several files, as follows.

The first function will return the Huffman dictionary, with this signature


	function dict = coriolandict
	% Your implementation here.	
	end
      
(in the file 'coriolandict.m') You can read the file 'coriolanus.txt' from this function, I will make sure it will be found in the same folder as your functions. The dictionary should be in the format

	dict = {'a', 0; 'b', [1,0]; 'c', [1,1,0]; 'd', [1,1,1,0]; 'e', [1,1,1,1]}
      
That is, it is a cell array with two columns, with the letters and symbols of the play in the first column, and the Huffman codes in the second.

The second function should be able to encode any part of 'coriolanus.txt'


	function code = coriolanencoder(message, dict)
	% Your implementation here.	
	end
      
and the third function should be able to decode the message:

	function message = coriolandecoder(code, dict)
	% Your implementation here.	
	end
      
I will pass the dictionary you developed to the encoder and decoder.

You should check that your code is lossles, i.e., the test


	assert(all ( message == coriolandecoder(coriolanencoder( message, dict), dict) ))
      
should always succeed, as long as the message is written in the alphabet covered by the dictionary.

Week4-Programming

The machine learning task in this assignment is to detect digit rotation in the MNIST data set using transfer learning. The strategy is to use to use two datasets available in MATLAB, on the page Data Sets for Deep Learning

Digits
Synthetic digits with known rotation
MNIST
Hand-written digits with unknown rotation
Here is the sequence of steps (to be discussed in class):