Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marcharper patch 1 fix type hints #1385

Merged
merged 5 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion axelrod/fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def fingerprint(
filename: str = None,
progress_bar: bool = True,
seed: int = None,
) -> np.array:
) -> np.ndarray:
"""Creates a spatial tournament to run the necessary matches to obtain
fingerprint data.

Expand Down
45 changes: 23 additions & 22 deletions axelrod/strategies/ann.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def num_weights(num_features, num_hidden):
return size


def compute_features(player: Player, opponent: Player) -> List[int]:
def compute_features(player: Player, opponent: Player) -> np.ndarray:
"""
Compute history features for Neural Network:
* Opponent's first move is C
Expand Down Expand Up @@ -91,38 +91,39 @@ def compute_features(player: Player, opponent: Player) -> List[int]:
total_player_c = player.cooperations
total_player_d = player.defections

return [
opponent_first_c,
opponent_first_d,
opponent_second_c,
opponent_second_d,
my_previous_c,
my_previous_d,
my_previous2_c,
my_previous2_d,
opponent_previous_c,
opponent_previous_d,
opponent_previous2_c,
opponent_previous2_d,
total_opponent_c,
total_opponent_d,
total_player_c,
total_player_d,
len(player.history),
]
return np.array(
(
opponent_first_c,
opponent_first_d,
opponent_second_c,
opponent_second_d,
my_previous_c,
my_previous_d,
my_previous2_c,
my_previous2_d,
opponent_previous_c,
opponent_previous_d,
opponent_previous2_c,
opponent_previous2_d,
total_opponent_c,
total_opponent_d,
total_player_c,
total_player_d,
len(player.history),
)
)


def activate(
bias: List[float],
hidden: List[float],
output: List[float],
inputs: List[int],
inputs: np.ndarray,
) -> float:
"""
Compute the output of the neural network:
output = relu(inputs * hidden_weights + bias) * output_weights
"""
inputs = np.array(inputs)
hidden_values = bias + np.dot(hidden, inputs)
hidden_values = relu(hidden_values)
output_value = np.dot(hidden_values, output)
Expand Down