def get_pre(self, agent, n_census): """ Gathers and uses env info to make a prehension transition matrix Args: self: the env agent: the agent acting in the env n_census: unused Returns: prehesion based on what Creatures are North, South, East, and West of self, determining what direction the agent might come. """ trans_str = "" d, total = self.dir_info(agent) if (type(agent) == Zombie): trans_str += self.zombie_trans(d, total) else: trans_str += self.human_trans(d, total) trans_matrix = markov.from_matrix(np.matrix(trans_str)) return trans_matrix
def get_pre(self, agent, n_census): numRH = 0 numBH = 0 numRF = 0 numBF = 0 if(REDHIPSTER in n_census): numRH = n_census[REDHIPSTER] if(BLUEHIPSTER in n_census): numBH = n_census[BLUEHIPSTER] if(REDFOLLOWER in n_census): numRF = n_census[REDFOLLOWER] if(BLUEFOLLOWER in n_census): numBF = n_census[BLUEFOLLOWER] rh = self.influence(numRH, 5) bh = self.influence(numBH, 5) rf = self.influence(numRF, 5) bf = self.influence(numBF, 5) str_trans = "" # THE TRANSITION MATRIX # See documentation. str_trans += str(1 - rf) + " " + str(rf) + " 0 0;" str_trans += str(bf) + " " + str(1 - bf) + " 0 0;" str_trans += "0 0 " + str(1 - bh) + " " + str(bh) + ";" str_trans += "0 0 " + str(rh) + " " + str(1 - rh) trans_matrix = markov.from_matrix(np.matrix(str_trans)) return trans_matrix
def get_pre(self, agent, n_census): """ Gathers and uses env info to make a prehension transition matrix Args: self: the env agent: the agent acting in the env n_census: unused Returns: prehesion based on what Creatures are North, South, East, and West of self, determining what direction the agent might come. """ trans_str = "" d, total = self.dir_info(agent) if(type(agent) == Wolf): trans_str += self.wolf_trans(d, total) else: trans_str += self.sheep_trans(d, total) trans_matrix = markov.from_matrix(np.matrix(trans_str)) return trans_matrix
def get_pre(self, agent, n_census): """ See documentation for how this is built, what effect it produces, and why it produces it. """ trans_matrix = markov.create_iden_matrix(self.max_pile_size) i=2 j=i count=0.0 """ These while loops aren't a big drag. It makes a lower triangular matrix of size ~vlen**2, and we ony cycle through at most 4 times in the innermost loop. """ while(i<self.max_pile_size): while(1<=j): if(str(j) in n_census): while(n_census(str(j))>0): count+=1 n_census[str(j)]-=1 trans_matrix[i,j] = (count/4)**(i+1/j) j-=1 trans_matrix[i,i]= 1 - (count/4) i+=1 j=i count=0 return markov.from_matrix(trans_matrix)
def __init__(self, name, width, height, trans_str=None, torus=False, matrix_dim=2, model_nm=None, preact=False, postact=False, mobile_agents=False, props=None): """ Create a new markov env. By default the transition matrix is identity. """ if trans_str is None: self.def_trans_matrix = markov.from_matrix(markov.create_iden_matrix(matrix_dim)) else: self.def_trans_matrix = markov.MarkovPre(trans_str) super().__init__(name, width, height, torus, preact, postact, model_nm=model_nm, props=props)
def get_pre(self, agent, n_census): trans_str = "" d, total = self.dir_info(agent) if type(agent) == Zombie: trans_str += self.zombie_trans(d, total) else: trans_str += self.human_trans(d, total) trans_matrix = markov.from_matrix(np.matrix(trans_str)) return trans_matrix
def __init__(self, name, goal, vlen, init_state, max_detect=1): super().__init__(name, goal, max_move=1, max_detect=max_detect) self.state_pre = markov.from_matrix( markov.state_vector(vlen, init_state)) self.state = markov.get_state(markov.to_matrix(self.state_pre))