Skip to content

Chore: Game Theory algorithms are missing #11804 #11859

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

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 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 computer_vision/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Image processing and computer vision are a little different from each other. Ima
While computer vision comes from modelling image processing using the techniques of machine learning, computer vision applies machine learning to recognize patterns for interpretation of images (much like the process of visual reasoning of human vision).

* <https://en.wikipedia.org/wiki/Computer_vision>
* <https://www.datarobot.com/blog/introduction-to-computer-vision-what-it-is-and-how-it-works/>
* <https://docs.opencv.org/4.x/>
27 changes: 27 additions & 0 deletions game_theory/best_response_dynamics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def best_response_dynamics(payoff_matrix_A, payoff_matrix_B, iterations=10):

Check failure on line 1 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (INP001)

game_theory/best_response_dynamics.py:1:1: INP001 File `game_theory/best_response_dynamics.py` is part of an implicit namespace package. Add an `__init__.py`.

Check failure on line 1 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N803)

game_theory/best_response_dynamics.py:1:28: N803 Argument name `payoff_matrix_A` should be lowercase

Check failure on line 1 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N803)

game_theory/best_response_dynamics.py:1:45: N803 Argument name `payoff_matrix_B` should be lowercase

Choose a reason for hiding this comment

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

Please provide return type hint for the function: best_response_dynamics. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/best_response_dynamics.py, please provide doctest for the function best_response_dynamics

Please provide type hint for the parameter: payoff_matrix_A

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_A

Please provide type hint for the parameter: payoff_matrix_B

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_B

Please provide type hint for the parameter: iterations

Choose a reason for hiding this comment

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

Please provide return type hint for the function: best_response_dynamics. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/best_response_dynamics.py, please provide doctest for the function best_response_dynamics

Please provide type hint for the parameter: payoff_matrix_A

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_A

Please provide type hint for the parameter: payoff_matrix_B

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_B

Please provide type hint for the parameter: iterations

Choose a reason for hiding this comment

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

Please provide return type hint for the function: best_response_dynamics. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/best_response_dynamics.py, please provide doctest for the function best_response_dynamics

Please provide type hint for the parameter: payoff_matrix_A

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_A

Please provide type hint for the parameter: payoff_matrix_B

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_B

Please provide type hint for the parameter: iterations

Choose a reason for hiding this comment

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

Please provide return type hint for the function: best_response_dynamics. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/best_response_dynamics.py, please provide doctest for the function best_response_dynamics

Please provide type hint for the parameter: payoff_matrix_A

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_A

Please provide type hint for the parameter: payoff_matrix_B

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_B

Please provide type hint for the parameter: iterations

n = payoff_matrix_A.shape[0]
m = payoff_matrix_A.shape[1]

# Initialize strategies
strategy_A = np.ones(n) / n

Check failure on line 6 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N806)

game_theory/best_response_dynamics.py:6:5: N806 Variable `strategy_A` in function should be lowercase

Check failure on line 6 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

game_theory/best_response_dynamics.py:6:18: F821 Undefined name `np`

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

strategy_B = np.ones(m) / m

Check failure on line 7 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N806)

game_theory/best_response_dynamics.py:7:5: N806 Variable `strategy_B` in function should be lowercase

Check failure on line 7 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

game_theory/best_response_dynamics.py:7:18: F821 Undefined name `np`

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B


for _ in range(iterations):
# Update strategy A
response_A = np.argmax(payoff_matrix_A @ strategy_B)

Check failure on line 11 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N806)

game_theory/best_response_dynamics.py:11:9: N806 Variable `response_A` in function should be lowercase

Check failure on line 11 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

game_theory/best_response_dynamics.py:11:22: F821 Undefined name `np`

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: response_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: response_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: response_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: response_A

strategy_A = np.zeros(n)

Check failure on line 12 in game_theory/best_response_dynamics.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N806)

game_theory/best_response_dynamics.py:12:9: N806 Variable `strategy_A` in function should be lowercase

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

strategy_A[response_A] = 1

# Update strategy B
response_B = np.argmax(payoff_matrix_B.T @ strategy_A)

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: response_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: response_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: response_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: response_B

strategy_B = np.zeros(m)

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

strategy_B[response_B] = 1

return strategy_A, strategy_B


# Example usage
payoff_A = np.array([[3, 0], [5, 1]])

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_A

payoff_B = np.array([[2, 4], [0, 2]])

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_B

strategies = best_response_dynamics(payoff_A, payoff_B)
print("Final strategies:", strategies)
32 changes: 32 additions & 0 deletions game_theory/fictitious_play.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def fictitious_play(payoff_matrix_A, payoff_matrix_B, iterations=100):

Choose a reason for hiding this comment

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

Please provide return type hint for the function: fictitious_play. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/fictitious_play.py, please provide doctest for the function fictitious_play

Please provide type hint for the parameter: payoff_matrix_A

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_A

Please provide type hint for the parameter: payoff_matrix_B

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_B

Please provide type hint for the parameter: iterations

Choose a reason for hiding this comment

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

Please provide return type hint for the function: fictitious_play. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/fictitious_play.py, please provide doctest for the function fictitious_play

Please provide type hint for the parameter: payoff_matrix_A

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_A

Please provide type hint for the parameter: payoff_matrix_B

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_B

Please provide type hint for the parameter: iterations

Choose a reason for hiding this comment

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

Please provide return type hint for the function: fictitious_play. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/fictitious_play.py, please provide doctest for the function fictitious_play

Please provide type hint for the parameter: payoff_matrix_A

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_A

Please provide type hint for the parameter: payoff_matrix_B

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_B

Please provide type hint for the parameter: iterations

Choose a reason for hiding this comment

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

