Groups

class abcEconomics.Group(sim, scheduler, names, agent_arguments=None)[source]

Bases: object

A group of agents. Groups of agents inherit the actions of the agents class they are created by. When a group is called with an agent action all agents execute this actions simultaneously. e.G. banks.buy_stocks(), then all banks buy stocks simultaneously.

agents groups are created like this:

sim = Simulation()

Agents = sim.build_agents(AgentClass, 'group_name', number=100, param1=param1, param2=param2)
Agents = sim.build_agents(AgentClass, 'group_name',
                          param1=param1, param2=param2,
                          agent_parameters=[dict(ap=ap1_agentA, ap=ap2_agentA),
                                            dict(ap=ap1_agentB, ap=ap2_agentB),
                                            dict(ap=ap1_agentC, ap=ap2_agentC)])

Agent groups can be combined using the + sign:

financial_institutions = banks + hedgefunds
...
financial_institutions.buy_stocks()

or:

(banks + hedgefunds).buy_stocks()

Simultaneous execution means that all agents act on the same information set and influence each other only after this action.

individual agents in a group are addressable, you can also get subgroups (only from non combined groups):

banks[5].buy_stocks()

(banks[6,4] + hedgefunds[7,9]).buy_stocks()

agents actions can also be combined:

buying_stuff = banks.buy_stocks & hedgefunds.buy_feraries
buy_stocks()

or:

(banks.buy_stocks & hedgefunds.buy_feraries)()
agg_log(variables=[], goods=[], func={}, len=[])[source]

agg_log(.) writes a aggregate data of variables and goods of a group of agents into the database, so that it is displayed in the gui.

Args:
goods (list, optional):
a list of all goods you want to track as ‘strings’
variables (list, optional):
a list of all variables you want to track as ‘strings’
func (dict, optional):
accepts lambda functions that execute functions. e.G. func = lambda self: self.old_money - self.new_money
len (list, optional):
records the length of the list or dictionary with that name.

Example in start.py:

for round in simulation.next_round():
    firms.produce_and_sell()
    firms.agg_log(goods=['money', 'input'],
                variables=['production_target', 'gross_revenue'])
    households.buying()
by_name(name)[source]

Return a group of a single agents by its name

by_names(names)[source]

Return a callable group of agents from a list of names.group

Example:

banks.by_names(['UBS', 'RBS', "DKB"]).give_loans() 
create_agents(Agent, number=1, agent_parameters=None, **common_parameters)[source]

Create new agents to this group. Works only for non-combined groups

Args:
Agent:
The class used to initialize the agents
agent_parameters:
List of dictionaries of agent_parameters
number:
number of agents to create if agent_parameters is not set
any keyword parameter:
parameters directly passed to agent.init methood
Returns:
The id of the new agent
delete_agents(names)[source]

Remove an agents from a group, by specifying their id.

Args:
ids:
list of ids of the agent

Example:

students.delete_agents([1, 5, 15])
panel_log(variables=[], goods=[], func={}, len=[])[source]

panel_log(.) writes a panel of variables and goods of a group of agents into the database, so that it is displayed in the gui.

Args:
goods (list, optional):
a list of all goods you want to track as ‘strings’
variables (list, optional):
a list of all variables you want to track as ‘strings’
func (dict, optional):
accepts lambda functions that execute functions. e.G. func = lambda self: self.old_money - self.new_money
len (list, optional):
records the length of the list or dictionary with that name.

Example in start.py:

for round in simulation.next_round():
    firms.produce_and_sell()
    firms.panel_log(goods=['money', 'input'],
                variables=['production_target', 'gross_revenue'])
    households.buying()