Game theory: decision making with examples on Kotlin

3r31289. 3r3-31. Game theory is a mathematical discipline that considers the modeling of actions of players who have a goal, which is to choose the optimal strategies of behavior in conditions of conflict. On Habré, this topic is already was covered , but today we will talk about some of its aspects in more detail and consider examples at Kotlin. here is . 3r31277. 3r31289. Now we will consider decision criteria in pure strategies, and at the end of the article we will solve the game in mixed strategies by an analytical method. 3r31277. 3r31289. 3r31233. 3r31234. Disclaimer [/b] 3r31236. I am not an expert in game theory, and in this work I used Kotlin for the first time. However, I decided to share my results. If you notice errors in the article or want to give advice, please in PM. 3r31277. 3r31289. 3r31285. 3r31285. 3r31277. 3r31289. 3r31271. Setting the task

3r31277. 3r31289. All decision criteria, we will examine the end-to-end example. The task is this: the farmer needs to determine in what proportions to sow his field with three crops, if the yield of these crops, and, therefore, profit, depend on what summer will be: cool and rainy, normal, or hot and dry. The farmer calculated the net profit from 1 hectare from different crops depending on the weather. The game is defined by the following matrix: 3r31277. 3r31289. 3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r31266. 3r31226. 3r31277. 3r31289. Looking for the optimal strategy we denote

3r31266. . We will solve the game using the criteria of Wald, optimism, pessimism, Savage and Hurwitz under conditions of uncertainty and the criteria of Bayes and Laplace under conditions of risk. 3r31277. 3r31289. As mentioned above, examples will be on Kotlin. I note that there are generally solutions like Gambit (written in C), Axelrod and PyNFG (written in Python), but we will ride our own bike, assembled on the knee, just to poke a little stylish, trendy and youth programming language. 3r31277. 3r31289. In order to programmatically implement the solution of the game we will get several classes First we need a class that allows us to describe a row or column of the game matrix. The class is extremely simple and contains a list of possible values (alternatives or states of nature) and the corresponding name. Field ` key `

We will use for identification, as well as for comparison, and comparison will be needed in the implementation of dominance. 3r31277. 3r31289. 3r31233. 3r31234. Row or column of the game matrix [/b] 3r31236. 3r31237. 3r31238. import java.text.DecimalFormat

import java.text.NumberFormat

3r31289. open class GameVector (name: String, values: List , key: Int = -1): Comparable {

3r31289. val name: String

val values: List 3r31289. val key: Int

3r31289. private val formatter: NumberFormat = DecimalFormat ("# ???")

3r31289. init {

this.name = name; 3r31289. this.values = values; 3r31289. this.key = key; 3r31289.}

3r31289. public fun max (): Double? {

return values.max (); 3r31289.}

3r31289. public fun min (): Double? {

return values.min (); 3r31289.}

3r31289. override fun toString (): String {

return name + ":" + values

.map {v -> formatter.format (v)}

.reduce ({f1: String, f2: String -> "$ f1 $ f2"}) 3r31229.}

3r31289. override fun compareTo (other: GameVector): Int {

var compare = 0

if (this.key == other.key) {

return compare

}

var great = true

for (i in 0this.values.lastIndex) {

great = great && this.values [i]> = other.values [i]3r31289.}

if (great) {

compare = 1

} else {

var less = true

for (i in 0this.values.lastIndex) {

less = less && this.values [i]<= other.values [i]3r31289.}

if (less) {

compare = -1

}

}

return compare

}

}

3r31258. 3r31259. 3r31285. 3r31285. 3r31277. 3r31289. The game matrix contains information about alternatives and states of nature. In addition, it implements some methods, such as finding the dominant set and the net price of the game. 3r31277. 3r31289. 3r31233. 3r31234. The game matrix [/b] 3r31236. 3r31237. 3r31238. open class GameMatrix (matrix: List , natureStateNames: List ) {

val matrix: List 3r31289. val natureStateNames: List 3r31289. 3r31289. val alternatives: List 3r31289. val natureStates: List 3r31289. 3r31289. init {

this.matrix = matrix; 3r31289. this.alternativeNames = alternativeNames

this.natureStateNames = natureStateNames

3r31289. var alts: MutableList = mutableListOf ()

for (i in 0matrix.lastIndex) {

val currAlternative = alternativeNames[i]3r31289. val gameVector = GameVector (currAlternative, matrix[i], i)

alts.add (gameVector)

}

alternatives = alts.toList () 3r31289. 3r31289. var nss: MutableList = mutableListOf ()

val lastIndex = matrix[0].lastIndex //there is no check for equality of the lengths of all strings, we believe that they are equal to 3r31228. for (j in 0lastIndex) {3r31229. val currState = natureStateNames[j]3r31289. var states: MutableList = mutableListOf ()

for (i in 0matrix.lastIndex) {

states.add (matrix[i] [j])

}

val gameVector = GameVector (currState, states.toList (), j)

nss.add (gameVector)

}

natureStates = nss.toList ()

}

