Skip to content

Commit

Permalink
Migrate documentation of QRE tools.
Browse files Browse the repository at this point in the history
Closes #336.
  • Loading branch information
tturocy committed Sep 1, 2023
1 parent ecb94a6 commit bc95936
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 68 deletions.
3 changes: 3 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ Computation of Nash equilibria
.. automodule:: pygambit.nash
:members:

.. automodule:: pygambit.qre
:members:

1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Table of Contents
gui
tools
pyapi
api
samples
ideas
build
Expand Down
66 changes: 0 additions & 66 deletions doc/pyapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -440,69 +440,3 @@ For example, taking again the game :file:`e02.efg` as an example::



API documentation
-----------------



Analysis of quantal response equilibria
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~---------

.. py:module:: pygambit.qre
.. py:function:: fit_fixedpoint(data)
.. versionadded:: 16.1.0

Use maximum likelihood estimation to find the point on the
principal branch of strategic form game closest to `data`.
The `data` are expressed as an instance of a mixed strategy
profile on the game. The `data` should typically be expressed
as the counts of observations of each strategy.

:param data: The observed data to use in fitting.
:type data: :py:class:`MixedStrategyProfile`
:rtype: :py:class:`LogitQREMixedStrategyFitResult`

.. py:function:: fit_empirical(data)
.. versionadded:: 16.1.0

Use maximum likelihood estimation to estimate a quantal
response equilibrium using the empirical payoff method.
The `data` are expressed as an instance of a mixed strategy
profile on the game. The `data` should typically be expressed
as the counts of observations of each strategy.

:param data: The observed data to use in fitting.
:type data: :py:class:`MixedStrategyProfile`
:rtype: :py:class:`LogitQREMixedStrategyFitResult`

.. py:class:: LogitQREMixedStrategyFitResult
.. versionadded:: 16.1.0

The result of estimating a quantal response equilibrium
using given data on a game.

.. py:attribute:: method
A text string indicating the estimation method used.
This can be "fixedpoint" or "empirical".

.. py:attribute:: profile
The estimated :py:class:`MixedStrategyProfile`.

.. py:attribute:: lam
The estimated value of the precision parameter lambda.

.. py:attribute:: data
The data used in the estimation, represented as a
:py:class:`MixedStrategyProfile`.

.. py:attribute:: log_like
The log of the likelihood function at the estimated profile.
18 changes: 16 additions & 2 deletions src/pygambit/qre.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,14 @@ def __repr__(self):
def fit_fixedpoint(
data: gambit.MixedStrategyProfileDouble
) -> LogitQREMixedStrategyFitResult:
"""Estimate a QRE using the fixed-point method."""
"""Use maximum likelihood estimation to find the point on the
principal branch of strategic form game closest to `data`.
The `data` are expressed as an instance of a mixed strategy
profile on the game. The `data` should typically be expressed
as the counts of observations of each strategy.
.. versionadded:: 16.1.0
"""
res = gambit.logit_estimate(data)
return LogitQREMixedStrategyFitResult(
data, "fixedpoint", res.lam, list(res.profile), res.log_like
Expand All @@ -374,7 +381,14 @@ def fit_fixedpoint(
def fit_empirical(
data: gambit.MixedStrategyProfileDouble
) -> LogitQREMixedStrategyFitResult:
"""Estimate a QRE using the empirical payoff method."""
"""Use maximum likelihood estimation to estimate a quantal
response equilibrium using the empirical payoff method.
The `data` are expressed as an instance of a mixed strategy
profile on the game. The `data` should typically be expressed
as the counts of observations of each strategy.
.. versionadded:: 16.1.0
"""
def do_logit(lam: float):
logit_probs = [[math.exp(lam*v) for v in player] for player in values]
sums = [sum(v) for v in logit_probs]
Expand Down

0 comments on commit bc95936

Please sign in to comment.