The code in this repository is meant to find Nash equilibria for the following model:
We assume that n players produce safety, s, and performance, p, as
for i = 1, ..., n. The X are inputs chosen by the players, and all other variables are fixed parameters.
In a Nash equilibrium, each player i chooses Xs,i and Xp,i to maximize the payoff
subject to the other players' choices of Xs and Xp. The components of this expression will be explained more below, but the basic parts are as follows:
- qi(p) is the probability that player i wins a contest between all players.
- σi(s) is the probability of a safe outcome given that player i wins the contest.
- ρij(p) is player i's payoff if player j wins the contest, and the outcome is safe.
- di is the cost incurred by player i in the event of an unsafe (disaster) outcome.
- ci(Xs, Xp) is the price that player i pays for the inputs.
Note that the weighted sum Σi σi qi is the unconditional probability of a safe outcome (no disaster).
If you don't have Julia, download it from https://julialang.org/downloads/ and install. (You'll need at least version 1.6.7.)
Next, you'll need to install the project code. The easiest way to do this is to open a new Julia REPL session, then run
] add https://github.com/quevivasbien/AIIncentives.jl
which will automatically download and install the project as a package on your computer. (You'll only need to do this last step once, but after that you can run ] update AIIncentives
every now and then to make sure you're up to date with the latest available version.)
You should now be able import the package:
using AIIncentives
You can then create and solve a scenario like
scenario = Scenario(
n = 2,
A = 10.,
α = 0.5,
B = 10.,
β = 0.5,
θ = 0.25,
d = 1.,
r = range(0.01, 0.1, length = 20),
varying = :r
)
solution = solve(scenario)
[
A couple of tangential tips here:
-
To use math-related characters in most Julia code, you can typically just type the Latex code then press Tab. For example,
\alpha
+[Tab]
becomesα
. I've also allowed the spelled-out versions of Greek letters to work in most places in this code; for example, you could usealpha
,beta
, andtheta
instead ofα
,β
, andθ
in the example above. -
You can speed up a lot of solve calls by enabling multithreading. To do that, follow the instructions here.
]
This will find Nash equilibria over the given parameterization and range of values for r
. To generate a plot of the result, you can execute
plot(solution)
The first time you run something in the Julia session, it will take a while, since Julia compiles your code the first time you run it in a new setting. It should run a lot faster after that.
For more detailed documention, see this document.