3r31289. open fun change (i: int, j: int, value: Double): GameMatrix {

var mml = this.matrix.toMutableList ()

3r31289. var rowi = mml[i].toMutableList ()

rowi.set (j, value)

3r31289. mml.set (i, rowi)

3r31289. return GameMatrix (mml.toList (), alternativeNames, natureStateNames)

}

3r31289. open fun changeAlternativeName (i: Int, value: String): GameMatrix {

var list = alternativeNames.toMutableList ()

list.set (i, value)

3r31289. return GameMatrix (matrix, list.toList (), natureStateNames)

}

3r31289. open fun changeNatureStateName (j: Int, value: String): GameMatrix {

var list = natureStateNames.toMutableList ()

list.set (j, value)

3r31289. return GameMatrix (matrix, alternativeNames, list.toList ())

}

3r31289. fun size (): Pair {

Return Pair (alternatives.size, natureStates.size)

}

3r31289. override fun toString (): String {

Return "States of nature: n" +

natureStateNames.reduce {n1: String, n2: String -> "$ n1; n $ n2"} +

"n Matrix of the game: n" +

alternatives 3r31289. .map {a: GameVector -> a.toString ()}

.reduce {a1: String, a2: String -> "$ a1; n $ a2"}

}

3r31289. protected fun dominateSet (gvl: List , list: MutableList , dvv: Int): MutableSet {

var dSet: MutableSet = mutableSetOf ()

for (gv in gvl) {3r312389. for (gvv in gvl) {3r31289. if (! dSet.contains (gv) &&! dSet.contains (gvv)) {3r31229. if (gv.compareTo (gvv) == dvv) {

dSet.add (gv)

list.add ("[$gvv]dominates[$gv]") 3r31229.}

}

}

}

return dSet

}

3r31289. open fun newMatrix (dCol: MutableSet , dRow: MutableSet )

: GameMatrix {

var result: MutableList = mutableListOf ()

var rnatureStateNames: MutableList = mutableListOf ()

3r31289. val dIndex = dCol.map {c -> c.key} .toList ()

3r31289. for (i in 0 natureStateNames.lastIndex) {

if (! dIndex.contains (i)) {

rnatureStateNames.add (natureStateNames[i])

}

}

3r31289. for (gv in this.alternatives) {

if (! dRow.contains (gv)) {3r31229. var nr: MutableList = mutableListOf ()

for (i in 0 gv.values.lastIndex) {

if (! dIndex.contains (i)) {

nr.add (gv.values [i])

}

}

result.add (nr)

ralternativeNames.add (gv.name)

}

}

3r31289. val rlist = result.map {r -> r.toList ()} .toList ()

return GameMatrix (rlist, ralternativeNames.toList (), rnatureStateNames.toList ())

}

3r31289. fun dominateMatrix (): Pair = mutableListOf ()

3r31289. var dCol: MutableSet = dominateSet (this.natureStates, list, 1)

var dRow: MutableSet = dominateSet (this.alternatives, list, -1)

3r31289. val newMatrix = newMatrix (dCol, dRow)

3r31289. var ddgm = Pair (newMatrix, list.toList ())

3r31289. val ret = iterate (ddgm, list)

return ret; 3r31289.}

3r31289. protected fun iterate (ddgm: Pair )

: Pair = this.alternatives.map {a -> a? .min ()?: 0.0}

return map? .max ()?: ???r3r31289.}

3r31289. fun maxClearPrice (): Double {

val map: List = this.natureStates.map {a -> a? .max ()?: 0.0}

return map? .min ()?: ???r3r31289.}

