Esempio n. 1
0
def test_with_and_without_js():
    dir = os.path.join(os.path.dirname(__file__), 'data')
    name = 'gaussian-2d-mean0-std1,2'
    feats = Features.load_from_hdf5(os.path.join(dir, name + '.h5'))

    specs = ['hellinger']
    Ks = [3, 5]

    with h5py.File(os.path.join(dir, name + '.divs.h5'), 'r') as f:
        expected = load_divs(f, specs, Ks)
        min_dist = f.attrs['min_dist']

    est = partial(estimate_divs, feats, Ks=Ks, min_dist=min_dist,
                  status_fn=None)

    with capture_output(True, True, merge=False):
        ds = est(specs=specs + ['js'])
        oth_with = ds[:, :, :-1, :]
        js_with = ds[:, :, -1, :]

        js_without = est(specs=['js'])[:, :, 0, :]

    assert_close(oth_with, expected, atol=5e-5,
                 msg="others ({}) broke with JS".format(', '.join(specs)))
    assert_close(js_with, js_without, atol=5e-5,
                 msg="JS different with/without others")
Esempio n. 2
0
def test_with_and_without_js():
    dir = os.path.join(os.path.dirname(__file__), 'data')
    name = 'gaussian-2d-mean0-std1,2'
    feats = Features.load_from_hdf5(os.path.join(dir, name + '.h5'))

    specs = ['hellinger']
    Ks = [3, 5]

    with h5py.File(os.path.join(dir, name + '.divs.h5'), 'r') as f:
        expected = load_divs(f, specs, Ks)
        min_dist = f.attrs['min_dist']

    est = partial(estimate_divs,
                  feats,
                  Ks=Ks,
                  min_dist=min_dist,
                  status_fn=None)

    with capture_output(True, True, merge=False):
        ds = est(specs=specs + ['js'])
        oth_with = ds[:, :, :-1, :]
        js_with = ds[:, :, -1, :]

        js_without = est(specs=['js'])[:, :, 0, :]

    assert_close(oth_with,
                 expected,
                 atol=5e-5,
                 msg="others ({}) broke with JS".format(', '.join(specs)))
    assert_close(js_with,
                 js_without,
                 atol=5e-5,
                 msg="JS different with/without others")
Esempio n. 3
0
def test_divs():
    dir = os.path.join(os.path.dirname(__file__), 'data')
    argses = [{'cores': cores, 'status_fn': status_fn}
              for cores in [1, None]
              for status_fn in [None]]  # , True]]
    # TODO: test a custom status_fn also

    specs = ['hellinger', 'kl', 'l2', 'linear',
             'renyi:0.5', 'renyi:0.7', 'renyi:0.9', 'renyi:0.99']
    Ks = [1, 3, 5, 10]
    for name in ['gaussian-2d-mean0-std1,2', 'gaussian-20d-mean0-std1,2']:
        for dtype in [np.float64, np.float32]:
            feats = Features.load_from_hdf5(
                os.path.join(dir, name + '.h5'),
                features_dtype=dtype)

            with h5py.File(os.path.join(dir, name + '.divs.h5'), 'r') as f:
                expected = load_divs(f, specs, Ks)
                min_dist = f.attrs['min_dist']

            tests = []
            for args in argses:
                tests.extend(check_div(feats, expected, specs, Ks, name,
                                       min_dist=min_dist, **args))
            for test in sorted(tests, key=lambda t: t[0].description):
                yield test
Esempio n. 4
0
def test_divs():
    dir = os.path.join(os.path.dirname(__file__), 'data')
    argses = [{
        'cores': cores,
        'status_fn': status_fn
    } for cores in [1, None] for status_fn in [None]]  # , True]]
    # TODO: test a custom status_fn also

    specs = [
        'hellinger', 'kl', 'l2', 'linear', 'renyi:0.5', 'renyi:0.7',
        'renyi:0.9', 'renyi:0.99'
    ]
    Ks = [1, 3, 5, 10]
    for name in ['gaussian-2d-mean0-std1,2', 'gaussian-20d-mean0-std1,2']:
        for dtype in [np.float64, np.float32]:
            feats = Features.load_from_hdf5(os.path.join(dir, name + '.h5'),
                                            features_dtype=dtype)

            with h5py.File(os.path.join(dir, name + '.divs.h5'), 'r') as f:
                expected = load_divs(f, specs, Ks)
                min_dist = f.attrs['min_dist']

            tests = []
            for args in argses:
                tests.extend(
                    check_div(feats,
                              expected,
                              specs,
                              Ks,
                              name,
                              min_dist=min_dist,
                              **args))
            for test in sorted(tests, key=lambda t: t[0].description):
                yield test