test_learn_d_z.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:alphacsc 作者: alphacsc 项目源码 文件源码
def test_learn_codes():
    """Test learning of codes."""
    thresh = 0.25

    X, ds, z = simulate_data(n_trials, n_times, n_times_atom, n_atoms)

    for solver in ('l_bfgs', 'ista', 'fista'):
        z_hat = update_z(X, ds, reg, n_times_atom, solver=solver,
                         solver_kwargs=dict(factr=1e11, max_iter=50))

        X_hat = construct_X(z_hat, ds)
        assert_true(np.corrcoef(X.ravel(), X_hat.ravel())[1, 1] > 0.99)
        assert_true(np.max(X - X_hat) < 0.1)

        # Find position of non-zero entries
        idx = np.ravel_multi_index(z[0].nonzero(), z[0].shape)
        loc_x, loc_y = np.where(z_hat[0] > thresh)
        # shift position by half the length of atom
        idx_hat = np.ravel_multi_index((loc_x, loc_y), z_hat[0].shape)
        # make sure that the positions are a subset of the positions
        # in the original z
        mask = np.in1d(idx_hat, idx)
        assert_equal(np.sum(mask), len(mask))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号