Skip to content
Snippets Groups Projects
Linear transforms.ipynb 31.6 KiB
Newer Older
Nicolas Aspert's avatar
Nicolas Aspert committed
         "code": ">>> with np.testing.assert_raises(ValueError):\n...     get_haar_matrix(-1, 0)\n>>> with np.testing.assert_raises(ValueError):\n...     get_haar_matrix(16, 0)\n>>> with np.testing.assert_raises(ValueError):\n...     get_haar_matrix(4, 3)\n",
         "failure_message": "Did you forget to validate the input size before performing the computation ?",
         "hidden": false,
         "locked": false,
         "points": 1,
         "success_message": "Good, you properly validated size/level before computing the result"
        },
        {
         "code": ">>> H = get_haar_matrix(4, 2)\n>>> a = 1 / np.sqrt(2)\n>>> np.testing.assert_array_almost_equal(H, [[0.5, 0.5, 0.5, 0.5], [0.5, 0.5, -0.5, -0.5], [a, -a, 0.0, -0.0], [0.0, -0.0, a, -a]])\n",
         "failure_message": "Results seem incorrect, check your implementation",
         "hidden": false,
         "locked": false,
         "points": 2,
         "success_message": "Good, results look correct"
        },
        {
         "code": ">>> H = get_haar_matrix(64, 4)\n>>> np.testing.assert_array_almost_equal(H @ H.T, np.eye(64))\n>>> np.testing.assert_array_almost_equal(H.T @ H, np.eye(64))\n",
         "failure_message": "Results seem incorrect, check your implementation",
         "hidden": false,
         "locked": false,
         "points": 1,
         "success_message": "Good, matrix is orthogonal"
        }
       ],
       "scored": true,
       "setup": "",
       "teardown": "",
       "type": "doctest"
      }
     ]
    },
    "q14": {
     "name": "q14",
     "points": 6,
     "suites": [
      {
       "cases": [
        {
         "code": ">>> waverec = denoise_signal(get_fourier_matrix(len(wave_noisy)), wave_noisy, 0.0)\n>>> np.testing.assert_array_almost_equal(waverec, wave_noisy)\n",
         "failure_message": "Results seem incorrect, check your implementation",
         "hidden": false,
         "locked": false,
         "success_message": "Good, not denoising the noisy signal does not modify it."
        }
       ],
       "scored": true,
       "setup": "",
       "teardown": "",
       "type": "doctest"
      }
     ]
    },
    "q4": {
     "name": "q4",
     "points": 1,
     "suites": [
      {
       "cases": [
        {
         "code": ">>> from scipy.linalg import dft\n>>> np.testing.assert_array_almost_equal(get_fourier_matrix(16), dft(16, scale='sqrtn'))\n",
         "failure_message": "Check your implementation",
         "hidden": false,
         "locked": false,
         "success_message": "Good, your implementation returns correct results"
        },
        {
         "code": ">>> from unittest.mock import patch\n>>> def check_fourier_dft(N):\n...     with patch('scipy.linalg.dft') as mock_dft:\n...         get_fourier_matrix(N)\n...         mock_dft.assert_not_called()\n>>> check_fourier_dft(32)\n",
         "failure_message": "Do not use scipy.linalg.dft in your implementation",
         "hidden": false,
         "locked": false,
         "success_message": "Good, you did not use the scipy.linalg.dft function"
        },
        {
         "code": ">>> from unittest.mock import patch\n>>> def check_fourier_fft(N):\n...     with patch('scipy.fft.fft') as mock_fft:\n...         get_fourier_matrix(N)\n...         mock_fft.assert_not_called()\n>>> check_fourier_fft(24)\n",
         "failure_message": "Do not use scipy.fft.fft in your implementation",
         "hidden": false,
         "locked": false,
         "success_message": "Good, you did not use the scipy.fft.fft function"
        },
        {
         "code": ">>> from unittest.mock import patch\n>>> def check_fourier_npfft(N):\n...     with patch('numpy.fft.fft') as mock_fft:\n...         get_fourier_matrix(N)\n...         mock_fft.assert_not_called()\n>>> check_fourier_npfft(48)\n",
         "failure_message": "Do not use numpy.fft.fft in your implementation",
         "hidden": false,
         "locked": false,
         "success_message": "Good, you did not use the numpy.fft.fft function"
        },
        {
         "code": ">>> W = get_fourier_matrix(8)\n>>> np.testing.assert_array_almost_equal(np.conj(W.T) @ W, np.eye(8))\n",
         "failure_message": "Check your implementation, resulting matrix should be orthogonal.",
         "hidden": false,
         "locked": false,
         "success_message": "Good, your implementation returns an orthogonal matrix"
        },
        {
         "code": ">>> with np.testing.assert_raises(ValueError):\n...     get_fourier_matrix(0)\n>>> with np.testing.assert_raises(ValueError):\n...     get_fourier_matrix(-5)\n",
         "failure_message": "Did you forget to validate the input size before performing the computation ?",
         "hidden": false,
         "locked": false,
         "success_message": "Good, you properly validated size before computing the result"
        }
       ],
       "scored": true,
       "setup": "",
       "teardown": "",
       "type": "doctest"
      }
     ]
    },
    "q6": {
     "name": "q6",
     "points": 4,
     "suites": [
      {
       "cases": [
        {
         "code": ">>> W = get_block_dft_matrix(32, 8)\n>>> np.testing.assert_array_almost_equal(np.conj(W.T) @ W, np.eye(32))\n",
         "failure_message": "Check your implementation, resulting matrix should be orthogonal.",
         "hidden": false,
         "locked": false,
         "points": 1,
         "success_message": "Good, your implementation returns an orthogonal matrix"
        },
        {
         "code": ">>> with np.testing.assert_raises(ValueError):\n...     get_block_dft_matrix(64, 7)\n",
         "failure_message": "Did you forget to validate the input size before performing the computation ?",
         "hidden": false,
         "locked": false,
         "points": 1,
         "success_message": "Good, you properly validated size before computing the result"
        },
        {
         "code": ">>> W = get_block_dft_matrix(4, 2)\n>>> np.testing.assert_array_almost_equal(W[0:2, 0:2], get_fourier_matrix(2))\n>>> np.testing.assert_array_almost_equal(W[2:4, 2:4], get_fourier_matrix(2))\n>>> np.testing.assert_array_almost_equal(W[2:4, 0:2], np.zeros((2, 2)) * 1j)\n>>> np.testing.assert_array_almost_equal(W[0:2, 2:4], np.zeros((2, 2)) * 1j)\n",
         "failure_message": "Check your implementation !",
         "hidden": false,
         "locked": false,
         "points": 2,
         "success_message": "Good, your implementation returns the correct result"
        }
       ],
       "scored": true,
       "setup": "",
       "teardown": "",
       "type": "doctest"
      }
     ]
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}