Beispiel #1
0
def metric(name, winSize, winAlpha, nBits=0):  # {{{
    '''Take attributes of a metric, return a callable implementation.

    E.g. Use like: metric("foo")(x, y)

    NOTE: Ex isn't really a metric but it's a convenient place to choose between
    implementations by nBits.
    '''
    if name is None:
        return None

    w = powsineCoeffs(winSize, winAlpha)

    assert 0 == nBits, "TODO: Implement fx*()"
    assert name in metricNames or name in ["Ex"], name
    fs = {
        "Ex": partial(fxEx if 0 < nBits else ndEx, w, nBits=nBits),
        "Cex": partial(fxCex if 0 < nBits else ndCex, w, nBits=nBits),
        "Cls": partial(fxCls if 0 < nBits else ndCls, w, nBits=nBits),
        "Cos": partial(fxCos if 0 < nBits else ndCos, w, nBits=nBits),
        "Cov": partial(fxCov if 0 < nBits else ndCov, w, nBits=nBits),
        "Dep": partial(fxDep if 0 < nBits else ndDep, w, nBits=nBits),
        "Ham": partial(fxHam if 0 < nBits else ndHam, w, nBits=nBits),
        "Tmt": partial(fxTmt if 0 < nBits else ndTmt, w, nBits=nBits),
    }

    return fs[name]
Beispiel #2
0
 def test_SineWin(self):
     w = powsineCoeffs(6, 2)
     x = np.array([1, 1, 1, 0, 0, 0])
     y = np.array([1, 1, 1, 0, 0, 0])
     result = ndTmt(w, x, y)
     self.assertAlmostEqual(result, 1.0)
Beispiel #3
0
 def test_SineWin(self):
     w = powsineCoeffs(6, 2)
     x = np.array([1, 1, 1, 0, 0, 0])
     result = ndEx(w, x)
     self.assertAlmostEqual(result, 0.5)