\section{Introduction}

The application of deep reinforcement learning to solve single player Markov Decision Processes are relatively well-researched in today's machine learning literature, however, the application of novel deep reinforcement learning methods to solve multi-agent competitive MDP's are relatively few. Particularly, the challenge revolves around competing objectives and solving for, often computationally intractable, Nash equilibria \citep{Nash:1950} in a competitive setting, where agents cannot merely maximize only their respective Q functions. Nash equilibria in Markov Games are particularly useful in the area of \textit{dynamic pricing}, a well-known problem in today's online eCommerce marketplaces.  In a \textit{dynamic pricing} game, multiple firms compete for market share of their product on the same online platform. To model this market, we adopt a modified version of Bertrand oligopoly \citep{bertrand:1883}, where the marginal cost of production is 0, and where purchasing behaviour is probabilistic.



\subsection{Market Oligopoly}

Especially in today's online commerce industries, dynamic pricing provides platform firms with an adversarial advantage and increases profit margins in a competitive economy. In an ideal case, a firm's pricing strategy should consider the actions of other firms, providing the justification for Nash equilibrium policies over unilateral reward maximization policies. In previous approaches, \citep{Liu:2019-dyp} modelled the dynamic pricing problem using deep reinforcement learning, however, focused primarily on single agent revenue maximization and not solving for multi-agent Nash equilibria. \citep{Schlosser:2018} apply stochastic dynamic programming in a simulated environment to estimate consumer demand and maximize expected profit, however, do not consider the equilibrium solution of the market. \citep{vandergeer:2018-dpc} model market demand using parametric functions, with unknown parameters, yet they do not consider a Nash equilibrium nor the actions of previous pricing on demand. Thus, in almost all recent research on the dynamic pricing problem under uncertainty, there exists a desideratum to compute and promote Nash equilibria for market pricing strategies. Such strategies can be applied to eCommerce platforms such as Amazon auto pricing, allowing firms to opt for an automated pricing algorithm.



A large body of literature on dynamic pricing has assumed an unknown demand function and tried to learn the intrinsic  relationship between price and demand. \citep{harrison2012bayesian} showed that a myopic Bayesian policy may lead to incomplete learning and poor profit performance. \citep{liu2020dynamic} studied a joint pricing and inventory problem while learning the price-sensitive demand using a Bayesian dynamic program. Many recent studies have revolved around non-parametric methods. \citep{besbes2009dynamic} developed a pricing strategy that balances the trade-off between exploration and exploitation. Furthermore, in \citep{Liu:2019-dyp} the demand function was a black box system where the demand was approximated from experience replay and live online testing in a reinforcement learning framework.

Dynamic pricing in oligopolies presents multiple problems. One aspect is the optimization problem, where we learn a Nash equilibrium policy when presented with the parameters of the market demand function, and second is the learning of the demand parameters itself. For example, \citep{den2014simultaneously} and \citep{keskin2014dynamic} studied parametric approaches, using maximum likelihood to estimate unknown parameters of the demand function. Recent research has been conducted in demand learning, for example in cases where multiple products exist, and firms can learn to price on an assortment of items \citep{ferreira:2022demand} using multinomial logit regression, or when multiple products exist in a demand learning scenario, and a limited inventory exists, Multi-Armed Bandit approaches have shown to be effective at devising profitable policies \citep{ferreira:2018thompson}. However, these approaches do not consider past pricing actions influencing the future market demand parameters. Furthermore, they do not consider competing firms aiming for a Nash equilibrium.

We propose a demand market where past pricing affects the future market demand in a market competition. To search for a Nash equilibrium, we apply a multi-agent Markov Decision Process, where the state transition is driven by the joint pricing actions of all players (or firms). To simplify the problem, we assume that each firm has unlimited inventory, and there is only a single product with no substitutes.



\subsection{Multi-agent Markov Decision Processes}