3r31289. fun existsClearStrategy (): Boolean {

return minClearPrice ()> = maxClearPrice ()

}

} 3r31259. 3r31285. 3r31285. 3r31277. 3r31289. We describe the interface that meets the criteria 3r31277. 3r31289. 3r31233. 3r31234. Criterion 3r312335. 3r31236. 3r31237. 3r31238. interface ICriteria {

fun optimum (): List 3r31289.}

3r31258. 3r31259. 3r31285. 3r31285. 3r31277. 3r31289. 3r3761. Decision making under uncertainty 3r31277. 3r31289. Decision making under uncertainty implies that the player is not opposed by a reasonable opponent. 3r31277. 3r31289. 3r31277. 3r31289. 3r31271. Wald Criterion 3r31277. 3r31289. The Wald criterion maximizes the worst possible outcome: 3r31277. 3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r31226. 3r31277. 3r31289. Using the criterion insures against the worst result, but the price of such a strategy is the loss of the opportunity to get the best possible result. 3r31277. 3r31289. Consider an example. For strategies 3r31264. 3r3600. 3r31266. Find the minima and get the next three 3r3-31264. 3r33333. 3r31266. . The maximum for the indicated three will be the value ? therefore, according to the Wald criterion, the winning strategy is the strategy 3r31264. 3r33393. 3r31266. corresponding to the landing of Culture 2.

3r31289. Software implementation of the Wald criterion is simple: 3r31277. 3r31289. 3r31237. 3r31238. class WaldCriteria (gameMatrix: GameMatrix): ICriteria {

3r31289. val gameMatrix: GameMatrix

3r31289. init {

this.gameMatrix = gameMatrix

}

3r31289. override fun optimum (): List {

val mins = gameMatrix.alternatives.map {a -> Pair (a, a.min ())}

val max = mins.maxWith (Comparator {o? o2 -> o1.second !!. compareTo (o2.second !!)})

return mins

.filter {m -> m.second == max !!. second}

.map {m -> m.first}

}

}

3r31258. 3r31259. 3r31277. 3r31289. For greater clarity, for the first time I will show you how the solution would look like a test: 3r3r12777. 3r31289. 3r31233. 3r31234. Test 3r31235. 3r31236. 3r31237. 3r31238. private fun matrix (): GameMatrix {

val alternativeNames: List = listOf ("Culture 1", "Culture 2", "Culture 3")

val natureStateNames: List = listOf ("Cool and rainy", "Normal", "Roast and dry")

val matrix: List println (o.toString ())}

}

@Test

fun testWaldCriteria () {

val matrix = matrix (); 3r31289. val criteria = WaldCriteria (matrix)

testCriteria (matrix, criteria, "Wald criterion")

}

3r31258. 3r31259. 3r31285. 3r31285. 3r31277. 3r31289. It is not difficult to guess that for other criteria the difference will be only in the creation of the object 3r31238. criteria 3r31258. . 3r31277. 3r31289. 3r31277. 3r31289. 3r31271. The criterion of optimism 3r31277. 3r31289. When using the optimist criterion, the player chooses the solution that gives the best result, while the optimist assumes that the conditions of the game will be most favorable for him: 3r31277. 3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r31226. 3r31277. 3r31289. An optimist%27s strategy can lead to negative consequences when the maximum supply coincides with the minimum demand — a firm may suffer losses when writing off unsold products. At the same time, the strategy of the optimist has a certain meaning, for example, there is no need to worry about unsatisfied customers, since any possible demand is always satisfied, therefore there is no need to maintain the location of customers. If the maximum demand is realized, then the strategy of the optimist allows to obtain the maximum utility, while other strategies will lead to lost profit. This gives certain competitive advantages. 3r31277. 3r31289. Consider an example. For strategies 3r31264. 3r3600. 3r31266. find the maximum and get the next three 3r31264. 3r31266. . The maximum for the indicated three will be ? therefore, according to the criterion of optimism, the winning strategy is the strategy 3r31264. 3r31266. corresponding to the landing of Culture 1.

3r31289. The implementation of the optimism criterion hardly differs from the Wald criterion:

