def test_apply_transform(): hashed_table = np.array([0, 1, 2, 0, 1], dtype=np.int) w0 = np.array([0.1, 0.05, 0.0, 0.05, 0.2]) w1 = np.array([0.05, 0.05, 0.1, 0.15, 0.25]) sum0 = np.array([w0[0] + w0[3], w0[1] + w0[4], w0[2]]) sum1 = np.array([w1[0] + w1[3], w1[1] + w1[4], w1[2]]) expected_error = sum0.sum() expected_table = np.ones(5) _error, _table, u_index = cl._apply_transform(hashed_table, w0, w1) nt.assert_almost_equal(_error, expected_error) nt.assert_allclose(_table, expected_table) del w0, w1, sum0, sum1, expected_error, expected_table, _error, _table, u_index w0 = np.array([0.13, 0.05, 0.08, 0.15, 0.2]) w1 = np.array([0.02, 0.05, 0.02, 0.05, 0.25]) sum0 = np.array([w0[0] + w0[3], w0[1] + w0[4], w0[2]]) sum1 = np.array([w1[0] + w1[3], w1[1] + w1[4], w1[2]]) expected_error = sum1[0] + sum0[1] + sum1[2] expected_table = np.array([0, 1, 0, 0, 1]) _error, _table, u_index = cl._apply_transform(hashed_table, w0, w1) nt.assert_almost_equal(_error, expected_error) nt.assert_allclose(_table, expected_table)
def _single_iteration(table, w0, w1): _table = cl.product_hash(table) return _table, cl._apply_transform(_table, w0, w1)