Esempio n. 1
0
 def request_available_agent(self, message: Message):
     # ensure that the actor system and institution are running...
     # message = MessageSpace.create_agent(agent_class)
     num_agents = message.get_payload()["num_agents"]
     agent_class = message.get_payload()["agent_class"]
     for i in range(num_agents):
         new_agent = self.createActor(agent_class)
         self.agents.append(new_agent)
Esempio n. 2
0
    def initialize_agents(self, message:Message):
        '''give the agent its theta and delta'''

        payload = message.get_payload()
        self.theta = payload["theta"]
        self.delta = payload["delta"]
        self.epsilon = payload["epsilon"]
    def theta_sd(self, message: Message):
        '''gives theta and sd to self '''

        payload = message.get_payload()
        self.theta = payload["theta"]
        self.delta = payload["delta"]
        self.epsilon = payload["epsilon"]
    def returned_response(self, message: Message):
        ''''records the response of the agent'''

        payload = message.get_payload()
        response = (payload["choice"][0])  #reset every choice everytime
        #print(response) #check here

        self._outcome(response)  # calculates which payout is chosen
 def fill_in_rows(self, message: Message):
     ''' puts in the rows into the bundles + set period '''
     payload = message.get_payload()
     self.bundles = payload["bundle"]
     self.experiment = payload["experiment"]
     self.total_experiments = payload["total_experiments"]
     self.run = payload["run"]
     self.total_runs = payload["total_runs"]
Esempio n. 6
0
    def returned_response(self, message: Message):
        '''records the response of the agent'''

        payload = message.get_payload()
        response = (payload["choice"][0])  #reset every choice everytime
        #print(response)

        self.collect_data(response)  # collect data and calculate payoff
Esempio n. 7
0
    def make_choice(self, message:Message):  # get row from bundle
        '''agent making choice'''

        #the agents gets the row and sd
        payload = message.get_payload()
        row = payload["row"]

        delta = self.delta

        #calculates the theta w/ triangularlly distributed delta
        if delta == 0:
            self.error = 0
        else:
            self.error = np.random.triangular(-delta, 0, delta)

        theta = self.theta + self.error

        OptionA = row[0] # set optionA
        OptionB = row[1] # set optionB

        if len(OptionA) != len(OptionB):  # ensure that there is no error in the row data
            raise ValueError("Length of options must be the same")

        # the probability and utility of OptionA Choice 1
        prob_a1 = (OptionA[0][0])
        out_a1 = self.CRRA(OptionA[0][1], theta)


        # the probability and utility OptionA Choice 2
        prob_a2 = OptionA[1][0]
        out_a2 = self.CRRA(OptionA[1][1], theta)

        # the probability and utility OptionB Choice 1
        prob_b1 = (OptionB[0][0])
        out_b1 = self.CRRA(OptionB[0][1], theta)

        # the probability and utility OptionB Choice 2
        prob_b2 = OptionB[1][0]
        out_b2 = self.CRRA(OptionB[1][1], theta)

        e = self.epsilon

        # calculates the utility w/ triangularlly distributed epsilon
        if e == 0:
            self.e = 0
        else:
            self.e = np.random.triangular(-e, 0, e)

        # expected utility of OptionA and OptionB
        util_a = prob_a1 * out_a1 + prob_a2 * out_a2 + self.e
        util_b = prob_b1 * out_b1 + prob_b2 * out_b2 + self.e

        # selects and records the option according to agent's preferences
        if util_a > util_b:
            self.choice.append(OptionA)

        else:
            self.choice.append(OptionB)
Esempio n. 8
0
 def make_choice(self, message: Message):  # get row from bundle
     '''agent makes their choice'''
     payload = message.get_payload()
     row = payload["row"]
     OptionA = row[0]
     OptionB = row[1]
     choice = input("You choose:")
     if choice == "A":
         self.choice.append(OptionA)
     elif choice == "B":
         self.choice.append(OptionB)