Please provide return type hint for the function: fictitious_play. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/fictitious_play.py, please provide doctest for the function fictitious_play

Please provide type hint for the parameter: payoff_matrix_A

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_A

Please provide type hint for the parameter: payoff_matrix_B

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_matrix_B

Please provide type hint for the parameter: iterations

n = payoff_matrix_A.shape[0]
m = payoff_matrix_A.shape[1]

# Initialize counts and strategies
counts_A = np.zeros(n)

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: counts_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: counts_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: counts_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: counts_A

counts_B = np.zeros(m)

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: counts_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: counts_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: counts_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: counts_B

strategy_A = np.ones(n) / n

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

strategy_B = np.ones(m) / m

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B


for _ in range(iterations):
# Update counts
counts_A += strategy_A
counts_B += strategy_B

# Calculate best responses
best_response_A = np.argmax(payoff_matrix_A @ strategy_B)

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: best_response_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: best_response_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: best_response_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: best_response_A

best_response_B = np.argmax(payoff_matrix_B.T @ strategy_A)

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: best_response_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: best_response_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: best_response_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: best_response_B


# Update strategies
strategy_A = np.zeros(n)

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_A

strategy_A[best_response_A] = 1
strategy_B = np.zeros(m)

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: strategy_B

strategy_B[best_response_B] = 1

return strategy_A, strategy_B

# Example usage
payoff_A = np.array([[3, 0], [5, 1]])

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_A

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_A

payoff_B = np.array([[2, 4], [0, 2]])

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_B

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: payoff_B

strategies = fictitious_play(payoff_A, payoff_B)
print("Fictitious Play strategies:", strategies)
28 changes: 28 additions & 0 deletions game_theory/minimax_algorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def minimax(depth, node_index, is_maximizing_player, values, alpha, beta):

Choose a reason for hiding this comment

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

Please provide return type hint for the function: minimax. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/minimax_algorithm.py, please provide doctest for the function minimax

Please provide type hint for the parameter: depth

Please provide type hint for the parameter: node_index

Please provide type hint for the parameter: is_maximizing_player

Please provide type hint for the parameter: values

Please provide type hint for the parameter: alpha

Please provide type hint for the parameter: beta

Choose a reason for hiding this comment

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

Please provide return type hint for the function: minimax. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/minimax_algorithm.py, please provide doctest for the function minimax

Please provide type hint for the parameter: depth

Please provide type hint for the parameter: node_index

Please provide type hint for the parameter: is_maximizing_player

Please provide type hint for the parameter: values

Please provide type hint for the parameter: alpha

Please provide type hint for the parameter: beta

Choose a reason for hiding this comment

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

Please provide return type hint for the function: minimax. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/minimax_algorithm.py, please provide doctest for the function minimax

Please provide type hint for the parameter: depth

Please provide type hint for the parameter: node_index

Please provide type hint for the parameter: is_maximizing_player

Please provide type hint for the parameter: values

Please provide type hint for the parameter: alpha

Please provide type hint for the parameter: beta

Choose a reason for hiding this comment

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

Please provide return type hint for the function: minimax. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/minimax_algorithm.py, please provide doctest for the function minimax

Please provide type hint for the parameter: depth

Please provide type hint for the parameter: node_index

Please provide type hint for the parameter: is_maximizing_player

Please provide type hint for the parameter: values

Please provide type hint for the parameter: alpha

Please provide type hint for the parameter: beta

if depth == 0:
return values[node_index]

if is_maximizing_player:
best_value = float('-inf')
for i in range(2): # Two children (0 and 1)
value = minimax(depth - 1, node_index * 2 + i, False, values, alpha, beta)
best_value = max(best_value, value)
alpha = max(alpha, best_value)
if beta <= alpha:
break # Beta cut-off
return best_value
else:
best_value = float('inf')
for i in range(2): # Two children (0 and 1)
value = minimax(depth - 1, node_index * 2 + i, True, values, alpha, beta)
best_value = min(best_value, value)
beta = min(beta, best_value)
if beta <= alpha:
break # Alpha cut-off
return best_value

# Example usage
values = [3, 5, 2, 9, 0, 1, 8, 6] # Leaf node values
depth = 3 # Depth of the game tree
result = minimax(depth, 0, True, values, float('-inf'), float('inf'))
print("The optimal value is:", result)
19 changes: 19 additions & 0 deletions game_theory/shapley_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def shapley_value(payoff_matrix):

Choose a reason for hiding this comment

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

Please provide return type hint for the function: shapley_value. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/shapley_value.py, please provide doctest for the function shapley_value

Please provide type hint for the parameter: payoff_matrix

Choose a reason for hiding this comment

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

Please provide return type hint for the function: shapley_value. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/shapley_value.py, please provide doctest for the function shapley_value

Please provide type hint for the parameter: payoff_matrix

Choose a reason for hiding this comment

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

Please provide return type hint for the function: shapley_value. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file game_theory/shapley_value.py, please provide doctest for the function shapley_value

Please provide type hint for the parameter: payoff_matrix

n = payoff_matrix.shape[0]
shapley_values = np.zeros(n)

for i in range(n):
for S in range(1 << n): # All subsets of players
if (S & (1 << i)) == 0: # i not in S
continue

S_without_i = S & ~(1 << i)

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: S_without_i

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: S_without_i

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: S_without_i

marginal_contribution = payoff_matrix[S][i] - (payoff_matrix[S_without_i][i] if S_without_i else 0)
shapley_values[i] += marginal_contribution / (len(bin(S)) - 2) # Normalize by size of S

return shapley_values

# Example usage
payoff_matrix = np.array([[1, 2], [3, 4]])
shapley_vals = shapley_value(payoff_matrix)
print("Shapley Values:", shapley_vals)
Loading