3r31289. 3r31237. 3r31238. class WaldCriteria (gameMatrix: GameMatrix): ICriteria {

3r31289. val gameMatrix: GameMatrix

3r31289. init {

this.gameMatrix = gameMatrix

}

3r31289. override fun optimum (): List {

val mins = gameMatrix.alternatives.map {a -> Pair (a, a.min ())}

val max = mins.maxWith (Comparator {o? o2 -> o1.second !!. compareTo (o2.second !!)})

return mins

.filter {m -> m.second == max !!. second}

.map {m -> m.first}

}

}

3r31258. 3r31259. 3r31277. 3r31289. 3r31277. 3r31289. 3r31271. Pessimism criterion 3r31277. 3r31289. This criterion is designed to select the smallest element of the game matrix from its minimum possible elements: 3r3r1277. 3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r31226. 3r31277. 3r31289. The criterion of pessimism suggests that the development of events will be unfavorable for the decision maker. When using this criterion, the decision maker is guided by the possible loss of control over the situation, therefore, he tries to eliminate potential risks by choosing the option with the minimum yield. 3r31277. 3r31289. Consider an example. For strategies 3r31264. 3r3600. 3r31266. let%27s find a minimum and get the next three 3r31264. 3r3544. 3r31266. . The minimum for the indicated three will be -? therefore, according to the criterion of pessimism, the winning strategy is 3r31264. 3r31266. corresponding to the landing of Culture 3.

3r31289. After getting acquainted with the Wald and optimism criteria, I think it is easy to guess how the pessimism criterion class will look like: 3r3r1277. 3r31289. 3r31237. 3r31238. class PessimismCriteria (gameMatrix: GameMatrix): ICriteria {

3r31289. val gameMatrix: GameMatrix

3r31289. init {

this.gameMatrix = gameMatrix

}

3r31289. override fun optimum (): List {

val mins = gameMatrix.alternatives.map {a -> Pair (a, a.min ())}

val min = mins.minWith (Comparator {o? o2 -> o1.second !!. compareTo (o2.second !!)})

return mins

.filter {m -> m.second == min !!. second}

.map {m -> m.first}

}

}

3r31258. 3r31259. 3r31277. 3r31289. 3r31277. 3r31289. 3r31271. Savage Criterion 3r31277. 3r31289. The Savage criterion (the regretting pessimist criterion) suggests minimizing the largest lost profit, in other words, the greatest regret for the lost profit is 3r31277. 3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r31226. 3r31277. 3r31289. In this case, S is a regret matrix. 3r31277. 3r31289. The optimal solution for the Savage criterion should give the least regret of the regrets found in the previous step. The solution corresponding to the found utility will be optimal. 3r31277. 3r31289. The peculiarities of the solution obtained include the guaranteed absence of the biggest disappointments and the guaranteed reduction of the maximum possible gains of other players. 3r31277. 3r31289. Consider an example. For strategies 3r31264. 3r3600. 3r31266. compile a regret matrix 3r31277. 3r31289. 3r3604. 3r31277. 3r31289. Three of maximum regrets 3r3608. 3r31266. . The minimum value of these risks will be ? which corresponds to the strategies 3r31264. 3r31266. and 3r31264. 3r31414. 3r31266. . 3r31277. 3r31289. Programming the Savage criterion is a little more difficult:

3r31289. 3r31237. 3r31238. class SavageCriteria (gameMatrix: GameMatrix): ICriteria {

3r31289. val gameMatrix: GameMatrix

3r31289. init {

this.gameMatrix = gameMatrix

}

3r31289. fun GameMatrix.risk (): List Pair (n, n.values.max ())}

.map {n -> n.first.key to n.second} .toMap ()

3r31289. var am: MutableList = mutableListOf ()

for (i in 0a.values.lastIndex) {3r31229. val mn = maxStates.get (i)

v.add (mn !! - a.values [i])

}

am.add (Pair (a, v.toList ()))

}

return am.map {m -> Pair (m.first, m.second.max ())}

}

3r31289. override fun optimum (): List {

val risk = gameMatrix.risk ()

val minRisk = risk.minWith (Comparator {o? o2 -> o1.second !!. compareTo (o2.second !!)})

return risk

.filter {r -> r.second == minRisk !!. second}

.map {m -> m.first}

}

}