Esempio n. 9
0
    def make_choice(self, message: Message):  # get row from bundle
        '''agent makes their choice here'''

        #the agents gets the row and sd
        payload = message.get_payload()
        row = payload["row"]
        delta = self.delta

        #calculates the theta w/ normal distributed sd
        if delta == 0:
            error = 0
        else:
            error = np.random.triangular(-delta, 0, delta)

        theta = self.theta + error + self.epsilon

        OptionA = row[0]  # tuple of option 1
        OptionB = row[1]  # tuple of optoin 2

        if len(OptionA) != len(
                OptionB):  # ensure that there is no error in the row data
            raise ValueError("Length of options must be the same")

        # the probability and utility of OptionA Choice 1
        prob_a1 = (OptionA[0][0])
        out_a1 = self.CRRA(OptionA[0][1], theta)

        # the probability and utility OptionA Choice 2
        prob_a2 = OptionA[1][0]
        out_a2 = self.CRRA(OptionA[1][1], theta)

        # the probability and utility OptionB Choice 1
        prob_b1 = (OptionB[0][0])
        out_b1 = self.CRRA(OptionB[0][1], theta)

        # the probability and utility OptionB Choice 2
        prob_b2 = OptionB[1][0]
        out_b2 = self.CRRA(OptionB[1][1], theta)

        # expected utility of OptionA and OptionB
        util_a = prob_a1 * out_a1 + prob_a2 * out_a2
        util_b = prob_b1 * out_b1 + prob_b2 * out_b2

        # selects and records the option with larger expected utility
        if util_a > util_b:
            self.choice.append(OptionA)

        else:
            self.choice.append(OptionB)
Esempio n. 10
0
    def simulation_properties(self, message: Message):
        self.address_book = AddressBook(self)

        self.environment = message.get_sender()
        self.log_actor = message.get_payload()["log_actor"]
        if "mtree_properties" not in dir(self):
            self.mtree_properties = {}
        # if "agent_memory" not in dir(self):
        #     self.agent_memory = {}

        if "properties" in message.get_payload().keys():
            self.mtree_properties = message.get_payload()["properties"]

        if "agent_information" in message.get_payload().keys():
            self.short_name = message.get_payload(
            )["agent_information"]["short_name"]
            self.agent_information = message.get_payload()["agent_information"]

        if "subject_id" in message.get_payload().keys():
            self.subject_id = message.get_payload()["subject_id"]
Esempio n. 11
0
    def fill_in_institution(self, message: Message):
        ''' let the agent know the institution '''

        payload = message.get_payload()
        self.institutions = payload["institutions"]
Esempio n. 12
0
    def initialize_agents(self, message: Message):
        '''give the agent its theta and delta'''

        payload = message.get_payload()
        self.agent_id = payload["agent_id"]
Esempio n. 13
0
    def fill_in_institution(self, message: Message):
        ''' register agent in the institution '''

        payload = message.get_payload()
        self.institutions = payload["institutions"]
Esempio n. 14
0
 def fill_in_institution(self, message: Message):
     ''' gives the agent a list of institutions '''
     payload = message.get_payload()
     self.institutions = payload["institutions"]
Esempio n. 15
0
 def initialize_agent(self, message: Message):
     print("initializing agent")
     payload = message.get_payload()
     self.institution = payload["institution"]
Esempio n. 16
0
    def fill_in_agents(self, message: Message):
        '''give agents to self'''

        payload = message.get_payload()
        self.agents = payload["agents"]
Esempio n. 17
0
    def fill_in_rows(self, message: Message):
        ''' puts in the rows into the bundles & set num of experiments/runs '''

        payload = message.get_payload()
        self.bundles = payload["bundle"]
 def initialize_institution(self, message: Message):
     print("initializing an institution")
     payload = message.get_payload()
     self.agents = payload["agent_list"]
Esempio n. 19
0
    def get_payoff(self, message: Message):
        '''agent receive payoff after completion of all lotteries'''

        payload = message.get_payload()
        self.payoff.append(payload["payoff"])
        print("You received:", payload["payoff"])
Esempio n. 20
0
 def setup_boxes(self, message: Message):
     payload = message.get_payload()
     self.box_list = payload["box_list"]
Esempio n. 21
0
    def theta_delta(self, message: Message):
        '''keep track of agent's theta, delta'''

        payload = message.get_payload()
        self.agent_id = payload["agent_id"]
Esempio n. 22
0
 def external_reminder(self, message: Message):
     reminder_message = message.get_payload()["reminder_message"]
     seconds_to_reminder = message.get_payload()["seconds_to_reminder"]
     self.reminder(seconds_to_reminder, reminder_message)