forked from SSchwoebel/ActiveInferenceBPBethe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.py
77 lines (50 loc) · 2.53 KB
/
environment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""This module contains various experimental environments used for testing
human behavior."""
import numpy as np
class GridWorld(object):
def __init__(self, Omega, Theta,
trials = 1, T = 10):
#set probability distribution used for generating observations
self.Omega = Omega.copy()
#set probability distribution used for generating state transitions
self.Theta = Theta.copy()
#set container that keeps track the evolution of the hidden states
self.hidden_states = np.zeros((trials, T), dtype = int)
def set_initial_states(self, tau):
#start in lower corner
self.hidden_states[tau, 0] = 1
if tau%100==0:
print("trial:", tau)
def generate_observations(self, tau, t):
#generate one sample from multinomial distribution
o = np.random.multinomial(1, self.Omega[:, self.hidden_states[tau, t]]).argmax()
return o
def update_hidden_states(self, tau, t, response):
current_state = self.hidden_states[tau, t-1]
self.hidden_states[tau, t] = np.random.choice(self.Theta.shape[0],
p = self.Theta[:, current_state, int(response)])
"""
test: please ignore
"""
class FakeGridWorld(object):
def __init__(self, Omega, Theta,
hidden_states, trials = 1, T = 10):
#set probability distribution used for generating observations
self.Omega = Omega.copy()
#set probability distribution used for generating state transitions
self.Theta = Theta.copy()
#set container that keeps track the evolution of the hidden states
self.hidden_states = np.zeros((trials, T), dtype = int)
self.hidden_states[:] = np.array([hidden_states for i in range(trials)])
def set_initial_states(self, tau):
#start in lower corner
self.hidden_states[tau, 0] = 1
#print("trial:", tau)
def generate_observations(self, tau, t):
#generate one sample from multinomial distribution
o = np.random.multinomial(1, self.Omega[:, self.hidden_states[tau, t]]).argmax()
return o
def update_hidden_states(self, tau, t, response):
current_state = self.hidden_states[tau, t-1]
self.hidden_states[tau, t] = np.random.choice(self.Theta.shape[0],
p = self.Theta[:, current_state, int(response)])