def test_remove_zeros(self):
     values = np.array([[1.0, 0.0], [1.0, 1.0]])
     c = Categorical(values=values)
     self.assertTrue((c.values == 0.0).any())
     c.remove_zeros()
     self.assertFalse((c.values == 0.0).any())
Esempio n. 2
0
of the generative model to be a set of uniform Categorical distributions. Namely, the agent has no strong prior beliefs
about where it is likely to move. However, it will build beliefs about these transitions as it observes itself moving.

@NOTE: Linear indices are in row-major ordering (the default for numpy), to be contrasted with column-major ordering
(the default for MATLAB). This means that the upper-right position in the grid [0,1] corresponds to linear index 1, and the lower-left position [1,0]
corresponds to linear index 2. [0,0] and [1,1] are linear indices 0 and 3, respectively (invariant w.r.t row-major and column-major indexing).

# Posterior (recognition density)
We initialise the posterior beliefs `qs` about hidden states (namely, beliefs about 'where I am') as a flat distribution over the possible states. This requires the
agent to first 'evince' a proprioceptive observation from the environment (e.g. a bodily sensation of where the agent is) before updating its posterior to be centered
on the true, evidence-supported location.

"""

env_shape = [3, 3]
n_states = np.prod(env_shape)

env = GridWorldEnv(shape=env_shape)

likelihood_matrix = env.get_likelihood_dist()
A = Categorical(values=likelihood_matrix)
A.remove_zeros()
plot_likelihood(A, 'Observation likelihood')

B = Categorical(values=np.ones((n_states, n_states)))
B.normalize()
plot_likelihood(B, 'Transition likelihood')

qs = Categorical(dims=[env.n_states])
qs.normalize()