3r31258. 3r31259. 3r31277. 3r31289. 3r31277. 3r31289. 3r31271. The Hurwitz Criterion 3r31277. 3r31289. The Hurwitz criterion is a regulated compromise between extreme pessimism and complete optimism: 3r31277. 3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r3673. 3r31266. 3r31226. 3r31277. 3r31289. A (0) is the strategy of the extreme pessimist, A (k) is the strategy of a complete optimist, 3r31264. 3r31266. - set value of the weight coefficient: 3r31266. ; 3r31264. 3r31266. - extreme pessimism, 3r31266. - complete optimism. 3r31277. 3r31289. With a small number of discrete strategies, setting the desired value of the weighting factor 3r31264. 3r3693. 3r31266. and then round the result to the nearest possible value, taking into account the performed sampling. 3r31277. 3r31289. Consider an example. For strategies 3r31264. 3r31266. . Let us assume that the coefficient of optimism is 3r33700. 3r31266. . Now we will make the table: 3r3r1277. 3r31289. 3r3704. 3r31277. 3r31289. The maximum value of the calculated H will be ? which corresponds to the strategy 3r31264. 3r31266. . 3r31277. 3r31289. The implementation of the Hurwitz criterion is more voluminous: 3r31277. 3r31289. 3r31237. 3r31238. class HurwitzCriteria (gameMatrix: GameMatrix, optimisticKoef: Double): ICriteria {

3r31289. val gameMatrix: GameMatrix

val optimisticKoef: Double

3r31289. init {

this.gameMatrix = gameMatrix

this.optimisticKoef = optimisticKoef

}

3r31289. inner class HurwitzParam (xmax: Double, xmin: Double, optXmax: Double) {

val xmax: Double

val xmin: Double

val optXmax: Double

3r31289. val value: Double

3r31289. init {

this.xmax = xmax

this.xmin = xmin

this.optXmax = optXmax

value = xmax * optXmax + xmin * (1 - optXmax)

}

3r31289.}

3r31289. fun GameMatrix.getHurwitzParams (): List Pair (a, HurwitzParam (a.max () !!, a.min () !!, optimisticKoef))}

}

3r31289. override fun optimum (): List {

val hpar = gameMatrix.getHurwitzParams ()

val maxHurw = hpar.maxWith (Comparator {o? o2 -> o1.second.value.compareTo (o2.second.value)})

return hpar

.filter {r -> r.second == maxHurw !!. second}

.map {m -> m.first}

}

}

