Skip to content

Commit

Permalink
Fix Social Update
Browse files Browse the repository at this point in the history
had error in runner:
TypeError: 'dict_keyiterator' object cannot be interpreted as an integer
[...]
in numpy.random.mtrand.RandomState.choice ValueError: a must be 1-dimensional or an integer
File "C:\Users\bigma\PycharmProjects\pycopancore\pycopancore\model_components\exploit_social_learning\implementation\culture.py", line 42, in social_update
    agent_j = np.random.choice(self.acquaintance_network.neighbors(agent_i))
with (self.acquaintance_network.neighbors(agent_i)) being
<dict_keyiterator object at 0x00000226F0049F90>

FIX:
extracting list from key with list()

agent_j = np.random.choice(list(self.acquaintance_network.neighbors(agent_i)))
  • Loading branch information
zugnachpankow committed Jun 1, 2022
1 parent c574108 commit 1ffd331
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def social_update(self, t):
# Step (1)
if self.acquaintance_network.neighbors(agent_i):
agent_j = np.random.choice(
self.acquaintance_network.neighbors(agent_i))
list(self.acquaintance_network.neighbors(agent_i)))
# Step (2): Compare strategies of i and j:
# If they are the same, do nothing. Else change i's strategy.
if agent_i.strategy != agent_j.strategy:
Expand Down

2 comments on commit 1ffd331

@zugnachpankow
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right? After adjusting this the runner finished without errors, but I am not sure if by applying random.choice to a list instead of directly I changed something qualitatively.
Maybe someone can check and confirm? @mensch72 @jdonges @

@zugnachpankow
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more context:
-Trying to get exploit to run
-study script: run_exploit.py

Please sign in to comment.