Multi-agent Markov Decision Processes, or \textit{Markov Games} (MG's), constitute an important area of research, especially when multiple agents are self-interested, and an exact or approximate Nash equilibrium for the system is desired. The computation of Nash equilibria additionaly presents great difficulty when searching over the enormous joint state action space of the problem, and approximations to this search problem do exist \citep{Porter:2008}. Moreover, the existence of multiple Nash equilibria can further complicate the solution, as some solutions may be more desirable than others. 

Yet approximate search algorithms require prior knowledge of the joint reward function and are often limited to two players, modelled by a \textit{best response function}. We treat our payoff function as an \textit{oracle} \citep{Vorobeychik:2008}, meaning we have knowledge regarding the parametric form of the payoff function, however, there is no knowledge to the agents in the MG regarding how the reward function generates rewards for the players. The state of the game is visible to the agents, yet the agents have no knowledge regarding the state transition function. Nevertheless, the market demand parameters and Nash equilibria are known for purposes of experimentation. This eliminates the need for pre-period model fitting to pre-estimate market demand parameters \citep{ferreira2016:6analytics} allowing us to compare our solution to the theoretical solution, as opposed to an empirical estimate.


Model-based approaches furthermore exist to provably find the existence of a Nash equilibrium \citep{Zhang:2020}. However, we aim for a Nash equilibrium solver which is model-free, where no knowledge regarding the reward or transition function is known to the agents. In recent literature, \citep{Raponi:2021} present a model-free algorithm to solve competitive MDP's when the environment parameters can be altered by an external party - but this is not always the case in market economics. Furthermore, \citep{Sayin:2021} propose a model-free decentralized deep learning framework, where the agent is blind to the other agents actions, and convergence to a Nash equilibrium is proven. \citep{Guan:2021} propose a convergent solution for zero-sum MG's via entropy-regularization. However, both \citep{Guan:2021} and \citep{Sayin:2021} impose a number of theoretical restrictions on the MG in order for this convergence to occur. Moreover, \citep{Kozuno:2021} present a provably convergent MG solver for imperfect information restricted to two agents. Nevertheless, we are concerned with an approximate solution to a full information MG for N agents.


\textbf{Contributions:} This work outlines a methodology for Deep Q Learning, as introduced in \citep{mnih:2015}, by extending the framework to multi-agent reinforcement learning (MARL) with a Nash equilibrium objective based on the methods in \citep{hu:2003} and \citep{wang:2003-mgames}. Although the framework presented in \citep{hu:2003} is theoretically sound, the solution to the Nash equilibrium function is often intractable. We therefore apply approximation methods to compute a Nash equilibrium. Black box optimization is applied to estimate an $\epsilon$-Nash Equilibrium policy, and this approximation is learned as a series of neural networks. This MARL model is then applied to the domain of dynamic pricing.







\section{Dynamic Pricing Game} \label{sec:dynamic-pricing-game}

An oligopoly across $N$ firms is modelled as a multi-agent Markov Decision Process with a fully observable state action space. The state space is represented by the fully-observable demand-influencing reference price $\bar{p_t}$ being the state of the game $s^t$. In discrete intervals at time $t$, each agent issues a price for the item to be sold to the general market, $x^t_n$. The reference price, of the market at time $t$ is determined by a stochastic function of all the agents actions at time $t-1$. To focus the problem strictly on dynamic pricing, for each firm we assume a sufficiently large inventory, with no marginal costs of production, no possibility for inventory stockouts, no holding costs, and the capacity to always meet any realization of market demand.

\subsection{Markov Game Parameters} \label{sec:markov-game-params}

The joint action space $\{x_1^t \ ... \ x_n^t\} \in \mathbf{X}$ constitutes the current actions of all agents at time $t$, which drive the state transition by setting prices at time $t$ and represent the set price of the item from agent $n$ at time $t$. The state-action-reward space is defined as a tuple $(s^{t}, x_1^{t}, . . . , x_N^{t}, r_1^{t}, . . . , r_N^{t}, s^{t+1})$ where $r_n^{t}$ is the reward for agent $n$ at time $t$. The joint reward can be written as $\bar{r}_t = (r_1^{t}, . . . , r_N^{t})$, and the joint action can be written as $\bar{x}_t = (x_1^{t}, . . . , x_N^{t})$. $N$ denotes the number of agents. The exact transition probabilities are not known to the agents. Each agent must learn the demand function and optimal strategy as the MG progresses. A state $s^{t}$ is determined by the reference price of the market observable to all agents, $s \in \mathbb{R}$. We discretize the action space into even segments representing a firm's price. Where each segment represents an action $x_n \in X_n$, and $X_n$ is the action space for any agent $n \in N$.












\subsection{Reference Pricing} \label{sec:refernce-pricing}




The first pillar of any market dynamic is constituted by the \textit{demand function}, dictated by both the historical and contemporary prices, of the firms in the market. Demand processes can be ideally linear and continuous, however may not be guaranteed to be stationary or continuous \citep{vdenboer:2020-discon}, and can be subject to various exogenous factors such as environmental carryover effects \citep{rao1993pricing}. 

We create an idealization of a market based on \citep{taudes2012integrating}, where a dynamic pricing problem, with reference price effects and a linear demand function, is imposed. The expected current demand of a product is a function of the average price set by all firms, denoted as $\tilde{x}$, and a historical reference price, $\bar{p}$. The reference price $\bar{p}$ is given, and cannot be modified during the current time $t$, moreover, it is a function of the immediate past, $t-1$. Although \citep{taudes2012integrating} is not necessarily the only model that incorporates reference pricing \citep{mazumdar2005reference}, \citep{fibich2003explicit}, \citep{popescu2007dynamic}, \citep{heidhues2014regular}, we adopt it due to its simplicity and the existence of provable Nash equilibria in an oligopolistic framework.





\begin{align}
    f(\tilde{x}) = \beta_0 + \beta_1 \tilde{x} + \beta_2(\tilde{x} - \bar{p}), \quad \beta_0  &\geq 0, \ \beta_1 < 0, \ \beta_2 \leq 0, \ f(\tilde{x}) \geq  0, \tilde{x} \geq 0  \label{eq:taudes-demand} 
   
   
\end{align}

$\epsilon_D$ is defined as the noise from a Poisson process. Such a Poisson process has the arrival rate $\lambda_t(\tilde{x}) = f(\tilde{x})$ from Eq. \eqref{eq:taudes-demand}, and standard deviation $\sigma = \sqrt{\lambda_t(\tilde{x})}$. Furthermore, \citep{taudes2012integrating} make the stipulation of decreasing demand with respect to increasing price, as illustrated in Condition \eqref{eq:taudes-demand}.



This demand-influencing reference price can be affected by a variety of factors, such as inflation, unemployment, psychological perception \citep{raman:2002}. Moreover, in many proposed oligopoly models, as in \citep{janiszewski:1999range} and \citep{briesch:1997comparative}, the reference price is dictated by a historical joint market price of multiple firms. However, modelling a competitive market oligopoly with an autocorrelated reference price in a MG setting is not heavily investigated until now. In our model, we focus on designing a market whose reference price is driven by the historical $t-1$ joint market price, and additional factors which also affect the reference price are represented as noise $\epsilon_D$. Thus the transition of the reference price is determined by the average of the previous joint prices plus some Guassian randomness, $\epsilon_D$.

In our experiment, the reference price of a product is determined by the previous actions of the firms. We express the reference price function as $\bar{p}(t): \ \mathbb{R}^{N} \xrightarrow[]{} \mathbb{R}$, mapping a vector of historical pricing actions $\mathbf{x}^{t-1}$ to $\mathbb{R}$.  In the beginning of the Markovian process, the reference price is randomly generated within the action space of the pricing range. The stochastic nature of the market price transition entail the Markov property of the MG.



\begin{align} 
 
 
  \bar{p}(t) &\vcentcolon= \frac{1}{N} \sum^{N}_{n=1} x^{t-1}_n + \epsilon_D, \quad \text{where} \quad \bar{p}(t=0) = \frac{1}{N} \sum^{\mathbf{x^0}}_{n=1} x^{0}_n + \epsilon_D
\end{align} 





\subsection{Probabilistic Demand Function} \label{sec:profit-func}

The expected profit for player $n$ is $\mathbf{E}[\Pi_n(x_n)]$, which equals revenue as the marginal cost is of production is assumed to be 0, is defined as, 

\begin{align}
    \mathbf{E}[\Pi_n(x_n)] &= \Phi_n(x_n, x_{-n}) x_n f(\tilde{x}) \label{eq:profit-func1} \\
    \Phi_n(x_n, x_{-n}) &= \frac{ e ^{\phi(x_n)} }{\sum^{N}_{i=1} e^{\phi(x_i)}  } \label{eq:softmax-elas}
\end{align}

$\Phi_n(x_n, x_{-n})$ in Eq. \eqref{eq:softmax-elas} represents the probability that a customer purchases the item sold by firm $n$, where the player $n$ prices their merchandise with price $x_n$. $f(x_n)$ is the expected demand during the single stage game for a fixed time period. Following the quantal response function from \citep{luce:1959} and \citep{goeree:2020}, we define a \textit{purchase elasticity function}, $\phi_n(x_n, x_{-n})$,

\begin{align} 
  \phi(x) = & 
    \begin{cases} 
      b_n - a_n x
        &\text{for \quad} 0 < x < b_n / a_n \\ 
      0 &\text{for \quad}  x > b_n / a_n 
    \end{cases} \label{eq:puchase-elas-function} \\
    \text{where} \quad &  x \in \mathbb{R}, x > 0, a \geq 0, b_n = 1 \label{eq:purchase_elas_price_constraints}
\end{align} 

In $\phi(x)$, $b_n$ represents the maximum weighted contribution to the probability of an item being purchased by a customer given a price. When the price $x$ is 0, this measure is $b_n$. For simplification, we assume the linear marginal decline of this measure of all players $a_n$ as equal, $a_n = a$, that is the market has the same elasticity regarding the marginal decrease of the customer willingness to purchase from any firm as price increases, with a negative slope $a$. The probability of a customer choosing to purchase from firm $n$ at price $x_n$ among prices set by other firms $x_{-n}$ is defined by combining a softmax function and purchase elasticity function, $\phi(x)$. This mechanism will prevent a solution where each firm undercuts each other to set their prices to 0, as the lowest price need not guarantee that a consumer will buy their product.













\section{Nash Equilibrium Conditions} \label{sec:eq-setting-main}

Computation of exact Nash, or approximate $\epsilon$-Nash, equilibria is an NP-hard problem and notoriously difficult to compute \citep{Daskalakis:2006}. This involves a search over the entire joint state action space, computing the value of each state under a candidate policy. Furthermore, it involves knowledge of the joint Q function and the transition probability of the system. In our scenario, we have the condition that all agents are identical, therefore the solution of one agent can apply to the solution of another. 

\subsection{Theoretical $\epsilon$-Nash Equilibria}

Under the market outlined in Section \ref{sec:dynamic-pricing-game}, given the market inputs $\bar{p}$ and $\tilde{x}$, in any pricing strategy, there exists an optimal deviation $d^* \in \mathbf{R}$, such that $\mathbf{E}[\Pi_n(x_n - d^*)]$ will yield the maximum profit advantage $\epsilon$.




\begin{align}
    \epsilon &= \underset{d^* \in \mathbf{R} }{\mathrm{max}} \ \Bigg(  \mathbf{E}[\Pi_n(x_n - d^*)] - \mathbf{E}[\Pi_n(x_n)] \Bigg) \label{eq:nash-def-diff} 
   
   
   
   
\end{align}

An increase in the individual profit of an agent $n$ from unilaterally deviating is denoted as $\epsilon$. Given this optimal deviation, $d^*$, a maximum theoretical upper bound on the profit advantage $\epsilon$ that can be obtained. Eq. \eqref{eq:d-star-main} provides the theoretical value of $d^*$ which is a function of both reference price $\bar{p}$ and market price $\tilde{x}$, as well as the fixed market parameters $\beta_0, \beta_1, \beta_2$. A derivation of $d^*$ can be found in Appendix \ref{sec:eq-setting}.

\begin{align}
    d^* &= \frac{ \sqrt{c_1^2 - c_1 + 4(c_2-1)c_2 - 2c_2} }{2c_2}  \label{eq:d-star-main} \\
    \text{where} \quad  c_1 &= \frac{- (\beta_1 + \beta_2)}{f(\tilde{x})} - \frac{1}{\tilde{x}}, \quad c_2 = \frac{- (\beta_1 + \beta_2)}{f(\tilde{x})\tilde{x}} \nonumber
\end{align}


\begin{figure}[!htb]
\minipage{0.5\textwidth}
  \includegraphics[width=\linewidth]{plots/market2.png}
  \caption*{\textbf{Market Scenario 1:} \\ $\beta_0 = 15, \beta_1 = -1.05, \beta_2 = -3.1, a = 0.1$
\endminipage\hfill
\minipage{0.5\textwidth}
  \includegraphics[width=\linewidth]{plots/market3.png}
  \caption*{\textbf{Market Scenario 2:} \\ $\beta_0 = 25, \beta_1 = -0.6, \beta_2 = -6.1, a = 0.1$
\endminipage\hfill
\caption{Surface plot of potential advantage from deviation ($\epsilon$-deviation) from Nash equilibrium with respect to market price $\tilde{x}$, and reference price $\bar{p}$, with their respective market parameters $\beta_0, \beta_1, \beta_2, a$ for arrival of a single sales event. } \label{fig:market-topo-main}
\end{figure}



Using the Eq. \eqref{eq:d-star-main}, as visualized in Fig. \ref{fig:market-topo-main}, multiple Nash equilibria can exist when $\epsilon = 0$, or when $\epsilon$ is sufficiently small (see Section \ref{sec:results}). Such behaviour occurs when one agent unilaterally deviates from $\tilde{x}$, under reference price $\bar{p}$. Thus, the lower plateau from Fig. \ref{fig:market-topo-main} represents the region where a theoretical Nash Equilibrium exists. Bounds on the state space and action space are limited to $|S| = |X_n| = 10$, that is there are 10 discrete intervals for each state $s^t$ and action $x_n^t$, representing price values.

\subsection{Nash Equilibrium in Markov Games ($\delta$)}

The value of a policy, at each state, can be represented by a joint action which maximizes the joint Q function \citep{Watkins:1992} under policy $\pi(s)$. The probability of  agent $n$ taking action $x_n$ is defined as $\pi_n(s, x_n)$.

\begin{align} 
    v(s, \pi_n, \pi_{-n}) = \underset{\bar{x} \in \mathbf{X} }{\mathrm{max}} \ \prod_{n=1}^N \pi_n(s, x_n) Q_n(s, x_{n}, x_{-n}) \label{eq:val-joint-policy}
\end{align}



An $\epsilon$-Nash equilibrium is defined as a joint policy such that the reward of a single stage game will not result in a greater payoff to the agent $n$ by more than $\epsilon$, when any agent unilaterally deviates from said joint policy. Provided $\epsilon$, we consider a bound on the corresponding MG, $\delta$, which defines a bound on the gain of the \textit{value} of a policy, $v(s, {\pi_{n}}^*, \pi^*_{-n})$, should agent $n$ unilaterally deviate with an alternative policy. The solution to Eq. \eqref{eq:val-joint-policy} can be computed by searching over the joint action space $\{ x_n, x_{-n} \}$.

\begin{align} 
    \underset{\bar{x} \in \mathbf{X} }{\mathrm{argmax}} \prod_{n=1}^N \pi_n(s, x_n) Q_n(s, x_{n}, x_{-n}^*) &\leq \underset{\bar{x} \in \mathbf{X} }{\mathrm{argmax}} \prod_{n=1}^N \pi_n(s, x_n) Q_n(s, x_{n}^*, x_{-n}^*) + \delta \label{eq:nash-cond-q} \\
    v(s, \pi_n, \pi_{-n}^*) &\leq v(s, \pi_{n}^*, \pi_{-n}^*)  + \delta, \quad \forall s \in \mathbf{S} \label{eq:nash-cond-v} 
\end{align}


$\delta$ serves as an upper bound on $\epsilon$, therefore the minimization of $\delta$ will also minimize any possible existence of $\epsilon$ for each single stage game in the MG. In fact, the existence of $\epsilon$ implies the existence of upper bound $\delta$, we provide a proof of this existence in Appendix \ref{sec:eps-delta-exis}.


\section{Multi-Agent Nash Q Learning} \label{sec:ma-ql}


In our model, the game provides full information, where information regarding the state and the actions of all agents are visible to any agent. This allows for \textit{experience replay} for Q learning \citep{mnih:2015} to occur, and the Q function can be shared for all agents as they are assumed to be identical. The joint action space $\bar{x} = (x_1, ..., x_N)$ is defined as the combined actions of all agents at time $t$. Normally, in Q learning, the update mechanism searches for the action that maximizes the Q function, however, in \textit{Nash Q learning}, we must update the Q function with the solution to the Nash equilibrium. In our model, we represent the tabular Q function via a function approximator, which is denoted simply as $Q(s, \bar{x})$. As new experiences are obtained when the MG is played, the Nash Q value is updated. We utilize the Q update mechanism defined in \citep{hu:2003} as the update mechanism for the Nash Q estimator for Q learning. Given a Q function and a Nash policy, we search over the joint action that maximizes the scaled Q function \citep{laumonier:2005-multiagent}, as in Eq. \eqref{eq:nash-q-max}. In our representation, the Q function is a vector, returning the respective Q value for each agent, based on the joint probability input for the joint policy.


\begin{align} 
    Q'(s, \bar{x}) &\xleftarrow[]{} (1-\alpha) Q(s, \bar{x}) + \alpha [r + \gamma \mathcal{N}(s') ] \label{eq:q-update} \\
    \bar{x}^* &= \underset{\bar{x}}{\mathrm{argmax}} \ Q(s', \bar{x}) \prod_{i=1}^N \pi_n^*(s', x_n) \label{eq:nash-q-max}\\
    \mathcal{N}(s') &= Q(s', \bar{x}^*) \prod_{i=1}^N \pi_n^*(s', x^*_n)  \label{eq:nash-operator}
   
\end{align}

$\mathcal{N}(s')$ represents a \textit{Nash Operator}, indicating the Q value of a Nash equilibrium, this is approximated by a scaling factor, according to the Nash equilibrium policy, $\pi^*$, multiplied by the Q value of the joint action, $Q(s, \bar{x})$. Extending from the work of \citep{hu:2003}, we introduce a neural network for mapping any state action combination to its Nash policy, where the Nash scaling factor derives from and is used to compute $\mathcal{N}(s')$ in conjunction with the Q function. The Q-function used in Eq. \eqref{eq:nash-operator} and \eqref{eq:q-update} is represented by a deep neural network, simply referred to as the Nash Q Net $Q(s)$. In a full information game with homogenous agents, a shared neural network representing $Q(s, \bar{x})$ can be used for all agents in the Markov Game (if not homogeneous a separate Q network must be retained and updated separately for each agent). The Q Network parameters representing $\mathcal{N}(s')$ is learned in the same method as Deep Q learning \citep{mnih:2015}, the key innovation, is that the scaling factor to compute $\mathcal{N}(s')$ is obtained via a Nash Policy Net, $\Psi(s)$ (defined later in Section \ref{sec:nash-pol-learn}).

\subsection{Estimating Value Advantage via Black Box Optimization}

We apply a deep neural network to represent a mapping of a joint policy to its respective $\delta$ from Eq. \eqref{eq:nash-cond-v}, designated as $\Gamma(\pi) \xrightarrow[]{} \bm{\delta}$, where $\bm{\delta}$ is a vector containing the $\delta_s$ of each state. As the gradient of $\Gamma(\pi)$ cannot be easily evaluated, we apply gradient free black box optimization for $\delta$ minimization. Trust Region Optimization (TRO) has been shown to be effective for solving high-dimensional optimization problems \citep{wang:2021-lamcts} \citep{ericksson:2020-turbo} \citep{Diouane:2021-trego} \citep{Regis:2016}, particularly when the computational resources are available. To compute the existence of an $\epsilon$-Nash equilibrium in the high-dimensional policy space efficiently, we apply model-based Bayesian Optimization via Trust Region optimization (\texttt{TuRBO}) from \citep{ericksson:2020-turbo}. \texttt{TuRBO} combines standard TRO with a multi-armed bandit system via Thompson Sampling \citep{Thompson:1933} to optimize for local multiple trust regions simultaneously, with sufficient convergence time. However, the candidate generation step in \texttt{TuRBO} is not constrained to account for the valid joint probabilities of each agent, in which the sum of probabilities for each agent in its respective action space must sum to 1. We alter \texttt{TuRBO} by simply normalizing the original candidate probabilities over each set of probabilities belonging to an agent $n$. The resulting modified algorithm is denoted \texttt{TuRBO-p}, where any candidate value generated by \texttt{TuRBO-p} will have joint probabilities that sum to 1 for policies corresponding to each agent.

\begin{align} 
    V(s, \pi) &= \underset{\bar{x}}{\mathrm{max}} \ Q(s, \bar{x}) \prod_{i=1}^N \pi_n(s, x_n) \\
    \delta &= \underset{\pi_n'}{\mathrm{max}} \ \Bigg( V(s, \pi_n', \pi_{-n}) - V(s, \pi_{n}, \pi_{-n}) \Bigg) \quad \forall s \in \mathbf{S} \label{eq:delta-max}
   
\end{align}

The maximization problem is formulated in Eq. \eqref{eq:delta-max} representing the maximum gain in value of a policy, where agent $n$ deviates from policy $\pi_{n}$ with $\pi_n^{'}$. 

\subsection{Nash Policy Learning} \label{sec:nash-pol-learn}

The $\epsilon$-Nash policy is defined as a joint policy $(\pi^*_n, \pi^*_{-n})$ that minimizes $\delta$ from Eq. \eqref{eq:nash-cond-v}. Drawing inspiration from \citep{Ceppi:2010}, where a Nash equilibrium is found by effectively minimizing for $\epsilon$ via linear programming, we apply a similar technique of $\delta$-minimization. However, in \citep{Ceppi:2010}, the model parameters are known to the agents, and the Markov game was constrained to two players. In our MG, the joint reward function must be learned. Therefore, we perform approximate search over the policy space instead of using exact methods to discover any possible approximate Nash equilibrium policies. In principle, each state has maps to a corresponding probability in accordance with the Nash Policy which minimizes $\delta$ in Eq. \ref{eq:delta-max}. However, a table keeping track of such an enormous state policy space is not feasible. Therefore, we implement a Nash Policy Net $\Psi(s) \xrightarrow[]{} \pi^*$ to learn the state to policy mapping, which is the joint policy $\pi$ producing an approximate Nash equilibrium as approximated via \texttt{TuRBO-p}, designated as $\hat{\pi}^*(s)$.

\begin{align} 
    \hat{\pi}^*(s) = \underset{\pi}{\mathrm{argmin}} \ \Gamma(\pi)_s \label{eq:gamma-min}
\end{align}










\begin{algorithm}[h!]
\caption{Nash equilibrium learning}\label{algo:nash-eq-learning}
\begin{algorithmic}[1]

    \State Initialize state joint policy $\pi$.
    \State Initialize random parameters for $\Psi(s_t)$, $Q(s_t)$ and $\Gamma(\pi)$, as $\theta_{Q}$, $\theta_{\Psi}$, and $\theta_{\Gamma}$.
    \State Initialize MDP Environment, $\mathcal{M}$.
    
    \For {$e \in episodes $}:
        \State Get initial state $s_0$ from $\mathcal{M}$.
        \For {$t \in (0, t_{max})$}: Iterate until end of episode.
           
           
            \State Get action probabilities $\pi(s_t, x_n)$ from Nash Policy Net $\Psi(s_t)$.
                \For {$n \in (1, N)$}: Iterate through agents.
                   
                   
                    \State Sample selected action from Nash policy. $x_n \thicksim Multinomial(s_t, \pi(\overline{x}))$ 
                \EndFor
            \State Obtain joint action $\overline{x} \xleftarrow[]{}  \{ x_1, ... , x_N \}$
            \State Assign  $\delta_s \xleftarrow[]{} \underset{\pi_n'}{\mathrm{max}} \ \Bigg( V(s, \pi_n', \pi_{-n}) - V(s, \pi_{n}, \pi_{-n}) \Bigg)$ via \texttt{TuRBO-p}.
            \State Find the Nash policy $\pi^* \xleftarrow[]{}  \underset{\pi}{\mathrm{argmin}} \ \Gamma(\pi, s_t)$ via \texttt{TuRBO-p}.
            \State Execute joint action $\overline{x}$ in $(\mathcal{M}, \ s_{t})$ to obtain $s_{t+1}, \overline{r}_t$.
            \State Append experience $(s_t, \overline{x}_t, \overline{r}_t, \epsilon_s, \pi, s_{t+1} )$ to experience replay $\mathcal{D}$.
           
            \State Update State $s_{t} \xleftarrow[]{} s_{t+1}$.

            \If {$|\mathcal{D}| > batchsize$}:
                \State Sample minibatch $d$ from $\mathcal{D}$.
                \State Set $Q'(s_t, \bar{x}) \xleftarrow[]{}  
                    \begin{cases} 
                      r_t &\text{for \ } s_t \ \text{terminal} \\ 
                      (1-\alpha) Q(s, \bar{x}) + \alpha [r + \gamma \mathcal{N}(s') ] &\text{for \ }  s_t \ \text{not terminal} 
                    \end{cases} $
                
                    \State $\mathcal{L}_{Q} \xleftarrow[]{} (Q'(S_t, \bar{x}) - Q(S_t, \bar{x}))^2$ Nash Q Update.
                \State $\mathcal{L}_{\Psi} \xleftarrow[]{} (\hat{\pi} - \pi^*)^2$ Nash policy update, where $\hat{\pi}$ is from $\Psi(s)$.
                \State $\mathcal{L}_{\Gamma} \xleftarrow[]{} (\hat{\epsilon} - \epsilon)^2$ Nash $\epsilon$ update, where $\hat{\epsilon}$ is from $\Gamma(\pi)$
                \State Backpropagate loss functions $\mathcal{L}_{Q}$, $\mathcal{L}_{\Psi}$ and $\mathcal{L}_{\Gamma}$ on $\mathcal{Q}$, $\Psi$, and $\Gamma$.
                \State Update model parameters $\theta_{Q}$, $\theta_{\Psi}$, and $\theta_{\Gamma}$ via gradient descent.
                
               
            \EndIf
            
            \State Update joint policy $\overline{\pi} \xleftarrow[]{} \overline{\pi}^*$.
        \EndFor
    \EndFor

\end{algorithmic}
\end{algorithm}








\section{Results} \label{sec:results}

\begin{figure}[!htb]
\minipage{0.5\textwidth}
  \includegraphics[width=\linewidth]{plots/sc1_loss.png}
  \caption*{Loss behaviour of Scenario 1 with $n=3$.
\endminipage\hfill
\minipage{0.5\textwidth}
  \includegraphics[width=\linewidth]{plots/market2_loss_5n.png}
  \caption*{Loss behaviour of Scenario 2 with $n=5$.
\endminipage\hfill
\caption{Decreasing loss behaviour of batch update during Deep Q Learning $Q$ (left y axis) and Nash Net update $\Psi(s)$ (right y axis) demonstrating that $\Psi(s)$ has learned a representation of the Nash policy (x-axis represents iterations multiplied by episode).} \label{fig:loss_plot_main}
\end{figure}

\textbf{Stabilization of realized market rewards to Nash equilibrium:} Fig. \ref{fig:reward_plots_main} represents the convergence of the average market reward of a single agent (randomly selected as agent 0) towards a Nash equilibrium. We superimpose the boundaries of the theoretical Nash equilibrium reward over the plot. The reward is obtained from the boundaries of theoretical Nash equilibria, where $\epsilon < \epsilon_l$ ($\epsilon_l = 0.0001$). The topology of this function is illustrated in Fig. \ref{fig:market-topo-main}, and for each state, or reference price, there exists a boundary where the policy deviation of any agent can occur without significant unilateral reward gain. The expected reward is computed using the market model parameters per Scenario ($\beta_0, \beta_1, \beta_2, a$). From the expected reward, we compare it with the positive difference of theoretical equilibrium reward $\Pi' = f(x_n') \ x_n'$ where $x_n'$. This exists as two boundary points indicating the area where $\epsilon < \epsilon_l$. For each episode the average reward per timestep over the episode lengths is recorded. From Fig. \ref{fig:reward_plots_main}, we observe the average reward per agent of the system per episode (blue dashed line), and the average reward of a single agent per episode (orange dashed line), to converge within the boundary of Nash equilibrium (blue shade). However, due to randomization from black box optimization and/or stochastic behaviour of the Markov Game this expected reward can sometimes fall outside of the NE region.

\textbf{Diminishing loss function:} We demonstrate empirically, as shown in Fig. \ref{fig:loss_plot_main}, that the loss function of $Q(s)$ and $\Psi(s)$ decrease with each RL episode. This merely indicates that a representation of the function mapping state to its corresponding Nash policy based on policy-to-$\epsilon$ model $\Gamma(\pi)$ is being learned, and a stable solution is proposed. Hyperparameters are presented in Appendix \ref{sec:hardware-hyperparam}.


\begin{figure}[!htb]
\minipage{0.5\textwidth}
  \includegraphics[width=\linewidth]{plots/sc1_rewards.png}
  \caption*{Market rewards per episode Scenario 1, $n=3$.}\label{fig:market3_reward}
\endminipage\hfill
\minipage{0.5\textwidth}
  \includegraphics[width=\linewidth]{plots/market2_rewards_5n.png}
  \caption*{Market rewards per episode Scenario 2, $n=5$.}\label{fig:market2_reward}
\endminipage\hfill
\caption{In a Nash equilibrium, both the market average reward (blue), and single agent reward (orange) should fall within the Nash equilibria boundary (blue shade), as the MG progresses. }\label{fig:reward_plots_main}
\end{figure}





\textbf{Comparison with baseline cooperative Q-learning model:} We compare our NE learning model wit a naive cooperative Q learning model to serve as a baseline measure of model performance. In the naive Q learning model, the objective is simply to maximize each agent's respective rewards, and avoid any kind of NE computation. The Q update function in Eq. \eqref{eq:q-update} is simply a maximization of the joint Q function, instead of using $\mathcal{N}(s')$. From Fig.\ref{fig:baseline_comp}, we generally observe lower average reward values from the baseline model compared to the NE learning model. The NE reward ranges remain very similar. From an economic perspective, the Nash Q learning agents take into account that other agents will compete against them, and the solver optimizes accordingly, whereas, in cooperative Q learning no consideration for the other agents' strategies are taken, and agents may to over-compete, driving average rewards lower in an oligopoly.



\begin{figure}[!htb]
\minipage{0.5\textwidth}
  \includegraphics[width=\linewidth]{plots/sc1_baseline_comp_reward.png}
  \caption*{Scenario 1 - NE Learning vs Q learning, $n=3$.}\label{fig:market3_max_gain}
\endminipage\hfill
\minipage{0.5\textwidth}
  \includegraphics[width=\linewidth]{plots/sc2_baseline_comp_reward.png}
  \caption*{Scenario 2 - NE Learning vs Q learning, $n=5$.}\label{fig:market2_reward}
\endminipage\hfill
\caption{Average revenue per episode from a NE learning model (blue) versus a baseline Q learning model (green), with NE reward boundaries overlayed in their respective colours.  }\label{fig:baseline_comp}
\end{figure}


\section{Conclusion} \label{sec:conclusion}

We created a Markov Game that represents an n-firm oligopoly, based on previously established market models where theoretical $\epsilon$ bounds for a Nash equilibrium policy exist. A black box algorithm is applied to estimate an upper bound on the $\epsilon$ value of a joint policy, represented by neural network $\Gamma(\pi)$. Similarly a Nash Policy Net $\Psi(s)$ is learned to represent the $\epsilon$-minimizing policy from black box optimization, constituting an $\epsilon$-Nash policy. Thus $\Psi(s)$ can be used together with traditional Deep Q learning, to solve for a Nash equilibrium. Empirically, we show that the average reward of all agents, and the reward of a respective single agent, converges to an approximate Nash equilibrium. The limitations of this research are the limited action space of the agents, as well as the identical nature of the agents. Larger scale experimentation under this framework is suggested. Furthermore, the proposed market model could be enhanced by implementing more complex non-linear market oligopoly environments.

