Skip to content

Commit

Permalink
with no ex ante heterogeneity, properly compute class_stats. Fixes #195
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Feb 20, 2023
1 parent f817945 commit cd70a7a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
41 changes: 23 additions & 18 deletions sharkfin/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,18 @@ def agent_data(self):
agent_data = self.agent_database[self.ex_ante_hetero_params + ["agents"]]

data_calls = {
"aLvl": lambda a: a.state_now["aLvl"][0],
"mNrm": lambda a: a.state_now["mNrm"][0],
"cNrm": lambda a: a.controls["cNrm"][0] if "cNrm" in a.controls else None,
"mNrm_ratio_StE": lambda a: a.state_now["mNrm"][0] / a.mNrmStE,
"aLvl": lambda a: a.state_now["aLvl"],
"mNrm": lambda a: a.state_now["mNrm"],
"cNrm": lambda a: a.controls["cNrm"] if "cNrm" in a.controls else np.full(a.AgentCount, np.nan),
"mNrm_ratio_StE": lambda a: a.state_now["mNrm"] / a.mNrmStE,
}

for dc in data_calls:
col = agent_data.loc[:, "agents"].apply(data_calls[dc])
agent_data[dc] = col

agent_data = agent_data.explode(list(data_calls.keys()))

pd.options.mode.chained_assignment = pdomca

return agent_data
Expand All @@ -201,16 +203,23 @@ def class_stats(self, store=False):
agent_data = self.agent_data().drop(columns="agents")

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"
cs = agent_data.aggregate(["mean", "std"])

mean_data = cs.loc['mean'].to_dict()
std_data = cs.loc['std'].to_dict()

# this collapse the data into one row with appropriate column names
all_data = {k + '_mean' : [mean_data[k]] for k in mean_data}
all_data.update({
k + '_std' : [std_data[k]]
for k
in std_data
})
all_data['label'] = ["all"]


cs = pd.DataFrame.from_dict(all_data)

else:
cs = (
agent_data.groupby(self.ex_ante_hetero_params)
Expand All @@ -227,10 +236,6 @@ def class_stats(self, store=False):

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
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"] = 1 # TODO: What should this be?
lucas0_parameter_dict["AgentCount"] = 10 # TODO: What should this be?


LUCAS0 = lucas0_parameter_dict

0 comments on commit cd70a7a

Please sign in to comment.