コード例 #1
0
ファイル: test_gmm.py プロジェクト: ltyong/scikit-learn
def test_lmvnpdf_spherical():
    n_features, n_components, n_obs = 2, 3, 10

    mu = rng.randint(10) * rng.rand(n_components, n_features)
    spherecv = rng.rand(n_components, 1) ** 2 + 1
    obs = rng.randint(10) * rng.rand(n_obs, n_features)

    cv = np.tile(spherecv, (n_features, 1))
    reference = _naive_lmvnpdf_diag(obs, mu, cv)
    lpr = mixture.lmvnpdf(obs, mu, spherecv, 'spherical')
    assert_array_almost_equal(lpr, reference)
コード例 #2
0
def test_lmvnpdf_spherical():
    n_features, n_states, n_obs = 2, 3, 10

    mu = np.random.randint(10) * np.random.rand(n_states, n_features)
    spherecv = np.random.rand(n_states, 1)**2 + 1
    obs = np.random.randint(10) * np.random.rand(n_obs, n_features)

    cv = np.tile(spherecv, (n_features, 1))
    reference = _naive_lmvnpdf_diag(obs, mu, cv)
    lpr = mixture.lmvnpdf(obs, mu, spherecv, 'spherical')
    assert_array_almost_equal(lpr, reference)
コード例 #3
0
ファイル: test_gmm.py プロジェクト: ltyong/scikit-learn
def test_lmvnpdf_full():
    n_features, n_components, n_obs = 2, 3, 10

    mu = rng.randint(10) * rng.rand(n_components, n_features)
    cv = (rng.rand(n_components, n_features) + 1.0) ** 2
    obs = rng.randint(10) * rng.rand(n_obs, n_features)

    fullcv = np.array([np.diag(x) for x in cv])

    reference = _naive_lmvnpdf_diag(obs, mu, cv)
    lpr = mixture.lmvnpdf(obs, mu, fullcv, 'full')
    assert_array_almost_equal(lpr, reference)
コード例 #4
0
def test_lmvnpdf_full():
    n_features, n_states, n_obs = 2, 3, 10

    mu = np.random.randint(10) * np.random.rand(n_states, n_features)
    cv = (np.random.rand(n_states, n_features) + 1.0)**2
    obs = np.random.randint(10) * np.random.rand(n_obs, n_features)

    fullcv = np.array([np.diag(x) for x in cv])

    reference = _naive_lmvnpdf_diag(obs, mu, cv)
    lpr = mixture.lmvnpdf(obs, mu, fullcv, 'full')
    assert_array_almost_equal(lpr, reference)
コード例 #5
0
ファイル: test_gmm.py プロジェクト: ltyong/scikit-learn
def test_lmvnpdf_diag():
    """
    test a slow and naive implementation of lmvnpdf and
    compare it to the vectorized version (mixture.lmvnpdf) to test
    for correctness
    """
    n_features, n_components, n_obs = 2, 3, 10
    mu = rng.randint(10) * rng.rand(n_components, n_features)
    cv = (rng.rand(n_components, n_features) + 1.0) ** 2
    obs = rng.randint(10) * rng.rand(n_obs, n_features)

    ref = _naive_lmvnpdf_diag(obs, mu, cv)
    lpr = mixture.lmvnpdf(obs, mu, cv, 'diag')
    assert_array_almost_equal(lpr, ref)
コード例 #6
0
def test_lmvnpdf_diag():
    """
    test a slow and naive implementation of lmvnpdf and
    compare it to the vectorized version (mixture.lmvnpdf) to test
    for correctness
    """
    n_features, n_states, n_obs = 2, 3, 10
    mu = np.random.randint(10) * np.random.rand(n_states, n_features)
    cv = (np.random.rand(n_states, n_features) + 1.0)**2
    obs = np.random.randint(10) * np.random.rand(n_obs, n_features)

    ref = _naive_lmvnpdf_diag(obs, mu, cv)
    lpr = mixture.lmvnpdf(obs, mu, cv, 'diag')
    assert_array_almost_equal(lpr, ref)