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

Add GeorgeBPaul to list of contributors #224

Closed
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
56 changes: 56 additions & 0 deletions benchmarks/test_benchmarking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
"""test_benchmarking.ipynb

Automatically generated by Colaboratory.

Original file is located at
https://colab.research.google.com/drive/1myqTW8ocmWO2V9KIAWpnLfxy2ShfsGGD
"""

import numpy as np
import time
from nashpy import Game

def generate_payoff_matrix(size):
"""
Generates a random payoff matrix of a specified size for a game.

Parameters:
- size (int): The size of the payoff matrix to generate.

Returns:
- numpy.ndarray: A square matrix of shape (size, size) filled with random values.
"""
return np.random.rand(size, size)

def benchmark_algorithm(algorithm, game):
"""
Measure the time taken by a Nash equilibrium finding algorithm to compute equilibria for a given game.

Parameters:
- algorithm (callable): The Nash equilibrium algorithm to be benchmarked.
- game (nashpy.Game): The game instance on which the algorithm is applied.

Returns:
- list: A list of calculated Nash equilibria.
- float: The time taken to compute the equilibria, in seconds.
"""
start_time = time.time()
equilibria = list(algorithm())
end_time = time.time()
return equilibria, end_time - start_time

def profile_memory(algorithm, *args):
"""
Profiles the peak memory usage of a given algorithm.

Parameters:
- algorithm (callable): The algorithm to profile.
- *args: Arguments to be passed to the algorithm.

Returns:
- float: The peak memory usage in MiB.
"""
mem_usage = memory_usage((algorithm, args), interval=0.01, timeout=120)
return max(mem_usage)

1 change: 1 addition & 0 deletions docs/contributing/reference/contributors/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ List of contributors
- `@theref <https://github.com/theref>`_
- `@robert-szeto <https://github.com/robert-szeto>`_
- `@arwheel <https://github.com/arwheel>`_
- `@GeorgeBPaul<https://github.com/GeorgeBPaul>`_
- Computing for Mathematics class of 2023