3r31258. 3r31259. 3r31277. 3r31289. 3r31277. 3r31289. 3r3761. Making decisions at risk 3r31277. 3r31289. Decision-making methods can rely on decision-making criteria under conditions of risk, subject to the following conditions: 3r31277. 3r31289. 3r33767. 3r31289. lack of reliable information on possible consequences; 3r31289. availability of probability distributions; 3r31289. knowledge of the likelihood of outcomes or consequences for each decision. 3r31289. 3r3778. 3r31277. 3r31289. If the decision is made under risk, then the cost of alternative decisions are described by probability distributions. In this regard, the decision is based on the use of the criterion of the expected value, according to which alternative solutions are compared in terms of maximizing the expected profit or minimizing the expected costs. 3r31277. 3r31289. The expected value criterion can be reduced to either maximizing the expected (average) profit, or minimizing the expected costs. In this case, it is assumed that the profit (cost) associated with each alternative solution is a random variable. 3r31277. 3r31289. The formulation of such tasks is usually the following: a person chooses some actions in a situation where random events affect the outcome of actions. But the player has some knowledge of the probabilities of these events and can calculate the most advantageous set and sequence of his actions. 3r31277. 3r31289. So that you can continue to give examples, we add the probabilities of the game matrix: 3r31277. 3r31289. 3r31236. 3r31237. 3r31238. open class ProbabilityGameMatrix (matrix: List ,

natureStateNames: List , probabilities: List ): 3r3r131289. GameMatrix (matrix, alternativeNames, natureStateNames) {3r31212. val probabilities: List 3r31289. 3r31289. init {

this.probabilities = probabilities; 3r31289.}

3r31289. override fun change (i: int, j: int, value: Double): GameMatrix {

val cm = super.change (i, j, value)

return ProbabilityGameMatrix (cm.matrix, cm.alternativeNames, cm.natureStateNames, probabilities)

}

3r31289. override fun changeAlternativeName (i: Int, value: String): GameMatrix {

val cm = super.changeAlternativeName (i, value)

return ProbabilityGameMatrix (cm.matrix, cm.alternativeNames, cm.natureStateNames, probabilities)

}

3r31289. override fun changeNatureStateName (j: Int, value: String): GameMatrix {

val cm = super.changeNatureStateName (j, value)

return ProbabilityGameMatrix (cm.matrix, cm.alternativeNames, cm.natureStateNames, probabilities)

}

3r31289. fun changeProbability (j: Int, value: Double): GameMatrix {

var list = probabilities.toMutableList ()

list.set (j, value)

3r31289. return ProbabilityGameMatrix (matrix, alternativeNames, natureStateNames, list.toList ())

}

3r31289. override fun toString (): String {

var s = ""

val formatter: NumberFormat = DecimalFormat ("# ???")

for (i in 0 natureStateNames.lastIndex) {

s + = natureStateNames[i]+ "=" + formatter.format (probabilities[i]) + "n"

}

Return "States of nature: n" +

s +

"The matrix of the game: n" +

alternatives 3r31289. .map {a: GameVector -> a.toString ()}

.reduce {a1: String, a2: String -> "$ a1; n $ a2"}

}

3r31289. override fun newMatrix (dCol: MutableSet , dRow: MutableSet )

: GameMatrix {

var result: MutableList = mutableListOf ()

var rnatureStateNames: MutableList = mutableListOf ()

var rprobailities: MutableList = mutableListOf ()

3r31289. val dIndex = dCol.map {c -> c.key} .toList ()

3r31289. for (i in 0 natureStateNames.lastIndex) {

if (! dIndex.contains (i)) {

rnatureStateNames.add (natureStateNames[i])

}

}

3r31289. for (i in 0 probabilities.lastIndex) {

if (! dIndex.contains (i)) {

rprobailities.add (probabilities[i])

}

}

3r31289. for (gv in this.alternatives) {

if (! dRow.contains (gv)) {3r31229. var nr: MutableList = mutableListOf ()

for (i in 0 gv.values.lastIndex) {

if (! dIndex.contains (i)) {

nr.add (gv.values [i])

}

}

result.add (nr)

ralternativeNames.add (gv.name)

}

}

3r31289. val rlist = result.map {r -> r.toList ()} .toList ()

return ProbabilityGameMatrix (rlist, ralternativeNames.toList (), rnatureStateNames.toList (),

rprobailities.toList ())

}

3r31289.}

}

3r31258. 3r31259. 3r31285. 3r31285. 3r31277. 3r31289. 3r31271. Criterion Bayesa 3r31277. 3r31289. The Bayes criterion (criterion of mathematical expectation) is used in decision-making problems under risk conditions as an evaluation of the strategy 3-331264. 3r33924. 3r31266. the mathematical expectation of the corresponding random variable appears. In accordance with this rule, the optimal strategy of the player is 3r3r12264. 3r33339. 3r31266. found from the condition:

