Skip to content

Commit

Permalink
Merge pull request #1126 from adler-j/fom_tests
Browse files Browse the repository at this point in the history
ENH: Add some tests for supervised FoM
  • Loading branch information
adler-j committed Sep 22, 2017
2 parents 95a7934 + 3d28a1b commit c683fbd
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions odl/contrib/fom/test/test_supervised.py
Expand Up @@ -3,13 +3,17 @@
import scipy.signal
import scipy.misc
import odl
import odl.contrib.fom
from odl.contrib.fom.util import filter_image_sep2d
from odl.util.testutils import simple_fixture

fft_impl_params = [odl.util.testutils.never_skip('numpy'),
odl.util.testutils.skip_if_no_pyfftw('pyfftw')]
fft_impl = simple_fixture('fft_impl', fft_impl_params,
fft_impl = simple_fixture('fft_impl',
[odl.util.testutils.never_skip('numpy'),
odl.util.testutils.skip_if_no_pyfftw('pyfftw')],
fmt=" {name} = '{value.args[1]}' ")
space = simple_fixture('space',
[odl.rn(3),
odl.uniform_discr(0, 1, 10)])


def filter_image(image, fh, fv):
Expand All @@ -32,5 +36,38 @@ def test_filter_image_fft(fft_impl):
assert np.allclose(conv_real, conv_fft)


def test_mean_squared_error(space):
true = odl.phantom.white_noise(space)
data = odl.phantom.white_noise(space)

result = odl.contrib.fom.mean_squared_error(data, true)
expected = np.mean((true - data) ** 2)

assert result == pytest.approx(expected)


def test_mean_absolute_error(space):
true = odl.phantom.white_noise(space)
data = odl.phantom.white_noise(space)

result = odl.contrib.fom.mean_absolute_error(data, true)
expected = np.mean(np.abs(true - data))

assert result == pytest.approx(expected)


def test_psnr(space):
true = odl.phantom.white_noise(space)
data = odl.phantom.white_noise(space)

result = odl.contrib.fom.psnr(data, true)

mse = np.mean((true - data) ** 2)
maxi = np.max(np.abs(true))
expected = 10 * np.log10(maxi**2 / mse)

assert result == pytest.approx(expected)


if __name__ == '__main__':
pytest.main([str(__file__.replace('\\', '/')), '-v'])

0 comments on commit c683fbd

Please sign in to comment.