Пример #1
0
 def test_normalize_multi_factor(self):
     values_1 = np.random.rand(5)
     values_2 = np.random.rand(4, 3)
     values = np.array([values_1, values_2])
     d = Dirichlet(values=values)
     normed = Categorical(values=d.mean(return_numpy=True))
     self.assertTrue(normed.is_normalized())
Пример #2
0
 def test_normalize_two_dim(self):
     values = np.array([[1.0, 1.0], [1.0, 1.0]])
     d = Dirichlet(values=values)
     expected_values = np.array([[0.5, 0.5], [0.5, 0.5]])
     self.assertTrue(
         np.array_equal(d.mean(return_numpy=True), expected_values))
# Prior
We initialise the agent's prior over hidden states at the start to be a flat distribution (i.e. the agent has no strong beliefs about what state it is starting in)

# 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 gather a proprioceptive observation from the environment (e.g. a bodily sensation of where it feels itself to be) before updating its posterior to be centered
on the true, evidence-supported location.
"""

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

b = Dirichlet(values=np.ones((n_states, n_states)))
B = b.mean()
plot_likelihood(B, 'Initial transition likelihood')

D = Categorical(values=np.ones(n_states))
D.normalize()

qs = Categorical(dims=[env.n_states])
qs.normalize()
"""
Run the dynamics of the environment and inference. Start by eliciting one observation from the environment
"""

# reset environment
first_state = env.reset(init_state=s[0])

# get an observation, given the state