Skip to content

Commit

Permalink
fix 193
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlujan91 committed Feb 17, 2023
1 parent 8828df6 commit 818a6c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
47 changes: 33 additions & 14 deletions sharkfin/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,36 @@ def class_stats(self, store=False):
"""
agent_data = self.agent_data().drop(columns="agents")

cs = (
agent_data.groupby(self.ex_ante_hetero_params)
.aggregate(["mean", "std"])
.reset_index()
)
if self.ex_ante_hetero_params is None or len(self.ex_ante_hetero_params) == 0:
cs = agent_data.copy()
cs["aLvl_mean"] = agent_data["aLvl"]
cs["aLvl_std"] = 0
cs["mNrm_mean"] = agent_data["mNrm"]
cs["mNrm_std"] = 0
cs["cNrm_mean"] = agent_data["cNrm"]
cs["cNrm_std"] = 0
cs["mNrm_ratio_StE_mean"] = agent_data["mNrm_ratio_StE"]
cs["mNrm_ratio_StE_std"] = 0
cs["label"] = "all"
else:
cs = (
agent_data.groupby(self.ex_ante_hetero_params)
.aggregate(["mean", "std"])
.reset_index()
)

cs.columns = ["_".join(col).strip("_") for col in cs.columns.values]
label = ""

label = ""
for param in self.ex_ante_hetero_params:
label += round(cs[param], 2).apply(lambda x: f"{param}={x}, ")

for param in self.ex_ante_hetero_params:
label += round(cs[param], 2).apply(lambda x: f"{param}={x}, ")
cs["label"] = label.str[:-2]

cs["label"] = label.str[:-2]
cs.columns = ["_".join(col).strip("_") for col in cs.columns.values]

# print(cs.columns)

# print(cs.columns)

if store:
self.stored_class_stats = cs
Expand Down Expand Up @@ -314,7 +330,7 @@ def attend(self, agent, price, risky_expectations):
# NOTE: This mutates the agent
agent.shares = target_shares

if agent.shares < 0:
if np.any(agent.shares < 0):
print(f"ERROR: Agent has negative shares after attention.")

return delta_shares
Expand All @@ -325,6 +341,9 @@ def assign_solution(self, agent):
the agent's perceptions of the market.
"""

if self.ex_ante_hetero_params is None or len(self.ex_ante_hetero_params) == 0:
return

# assign solution before simulating
# get master solution
pop_solution = self.solution.solution_database
Expand Down Expand Up @@ -440,14 +459,14 @@ def macro_update(self, agent, price):
agent.assign_parameters(**macro_risky_params)
agent.simulate(sim_periods=1)

if agent.state_now["aNrm"] < 0:
if np.any(agent.state_now["aNrm"]) < 0:
print("ERROR: Agent has negative assets after macro update.")

if agent.controls["Share"] < 0:
if np.any(agent.controls["Share"]) < 0:
print("ERROR: Agent has negative risky share after macro update.")
print(true_risky_expectations)

if agent.controls["Share"] > 1:
if np.any(agent.controls["Share"]) > 1:
print("ERROR: Agent has share > 1 after macro update.")
print(true_risky_expectations)

Expand Down
2 changes: 1 addition & 1 deletion simulate/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def build_population(agent_type, parameters, rng=None, dphm=1500):
}

lucas0_parameter_dict = lucas0_agent_population_params
lucas0_parameter_dict["AgentCount"] = 10 # TODO: What should this be?
lucas0_parameter_dict["AgentCount"] = 1 # TODO: What should this be?


LUCAS0 = lucas0_parameter_dict

0 comments on commit 818a6c1

Please sign in to comment.