3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r33918. 3r31266. 3r31226. 3r31277. 3r31289. In other words, an indicator of the ineffectiveness of the strategy 3r31264. 3r33924. 3r31266. according to the Bayes criterion with respect to risks, the average value (expectation expectation) of risks of the i-th row of the matrix 3r31264. 3r33939. 3r31266. whose probabilities coincide with the probabilities of nature. Then the optimal one among pure strategies according to Bayes' criterion with respect to risks is the strategy 3r3-31264. 3r33339. 3r31266. which has minimal inefficiency, that is, minimal average risk. The Bayes criterion is equivalent with respect to winnings and with respect to risks, i.e. if the strategy is 3r31264. 3r33339. 3r31266. is optimal by the Bayes criterion for winnings, it is optimal by the Bayes criterion for risks, and vice versa. 3r31277. 3r31289. Let's go over to the example and calculate the mathematical expectation: 3r31277. 3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r33943. 3r31266. 3r31226. 3r31277. 3r31289. The maximum expected value is 3r31264. 3r31266. therefore, the winning strategy is 3r3r1264. 3r3-1023. 3r31266. . 3r31277. 3r31289. Software implementation of the Bayesian criterion: 3r31277. 3r31289. 3r31237. 3r31238. class BayesCriteria (gameMatrix: ProbabilityGameMatrix): ICriteria {

3r31289. val gameMatrix: ProbabilityGameMatrix

3r31289. init {

this.gameMatrix = gameMatrix

}

3r31289. fun ProbabilityGameMatrix.bayesProbability (): List {

val risk = gameMatrix.bayesProbability ()

val maxBayes = risk.maxWith (Comparator {o? o2 -> o1.second !!. compareTo (o2.second !!)})

return risk

.filter {r -> r.second == maxBayes !!. second}

.map {m -> m.first}

}

} 3r31259. 3r31277. 3r31289. 3r31277. 3r31289. 3r31271. The Laplace criterion 3r31277. 3r31289. The Laplace criterion represents a simplified maximization of the expected value of the utility, when the assumption of equal probability of demand levels that are correctAvoids the need to collect real statistics. 3r31277. 3r31289. In the general case, when using the Laplace criterion, the matrix of expected utilities and the optimal criterion are determined as follows: 3r31277. 3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r31226. 3r31277. 3r31289. Consider an example of decision making by the Laplace criterion. We calculate the arithmetic mean for each strategy:

3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r31266. 3r31226. 3r31277. 3r31289. Thus, the winning strategy is 3r3r12264. 3r3-1023. 3r31266. . 3r31277. 3r31289. Software implementation of the Laplace criterion: 3r31277. 3r31289. 3r31237. 3r31238. class LaplaceCriteria (gameMatrix: GameMatrix): ICriteria {

3r31289. val gameMatrix: GameMatrix

3r31289. init {

this.gameMatrix = gameMatrix

}

3r31289. fun GameMatrix.arithemicMean (): List Pair (m, m.values.average ())}

}

3r31289. override fun optimum (): List {

val risk = gameMatrix.arithemicMean ()

val maxBayes = risk.maxWith (Comparator {o? o2 -> o1.second.compareTo (o2.second)})

return risk

.filter {r -> r.second == maxBayes !!. second}

.map {m -> m.first}

}

} 3r31259. 3r31277. 3r31289. 3r31277. 3r31289. 3r31271. Mixed strategies. Analytical Method 3r31272. 3r31277. 3r31289. The analytical method allows to solve the game in mixed strategies. In order to formulate an algorithm for finding the solution of a game by an analytical method, consider some additional concepts. 3r31277. 3r31289. Strategy 3r31266. dominated strategy 3r31067. 3r31266. , if all 3r31070. 3r31266. . In other words, if in a certain row of the payment matrix all elements are greater than or equal to the corresponding elements of another row, then the first row dominates the second and is called the dominant row. And also if in some column of the payment matrix all elements are less or equal to the corresponding elements of another column, then the first column dominates the second one and is called the dominant column. 3r31277. 3r31289. The bottom price of the game is called 3r31075. 3r31266. . 3r31277. 3r31289. The top price of the game is called 3r31080. 3r31266. . 3r31277. 3r31289. Now we can formulate an algorithm for solving a game using the analytical method: 3r31277. 3r31289. 3r3r1086. 3r31289. Calculate the lower 3r31266. and the top 3r31264. 3r31093. 3r31266. game prices. If 3r31096. 3r31266. , then write the answer in pure strategies, if not - continue the decision further 3r3-31106. 3r31289. Remove dominant rows dominant columns. There may be several. In their place in the optimal strategy, the corresponding components will be equal to 0 3r3-31106. 3r31289. Solve the matrix game linear programming method. 3r31276. 3r31289. 3r31277. 3r31289. In order to give an example, you must provide a class that describes the solution

