Пример #1
0
def test_inv_select_items_none():
    idx = as_variable(np.array([[0, 1, 2, 3], [0, 1, 2, 3]], dtype=np.int32))
    val = as_variable(np.array([[0.5, 3.14, 0.0, -9.9], [1.0, -1.0, 1.0,
                                                         4.0]]))

    out = inverse_select_items_per_row(val, idx)

    assert_allclose(out.data, np.array([[], []], dtype=np.int32))
Пример #2
0
def test_inv_select_items_less_idx():
    idx = as_variable(np.array([[3, 1], [1, 3]]))
    val = as_variable(np.array([[0.5, 3.14, 0.0, -9.9], [1.0, -1.0, 1.0,
                                                         4.0]]))
    exp = as_variable(np.array([[0.5, 0.0], [1.0, 1.0]]))

    out = inverse_select_items_per_row(val, idx)

    assert_allclose(out.data, exp.data)
    def log_propensity_independent(self, x, action):
        xp = cuda.get_array_module(action)
        pred = self._predict(x)

        final_action = action
        if self.k > 0 and action.shape[1] < pred.shape[1]:
            all_actions = F.broadcast_to(xp.arange(0, pred.shape[1],
                                                   dtype=action.data.dtype),
                                         pred.shape)
            inv_items = inverse_select_items_per_row(all_actions, action)
            items = select_items_per_row(all_actions, action)
            final_action = F.concat((items, inv_items), axis=1)

        pred = select_items_per_row(pred, final_action)

        results = F.log_softmax(pred)
        if self.k > 0:
            results = results[:, :self.k]
        return results