def expected_reward(b, R, a, T=None):
    """Returns the expected reward at a given belief"""
    r = 0.0
    for s in b:
        if T is not None:
            for sp in b:
                r += b[s] * R.sample(s, a, sp) * T.probability(sp, s, a)
        else:
            r += b[s] * R.sample(s, a, None)
    return r