3r31289. 3r31233. 3r31234. Solve [/b] 3r31236. 3r31237. 3r31238. class Solve (gamePriceObr: Double, solutions: List , names: List ) {

3r31289. val gamePrice: Double

val gamePriceObr: Double

val solutions: List 3r31289. val names: List 3r31289. 3r31289. private val formatter: NumberFormat = DecimalFormat ("# ???")

3r31289. init {

this.gamePrice = 1 /gamePriceObr

this.gamePriceObr = gamePriceObr; 3r31289. this.solutions = solutions

this.names = names

}

3r31289. override fun toString (): String {

var s = "Price of the game:" + formatter.format (gamePrice) + "n"

for (i in 0solutions.lastIndex) {3r31229. s + = "$ i)" + names[i]+ "=" + formatter.format (solutions[i]/gamePriceObr) + "n"

}

return s

}

3r31289. fun itersect (matrix: GameMatrix): String {

var s = "Price of the game:" + formatter.format (gamePrice) + "n"

for (j in 0matrix.alternativeNames.lastIndex) {

var f = false

val a = matrix.alternativeNames[j]3r31289. for (i in 0solutions.lastIndex) {3r31229. if (a.equals (names[i])) {3r312289. s + = "$ j)" + names[i]+ "=" + formatter.format (solutions[i]/gamePriceObr) + "n"

f = true

break

}

}

if (! f) {

s + = "$ j)" + a + "= 0n"

}

}

return s

}

} 3r31259. 3r31285. 3r31285. 3r31277. 3r31289. And the class that performs the solution simplex method. Since I don’t understand mathematics, I took advantage of the ready implementation of 3r31171. Apache Commons Math 3r31277. 3r31289. 3r31233. 3r31234. Solver [/b] 3r31236. 3r31237. 3r31238. 3r31289. open class Solver (gameMatrix: GameMatrix) {

3r31289. val gameMatrix: GameMatrix

3r31289. init {

this.gameMatrix = gameMatrix

}

3r31289. fun solve (): Solve {

val goalf: List

= gameMatrix.alternatives.map {a -> 1.0}

val f = LinearObjectiveFunction (goalf.toDoubleArray (), 0.0)

3r31289. val constraints = ArrayList

() 3r31289. for (alt in gameMatrix.alternatives) {

constraints.add (LinearConstraint (alt.values.toDoubleArray (), Relationship.LEQ, 1.0))

3r31289.}

3r31289. val solution = SimplexSolver (). optimize (f, LinearConstraintSet (constraints), GoalType.MAXIMIZE,

NonNegativeConstraint (true)) 3r31289. 3r31289. val sl: List

= solution.getPoint (). toList ()

val solve = Solve (solution.getValue (), sl, gameMatrix.alternativeNames)

3r31289. return solve

}

}

3r31258. 3r31259. 3r31285. 3r31285. 3r31277. 3r31289. Now we will execute the decision by an analytical method. For clarity, we take another game matrix: 3r31277. 3r31289. 3r31222. 3r31226. 3r31222. 3r31264. 3r31224. 3r31266. 3r31226. 3r31277. 3r31289. There is a dominant set in this matrix: 3r31277. 3r31289. begin {pmatrix} 2 & 4 6 & 2end {pmatrix}

3r31289. 3r31233. 3r31234. Solution [/b] 3r31236. 3r31237. 3r31238. 3r31289. val alternativeNames: List

= listOf ("Culture 1", "Culture 2", "Culture 3")

val natureStateNames: List

=

listOf ("Cool and rainy", "Normal", "Hot and dry", "Windy")

val matrix: List

s1 + "n" + s2}))

println () 3r31289. val s: Solver = Solver (dgm)

val solve = s.solve ()

println (solve) 3r31229. 3r31258. 3r31259. 3r31285. 3r31285. 3r31277. 3r31289. The game decision

3r31265. 3r31266. with the price of the game equal to ???r3r31277. 3r31289. 3r31277. 3r31289. 3r31271. Instead of conclusion

3r31277. 3r31289. I hope this article will be useful to those who need a first approximation with the decision of games with nature. Instead of conclusions link to GitHub https://github.com/altmf/game_theory 3r31277. 3r31289. I would be grateful for the constructive feedback! 3r31285. 3r31289. 3r31289. 3r31282. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d,! 1): e.attachEvent ("onload", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r31283. 3r31289. 3r31285. 3r31289. 3r31289. 3r31289. 3r31289.

It may be interesting

#### weber

Author**9-10-2018, 18:22**

Publication Date
#### Programming / Mathematics / Kotlin

Category- Comments: 0
- Views: 471

Lisa Zahner, an active investor and a recognized leader in San Francisco’s commercial real estate market, specializes in Multifamily and Investment Real Estate. Check Out: Multifamily Real Estate