Skip to content

Commit

Permalink
adding distributeParams to Market class. Seee econ-ark#669
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed May 15, 2020
1 parent 7baa869 commit 51d82de
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions HARK/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,36 @@ def __init__(self, agents=None, sow_vars=None, reap_vars=None, const_vars=None,
# "solveAgents" one time. If set to false, the error will never
# print. See "solveAgents" for why this prints once or never.

def distributeParams(self,param_name,param_count,center,spread,dist_type):
'''
Distributes heterogeneous values of one parameter to the AgentTypes in self.agents.
Parameters
----------
param_name : string
Name of the parameter to be assigned.
param_count : int
Number of different values the parameter will take on.
distribution : Distribution
A distribution.
Returns
-------
None
'''
param_dist = distribution.approx(N=param_count)

# Distribute the parameters to the various types, assigning consecutive types the same
# value if there are more types than values
replication_factor = len(self.agents) // param_count
# Note: the double division is intenger division in Python 3 and 2.7, this makes it explicit
j = 0
b = 0
while j < len(self.agents):
for n in range(replication_factor):
self.agents[j](AgentCount = int(self.Population*param_dist[0][b]*self.TypeWeight[n]))
exec('self.agents[j](' + param_name + '= param_dist[1][b])')
j += 1
b += 1

def solveAgents(self):
'''
Solves the microeconomic problem for all AgentTypes in this market.
Expand Down

0 comments on commit 51d82de

Please sign in to comment.