<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel rdf:about="https://community.wolfram.com">
    <title>Community RSS Feed</title>
    <link>https://community.wolfram.com</link>
    <description>RSS Feed for Wolfram Community showing any discussions tagged with Operations Research sorted by most likes.</description>
    <items>
      <rdf:Seq>
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2026904" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/820972" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/478669" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1378496" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/598249" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/220551" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1703087" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1907256" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1895675" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1762584" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1065416" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/944004" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/3055705" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1358396" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/138207" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2920790" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2674963" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/941017" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2333107" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/3763738" />
      </rdf:Seq>
    </items>
  </channel>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2026904">
    <title>[WSS20]Design &amp;amp; Implementation of Data Structure of Crystalline Atomic Data</title>
    <link>https://community.wolfram.com/groups/-/m/t/2026904</link>
    <description>![frontimage][1]&#xD;
&#xD;
&amp;amp;[Wolfram Notebook][2]&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=imagefront.jpg&amp;amp;userId=1316061&#xD;
  [2]: https://www.wolframcloud.com/obj/88bd85e6-8a15-4fe1-ab85-7da71b0ce10b</description>
    <dc:creator>Claudio Chaib</dc:creator>
    <dc:date>2020-07-14T02:04:22Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/820972">
    <title>Cops and Robbers (or Zombies and Humans): pursuit-evasion games</title>
    <link>https://community.wolfram.com/groups/-/m/t/820972</link>
    <description>![Cops and Robbers (or Zombies and Humans): pursuit-evasion games][1] ![Cops and Robbers (or Zombies and Humans): pursuit-evasion games][2]&#xD;
&#xD;
Cops and Robbers is a mathematical game in which pursuers (cops) attempt to capture evaders (robbers). The game is one of many [pursuit-evasion games][3], each of which is governed by a [different][4] set of rules. The general goal of these problems is to determine the number of pursuers required to capture a given number of evaders.&#xD;
&#xD;
The GIFs above show two versions of the game. The first is similar to the standard Cops and Robbers rendition, and the second is best described as &amp;#034;Zombies and Humans&amp;#034;.&#xD;
&#xD;
In both versions, an evader moves in the direction that gets it furthest away from the pursuers (focusing more on the closer pursuers), and a pursuer moves in the direction that gets it closest to the evaders (focusing more on the closer evaders).&#xD;
&#xD;
- In the first simulation, members of both groups have a constant speed. &#xD;
- In the second simulation, members of a group move more quickly the closer they are to members of the opposite group, and slower when further away.&#xD;
&#xD;
Additional sources not linked above:&#xD;
------------------------------------&#xD;
&#xD;
- [How to make a point&amp;#039;s position time-dependent given a formula for the next step?][5]&#xD;
- [Cops and Robbers (see also attached)][6]&#xD;
&#xD;
&#xD;
----------&#xD;
[*Originally published at FOURIEST SERIES*][7] &#xD;
&#xD;
Code:&#xD;
-----&#xD;
&#xD;
&amp;amp;[Wolfram Notebook][8]&#xD;
&#xD;
&#xD;
  [1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ezgif-940093865.gif&amp;amp;userId=11733&#xD;
  [2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ezgif-1908683973.gif&amp;amp;userId=11733&#xD;
  [3]: https://en.wikipedia.org/wiki/Pursuit-evasion&#xD;
  [4]: https://en.wikipedia.org/wiki/Pursuit-evasion#Continuous_formulation&#xD;
  [5]: http://mathematica.stackexchange.com/q/40375/13&#xD;
  [6]: http://math.bard.edu/student/pdfs/tina-zhang.pdf&#xD;
  [7]: http://fouriestseries.tumblr.com/post/96488907348/cops-and-robbers-and-zombies-and-humans&#xD;
  [8]: https://www.wolframcloud.com/obj/7c3e870f-23e6-4f77-a093-eea0bc35a1ba</description>
    <dc:creator>Brian Weinstein</dc:creator>
    <dc:date>2016-03-10T20:14:42Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/478669">
    <title>Doing a KenKen in Wolfram Language</title>
    <link>https://community.wolfram.com/groups/-/m/t/478669</link>
    <description>Here&amp;#039;s today&amp;#039;s New York Times 4x4 KenKen solved in Mathematica.  The approach is to first construct all possible arrays with different numbers in each row, from that select all arrays that have different numbers in each column, then apply the constraints on various cells.  For this particular example, it was not necessary to apply all the constraints to get the unique answer.  It is necessary to take the absolute value of some difference and ratio constraints, since it the order of the difference or ratio is not known.&#xD;
&#xD;
    Dimensions[p4 = Permutations[Range[4]]]&#xD;
    &#xD;
    Out[1]= {24, 4}&#xD;
    &#xD;
    Dimensions[a1 = Flatten[Outer[List, p4, p4, p4, p4, 1], 3]] &#xD;
    &#xD;
    Out[2]= {331776, 4, 4}&#xD;
    &#xD;
    Dimensions[&#xD;
     a2 = Select[&#xD;
       a1, (And @@ (And @@ Unequal[Sequence @@ #] &amp;amp;) /@ Transpose[#]) &amp;amp;]] &#xD;
    &#xD;
    Out[3]= {576, 4, 4}&#xD;
    &#xD;
    Dimensions[a3 = Select[a2, #[[1, 1]]*#[[1, 2]]*#[[2, 2]] == 12 &amp;amp;]]&#xD;
    &#xD;
    Out[4]= {112, 4, 4}&#xD;
    &#xD;
    Dimensions[a4 = Select[a3, Abs[Log[#[[1, 3]]/#[[1, 4]]]] == Log[2] &amp;amp;]]&#xD;
    &#xD;
    Out[5]= {64, 4, 4}&#xD;
    &#xD;
    In[6]:= Dimensions[&#xD;
     a5 = Select[&#xD;
       a4, #[[2, 1]] + #[[3, 1]] + #[[3, 2]] + #[[4, 1]] == 11 &amp;amp;]]&#xD;
    &#xD;
    Out[6]= {8, 4, 4}&#xD;
    &#xD;
    In[7]:= Dimensions[a6 = Select[a5, Abs[#[[2, 3]] - #[[3, 3]]] == 2 &amp;amp;]]&#xD;
    &#xD;
    Out[7]= {6, 4, 4}&#xD;
    &#xD;
    In[8]:= Dimensions[a7 = Select[a6, #[[2, 4]] == 2 &amp;amp;]]&#xD;
    &#xD;
    Out[8]= {1, 4, 4}&#xD;
    &#xD;
    In[10]:= a7&#xD;
    &#xD;
    Out[10]= {{{1, 3, 2, 4}, {3, 4, 1, 2}, {4, 2, 3, 1}, {2, 1, 4, 3}}}</description>
    <dc:creator>Frank Kampas</dc:creator>
    <dc:date>2015-04-13T20:56:51Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1378496">
    <title>[WSS18] A Game Theory Package for the Wolfram Language</title>
    <link>https://community.wolfram.com/groups/-/m/t/1378496</link>
    <description>Theory of Games has an impressive development during the last 70 years both as a domain of applied mathematics and a part of various important domains of human activity. It&amp;#039;s somewhat strange that Mathematica doesn&amp;#039;t include any functionality related to game theory. Our project intends to initiate a game theory Mathematica package.&#xD;
&#xD;
At the first initiation stage of the project development, we consider strategic finite (multi-matrix) games and some solution concepts: Nash equilibrium, Stackelberg equilibrium, and MaxMin strategies:&#xD;
&#xD;
Game statement&#xD;
-------------------------------------&#xD;
&#xD;
A strategic game  is defined by the tuple:&#xD;
$$\Gamma = \langle N, \{X_i\}_{i\in N}, \{f_i (x)\}_{i\in N}\rangle,$$&#xD;
where $N=\{1,2,...,n\}$ is a set of players, $X_i$ is a set of strategies of player $i\in N$ and $f_i:X\rightarrow R$ is a&#xD;
player&amp;#039;s $i\in N$ payoff function defined on the Cartesian product $X = \times_{i \in N} X_i$. Elements of $X$ are called outcomes of&#xD;
the game (strategy profiles). &#xD;
&#xD;
An outcome $x^*\in X$ of is a Nash equilibrium (shortly NE) of $\Gamma$ if&#xD;
$$f_i ( x_i, x_{-i}^*) \le f_i ( x^*_i, x_{-i}^* ), \forall x_i \in X_i,\,\, \forall i \in N,$$&#xD;
where&#xD;
$$x_{-i}^* = (x^*_1, x^*_2, ..., x^*_{i-1}, x^*_{i+1}, ..., x^*_n),$$&#xD;
$$x_{-i}^* \in X_{-i}=X_1 \times X_2 \times ... \times X_{i-1} \times X_{i+1} \times ... \times X_n,$$&#xD;
$$(x_i,x_{-i}^*) = (x^*_1, x^*_2, ..., x^*_{i-1},x_i, x^*_{i+1}, ..., x^*_n)\in X.$$&#xD;
&#xD;
We study Nash equilibrium sets as an intersection of best response mapping graphs [5,1, 2], i.e. the intersection of the sets:&#xD;
$$Gr_i=\{(x_i,x_{-i})\in X: x_{-i}\in X_{-i}, x_i\in {\rm Arg}\max_{x_i\in X_i} f_i(x_i,x_{-i})\},\,\, i\in N.$$&#xD;
&#xD;
Theorem 1. The outcome $x^*\in X$ is a Nash equilibrium if and only if $x^*\in \bigcap_{i \in N}Gr_i$.&#xD;
&#xD;
Theorem 1 stands for a main method that we will use to find Nash equilibrium set. So, we are looking to finding Nash equilibrium sets as the intersection of best response mapping graphs, both in pure and mixed strategy games.&#xD;
&#xD;
Package design&#xD;
-------------------------------------&#xD;
We have designed package structure and features that have to be applied to all its functions, their titles and  options. Main functions of the package a `GameTheory[]` and `GameTheoryPlot[]`. There is an idea to recall them `GameSolve[]` and `GameSolvePlot[]`. Formal parameters of the functions are initial data of the games, as well all the concepts that specifies a concrete game theory problem:&#xD;
&#xD;
    testOptionValue[&amp;#034;Criteria&amp;#034; -&amp;gt; crit, {&amp;#034;Maximize&amp;#034;, &amp;#034;Minimize&amp;#034;}];&#xD;
&#xD;
    testOptionValue[&amp;#034;Strategy&amp;#034; -&amp;gt; type, {&amp;#034;Pure&amp;#034;, &amp;#034;Mixed&amp;#034;}];&#xD;
&#xD;
    testOptionValue[&amp;#034;Concept&amp;#034; -&amp;gt; concept, {&amp;#034;NashEquilibrium&amp;#034;, &amp;#034;MaxMin&amp;#034;, &amp;#034;StackelbergEquilibrium&amp;#034;}]&#xD;
&#xD;
We have created algorithms and corresponding codes that solve problems of Nash equilibrium set finding, as well as MaxMin solutions computing. In this context we need to mention the following functions:&#xD;
&#xD;
    pureNashEquilibria[matr_] := ...&#xD;
    &#xD;
    maxMin[matr_] :=...&#xD;
    &#xD;
    pureStackelbergEquilibria[matr_] :=...&#xD;
&#xD;
We have also programmed the code that solves two-matrix mixed strategy games.&#xD;
&#xD;
    mixedNashEquilibria[m_] := ...&#xD;
&#xD;
The package includes, withal, a function that plot Nash equilibrium set in $2\times 2$ mixed strategy games.&#xD;
&#xD;
    game2x2Plot[m_]:= ...&#xD;
&#xD;
Some private functions and their application&#xD;
-------------------------------------&#xD;
&#xD;
For the problem of Nash equilibrium set computing the main function is:&#xD;
&#xD;
    bestResponse[m_]:=With[{ind=indexSets[Dimensions[m[[1]]]]},&#xD;
    	Intersection@@Table[&#xD;
    		Flatten[&#xD;
    			Thread/@Table[&#xD;
    				Replace[i, All:&amp;gt;maxPositions@m[[player,Sequence@@i]], {1}],&#xD;
    				{i, Tuples[ind[[player]]]}&#xD;
    			],&#xD;
    			1&#xD;
    		],&#xD;
    		{player, Length[m]}&#xD;
    	]&#xD;
    ]&#xD;
    &#xD;
The notation `m` is for  payoff matrices of the players. `Length[m]` gives the number of players. `Tuples[]` gives all possible tuples formed by player strategies. `maxPositions[]` gives positions on which maximal values are obtained. The intersection of all `Length[m]` lists of players offers the set of Nash equilibria.&#xD;
&#xD;
In practice, this function is called by `GameTheory[]` as in the following examples:&#xD;
&#xD;
    In[1]:= Clear[a, b]&#xD;
    a = {{2, 2, 3}, {7, 2, 2}, {1, 1, 4}};&#xD;
    b = {{5, 6, 1}, {5, 2, 3}, {3, 5, 7}}; &#xD;
    MatrixForm /@ {a, b};&#xD;
    &#xD;
    In[2]:= GameTheory[{a, b}, Method -&amp;gt; {&amp;#034;Criteria&amp;#034; -&amp;gt; &amp;#034;Maximize&amp;#034;, &amp;#034;Concept&amp;#034; -&amp;gt; &amp;#034;NashEquilibrium&amp;#034;,  &amp;#034;Strategy&amp;#034; -&amp;gt; &amp;#034;Pure&amp;#034;}]&#xD;
    &#xD;
    Out[2]= {&amp;lt;|&amp;#034;Player 1&amp;#034; -&amp;gt; 1, &amp;#034;Player 2&amp;#034; -&amp;gt; 2|&amp;gt; -&amp;gt; {2,  6}, &amp;lt;|&amp;#034;Player 1&amp;#034; -&amp;gt; 2, &amp;#034;Player 2&amp;#034; -&amp;gt; 1|&amp;gt; -&amp;gt; {7, 5},  &amp;lt;|&amp;#034;Player 1&amp;#034; -&amp;gt; 3, &amp;#034;Player 2&amp;#034; -&amp;gt; 3|&amp;gt; -&amp;gt; {4, 7}}&#xD;
&#xD;
Another private function is:&#xD;
&#xD;
    (* ------ MaxMin strategies ------ *)&#xD;
    &#xD;
    maxMin[matr_]:=Module[{dim=Dimensions[matr[[1]]], min, ind, tuples, payoffTuples},(*matr\[LeftDoubleBracket]1\[RightDoubleBracket] has the same dimensions as all other m\[LeftDoubleBracket]2\[RightDoubleBracket],...,m\[LeftDoubleBracket]n\[RightDoubleBracket]*)&#xD;
    	Table[&#xD;
    	    min=Table[0,dim[[player]]];&#xD;
    		Do[&#xD;
    		    ind=Table[Range[dim[[j]]],{j,Length[matr]}];                (* list of strategy sets *)&#xD;
    			ind[[player]]={str};                                         (* strategy set of the player is set simply formed by one element: {str} *)&#xD;
    			tuples=Tuples[ind];                                           (* generate the tuples *)&#xD;
    			payoffTuples=Table[matr[[player,Sequence@@t]],{t,tuples}];   (* the variable player gives the matrix of the player; other indeces give the payoff value *)&#xD;
    			min[[str]]=Min[payoffTuples],                                 (* for every player *)&#xD;
    		 {str,dim[[player]]}&#xD;
    		];&#xD;
    		&amp;#034;Player &amp;#034;&amp;lt;&amp;gt;ToString[player] -&amp;gt; &amp;lt;|&amp;#034;Strategy&amp;#034;-&amp;gt;maxPositions[min],&amp;#034;Payoff&amp;#034;-&amp;gt;min[[maxPositions[min]]][[1]]|&amp;gt;,&#xD;
    	 {player,Length[matr]}&#xD;
    	]&#xD;
    ]&#xD;
&#xD;
It is used to compute MaxMin strategies. This concept is more simple in comparison with the Nash equilibrium. It needs finding for every fixed strategy of the player the worst response of the other players. After knowing all such worst responses, every player computes the best from them, that being the MaxMin strategy.&#xD;
&#xD;
The following example illustrates how the function is applied really for the same above matrices:&#xD;
&#xD;
    In[3]:= GameTheory[{a, b}, &#xD;
     Method -&amp;gt; {&amp;#034;Criteria&amp;#034; -&amp;gt; &amp;#034;Maximize&amp;#034;, &amp;#034;Concept&amp;#034; -&amp;gt; &amp;#034;MaxMin&amp;#034;, &#xD;
       &amp;#034;Strategy&amp;#034; -&amp;gt; &amp;#034;Pure&amp;#034;}]&#xD;
    &#xD;
    Out[3]= {&amp;#034;Player 1&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;Strategy&amp;#034; -&amp;gt; {1, 2}, &amp;#034;Payoff&amp;#034; -&amp;gt; 2|&amp;gt;, &#xD;
     &amp;#034;Player 2&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;Strategy&amp;#034; -&amp;gt; {1}, &amp;#034;Payoff&amp;#034; -&amp;gt; 3|&amp;gt;}&#xD;
&#xD;
Sure, the function solves the above problems for an arbitrary number of players:&#xD;
&#xD;
    ------------------------------------------------------------------ 5 player game ---------------------------------------------------------------&#xD;
    &#xD;
    In[4]:= Clear[a, b, c, d, e]&#xD;
    a = RandomInteger[{-10, 1000}, {5, 5, 5, 5, 5}];&#xD;
    b = RandomInteger[{-10, 1000}, {5, 5, 5, 5, 5}];&#xD;
    c = RandomInteger[{-10, 1000}, {5, 5, 5, 5, 5}];&#xD;
    d = RandomInteger[{-10, 1000}, {5, 5, 5, 5, 5}];&#xD;
    e = RandomInteger[{-10, 1000}, {5, 5, 5, 5, 5}];&#xD;
    MatrixForm /@ {a, b, c, d, e};&#xD;
    &#xD;
    In[5]:= GameTheory[{a, b, c, d, e}, &#xD;
     Method -&amp;gt; {&amp;#034;Criteria&amp;#034; -&amp;gt; &amp;#034;Maximize&amp;#034;, &amp;#034;Concept&amp;#034; -&amp;gt; &amp;#034;MaxMin&amp;#034;, &#xD;
       &amp;#034;Strategy&amp;#034; -&amp;gt; &amp;#034;Pure&amp;#034;}]&#xD;
    &#xD;
    Out[5]= {&amp;#034;Player 1&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;Strategy&amp;#034; -&amp;gt; {5}, &amp;#034;Payoff&amp;#034; -&amp;gt; -7|&amp;gt;, &#xD;
     &amp;#034;Player 2&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;Strategy&amp;#034; -&amp;gt; {1, 5}, &amp;#034;Payoff&amp;#034; -&amp;gt; -7|&amp;gt;, &#xD;
     &amp;#034;Player 3&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;Strategy&amp;#034; -&amp;gt; {2}, &amp;#034;Payoff&amp;#034; -&amp;gt; -7|&amp;gt;, &#xD;
     &amp;#034;Player 4&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;Strategy&amp;#034; -&amp;gt; {4}, &amp;#034;Payoff&amp;#034; -&amp;gt; -8|&amp;gt;, &#xD;
     &amp;#034;Player 5&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;Strategy&amp;#034; -&amp;gt; {3}, &amp;#034;Payoff&amp;#034; -&amp;gt; -8|&amp;gt;}&#xD;
    &#xD;
    In[6]:= GameTheory[{a, b, c, d, e}, &#xD;
     Method -&amp;gt; {&amp;#034;Criteria&amp;#034; -&amp;gt; &amp;#034;Maximize&amp;#034;, &amp;#034;Concept&amp;#034; -&amp;gt; &amp;#034;NashEquilibrium&amp;#034;, &#xD;
       &amp;#034;Strategy&amp;#034; -&amp;gt; &amp;#034;Pure&amp;#034;}]&#xD;
    &#xD;
    Out[6]= {&amp;lt;|&amp;#034;Player 1&amp;#034; -&amp;gt; 1, &amp;#034;Player 2&amp;#034; -&amp;gt; 1, &amp;#034;Player 3&amp;#034; -&amp;gt; 2, &amp;#034;Player 4&amp;#034; -&amp;gt; 2, &#xD;
       &amp;#034;Player 5&amp;#034; -&amp;gt; 4|&amp;gt; -&amp;gt; {807, 935, 772, 829, 986}, &amp;lt;|&amp;#034;Player 1&amp;#034; -&amp;gt; 3, &#xD;
       &amp;#034;Player 2&amp;#034; -&amp;gt; 1, &amp;#034;Player 3&amp;#034; -&amp;gt; 5, &amp;#034;Player 4&amp;#034; -&amp;gt; 5, &#xD;
       &amp;#034;Player 5&amp;#034; -&amp;gt; 3|&amp;gt; -&amp;gt; {824, 939, 621, 776, 874}}&#xD;
&#xD;
It is important to remark here that not all pure strategy games have Nash equilibria. But, all mixed-strategy games have Nash equilibria.&#xD;
&#xD;
Next private function solve the problem of Nash equilibrium set finding in two-matrix mixed-strategy games:&#xD;
&#xD;
    mixedNashEquilibria[m_]:=With[{a=m[[1]],b=m[[2]]},&#xD;
    &#xD;
      NESet={};&#xD;
    &#xD;
      Do[&#xD;
         \[DoubleStruckCapitalU]=Range[i+1,Dimensions[a][[1]]];&#xD;
            Do[&#xD;
                  Do[&#xD;
                      If[X[b,i,j,\[DoubleStruckCapitalI],{}]==0,Break,Continue];&#xD;
                      \[DoubleStruckCapitalV]=Range[j+1,Dimensions[a][[2]]];&#xD;
                           Do[                                            &#xD;
                                If[Y[a,i,j,\[DoubleStruckCapitalI],\[DoubleStruckCapitalJ]]!=0&amp;amp;&amp;amp;X[b,i,j,\[DoubleStruckCapitalI],\[DoubleStruckCapitalJ]]!=0,&#xD;
                                          NESet=AppendTo[NESet,{XOut[b,i,j,\[DoubleStruckCapitalI],\[DoubleStruckCapitalJ]],YOut[a,i,j,\[DoubleStruckCapitalI],\[DoubleStruckCapitalJ]]}],&#xD;
                                          Break&#xD;
                                 ],&#xD;
                            {\[DoubleStruckCapitalJ],Subsets[\[DoubleStruckCapitalV]]}&#xD;
                           ],&#xD;
                   {j,Dimensions[a][[2]]}&#xD;
                  ],&#xD;
             {\[DoubleStruckCapitalI],Subsets[\[DoubleStruckCapitalU]]}&#xD;
            ],&#xD;
       {i,Dimensions[a][[1]]}&#xD;
      ];&#xD;
      DeleteDuplicates@NESet&#xD;
    ]&#xD;
&#xD;
The intersection method used for two-matrix mixed strategy games is described in details in [2]. Next, we illustrate its working out in the above form codding:&#xD;
&#xD;
    Clear[a, b]&#xD;
    a = {{2, 2, 3}, {7, 2, 2}, {1, 1, 4}};&#xD;
    b = {{5, 6, 1}, {5, 2, 3}, {3, 5, 7}}; &#xD;
    MatrixForm /@ {a, b};&#xD;
&#xD;
![enter image description here][1]&#xD;
&#xD;
For some strategic games it is possible to present graphically the set of Nash equilibria [6].&#xD;
&#xD;
All the code is very large, so we present here only on function used to manipulate all graphics objects appearing in the final image:&#xD;
&#xD;
    game2x2Plot[m_]:=Module[{matr=m},&#xD;
    				 {{{\[DoubleStruckA]11,\[DoubleStruckA]12},{\[DoubleStruckA]21,\[DoubleStruckA]22}},{{\[DoubleStruckB]11,\[DoubleStruckB]12},{\[DoubleStruckB]21,\[DoubleStruckB]22}}}=matr;&#xD;
    			    Manipulate[&#xD;
    					Grid[{{Graphics[{Thick,&#xD;
    						Blue,g1[a11-a12-a21+a22,a12-a22],&#xD;
    						Green,g2[b11-b12-b21+b22,b21-b22],&#xD;
    						Red,PointSize[Large],nes[a11-a12-a21+a22,a12-a22,b11-b12-b21+b22,b21-b22]},&#xD;
    						PlotRange-&amp;gt;{{0,1},{0,1}},Axes-&amp;gt;True,AxesLabel-&amp;gt;{&amp;#034;\!\(\*SubscriptBox[\(x\), \(1\)]\)&amp;#034;,&amp;#034;\!\(\*SubscriptBox[\(y\), \(1\)]\)&amp;#034;},&#xD;
    						ImageSize-&amp;gt;{300,300}]},{&amp;#034; &amp;#034;},{Text@Style[&amp;#034;Reference Nash Equilibria&amp;#034;,Bold]},&#xD;
    						{Text@Style[nes[a11-a12-a21+a22,a12-a22,b11-b12-b21+b22,b21-b22][[1,1]],Bold]}},ItemSize-&amp;gt;{Automatic,{10,1,1,3}},Alignment-&amp;gt;{Center,Top}&#xD;
    					],&#xD;
    						Style[&amp;#034;Matrix A&amp;#034;,Bold],&#xD;
    						{{a11,\[DoubleStruckA]11,&amp;#034;\!\(\*SubscriptBox[\(a\), \(11\)]\)&amp;#034;},-10,10,1,Appearance-&amp;gt; &amp;#034;Labeled&amp;#034;,ImageSize-&amp;gt;Tiny},&#xD;
    						{{a12,\[DoubleStruckA]12,&amp;#034;\!\(\*SubscriptBox[\(a\), \(12\)]\)&amp;#034;},-10,10,1,Appearance-&amp;gt; &amp;#034;Labeled&amp;#034;,ImageSize-&amp;gt;Tiny},&#xD;
    						{{a21,\[DoubleStruckA]21,&amp;#034;\!\(\*SubscriptBox[\(a\), \(21\)]\)&amp;#034;},-10,10,1,Appearance-&amp;gt; &amp;#034;Labeled&amp;#034;,ImageSize-&amp;gt;Tiny},&#xD;
    						{{a22,\[DoubleStruckA]22,&amp;#034;\!\(\*SubscriptBox[\(a\), \(22\)]\)&amp;#034;},-10,10,1,Appearance-&amp;gt; &amp;#034;Labeled&amp;#034;,ImageSize-&amp;gt;Tiny},&#xD;
    						Delimiter,{{NonAntagonistic,True, &amp;#034;NonAntagonistic&amp;#034;},{True,False}},&#xD;
    						Delimiter,Style[&amp;#034;Matrix B&amp;#034;,Bold],&#xD;
    						{{b11,\[DoubleStruckB]11,&amp;#034;\!\(\*SubscriptBox[\(b\), \(11\)]\)&amp;#034;},-10,10,1,Enabled-&amp;gt;NonAntagonistic,Appearance-&amp;gt; &amp;#034;Labeled&amp;#034;,ImageSize-&amp;gt;Tiny},&#xD;
    						{{b12,\[DoubleStruckB]12,&amp;#034;\!\(\*SubscriptBox[\(b\), \(12\)]\)&amp;#034;},-10,10,1,Enabled-&amp;gt;NonAntagonistic,Appearance-&amp;gt; &amp;#034;Labeled&amp;#034;,ImageSize-&amp;gt;Tiny},&#xD;
    						{{b21,\[DoubleStruckB]21,&amp;#034;\!\(\*SubscriptBox[\(b\), \(21\)]\)&amp;#034;},-10,10,1,Enabled-&amp;gt;NonAntagonistic,Appearance-&amp;gt; &amp;#034;Labeled&amp;#034;,ImageSize-&amp;gt;Tiny},&#xD;
    						{{b22,\[DoubleStruckB]22,&amp;#034;\!\(\*SubscriptBox[\(b\), \(22\)]\)&amp;#034;},-10,10,1,Enabled-&amp;gt;NonAntagonistic,Appearance-&amp;gt; &amp;#034;Labeled&amp;#034;,ImageSize-&amp;gt;Tiny},&#xD;
    						Delimiter,&#xD;
    						Style[&amp;#034;Matrices A and B&amp;#034;,Bold],&#xD;
    					Dynamic[&#xD;
    						TableForm[&#xD;
    							{{ToString[a11]&amp;lt;&amp;gt;&amp;#034; , &amp;#034;&amp;lt;&amp;gt;ToString[If[NonAntagonistic,b11,b11=-a11]],&#xD;
    							ToString[a12]&amp;lt;&amp;gt;&amp;#034; , &amp;#034;&amp;lt;&amp;gt;ToString[If[NonAntagonistic,b12,b12=-a12]]},&#xD;
    							{ToString[a21]&amp;lt;&amp;gt;&amp;#034; , &amp;#034;&amp;lt;&amp;gt;ToString[If[NonAntagonistic,b21,b21=-a21]],&#xD;
    							ToString[a22]&amp;lt;&amp;gt;&amp;#034; , &amp;#034;&amp;lt;&amp;gt;ToString[If[NonAntagonistic,b22,b22=-a22]]}},&#xD;
    							TableHeadings-&amp;gt;{{&amp;#034;1&amp;#034;,&amp;#034;2&amp;#034;},{&amp;#034;  1&amp;#034;,&amp;#034;  2&amp;#034;}},&#xD;
    						  TableSpacing-&amp;gt;{2,2}&#xD;
    						]&#xD;
    					],&#xD;
    					SaveDefinitions-&amp;gt;True&#xD;
    				]&#xD;
    ]&#xD;
&#xD;
In practice, the function is used at it follows:&#xD;
&#xD;
        Clear[a, b]&#xD;
        a = {{5, 3}, {7, 2}};&#xD;
        b = {{3, 6}, {5, 3}}; &#xD;
        MatrixForm /@ {a, b};&#xD;
        GameTheoryPlot[{a, b}]&#xD;
&#xD;
![enter image description here][2]&#xD;
&#xD;
Conclusions&#xD;
-------------------------------------&#xD;
We have passed only a first pre-initial state of the package construction. There is a lot of things that must be done to establish a successful game theory package. We can only emphasised here some other stages. So, we intend to develop the package in several successive stages and directions:&#xD;
&#xD;
 1. At the first initiation stage we plan to enlarge the number of strategic form game theory problems solved by the package, and to include more plotting possibilities.&#xD;
 2. At the second stage we intend to develop package functionality in order to solve extensive form games, and to include their abundant plotting functionality.&#xD;
 3. At the third stage, we are considering adding support for cooperative games.&#xD;
 4. At the fourth stage, we plan to consider differential games and control.&#xD;
 5. Next stages will include multi-criteria mixtures of simultaneous and sequential games, as well as a lot of applied problems from all the human activity.&#xD;
&#xD;
Bibliography&#xD;
-----------&#xD;
 1. [Ungureanu, Valeriu, Nash equilibria set computing in finite extended games, CSJM, 2006, Vol. 14, No. 3 (42), pp. 345-365.][3]&#xD;
 2. [Ungureanu, Valeriu, &amp;#034;Pareto-Nash-Stackelberg Game and Control Theory&amp;#034;, Springer International Publishing, 2018, XXI + 343 pp.][4]&#xD;
 3. [Ungureanu, Valeriu, Nash equilibrium set function in dyadic mixed-strategy games, CSJM v .25, n .1 (73), 2017.][5]&#xD;
 4. [Nash J.F., Noncooperative game, Annals of Mathematics, 54, 1951, pp. 280-295.][6]&#xD;
 5. Sagaidac, M., and Ungureanu, V., Operational research, Chi\sinau, CEP USM, 2004, 296 p. (in Romanian)&#xD;
 6. [Ungureanu, V., Nash Equilibrium Sets in Dyadic Bimatrix Mixed-Strategy Games,][7] &#xD;
&#xD;
&#xD;
  [1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=TwoMatrixMixedStrategyGame.png&amp;amp;userId=159033&#xD;
  [2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=game2x2Image.png&amp;amp;userId=159033&#xD;
  [3]: http://www.math.md/files/csjm/v14-n3/v14-n3-%28pp345-365%29.pdf&#xD;
  [4]: https://www.springer.com/gp/book/9783319751504&#xD;
  [5]: http://www.math.md/files/csjm/v25-n1/v25-n1-%28pp3-20%29.pdf&#xD;
  [6]: https://www.jstor.org/stable/1969529?seq=1#page_scan_tab_contents&#xD;
  [7]: http://community.wolfram.com/groups/-/m/t/892544?p_p_auth=LiMRfo3d</description>
    <dc:creator>Valeriu Ungureanu</dc:creator>
    <dc:date>2018-07-11T16:36:01Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/598249">
    <title>Ellipse Packing Via Hierarchical Optimization</title>
    <link>https://community.wolfram.com/groups/-/m/t/598249</link>
    <description>Packing ellipses into a circumscribing circle is more complex than packing circles, since there is no formula for the minimum distance between two ellipses or the maximum distance from the center of the circumscribing circle to an ellipse.  This is overcome by embedding constraints using Lagrange multipliers into the problem to locate the most distant point from the origin of an ellipse and the points on pairs of ellipses closest to each other.  A result of a packing, showing the ellipses and the determined points is shown here: &#xD;
&#xD;
![enter image description here][1]&#xD;
&#xD;
  [1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=EllipsePackingUsingEmbeddedLagrangeMultipliers.jpg&amp;amp;userId=29126&#xD;
&#xD;
The complete calculation is in the attached notebook.  The optimization was carried out as a local search using MathOptimizer Professional&#xD;
&#xD;
http://www.wolfram.com/products/applications/mathoptpro&#xD;
&#xD;
as FindMinimum does not converge for the calculation.</description>
    <dc:creator>Frank Kampas</dc:creator>
    <dc:date>2015-10-26T13:32:54Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/220551">
    <title>Mosaic plots for data visualization</title>
    <link>https://community.wolfram.com/groups/-/m/t/220551</link>
    <description>I just published a blog post proclaiming the implementation of the function MosaicPlot that gives visual representation of the contingencies of categorical variables in a list of records. The blog post has examples and explanations:
[url=http://mathematicaforprediction.wordpress.com/2014/03/17/mosaic-plots-for-data-visualization/]http://mathematicaforprediction.wordpress.com/2014/03/17/mosaic-plots-for-data-visualization/[/url]

If we consider the census income data set known as the [url=http://archive.ics.uci.edu/ml/datasets/Census+Income]&amp;#034;adult data set&amp;#034;[/url] that is summarized in this table:

[img=width: 800px; height: 375px;]http://mathematicaforprediction.files.wordpress.com/2014/03/adult-census-income-data-summary.png[/img]

we visualize the co-occurence of (categorical variable) values with mosaic plots like this one:

[img=width: 500px; height: 506px;]http://mathematicaforprediction.files.wordpress.com/2014/03/adult-census-income-data-sex-education-colored-mosaic-plot.png[/img]

By comparing the sizes of the rectangles corresponding to values Bachelors, Doctorate, Masters, and Some-college on the sex vs. education mosaic plot we can see that the fraction of men that have finished college is larger than the fraction of women that have finished college.
We can further subdivide the rectangles according the co-occurrence frequencies with a third categorical variable. We are going to choose that third variable to be income, the values of which can be seen as outcomes or consequents of the values of the first two variables of the mosaic plot.

[img=width: 550px; height: 509px;]http://mathematicaforprediction.files.wordpress.com/2014/03/adult-census-income-data-sex-education-income-colored-mosaic-plot.png[/img]

From the mosaic plot &amp;#034;sex vs. education vs. income&amp;#034; we can make the following observations.1. Approximately 75% of the males with doctorate degrees or with a professional school degree earn more than $50000 per year.2. Approximately 60% of the females with a doctorate degree earn more than $50000 per year.3. Approximately 45% of the females with a professional school degree earn more than $50000.4. Across all education type females are (much) less likely to earn more than $50000 per year.</description>
    <dc:creator>Anton Antonov</dc:creator>
    <dc:date>2014-03-17T21:29:53Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1703087">
    <title>Alternating terms of two lists, as function.</title>
    <link>https://community.wolfram.com/groups/-/m/t/1703087</link>
    <description>Hello community. I have created a function and would like to know if it is worth submitting in Function Repository or if there is already something simpler that does this same job? If anyone can give any opinion on this I will be very grateful.&#xD;
&#xD;
I modestly have created a function that can interleave two lists by alternating their terms (unlike Riffle, which only fits the terms into gaps, this function does this keeping the same number of terms as it replaces them by both functions simultaneously).&#xD;
&#xD;
- It works like this:&#xD;
&#xD;
If the third term inside the function (&amp;#034;c_&amp;#034;) is {} the function does this automatically in a 1 to 1 pattern of each group:&#xD;
&#xD;
    Alternate[a_, b_] := Alternate[a, b, {}]&#xD;
    Alternate[a_, b_, c_] := &#xD;
     PadRight[a*&#xD;
        PadRight[&#xD;
         Take[Flatten@Table[If[c == {}, {1, 0}, c], Count[a, _]], &#xD;
          Min[Count[a, _], Count[b, _]]], Count[a, _], 1], &#xD;
       Max[Count[a, _], Count[b, _]]] + &#xD;
      PadRight[b*&#xD;
        PadRight[&#xD;
         Take[Flatten@Table[Abs[If[c == {}, {1, 0}, c] - 1], Count[b, _]],&#xD;
           Min[Count[a, _], Count[b, _]]], Count[b, _], 1], &#xD;
       Max[Count[a, _], Count[b, _]]]&#xD;
    &#xD;
    r = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};&#xD;
    s = {3, 5, 7, 9, 11, 13, 15, 17, 19, 21};&#xD;
    &#xD;
    Alternate[r, s]&#xD;
    Alternate[s, r]&#xD;
&#xD;
![ie1][1]&#xD;
&#xD;
The function works even with lists of different sizes, keeping the terms in excess unchanged:&#xD;
&#xD;
    p = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};&#xD;
    q = {3, 5, 7, 9, 11, 13, 15, 17};&#xD;
    &#xD;
    Alternate[p, q]&#xD;
    Alternate[q, p]&#xD;
&#xD;
![ie2][2]&#xD;
&#xD;
Or you can change the third term (&amp;#034;c&amp;#034;) in the function to any pattern (eg: {0,1,1,1}). Where &amp;#034;1&amp;#034; refers to the first term (&amp;#034;a&amp;#034;) from within the function while &amp;#034;0&amp;#034; refers to the term (&amp;#034;b&amp;#034;) from within the function:&#xD;
&#xD;
    t = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};&#xD;
    u = {3, 5, 7, 9, 11, 13, 15, 17};&#xD;
    &#xD;
    Alternate[t, u, {0, 1, 1, 1}]&#xD;
    Alternate[u, t, {0, 1, 1, 1}]&#xD;
&#xD;
![ie3][3]&#xD;
&#xD;
I would like to know if is this a good idea or there is a simpler way to do this? Is it worth sending a repository request?&#xD;
&#xD;
Thank you.&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=ie1.png&amp;amp;userId=1316061&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=ie2.png&amp;amp;userId=1316061&#xD;
  [3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=ie3.png&amp;amp;userId=1316061</description>
    <dc:creator>Claudio Chaib</dc:creator>
    <dc:date>2019-06-12T19:48:51Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1907256">
    <title>WirVsVirus 2020 hackathon participation</title>
    <link>https://community.wolfram.com/groups/-/m/t/1907256</link>
    <description># Introduction&#xD;
&#xD;
Last weekend -- 2020-03-20 ÷ 2020-03-22 -- I participated in [the (Germany-centric) hackathon WirVsVirus](https://wirvsvirushackathon.org). (I friend of mine who lives in Germany asked me to team up and sign up. Participated together with Balint Badonfai and Diego Zviovich.)&#xD;
&#xD;
[Our idea proposal](https://github.com/antononcube/SystemModeling/blob/master/Projects/Coronavirus-propagation-dynamics/org/WirVsVirus-Hackathon-work-plan.org) was accepted, [listed in the dedicated overview table (see item 806)](https://airtable.com/shrs71ccUVKyvLlUA/tbl6Br4W3IyPGk1jt/viw7AlEju6qFtXJqL?blocks=hide). The title of our hackathon project is:&#xD;
&#xD;
**“Geo-spatial-temporal Economic Model for COVID-19 Propagation and Management in Germany”**&#xD;
&#xD;
[Nearly a dozen of people enlisted to help](https://devpost.com/software/geo-raumlich-zeitliches-wirtschaftsmodell-fur-covid-19). (We communicated through Slack.)&#xD;
&#xD;
```mathematica&#xD;
WebImage[&amp;#034;https://devpost.com/software/geo-raumlich-zeitliches-\&#xD;
wirtschaftsmodell-fur-covid-19&amp;#034;]&#xD;
```&#xD;
&#xD;
![13dzfagts8105](https://raw.githubusercontent.com/antononcube/SystemModeling/master/Projects/Coronavirus-propagation-dynamics/Documents/Diagrams/WirVsVirus-2020-hackathon-participation/13dzfagts8105.png)&#xD;
&#xD;
Multiple people helped with the discussion of ideas, directions where to find data, with actual data gathering, and related documented analysis. Of course, just discussing the proposed solutions was already a great help!&#xD;
&#xD;
# What was accomplished&#xD;
&#xD;
## Work plans&#xD;
&#xD;
The following mind-map reflects pretty well what was planned and done:&#xD;
&#xD;
![15n5cjaej10q8](https://raw.githubusercontent.com/antononcube/SystemModeling/master/Projects/Coronavirus-propagation-dynamics/Documents/Diagrams/WirVsVirus-2020-hackathon-participation/15n5cjaej10q8.png)&#xD;
&#xD;
There is also a related [org-mode file with the work plan](https://github.com/antononcube/SystemModeling/blob/master/Projects/Coronavirus-propagation-dynamics/org/WirVsVirus-Hackathon-work-plan.org).&#xD;
&#xD;
## Data&#xD;
&#xD;
I obtained Germany city data with Mathematica’s build-in functions and used it to heuristically derive a traveling patterns graph, [AA1]. &#xD;
&#xD;
Here is the data:&#xD;
&#xD;
```mathematica&#xD;
dsCityRecords = &#xD;
  ResourceFunction[&amp;#034;ImportCSVToDataset&amp;#034;][&#xD;
 &amp;#034;https://raw.githubusercontent.com/antononcube/SystemModeling/master/Data/dfGermanyCityRecords.csv&amp;#034;];&#xD;
Dimensions[dsCityRecords]&#xD;
&#xD;
(*{12538, 6}*)&#xD;
```&#xD;
&#xD;
Here is Geo-histogram of that data:&#xD;
&#xD;
```mathematica&#xD;
cellRadius = Quantity[70, &amp;#034;Kilometers&amp;#034;];&#xD;
aCoordsToPopulations = AssociationThread[Values /@ Normal[dsCityRecords[All, {&amp;#034;Lat&amp;#034;, &amp;#034;Lon&amp;#034;}]], Normal[dsCityRecords[All, &amp;#034;Population&amp;#034;]]];&#xD;
GeoHistogram[aCoordsToPopulations, cellRadius, ColorFunction -&amp;gt; (Opacity[#, Blue] &amp;amp;), PlotLegends -&amp;gt; Automatic]&#xD;
```&#xD;
&#xD;
![0t08vw1kjdzbc](https://raw.githubusercontent.com/antononcube/SystemModeling/master/Projects/Coronavirus-propagation-dynamics/Documents/Diagrams/WirVsVirus-2020-hackathon-participation/0t08vw1kjdzbc.png)&#xD;
&#xD;
We considered a fair amount of other data. But because of the time limitations of the hackathon we had to use only the one above.&#xD;
&#xD;
## Single-site models&#xD;
&#xD;
During the development phase I used the model SEI2R, but since we wanted to have a “geo-spatial-temporal epidemiological economics model” I productized the implementation of SEI2HR-Econ, [AAp1].&#xD;
&#xD;
Here are the stocks, rates, and equations of SEI2HR-Econ:&#xD;
&#xD;
```mathematica&#xD;
Magnify[ModelGridTableForm[SEI2HREconModel[t]], 0.85]&#xD;
```&#xD;
&#xD;
![0tbp6de6zdez0](https://raw.githubusercontent.com/antononcube/SystemModeling/master/Projects/Coronavirus-propagation-dynamics/Documents/Diagrams/WirVsVirus-2020-hackathon-participation/0tbp6de6zdez0.png)&#xD;
&#xD;
## Multi-site SEI2R (SEI2HR-Econ) over a hexagonal grid graph&#xD;
&#xD;
I managed to follow through with a large part of [the work plan for the hackathon](https://github.com/antononcube/SystemModeling/blob/master/Projects/Coronavirus-propagation-dynamics/org/WirVsVirus-hackathon-Geo-spatial-temporal-model-mind-map.pdf) and make multi-site scaled model that “follows the money”, [[AA1](https://github.com/antononcube/SystemModeling/blob/master/Projects/Coronavirus-propagation-dynamics/Documents/WirVsVirus-hackathon-Multi-site-SEI2R-over-a-hexagonal-grid-graph.md)]. Here is a diagram that shows the travelling patterns graph and solutions at one of the nodes:&#xD;
&#xD;
![1vnygv6t7chgg](https://raw.githubusercontent.com/antononcube/SystemModeling/master/Projects/Coronavirus-propagation-dynamics/Documents/Diagrams/WirVsVirus-2020-hackathon-participation/1vnygv6t7chgg.png)&#xD;
&#xD;
Here is an interactive interface for studying and investigating the solution results:&#xD;
&#xD;
![1pgmngb4uyuzb](https://raw.githubusercontent.com/antononcube/SystemModeling/master/Projects/Coronavirus-propagation-dynamics/Documents/Diagrams/WirVsVirus-2020-hackathon-participation/1pgmngb4uyuzb.png)&#xD;
&#xD;
For more details see the notebook [[AA1](https://github.com/antononcube/SystemModeling/blob/master/Projects/Coronavirus-propagation-dynamics/Documents/WirVsVirus-hackathon-Multi-site-SEI2R-over-a-hexagonal-grid-graph.md)]. Different parameters can be set in the “Parameters” section. Especially of interest are the quarantine related parameters: start, duration, effect on contact rates and traffic patterns.&#xD;
&#xD;
I also put simulations results code and programmed visualization routines in R, [AA2]. (In order other members of team to be able to explore the results.)&#xD;
&#xD;
# References&#xD;
&#xD;
\[DP1\] [47_wirtschaftliche Auswirkung_Geo-spatial-temp-econ-modell](https://devpost.com/software/geo-raumlich-zeitliches-wirtschaftsmodell-fur-covid-19), DevPost.&#xD;
&#xD;
\[WRI1\] Wolfram Research, Inc., [Germany city data records](https://github.com/antononcube/SystemModeling/blob/master/Data/dfGermanyCityRecords.csv), (2020), [SystemModeling at GitHub](https://github.com/antononcube/SystemModeling).&#xD;
&#xD;
\[AA1\] Anton Antonov, [&amp;#034;WirVsVirus hackathon multi-site SEI2R over a hexagonal grid graph&amp;#034;](https://github.com/antononcube/SystemModeling/blob/master/Projects/Coronavirus-propagation-dynamics/Documents/WirVsVirus-hackathon-Multi-site-SEI2R-over-a-hexagonal-grid-graph.md), (2020), [SystemModeling at GitHub](https://github.com/antononcube/SystemModeling).&#xD;
&#xD;
\[AA2\] Anton Antonov, [&amp;#034;WirVsVirus-Hackathon in R&amp;#034;](https://github.com/antononcube/SystemModeling/tree/master/Projects/Coronavirus-propagation-dynamics/R/WirVsVirus-Hackathon), (2020), [SystemModeling at GitHub](https://github.com/antononcube/SystemModeling).&#xD;
&#xD;
\[AAp1\] Anton Antonov, [&amp;#034;Epidemiology models Mathematica package&amp;#034;](https://github.com/antononcube/SystemModeling/blob/master/Projects/Coronavirus-propagation-dynamics/WL/EpidemiologyModels.m), (2020), [SystemsModeling at GitHub](https://github.com/antononcube/SystemModeling).</description>
    <dc:creator>Anton Antonov</dc:creator>
    <dc:date>2020-03-24T21:59:30Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1895675">
    <title>[NB] Basic experiments workflow for simple epidemiological models</title>
    <link>https://community.wolfram.com/groups/-/m/t/1895675</link>
    <description>*MODERATOR NOTE: coronavirus resources &amp;amp; updates:* https://wolfr.am/coronavirus&#xD;
&#xD;
&#xD;
&amp;amp;[Wolfram Notebook][1]&#xD;
&#xD;
&#xD;
  [1]: https://www.wolframcloud.com/obj/75ec2a4b-b7bd-4c7f-9a14-6e543085fc0e</description>
    <dc:creator>Anton Antonov</dc:creator>
    <dc:date>2020-03-10T20:51:05Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1762584">
    <title>Investigation - power outages in the UK</title>
    <link>https://community.wolfram.com/groups/-/m/t/1762584</link>
    <description>&amp;lt;h2&amp;gt;Introduction&amp;lt;/h2&amp;gt;&#xD;
&#xD;
On Friday 9th August 2019, Britain suffered one of the worst power outages in recent years. Over 1 million people in England and Wales were cut off from power for nearly 9 hours, preventing numerous rail services from running during the rush hour. &#xD;
&#xD;
![Photograph of the distruption in King&amp;#039;s Cross station][1]&#xD;
&#xD;
Was this a statistical misfortune, or a systemic failure which caused the recent power outages?&#xD;
&#xD;
&amp;lt;h2&amp;gt;Getting the data&amp;lt;/h2&amp;gt;&#xD;
&#xD;
To obtain the information required to do analysis of the events leading up to the catastrophic power outage, we will we will use a fantastic website, [GridWatch Templar][3], which has realtime data as to the different power supplies, resources and frequencies. From the download page, I downloaded all the data from 27th May 2011 to the current time. Be patient; it will take a considerable amount of time to download the entire dataset (and as it is too large, I have not attached this csv file to this page). Also, as we will be carrying out analysis on such a large dataset, some cells will take a considerable amount of time to run. &#xD;
&#xD;
&amp;lt;h2&amp;gt;Analysis of the frequencies&amp;lt;/h2&amp;gt;&#xD;
&#xD;
First, we import the dataset:&#xD;
&#xD;
```&#xD;
In[1]: data = Import[&amp;#034;D:\\Programming\\GridWatch\\gridwatch.csv&amp;#034;];&#xD;
```&#xD;
&#xD;
The data which it contains:&#xD;
&#xD;
```&#xD;
In[2]: data[[1]]&#xD;
&#xD;
Out[2]: {&amp;#034;id&amp;#034;, &amp;#034;timestamp&amp;#034;, &amp;#034;demand&amp;#034;, &amp;#034;frequency&amp;#034;, &amp;#034;coal&amp;#034;, &amp;#034;nuclear&amp;#034;, &amp;#034;ccgt&amp;#034;, \&#xD;
&amp;#034;wind&amp;#034;, &amp;#034;pumped&amp;#034;, &amp;#034;hydro&amp;#034;, &amp;#034;biomass&amp;#034;, &amp;#034;oil&amp;#034;, &amp;#034;solar&amp;#034;, &amp;#034;ocgt&amp;#034;, \&#xD;
&amp;#034;french_ict&amp;#034;, &amp;#034;dutch_ict&amp;#034;, &amp;#034;irish_ict&amp;#034;, &amp;#034;ew_ict&amp;#034;, &amp;#034;nemo&amp;#034;, &amp;#034;other&amp;#034;, \&#xD;
&amp;#034;north_south&amp;#034;, &amp;#034;scotland_england&amp;#034;}&#xD;
```&#xD;
&#xD;
To look at the frequencies:&#xD;
&#xD;
```&#xD;
In[3]: frequencies = &#xD;
 If[#[[4]] == 0, Nothing, {DateObject[#[[2]]], #[[4]]}] &amp;amp; /@ &#xD;
  data[[2 ;;]];&#xD;
```&#xD;
&#xD;
To show the minimum value:&#xD;
&#xD;
```&#xD;
In[4]: MinimalBy[frequencies, Last]&#xD;
&#xD;
Out[4]: {{DateObject[{2019, 8, 9, 15, 55, 37}, &amp;#034;Instant&amp;#034;, &amp;#034;Gregorian&amp;#034;, 1.], &#xD;
  48.889}}&#xD;
&#xD;
In[5]: DateListPlot[frequencies, PlotRange -&amp;gt; All, AxesLabel -&amp;gt; {&amp;#034;Time&amp;#034;, &amp;#034;Hz&amp;#034;}]&#xD;
```&#xD;
&#xD;
![The date plot][4]&#xD;
&#xD;
This is not particularly enlightening; although it does show how dramatic the recent drop of frequency is. In fact, it is known that if the frequency drops below 49.5 Hz, a blackout will occur - and this is the first time it has happened (at least since 2011). &#xD;
&#xD;
Let&amp;#039;s dive deeper -  we&amp;#039;ll use a normal distribution in approximation to the distribution:&#xD;
&#xD;
```&#xD;
In[6]: distribution = NormalDistribution[Mean[Last /@ frequencies], StandardDeviation[Last /@ frequencies]]&#xD;
&#xD;
Out[6]: NormalDistribution[50.0012, 0.0584802]&#xD;
```&#xD;
&#xD;
Now plotting it gives:&#xD;
&#xD;
```&#xD;
In[7]: Show[Histogram[Last /@ newfreqs, Automatic, &amp;#034;ProbabilityDensity&amp;#034;], &#xD;
 Plot[PDF[distribution, x], {x, 49.7, 50.3}, &#xD;
  PlotStyle -&amp;gt; Thick]]&#xD;
```&#xD;
&#xD;
This returns: &#xD;
![histogram][5]&#xD;
&#xD;
Observe how quickly this tapers off. Assuming the frequencies follow that normal distribution, the probability of this occurring is:&#xD;
&#xD;
```&#xD;
In[8]: Probability[freq &amp;lt;= 49.5, freq \[Distributed] distribution]&#xD;
&#xD;
Out[8]: 5.1191*10^-18&#xD;
```&#xD;
&#xD;
So we can be very confident that this was not just a statistical mishap - there was a genuine, systemic cause for this event to occur (see the comment below for explanation of this).&#xD;
&#xD;
Now let&amp;#039;s take a closer look at what happened that day.&#xD;
&#xD;
&amp;lt;h2&amp;gt;Focusing in further&amp;lt;/h2&amp;gt;&#xD;
&#xD;
A National Grid spokesperson said: &#xD;
&#xD;
&amp;gt; The root cause of yesterdays issue was not with our system but was a rare and unusual event, the almost simultaneous loss of two large generators, one gas and one offshore wind, at 4.54pm. We are still working with the generators to understand what caused the generation to be lost.&#xD;
&#xD;
 (courtesy of the [the Guardian][2] for this report). We will verify this report below.&#xD;
&#xD;
First, we will zoom in on the interval between one day before and one day after the event occurred.&#xD;
&#xD;
```&#xD;
In[9]: timeinterval = Select[data[[2;;]], &#xD;
 DateObject[{2019, 8, 9, 15, 55, 37}, &amp;#034;Instant&amp;#034;, &amp;#034;Gregorian&amp;#034;, 1.`] - &#xD;
    Quantity[1, &amp;#034;Days&amp;#034;] &amp;lt;= DateObject[#[[2]]] &amp;lt;= &#xD;
   DateObject[{2019, 8, 9, 15, 55, 37}, &amp;#034;Instant&amp;#034;, &amp;#034;Gregorian&amp;#034;, 1.`] +&#xD;
     Quantity[1, &amp;#034;Days&amp;#034;] &amp;amp;] &#xD;
```&#xD;
&#xD;
(This specific time interval data is attached to this post). &#xD;
&#xD;
To visualise it the frequencies:&#xD;
&#xD;
```&#xD;
In[11]: timeintervalfreqs = {DateObject[#[[2]]], #[[4]]} &amp;amp; /@ timeinterval;&#xD;
&#xD;
In[12]: DateListPlot[Out[51], PlotRange -&amp;gt; All, &#xD;
 Epilog -&amp;gt; {Red, &#xD;
   Text[Style[&amp;#034;\[SixPointedStar]&amp;#034;, &#xD;
       20], #] &amp;amp; /@ {{DateObject[{2019, 8, 9, 15, 55, 37}, &amp;#034;Instant&amp;#034;, &#xD;
       &amp;#034;Gregorian&amp;#034;, 1.`], 48.889`}}}]&#xD;
```&#xD;
&#xD;
which shows:                                                                      &#xD;
![2 day interval][6]&#xD;
&#xD;
Now let&amp;#039;s look at the specific types of energy generation:                  &#xD;
&#xD;
```&#xD;
In[13]: DateListPlot[&#xD;
 Table[{DateObject[#[[2]]], #[[k]]} &amp;amp; /@ timeinterval, {k, 5, 21}], &#xD;
 PlotLegends -&amp;gt; data[[1]][[5 ;;]], PlotRange -&amp;gt; All]&#xD;
```&#xD;
&#xD;
which returns &#xD;
![nuclear, coal etc.][7]&#xD;
&#xD;
Now let&amp;#039;s reduce down to the two energy sources which were mentioned in the report: namely, gas (or CCGT, OCGT), and offshore wind.&#xD;
&#xD;
```&#xD;
In[14]: indices = {3, 7, 8, 14};&#xD;
DateListPlot[&#xD;
 Table[{DateObject[#[[2]]], #[[k]]} &amp;amp; /@ timeinterval, {k, indices}], &#xD;
 PlotLegends -&amp;gt; data[[1]][[indices]], PlotRange -&amp;gt; All, &#xD;
 Epilog -&amp;gt; {Directive[{Thick, Red, Dashed}], &#xD;
   Line[{{DateObject[{2019, 8, 9, 15, 55, 37}, &amp;#034;Instant&amp;#034;, &amp;#034;Gregorian&amp;#034;,&#xD;
        1.`], 0}, {DateObject[{2019, 8, 9, 15, 55, 37}, &amp;#034;Instant&amp;#034;, &#xD;
       &amp;#034;Gregorian&amp;#034;, 1.`], 40000}}]}]&#xD;
```&#xD;
&#xD;
![graph_6][8]&#xD;
&#xD;
This clearly shows a drop in CCGT and wind power (and also the demand) subsequent to the incident. &#xD;
&#xD;
Finding peaks for the CCGT data to find when the drop occurs:&#xD;
&#xD;
```&#xD;
In[15]: ccgtdata = {AbsoluteTime[#[[2]]], -#[[8]]} &amp;amp; /@ timeinterval;&#xD;
&#xD;
In[16]: inter = Interpolation[ccgtdata[[All, 1]]];&#xD;
&#xD;
In[17]: peaks = FindPeaks[ccgtdata[[All, 2]]];&#xD;
&#xD;
In[18]: peak = Select[{inter[#1], #2} &amp;amp; @@@ &#xD;
  peaks, #[[1]] &amp;gt;= &#xD;
   AbsoluteTime[&#xD;
    DateObject[{2019, 8, 9, 15, 55, 37}, &amp;#034;Instant&amp;#034;, &amp;#034;Gregorian&amp;#034;, &#xD;
     1.`]] &amp;amp;][[1, 1]] (*This calculates the first trough since the event took place*)&#xD;
&#xD;
Out[18]: 3774356135&#xD;
```&#xD;
&#xD;
This means that, 20 minutes after the frequency collapses, the CCGT (and the Wind power) supply decrease dramatically.&#xD;
&#xD;
&amp;lt;h2&amp;gt;Conclusion&amp;lt;/h2&amp;gt;&#xD;
&#xD;
At 3:55 PM GMT +1 (so really 4:55 PM, confirming the report - this is on account of BST) on Friday the 9th of August, for the first time since 2011 (and probably many years before), frequency reached levels below 49.5 Hz, at which point blackouts would take place, affecting nearly 1 million people and disrupting multiple rail services across England and Wales. According to the National Grid, this had almost happened 3 times before this one took place; our data can confirm this (see the graph below input 5). We can be certain that this was not a statistical oddity; in fact, around 20 minutes later, we begin to see that the CCGT and offshore wind supplies decrease, which confirms the report stating that both had cut out simultaneously. Hopefully this will never happen again. With this dataset at hand, it seems likely that these outages could be more foreseen in the future. &#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=image1.jpg&amp;amp;userId=1719931&#xD;
  [2]: https://www.theguardian.com/business/2019/aug/10/uk-energy-watchdog-demands-answers-after-major-power-cut-england-wales&#xD;
  [3]: https://gridwatch.templar.co.uk/&#xD;
  [4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=graph_1.jpg&amp;amp;userId=1719931&#xD;
  [5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=graph_2.jpg&amp;amp;userId=1719931&#xD;
  [6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=graph_4.jpg&amp;amp;userId=1719931&#xD;
  [7]: https://community.wolfram.com//c/portal/getImageAttachment?filename=graph_3.PNG&amp;amp;userId=1719931&#xD;
  [8]: https://community.wolfram.com//c/portal/getImageAttachment?filename=graph_6.PNG&amp;amp;userId=1719931</description>
    <dc:creator>Henry Jaspars</dc:creator>
    <dc:date>2019-08-13T18:25:04Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1065416">
    <title>Deep Learning with Wolfram Neural Networks?</title>
    <link>https://community.wolfram.com/groups/-/m/t/1065416</link>
    <description>Is anyone interested in and actively using Wolfram to do Deep Learning research?&#xD;
&#xD;
I am doing research in all areas of Deep Learning with my focus currently on VGG style of convolution neural networks (CNN). I will be branching out very soon to RLN, RNN, and GAN research very soon. &#xD;
&#xD;
I would like to be able to compare experiences and lessons learned using Wolfram in these areas. &#xD;
&#xD;
Thanks for any interest in discussions on Deep Learning.</description>
    <dc:creator>Bryan Minor</dc:creator>
    <dc:date>2017-04-18T17:29:38Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/944004">
    <title>ROC for classifier ensembles, bootstrapping, damaging, and interpolation</title>
    <link>https://community.wolfram.com/groups/-/m/t/944004</link>
    <description># Introduction&#xD;
&#xD;
The main goals of this post/document are:&#xD;
&#xD;
**i)** to demonstrate how to create versions and combinations of classifiers utilizing different perspectives,&#xD;
&#xD;
**ii)** to apply the Receiver Operating Characteristic (ROC) technique into evaluating the created classifiers (see \[[2](https://en.wikipedia.org/wiki/Receiver_operating_characteristic),[3](https://ccrma.stanford.edu/workshops/mir2009/references/ROCintro.pdf)\]) and &#xD;
&#xD;
**iii)** to illustrate the use of the *Mathematica* packages \[[5](https://github.com/antononcube/MathematicaForPrediction/blob/master/ROCFunctions.m),[6](https://github.com/antononcube/MathematicaForPrediction/blob/master/ClassifierEnsembles.m)\]. &#xD;
&#xD;
The concrete steps taken are the following:&#xD;
&#xD;
1. Obtain data: *Mathematica* built-in or external. Do some rudimentary analysis.&#xD;
&#xD;
2. Create an ensemble of classifiers and compare its performance to the individual classifiers in the ensemble.&#xD;
&#xD;
3. Produce classifier versions with from changed data in order to explore the effect of records outliers.&#xD;
&#xD;
4. Make a bootstrapping classifier ensemble and evaluate and compare its performance.&#xD;
&#xD;
5. Systematically diminish the training data and evaluate the results with ROC.&#xD;
&#xD;
6. Show how to do classifier interpolation utilizing ROC.&#xD;
&#xD;
In the steps above we skip the necessary preliminary data analysis. For the datasets we use in this document that analysis has been done elsewhere. (See [,,,].) Nevertheless, since ROC is mostly used for binary classifiers we want to analyze the class labels distributions in the datasets in order to designate which class labels are &amp;#034;positive&amp;#034; and which are &amp;#034;negative.&amp;#034;&#xD;
&#xD;
## ROC plots evaluation (in brief)&#xD;
&#xD;
Assume we are given a binary classifier with the class labels ***P*** and ***N*** (for &amp;#034;positive&amp;#034; and &amp;#034;negative&amp;#034; respectively). &#xD;
&#xD;
Consider the following measures True Positive Rate (TPR):&#xD;
&#xD;
$$ TPR:= \frac {correctly \:  classified \:  positives}{total \:  positives}. $$ &#xD;
&#xD;
and False Positive Rate (FPR):&#xD;
&#xD;
$$ FPR:= \frac {incorrectly \:  classified \:  negatives}{total \:  negatives}. $$&#xD;
&#xD;
Assume that we can change the classifier results with a parameter $\theta$ and produce a plot like this one:&#xD;
&#xD;
[![AdultDatasetEnsembleClassifier][14]][14]&#xD;
&#xD;
For each parameter value $\theta _{i}$ the point ${TPR(\theta _{i}), FPR(\theta _{i})}$ is plotted; points corresponding to consecutive $\theta _{i}$&amp;#039;s &#xD;
are connected with a line. We call the obtained curve *the ROC curve* for the classifier in consideration.&#xD;
The ROC curve resides in *the ROC space* as defined by the functions FPR and TPR corresponding respectively to the $x$-axis and the $y$-axis.&#xD;
&#xD;
The ideal classifier would have its ROC curve comprised of a line connecting \{0,0\} to \{0,1\} and a line connecting \{0,1\} to \{1,1\}.&#xD;
&#xD;
Given a classifier the ROC point closest to \{0,1\}, generally, would be considered to be the best point.&#xD;
&#xD;
# Used packages &#xD;
&#xD;
These commands load the used *Mathematica* packages \[[4](https://github.com/antononcube/MathematicaForPrediction/blob/master/MathematicaForPredictionUtilities.m),[5](https://github.com/antononcube/MathematicaForPrediction/blob/master/ROCFunctions.m),6\]: &#xD;
&#xD;
    Import[&amp;#034;https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/MathematicaForPredictionUtilities.m&amp;#034;]&#xD;
    Import[&amp;#034;https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/ROCFunctions.m&amp;#034;]&#xD;
    Import[&amp;#034;https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/ClassifierEnsembles.m&amp;#034;]&#xD;
&#xD;
# Data used&#xD;
&#xD;
## The Titanic dataset&#xD;
&#xD;
These commands load the Titanic data (that is shipped with *Mathematica*).&#xD;
&#xD;
    data = ExampleData[{&amp;#034;MachineLearning&amp;#034;, &amp;#034;Titanic&amp;#034;}, &amp;#034;TrainingData&amp;#034;];&#xD;
    columnNames = (Flatten@*List) @@ ExampleData[{&amp;#034;MachineLearning&amp;#034;, &amp;#034;Titanic&amp;#034;}, &amp;#034;VariableDescriptions&amp;#034;];&#xD;
    data = ((Flatten@*List) @@@ data)[[All, {1, 2, 3, -1}]];&#xD;
    trainingData = DeleteCases[data, {___, _Missing, ___}];&#xD;
    Dimensions[trainingData]&#xD;
&#xD;
    (* {732, 4} *)&#xD;
&#xD;
    RecordsSummary[trainingData, columnNames]&#xD;
&#xD;
[![Records1][1]][1]&#xD;
&#xD;
    data = ExampleData[{&amp;#034;MachineLearning&amp;#034;, &amp;#034;Titanic&amp;#034;}, &amp;#034;TestData&amp;#034;];&#xD;
    data = ((Flatten@*List) @@@ data)[[All, {1, 2, 3, -1}]];&#xD;
    testData = DeleteCases[data, {___, _Missing, ___}];&#xD;
    Dimensions[testData]&#xD;
&#xD;
    (* {314, 4} *)&#xD;
&#xD;
    RecordsSummary[testData, columnNames]&#xD;
&#xD;
[![Records2][2]][2]&#xD;
&#xD;
    nTrainingData = trainingData /. {&amp;#034;survived&amp;#034; -&amp;gt; 1, &amp;#034;died&amp;#034; -&amp;gt; 0, &amp;#034;1st&amp;#034; -&amp;gt; 0, &amp;#034;2nd&amp;#034; -&amp;gt; 1, &amp;#034;3rd&amp;#034; -&amp;gt; 2, &amp;#034;male&amp;#034; -&amp;gt; 0, &amp;#034;female&amp;#034; -&amp;gt; 1};&#xD;
&#xD;
# Classifier ensembles&#xD;
&#xD;
This command makes a classifier ensemble of two built-in classifiers &amp;#034;NearestNeighbors&amp;#034; and &amp;#034;NeuralNetwork&amp;#034;:&#xD;
&#xD;
    aCLs = EnsembleClassifier[{&amp;#034;NearestNeighbors&amp;#034;, &amp;#034;NeuralNetwork&amp;#034;}, trainingData[[All, 1 ;; -2]] -&amp;gt; trainingData[[All, -1]]]&#xD;
&#xD;
[![Classifier][3]][3]&#xD;
&#xD;
A classifier ensemble of the package \[[6](https://github.com/antononcube/MathematicaForPrediction/blob/master/ClassifierEnsembles.m)\] is simply an association mapping classifier IDs to classifier functions.&#xD;
&#xD;
The first argument given to `EnsembleClassifier` can be `Automatic`:&#xD;
&#xD;
    SeedRandom[8989]&#xD;
    aCLs = EnsembleClassifier[Automatic, trainingData[[All, 1 ;; -2]] -&amp;gt; trainingData[[All, -1]]];&#xD;
&#xD;
With `Automatic` the following built-in classifiers are used:&#xD;
&#xD;
    Keys[aCLs]&#xD;
&#xD;
    (* {&amp;#034;NearestNeighbors&amp;#034;, &amp;#034;NeuralNetwork&amp;#034;, &amp;#034;LogisticRegression&amp;#034;, &amp;#034;RandomForest&amp;#034;, &amp;#034;SupportVectorMachine&amp;#034;, &amp;#034;NaiveBayes&amp;#034;} *)&#xD;
&#xD;
## Classification with ensemble votes&#xD;
&#xD;
Classification with the classifier ensemble can be done using the function `EnsembleClassify`. If the third argument of `EnsembleClassify` is &amp;#034;Votes&amp;#034; the result is the class label that appears the most in the ensemble results.&#xD;
&#xD;
    EnsembleClassify[aCLs, testData[[20, 1 ;; -2]], &amp;#034;Votes&amp;#034;]&#xD;
&#xD;
    (* &amp;#034;died&amp;#034; *)&#xD;
&#xD;
The following commands clarify the voting done in the command above.&#xD;
&#xD;
    Map[#[testData[[20, 1 ;; -2]]] &amp;amp;, aCLs]&#xD;
    Tally[Values[%]]&#xD;
&#xD;
    (* &amp;lt;|&amp;#034;NearestNeighbors&amp;#034; -&amp;gt; &amp;#034;died&amp;#034;, &amp;#034;NeuralNetwork&amp;#034; -&amp;gt; &amp;#034;survived&amp;#034;, &amp;#034;LogisticRegression&amp;#034; -&amp;gt; &amp;#034;survived&amp;#034;, &amp;#034;RandomForest&amp;#034; -&amp;gt; &amp;#034;died&amp;#034;, &amp;#034;SupportVectorMachine&amp;#034; -&amp;gt; &amp;#034;died&amp;#034;, &amp;#034;NaiveBayes&amp;#034; -&amp;gt; &amp;#034;died&amp;#034;|&amp;gt; *)&#xD;
&#xD;
    (* {{&amp;#034;died&amp;#034;, 4}, {&amp;#034;survived&amp;#034;, 2}} *)&#xD;
&#xD;
## Classification with ensemble averaged probabilities&#xD;
&#xD;
If the third argument of `EnsembleClassify` is &amp;#034;`ProbabilitiesMean`&amp;#034; the result is the class label that has the highest mean probability in the ensemble results.&#xD;
&#xD;
    EnsembleClassify[aCLs, testData[[20, 1 ;; -2]], &amp;#034;ProbabilitiesMean&amp;#034;]&#xD;
&#xD;
    (* &amp;#034;died&amp;#034; *)&#xD;
&#xD;
The following commands clarify the probability averaging utilized in the command above.&#xD;
&#xD;
    Map[#[testData[[20, 1 ;; -2]], &amp;#034;Probabilities&amp;#034;] &amp;amp;, aCLs]&#xD;
    Mean[Values[%]]&#xD;
&#xD;
    (* &amp;lt;|&amp;#034;NearestNeighbors&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;died&amp;#034; -&amp;gt; 0.598464, &amp;#034;survived&amp;#034; -&amp;gt; 0.401536|&amp;gt;, &amp;#034;NeuralNetwork&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;died&amp;#034; -&amp;gt; 0.469274, &amp;#034;survived&amp;#034; -&amp;gt; 0.530726|&amp;gt;, &amp;#034;LogisticRegression&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;died&amp;#034; -&amp;gt; 0.445915, &amp;#034;survived&amp;#034; -&amp;gt; 0.554085|&amp;gt;, &#xD;
    &amp;#034;RandomForest&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;died&amp;#034; -&amp;gt; 0.652414, &amp;#034;survived&amp;#034; -&amp;gt; 0.347586|&amp;gt;, &amp;#034;SupportVectorMachine&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;died&amp;#034; -&amp;gt; 0.929831, &amp;#034;survived&amp;#034; -&amp;gt; 0.0701691|&amp;gt;, &amp;#034;NaiveBayes&amp;#034; -&amp;gt; &amp;lt;|&amp;#034;died&amp;#034; -&amp;gt; 0.622061, &amp;#034;survived&amp;#034; -&amp;gt; 0.377939|&amp;gt;|&amp;gt; *)&#xD;
&#xD;
    (* &amp;lt;|&amp;#034;died&amp;#034; -&amp;gt; 0.61966, &amp;#034;survived&amp;#034; -&amp;gt; 0.38034|&amp;gt; *)&#xD;
&#xD;
## ROC for ensemble votes&#xD;
&#xD;
The third argument of `EnsembleClassifyByThreshold` takes a rule of the form *label-&amp;gt;threshold*; the fourth argument is eighter &amp;#034;Votes&amp;#034; or &amp;#034;ProbabiltiesMean&amp;#034;.&#xD;
&#xD;
The following code computes the ROC curve for a range of votes.&#xD;
&#xD;
    rocRange = Range[0, Length[aCLs] - 1, 1];&#xD;
    aROCs = Table[(&#xD;
        cres = EnsembleClassifyByThreshold[aCLs, testData[[All, 1 ;; -2]], &amp;#034;survived&amp;#034; -&amp;gt; i, &amp;#034;Votes&amp;#034;]; ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cres]), {i, rocRange}];&#xD;
    ROCPlot[rocRange, aROCs, &amp;#034;PlotJoined&amp;#034; -&amp;gt; Automatic, GridLines -&amp;gt; Automatic]&#xD;
&#xD;
[![Ensemble1][4]][4]&#xD;
&#xD;
## ROC for ensemble probabilities mean&#xD;
&#xD;
If we want to compute ROC of a range of probability thresholds we `EnsembleClassifyByThreshold` with the fourth argument being &amp;#034;ProbabilitiesMean&amp;#034;.&#xD;
&#xD;
    EnsembleClassifyByThreshold[aCLs, testData[[1 ;; 6, 1 ;; -2]], &amp;#034;survived&amp;#034; -&amp;gt; 0.2, &amp;#034;ProbabilitiesMean&amp;#034;]&#xD;
&#xD;
    (* {&amp;#034;survived&amp;#034;, &amp;#034;survived&amp;#034;, &amp;#034;survived&amp;#034;, &amp;#034;survived&amp;#034;, &amp;#034;survived&amp;#034;, &amp;#034;survived&amp;#034;} *)&#xD;
&#xD;
    EnsembleClassifyByThreshold[aCLs, testData[[1 ;; 6, 1 ;; -2]], &amp;#034;survived&amp;#034; -&amp;gt; 0.6, &amp;#034;ProbabilitiesMean&amp;#034;]&#xD;
&#xD;
    (* {&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;, &amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;, &amp;#034;died&amp;#034;, &amp;#034;survived&amp;#034;} *)&#xD;
&#xD;
The implementation of `EnsembleClassifyByThreshold` with &amp;#034;ProbabilitiesMean&amp;#034; relies on the `ClassifierFunction` signature:&#xD;
&#xD;
`ClassifierFunction[__][record_, &amp;#034;Probabilities&amp;#034;]`&#xD;
&#xD;
Here is the corresponding ROC plot:&#xD;
&#xD;
    rocRange = Range[0, 1, 0.025];&#xD;
    aROCs = Table[(&#xD;
        cres = EnsembleClassifyByThreshold[aCLs, testData[[All, 1 ;; -2]], &amp;#034;survived&amp;#034; -&amp;gt; i, &amp;#034;ProbabilitiesMean&amp;#034;]; ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cres]), {i, rocRange}];&#xD;
    rocEnGr = ROCPlot[rocRange, aROCs, &amp;#034;PlotJoined&amp;#034; -&amp;gt; Automatic, PlotLabel -&amp;gt; &amp;#034;Classifier ensemble&amp;#034;, GridLines -&amp;gt; Automatic]&#xD;
&#xD;
[![Ensemble2][5]][5]&#xD;
&#xD;
## Comparison of the ensemble classifier with the standard classifiers&#xD;
&#xD;
This plot compares the ROC curve of the ensemble classifier with the ROC curves of the classifiers that comprise the ensemble.&#xD;
&#xD;
    rocGRs = Table[&#xD;
       aROCs1 = Table[(&#xD;
          cres = ClassifyByThreshold[aCLs[[i]], testData[[All, 1 ;; -2]], &amp;#034;survived&amp;#034; -&amp;gt; th];&#xD;
          ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cres]), {th, rocRange}]; &#xD;
       ROCPlot[rocRange, aROCs1, PlotLabel -&amp;gt; Keys[aCLs][[i]], PlotRange -&amp;gt; {{0, 1.05}, {0.6, 1.01}}, &amp;#034;PlotJoined&amp;#034; -&amp;gt; Automatic, GridLines -&amp;gt; Automatic],&#xD;
       {i, 1, Length[aCLs]}];&#xD;
&#xD;
    GraphicsGrid[ArrayReshape[Append[Prepend[rocGRs, rocEnGr], rocEnGr], {2, 4}, &amp;#034;&amp;#034;], Dividers -&amp;gt; All, FrameStyle -&amp;gt; GrayLevel[0.8], ImageSize -&amp;gt; 1200]&#xD;
&#xD;
[![Ensemble3][6]][6]&#xD;
&#xD;
Let us plot all ROC curves from the graphics grid above into one plot. For that the single classifier ROC curves are made gray, and their threshold callouts removed. We can see that the classifier ensemble brings very good results for $\theta = 0.175$ and none of the single classifiers has a better point.&#xD;
&#xD;
    Show[Append[rocGRs /. {RGBColor[___] -&amp;gt; GrayLevel[0.8]} /. {Text[p_, ___] :&amp;gt; Null} /. ((PlotLabel -&amp;gt; _) :&amp;gt; (PlotLabel -&amp;gt; Null)), rocEnGr]]&#xD;
&#xD;
[![EnsembleFull][7]][7]&#xD;
&#xD;
# Classifier ensembles by bootstrapping&#xD;
&#xD;
There are several ways to produce ensemble classifiers using [bootstrapping](https://en.wikipedia.org/wiki/Bootstrapping_(statistics)) or [jackknife](https://en.wikipedia.org/wiki/Jackknife_resampling) resampling procedures.&#xD;
&#xD;
First, we are going to make a bootstrapping classifier ensemble using one of the `Classify` methods. Then we are going to make a more complicated bootstrapping classifier with six methods of `Classify`.&#xD;
&#xD;
## Bootstrapping ensemble with a single classification method&#xD;
&#xD;
First we select a classification method and make a classifier with it.&#xD;
&#xD;
    clMethod = &amp;#034;NearestNeighbors&amp;#034;;&#xD;
    sCL = Classify[trainingData[[All, 1 ;; -2]] -&amp;gt; trainingData[[All, -1]], Method -&amp;gt; clMethod];&#xD;
&#xD;
The following code makes a classifier ensemble of 12 classifier functions using resampled, slightly smaller (10%) versions of the original training data (with `RandomChoice`).&#xD;
&#xD;
    SeedRandom[1262];&#xD;
    aBootStrapCLs = Association@Table[(&#xD;
         inds = RandomChoice[Range[Length[trainingData]], Floor[0.9*Length[trainingData]]];&#xD;
         ToString[i] -&amp;gt; Classify[trainingData[[inds, 1 ;; -2]] -&amp;gt; trainingData[[inds, -1]], Method -&amp;gt; clMethod]), {i, 12}];&#xD;
&#xD;
Let us compare the ROC curves of the single classifier with the bootstrapping derived ensemble.&#xD;
&#xD;
    rocRange = Range[0.1, 0.9, 0.025];&#xD;
    AbsoluteTiming[&#xD;
     aSingleROCs = Table[(&#xD;
        cres = ClassifyByThreshold[sCL, testData[[All, 1 ;; -2]], &amp;#034;survived&amp;#034; -&amp;gt; i]; ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cres]), {i, rocRange}];&#xD;
     aBootStrapROCs = Table[(&#xD;
        cres = EnsembleClassifyByThreshold[aBootStrapCLs, testData[[All, 1 ;; -2]], &amp;#034;survived&amp;#034; -&amp;gt; i]; ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cres]), {i, rocRange}];&#xD;
    ]&#xD;
&#xD;
    (* {6.81521, Null} *)&#xD;
&#xD;
    Legended[&#xD;
     Show[{&#xD;
       ROCPlot[rocRange, aSingleROCs, &amp;#034;ROCColor&amp;#034; -&amp;gt; Blue, &amp;#034;PlotJoined&amp;#034; -&amp;gt; Automatic, GridLines -&amp;gt; Automatic],&#xD;
       ROCPlot[rocRange, aBootStrapROCs, &amp;#034;ROCColor&amp;#034; -&amp;gt; Red, &amp;#034;PlotJoined&amp;#034; -&amp;gt; Automatic]}],&#xD;
     SwatchLegend @@ Transpose@{{Blue, Row[{&amp;#034;Single &amp;#034;, clMethod, &amp;#034; classifier&amp;#034;}]}, {Red, Row[{&amp;#034;Boostrapping ensemble of\n&amp;#034;, Length[aBootStrapCLs], &amp;#034; &amp;#034;, clMethod, &amp;#034; classifiers&amp;#034;}]}}]&#xD;
&#xD;
[![Bootsrap1][8]][8]&#xD;
&#xD;
We can see that we get much better results with the bootstrapped ensemble.&#xD;
&#xD;
## Bootstrapping ensemble with multiple classifier methods&#xD;
&#xD;
This code creates an classifier ensemble using the classifier methods corresponding to `Automatic` given as a first argument to `EnsembleClassifier`.&#xD;
&#xD;
    SeedRandom[2324]&#xD;
    AbsoluteTiming[&#xD;
     aBootStrapLargeCLs = Association@Table[(&#xD;
          inds = RandomChoice[Range[Length[trainingData]], Floor[0.9*Length[trainingData]]];&#xD;
          ecls = EnsembleClassifier[Automatic, trainingData[[inds, 1 ;; -2]] -&amp;gt; trainingData[[inds, -1]]];&#xD;
          AssociationThread[Map[# &amp;lt;&amp;gt; &amp;#034;-&amp;#034; &amp;lt;&amp;gt; ToString[i] &amp;amp;, Keys[ecls]] -&amp;gt; Values[ecls]]&#xD;
         ), {i, 12}];&#xD;
    ]&#xD;
&#xD;
    (* {27.7975, Null} *)&#xD;
&#xD;
This code computes the ROC statistics with the obtained bootstrapping classifier ensemble:&#xD;
&#xD;
    AbsoluteTiming[&#xD;
     aBootStrapLargeROCs = Table[(&#xD;
         cres = EnsembleClassifyByThreshold[aBootStrapLargeCLs, testData[[All, 1 ;; -2]], &amp;#034;survived&amp;#034; -&amp;gt; i]; ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cres]), {i, rocRange}];&#xD;
    ]&#xD;
&#xD;
    (* {45.1995, Null} *)&#xD;
&#xD;
Let us plot the ROC curve of the bootstrapping classifier ensemble (in blue) and the single classifier ROC curves (in gray):&#xD;
&#xD;
    aBootStrapLargeGr = ROCPlot[rocRange, aBootStrapLargeROCs, &amp;#034;PlotJoined&amp;#034; -&amp;gt; Automatic];&#xD;
    Show[Append[rocGRs /. {RGBColor[___] -&amp;gt; GrayLevel[0.8]} /. {Text[p_, ___] :&amp;gt; Null} /. ((PlotLabel -&amp;gt; _) :&amp;gt; (PlotLabel -&amp;gt; Null)), aBootStrapLargeGr]]&#xD;
&#xD;
[![BootsrapFull][9]][9]&#xD;
&#xD;
Again we can see that the bootstrapping ensemble produced better ROC points than the single classifiers.&#xD;
&#xD;
# Damaging data&#xD;
&#xD;
This section tries to explain why the bootstrapping with resampling to smaller sizes produces good results.&#xD;
&#xD;
In short, the training data has outliers; if we remove small fraction of the training data we might get better results.&#xD;
&#xD;
The procedure described in this section can be used in conjunction with the procedures described in the guide for importance of variables investigation \[[7](https://github.com/antononcube/MathematicaForPrediction/blob/master/MarkdownDocuments/Importance-of-variables-investigation-guide.md)\].&#xD;
&#xD;
## Ordering function&#xD;
&#xD;
Let us replace the categorical values with numerical in the training data. There are several ways to do it, here is a fairly straightforward one:&#xD;
&#xD;
    nTrainingData = trainingData /. {&amp;#034;survived&amp;#034; -&amp;gt; 1, &amp;#034;died&amp;#034; -&amp;gt; 0, &amp;#034;1st&amp;#034; -&amp;gt; 0, &amp;#034;2nd&amp;#034; -&amp;gt; 1, &amp;#034;3rd&amp;#034; -&amp;gt; 2, &amp;#034;male&amp;#034; -&amp;gt; 0, &amp;#034;female&amp;#034; -&amp;gt; 1};&#xD;
&#xD;
## Decreasing proportions of females&#xD;
&#xD;
First, let us find all indices corresponding to records about females.&#xD;
&#xD;
    femaleInds = Flatten@Position[trainingData[[All, 3]], &amp;#034;female&amp;#034;];&#xD;
&#xD;
The following code standardizes the training data corresponding to females, finds the mean record, computes distances from the mean record, and finally orders the female records indices according to their distances from the mean record.&#xD;
&#xD;
    t = Transpose@Map[Rescale@*Standardize, N@Transpose@nTrainingData[[femaleInds, 1 ;; 2]]];&#xD;
    m = Mean[t];&#xD;
    ds = Map[EuclideanDistance[#, m] &amp;amp;, t];&#xD;
    femaleInds = femaleInds[[Reverse@Ordering[ds]]];&#xD;
&#xD;
The following plot shows the distances calculated above.&#xD;
&#xD;
    ListPlot[Sort@ds, PlotRange -&amp;gt; All, PlotTheme -&amp;gt; &amp;#034;Detailed&amp;#034;]&#xD;
&#xD;
[![FemaleRecord][10]][10]&#xD;
&#xD;
The following code removes from the training data the records corresponding to females according to the order computed above. The female records farthest from the mean female record are removed first.&#xD;
&#xD;
    AbsoluteTiming[&#xD;
     femaleFrRes = Association@&#xD;
        Table[cl -&amp;gt;&#xD;
          Table[(&#xD;
            inds = Complement[Range[Length[trainingData]], Take[femaleInds, Ceiling[fr*Length[femaleInds]]]];&#xD;
            cf = Classify[trainingData[[inds, 1 ;; -2]] -&amp;gt; trainingData[[inds, -1]], Method -&amp;gt; cl]; cfPredictedLabels = cf /@ testData[[All, 1 ;; -2]];&#xD;
            {fr, ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cfPredictedLabels]}),&#xD;
           {fr, 0, 0.8, 0.05}],&#xD;
         {cl, {&amp;#034;NearestNeighbors&amp;#034;, &amp;#034;NeuralNetwork&amp;#034;, &amp;#034;LogisticRegression&amp;#034;, &amp;#034;RandomForest&amp;#034;, &amp;#034;SupportVectorMachine&amp;#034;, &amp;#034;NaiveBayes&amp;#034;}}];&#xD;
    ]&#xD;
&#xD;
    (* {203.001, Null} *)&#xD;
&#xD;
The following graphics grid shows how the classification results are affected by the removing fractions of the female records from the training data. The results for none or small fractions of records removed are more blue. &#xD;
&#xD;
    GraphicsGrid[ArrayReshape[&#xD;
      Table[&#xD;
       femaleAROCs = femaleFrRes[cl][[All, 2]];&#xD;
       frRange = femaleFrRes[cl][[All, 1]]; ROCPlot[frRange, femaleAROCs, PlotRange -&amp;gt; {{0.0, 0.25}, {0.2, 0.8}}, PlotLabel -&amp;gt; cl, &amp;#034;ROCPointColorFunction&amp;#034; -&amp;gt; (Blend[{Blue, Red}, #3/Length[frRange]] &amp;amp;), ImageSize -&amp;gt; 300],&#xD;
       {cl, Keys[femaleFrRes]}],&#xD;
      {2, 3}], Dividers -&amp;gt; All]&#xD;
&#xD;
[![FemaleGrid][11]][11]&#xD;
&#xD;
We can see that removing the female records outliers has dramatic effect on the results by the classifiers &amp;#034;NearestNeighbors&amp;#034; and &amp;#034;NeuralNetwork&amp;#034;. Not so much on &amp;#034;LogisticRegression&amp;#034; and &amp;#034;NaiveBayes&amp;#034;.&#xD;
&#xD;
## Decreasing proportions of males&#xD;
&#xD;
The code in this sub-section repeats the experiment described in the previous one males (instead of females).&#xD;
&#xD;
    maleInds = Flatten@Position[trainingData[[All, 3]], &amp;#034;male&amp;#034;];&#xD;
&#xD;
    t = Transpose@Map[Rescale@*Standardize, N@Transpose@nTrainingData[[maleInds, 1 ;; 2]]];&#xD;
    m = Mean[t];&#xD;
    ds = Map[EuclideanDistance[#, m] &amp;amp;, t];&#xD;
    maleInds = maleInds[[Reverse@Ordering[ds]]];&#xD;
&#xD;
    ListPlot[Sort@ds, PlotRange -&amp;gt; All, PlotTheme -&amp;gt; &amp;#034;Detailed&amp;#034;]&#xD;
&#xD;
[![MaleRecord][12]][12]&#xD;
&#xD;
    AbsoluteTiming[&#xD;
     maleFrRes = Association@&#xD;
        Table[cl -&amp;gt;&#xD;
          Table[(&#xD;
            inds = Complement[Range[Length[trainingData]], Take[maleInds, Ceiling[fr*Length[maleInds]]]];&#xD;
            cf = Classify[trainingData[[inds, 1 ;; -2]] -&amp;gt; trainingData[[inds, -1]], Method -&amp;gt; cl]; cfPredictedLabels = cf /@ testData[[All, 1 ;; -2]];&#xD;
            {fr, ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cfPredictedLabels]}),&#xD;
           {fr, 0, 0.8, 0.05}],&#xD;
         {cl, {&amp;#034;NearestNeighbors&amp;#034;, &amp;#034;NeuralNetwork&amp;#034;, &amp;#034;LogisticRegression&amp;#034;, &amp;#034;RandomForest&amp;#034;, &amp;#034;SupportVectorMachine&amp;#034;, &amp;#034;NaiveBayes&amp;#034;}}];&#xD;
    ]&#xD;
&#xD;
    (* {179.219, Null} *)&#xD;
&#xD;
    GraphicsGrid[ArrayReshape[&#xD;
      Table[&#xD;
       maleAROCs = maleFrRes[cl][[All, 2]];&#xD;
       frRange = maleFrRes[cl][[All, 1]]; ROCPlot[frRange, maleAROCs, PlotRange -&amp;gt; {{0.0, 0.35}, {0.55, 0.82}}, PlotLabel -&amp;gt; cl, &amp;#034;ROCPointColorFunction&amp;#034; -&amp;gt; (Blend[{Blue, Red}, #3/Length[frRange]] &amp;amp;), ImageSize -&amp;gt; 300],&#xD;
       {cl, Keys[maleFrRes]}],&#xD;
      {2, 3}], Dividers -&amp;gt; All]&#xD;
&#xD;
[![MaleGrid][13]][13]&#xD;
&#xD;
&#xD;
# Classifier interpolation&#xD;
&#xD;
Assume that we want a classifier that for a given representative set of $n$ items (records) assigns the positive label to an exactly $n_p$ of them. (Or very close to that number.)&#xD;
&#xD;
If we have two classifiers, one returning more positive items than $n_p$, the other less than $n_p$, then we can use geometric computations in &#xD;
the ROC space in order to obtain parameters for a classifier interpolation that will bring positive items close to $n_p$; see \[3\]. &#xD;
Below is given *Mathematica* code with explanations of how that classifier interpolation is done.&#xD;
&#xD;
Assume that by prior observations we know that for a given dataset of $n$ items the positive class consists of $\approx 0.09 n$ items. &#xD;
Assume that for a given unknown dataset of $n$ items we want $0.2 n$ of the items to be classified as positive. We can write the equation:&#xD;
&#xD;
$$ {FPR} * ((1-0.09) * n) + {TPR} * (0.09 * n) = 0.2 * n ,$$&#xD;
&#xD;
which can be simplified to&#xD;
&#xD;
$$ {FPR} * (1-0.09) + {TPR} * 0.09 = 0.2 .$$&#xD;
&#xD;
## The two classifiers&#xD;
&#xD;
Consider the following two classifiers.&#xD;
&#xD;
    cf1 = Classify[trainingData[[All, 1 ;; -2]] -&amp;gt; trainingData[[All, -1]], Method -&amp;gt; &amp;#034;RandomForest&amp;#034;];&#xD;
    cfROC1 = ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cf1[testData[[All, 1 ;; -2]]]]&#xD;
    (* &amp;lt;|&amp;#034;TruePositive&amp;#034; -&amp;gt; 82, &amp;#034;FalsePositive&amp;#034; -&amp;gt; 22, &amp;#034;TrueNegative&amp;#034; -&amp;gt; 170, &amp;#034;FalseNegative&amp;#034; -&amp;gt; 40|&amp;gt; *)&#xD;
&#xD;
    cf2 = Classify[trainingData[[All, 1 ;; -2]] -&amp;gt; trainingData[[All, -1]], Method -&amp;gt; &amp;#034;LogisticRegression&amp;#034;];&#xD;
    cfROC2 = ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cf2[testData[[All, 1 ;; -2]]]]&#xD;
    (* &amp;lt;|&amp;#034;TruePositive&amp;#034; -&amp;gt; 89, &amp;#034;FalsePositive&amp;#034; -&amp;gt; 37, &amp;#034;TrueNegative&amp;#034; -&amp;gt; 155, &amp;#034;FalseNegative&amp;#034; -&amp;gt; 33|&amp;gt; *)&#xD;
&#xD;
## Geometric computations in the ROC space&#xD;
&#xD;
Here are the ROC space points corresponding to the two classifiers, cf1 and cf2: &#xD;
&#xD;
    p1 = Through[ROCFunctions[{&amp;#034;FPR&amp;#034;, &amp;#034;TPR&amp;#034;}][cfROC1]];&#xD;
    p2 = Through[ROCFunctions[{&amp;#034;FPR&amp;#034;, &amp;#034;TPR&amp;#034;}][cfROC2]];&#xD;
&#xD;
Here is the breakdown of frequencies of the class labels:&#xD;
&#xD;
    Tally[trainingData[[All, -1]]]&#xD;
    %[[All, 2]]/Length[trainingData] // N&#xD;
&#xD;
    (* {{&amp;#034;survived&amp;#034;, 305}, {&amp;#034;died&amp;#034;, 427}}&#xD;
       {0.416667, 0.583333}) *)&#xD;
&#xD;
We want to our classifier to produce $38$% people to survive. Here we find two points of the corresponding constraint line (on which we ROC points of the desired classifiers should reside):&#xD;
&#xD;
    sol1 = Solve[{{x, y} \[Element] ImplicitRegion[{x (1 - 0.42) + y 0.42 == 0.38}, {x, y}], x == 0.1}, {x, y}][[1]]&#xD;
    sol2 = Solve[{{x, y} \[Element] ImplicitRegion[{x (1 - 0.42) + y 0.42 == 0.38}, {x, y}], x == 0.25}, {x, y}][[1]]&#xD;
&#xD;
    (* {x -&amp;gt; 0.1, y -&amp;gt; 0.766667}&#xD;
       {x -&amp;gt; 0.25, y -&amp;gt; 0.559524} *)&#xD;
&#xD;
Here using the points q1 and q2 of the constraint line we find the intersection point with the line connecting the ROC points of the classifiers:&#xD;
&#xD;
    {q1, q2} = {{x, y} /. sol1, {x, y} /. sol2};&#xD;
    sol = Solve[ {{x, y} \[Element] InfiniteLine[{q1, q2}] \[And] {x, y} \[Element] InfiniteLine[{p1, p2}]}, {x, y}];&#xD;
    q = {x, y} /. sol[[1]]&#xD;
&#xD;
    (* {0.149753, 0.69796} *)&#xD;
&#xD;
Let us plot all geometric objects:&#xD;
&#xD;
    Graphics[{PointSize[0.015], Blue, Tooltip[Point[p1], &amp;#034;cf1&amp;#034;], Black, &#xD;
      Text[&amp;#034;cf1&amp;#034;, p1, {-1.5, 1}], Red, Tooltip[Point[p2], &amp;#034;cf2&amp;#034;], Black, &#xD;
      Text[&amp;#034;cf2&amp;#034;, p2, {1.5, -1}], Black, Point[q], Dashed, &#xD;
      InfiniteLine[{q1, q2}], Thin, InfiniteLine[{p1, p2}]}, &#xD;
     PlotRange -&amp;gt; {{0., 0.3}, {0.6, 0.8}}, &#xD;
     GridLines -&amp;gt; Automatic, Frame -&amp;gt; True]&#xD;
&#xD;
![Classifier-Interpolation-geometric-objects][15]&#xD;
&#xD;
## Classifier interpolation&#xD;
&#xD;
Next we find the ratio of the distance from the intersection point q to the cf1 ROC point and the distance between the ROC points of cf1 and cf2.&#xD;
&#xD;
    k = Norm[p1 - q]/Norm[p1 - p2]&#xD;
    (* 0.450169 *)&#xD;
&#xD;
The classifier interpolation is made by a weighted random selection based on that ratio (using `RandomChoice`):&#xD;
&#xD;
    SeedRandom[8989]&#xD;
    cres = MapThread[If, {RandomChoice[{1 - k, k} -&amp;gt; {True, False}, Length[testData]], cf1@testData[[All, 1 ;; -2]], cf2@testData[[All, 1 ;; -2]]}];&#xD;
    cfROC3 = ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cres];&#xD;
    p3 = Through[ROCFunctions[{&amp;#034;FPR&amp;#034;, &amp;#034;TPR&amp;#034;}][cfROC3]];&#xD;
    Graphics[{PointSize[0.015], Blue, Point[p1], Red, Point[p2], Black, Dashed, InfiniteLine[{q1, q2}], Green, Point[p3]}, &#xD;
     PlotRange -&amp;gt; {{0., 0.3}, {0.6, 0.8}}, &#xD;
     GridLines -&amp;gt; Automatic, Frame -&amp;gt; True]&#xD;
&#xD;
![Classifier-Interpolation-single-results][16]&#xD;
&#xD;
We can run the process multiple times in order to convince ourselves that the interpolated classifier ROC point is very close to the constraint line most of the time.&#xD;
&#xD;
    p3s =&#xD;
      Table[(&#xD;
        cres = &#xD;
         MapThread[If, {RandomChoice[{1 - k, k} -&amp;gt; {True, False}, Length[testData]], cf1@testData[[All, 1 ;; -2]], cf2@testData[[All, 1 ;; -2]]}]; &#xD;
        cfROC3 = ToROCAssociation[{&amp;#034;survived&amp;#034;, &amp;#034;died&amp;#034;}, testData[[All, -1]], cres];&#xD;
        Through[ROCFunctions[{&amp;#034;FPR&amp;#034;, &amp;#034;TPR&amp;#034;}][cfROC3]]), {1000}];&#xD;
&#xD;
    Show[{SmoothDensityHistogram[p3s, ColorFunction -&amp;gt; (Blend[{White, Green}, #] &amp;amp;), Mesh -&amp;gt; 3], &#xD;
      Graphics[{PointSize[0.015], Blue, Tooltip[Point[p1], &amp;#034;cf1&amp;#034;], Black, Text[&amp;#034;cf1&amp;#034;, p1, {-1.5, 1}], &#xD;
         Red, Tooltip[Point[p2], &amp;#034;cf2&amp;#034;], Black, Text[&amp;#034;cf2&amp;#034;, p2, {1.5, -1}], &#xD;
         Black, Dashed, InfiniteLine[{q1, q2}]}, GridLines -&amp;gt; Automatic]}, &#xD;
     PlotRange -&amp;gt; {{0., 0.3}, {0.6, 0.8}}, &#xD;
     GridLines -&amp;gt; Automatic, Axes -&amp;gt; True, &#xD;
     AspectRatio -&amp;gt; Automatic]&#xD;
&#xD;
![Classifier-Interpolation-1000-results][17]&#xD;
&#xD;
&#xD;
&#xD;
# References&#xD;
&#xD;
\[1\] Leo Breiman, Statistical Modeling: The Two Cultures, (2001), Statistical Science, Vol. 16, No. 3, 199\[Dash]231.&#xD;
&#xD;
\[2\] Wikipedia entry, Receiver operating characteristic. URL: http://en.wikipedia.org/wiki/Receiver_operating_characteristic .&#xD;
&#xD;
\[3\] Tom Fawcett, An introduction to ROC analysis, (2006), Pattern Recognition Letters, 27, 861\[Dash]874. ([Link to PDF](Link to PDF).)&#xD;
&#xD;
\[4\] Anton Antonov, [MathematicaForPrediction utilities](https://github.com/antononcube/MathematicaForPrediction/blob/master/MathematicaForPredictionUtilities.m), (2014), source code [MathematicaForPrediction at GitHub](https://github.com/antononcube/MathematicaForPrediction), package [MathematicaForPredictionUtilities.m](https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/MathematicaForPredictionUtilities.m).&#xD;
&#xD;
\[5\] Anton Antonov, [Receiver operating characteristic functions Mathematica package](https://github.com/antononcube/MathematicaForPrediction/blob/master/ROCFunctions.m), (2016), source code [MathematicaForPrediction at GitHub](https://github.com/antononcube/MathematicaForPrediction), package [ROCFunctions.m](https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/ROCFunctions.m).&#xD;
&#xD;
\[6\] Anton Antonov, [Classifier ensembles functions Mathematica package](https://github.com/antononcube/MathematicaForPrediction/blob/master/ClassifierEnsembles.m), (2016),  source code [MathematicaForPrediction at GitHub](https://github.com/antononcube/MathematicaForPrediction), package [ClassifierEnsembles.m](https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/ClassifierEnsembles.m).&#xD;
&#xD;
\[7\] Anton Antonov, &amp;#034;[Importance of variables investigation guide](https://github.com/antononcube/MathematicaForPrediction/blob/master/Documentation/Importance-of-variables-investigation-guide.pdf)&amp;#034;, (2016),  [MathematicaForPrediction at GitHub](https://github.com/antononcube/MathematicaForPrediction), https://github.com/antononcube/MathematicaForPrediction, folder [Documentation](https://github.com/antononcube/MathematicaForPrediction/tree/master/Documentation).&#xD;
&#xD;
[1]:http://i.imgur.com/WDNgwNf.png&#xD;
[2]:http://i.imgur.com/G6DD5DD.png&#xD;
[3]:http://i.imgur.com/annEj2s.png&#xD;
[4]:http://i.imgur.com/c4pPgnq.png&#xD;
[5]:http://i.imgur.com/JZ6JpfY.png&#xD;
[6]:http://i.imgur.com/C9ZBbEv.png&#xD;
[7]:http://i.imgur.com/jmdC521.png&#xD;
[8]:http://i.imgur.com/faspQpc.png&#xD;
[9]:http://i.imgur.com/IZLiMer.png&#xD;
[10]:http://i.imgur.com/XMPsiNO.png&#xD;
[11]:http://i.imgur.com/BkDTZXD.png&#xD;
[12]:http://i.imgur.com/bZY8pL3.png&#xD;
[13]:http://i.imgur.com/Te2kDxh.png&#xD;
[14]:http://i.imgur.com/OcCFBBH.png&#xD;
[15]:http://i.imgur.com/brboKWy.png&#xD;
[16]:http://i.imgur.com/uP4aexV.png&#xD;
[17]:http://i.imgur.com/8cZHK2o.png</description>
    <dc:creator>Anton Antonov</dc:creator>
    <dc:date>2016-10-15T17:12:50Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/3055705">
    <title>Generalized Lanchester combat models</title>
    <link>https://community.wolfram.com/groups/-/m/t/3055705</link>
    <description>&amp;amp;[Wolfram Notebook][1]&#xD;
&#xD;
&#xD;
  [1]: https://www.wolframcloud.com/obj/b1da2e64-8dfd-491e-95ee-a00662e000bf</description>
    <dc:creator>Anton Antonov</dc:creator>
    <dc:date>2023-10-25T19:28:53Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1358396">
    <title>The inverse of moving from a map to a network topology</title>
    <link>https://community.wolfram.com/groups/-/m/t/1358396</link>
    <description>Caveat: this may be more of a math problem than a Mathematica-specific problem, but I thought some in this group might have insight.&#xD;
&#xD;
A solved problem is moving from a map in which there are districts with boundaries to a representation of that map as a network in which the vertices are the districts and edges represent shared boundaries between districts. &#xD;
&#xD;
     fr = UndirectedGraph[&#xD;
       NestGraph[#[&amp;#034;BorderingCountries&amp;#034;] &amp;amp;, Entity[&amp;#034;Country&amp;#034;, &amp;#034;France&amp;#034;], &#xD;
        3]]&#xD;
&#xD;
But what about the inverse problem: how does one move from a network to a map which is consistent with that network. There are likely to be an infinite number of such maps, but how does one even find a single exemplar. I&amp;#039;m thinking this is actually quite a difficult problem, but perhaps some people here might have insight on the matter and how such an exercise might be tackled using Mathematica.</description>
    <dc:creator>Seth Chandler</dc:creator>
    <dc:date>2018-06-19T13:27:01Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/138207">
    <title>Ant Colony - Speeding up simulation &amp;amp; Extra Functionality</title>
    <link>https://community.wolfram.com/groups/-/m/t/138207</link>
    <description>Following up on Bernat&amp;#039;s posting here [url=http://community.wolfram.com/groups/-/m/t/136023?p_p_auth=2Af2XNsw]http://community.wolfram.com/groups/-/m/t/136023?p_p_auth=2Af2XNsw[/url], I attempted my first cut on simulating an ant colony hunting for food.
The code runs too slow, it processes 3.5 cycles (ticks) per second for 25 ants.

Would be very grateful for ideas on how to:[list=1]
[*]Improve performance of the code.
[*]Mathematica Functions/Ideas for adding diffusion to the pheromone field (represented by a matrix) without adding excessive performance cost (played with converting the matrix to an image &amp;gt; blurring &amp;gt; converting it back to a matrix) which adds and excessive time penalty.
[/list]Hope the code is clear enough. As written it takes 517 seconds in my PC.[mcode](*Define the world size*)
ymax = 200; xmax = 400;
(*Locate the colony somwhere in the world*)
nest = {RandomInteger[{1, xmax}], RandomInteger[{1, ymax}]};

maxAnts = 25;
ticks = 1;
maxSteps = 2000;
maxSpeed = 6;
maxAngle = 13 \[Pi]/16;
maxFoodPiles = 8;
smellRange = 12;
pheromoneDeposit = 1;
foodMultiplier = 1000;
pheromoneMultiplier = 10;
fieldCaptureInterval = 10;
discriminationFactor = 16;
noFood = 0;
withFood = 1;
antSymbol = \[Infinity];
evaporationRate = ConstantArray[(1 - 0.005), {xmax, ymax}];
pheromoneField = ConstantArray[0., {xmax, ymax}];
pheromoneField[[First@nest, Last@nest]] = 
  100000; (*Added a lot of pheromone at the nest to &amp;#039;help&amp;#039; the ants \
get back to the nest*)
foodField = ConstantArray[0., {xmax, ymax}];
(*Scatter the food in the world*)
foodPiles = 
  Transpose[{RandomInteger[{1, xmax}, maxFoodPiles], 
    RandomInteger[{1, ymax}, maxFoodPiles]}];
(foodField[[#[[1]], #[[2]]]] = 10) &amp;amp; /@ foodPiles;
(*We&amp;#039;ll record the history of the fields in these variables*)
pheromoneHistory = {pheromoneField};
foodHistory = {foodField};
(*Functions*)
(*Find out all positions that the ant will step as it moves \
forward/Keep ants within the world*)
calculateLoc[location_, direction_, steps_] := 
 Module[{loc, result = {}}, 
  Do[loc = Flatten[
     location + Round[{temp*Cos[direction], temp*Sin[direction]}]];
   loc = Min[#] &amp;amp; /@ Transpose[{loc, {xmax, ymax}}];
   loc = Max[#] &amp;amp; /@ Transpose[{loc, {1, 1}}];
   result = Append[result, loc], {temp, steps}];
  result]
(*Return the distribution probability of the direction that the ant \
will head to*)
(*It will add the smell of pheromones + food if no food is being \
carried *)
probDist[location_, direction_, hasFood_, range_, angle_, steps_] :=
 Module[{dist, total, bins, vals}, 
  dist = Flatten[
    Table[{direction + y , 
      Flatten[location + 
        Round[{x*Cos[direction + y ], 
          x*Sin[direction + y ]}]]}, {y, -angle/2, angle/2, 
      angle/steps}, {x, 1, range, 1}], 1];
  dist = DeleteCases[dist, 
    Alternatives[{_, {a_ /; a &amp;lt; 1, _}}, {_, {a_ /; 
        a &amp;gt; xmax, _}}, {_, {_, b_ /; b &amp;lt; 1}}, {_, {_, 
       b_ /; b &amp;gt; ymax}}]];
  (dist[[#, 
       2]] = ((1 - hasFood) foodMultiplier foodField[[
          First@dist[[#, 2]], Last@dist[[#, 2]]]] + 
        pheromoneField[[First@dist[[#, 2]], Last@dist[[#, 2]]]])) &amp;amp; /@
    Range[Length[dist]]; bins = Union[dist[[All, 1]]]; 
  vals = Cases[dist, {#, y_} -&amp;gt; y] &amp;amp; /@ bins; 
  vals = (Total[#] &amp;amp; /@ vals);
  total = Total[vals];
  If[total == 0, 
   UniformDistribution[{direction - angle/2, direction + angle/2}],
   EmpiricalDistribution[Rule[vals, bins]]]]
(*Routine Determines where the ant should head next*)
(*Also updates the pheromone field*)
update[agent[id_, symbol_, location_, direction_, hasFood_]] := 
 Module[{temp, dist, dir, speed, loc, path, status, foundDestination, 
   multiplier}, 
  dir = RandomVariate[
    probDist[location, direction, hasFood, smellRange, maxAngle, 
     discriminationFactor]];
  speed = RandomVariate[UniformDistribution[{1, maxSpeed}], 1];
  loc = calculateLoc[location, dir, speed];
  status = hasFood;
  If[status == noFood,
      multiplier = 1;
      foundDestination = 
       Select[loc, foodField[[#[[1]], #[[2]]]] &amp;gt; 0 &amp;amp;];
      If[Length@foundDestination != 0, status = withFood; 
       dir = dir + \[Pi]; multiplier = pheromoneMultiplier; 
       foundDestination = First@foundDestination; 
       foodField[[foundDestination[[1]], foundDestination[[2]]]] = 
        foodField[[foundDestination[[1]], foundDestination[[2]]]] - 
         1;],
      multiplier = pheromoneMultiplier;
      foundDestination = Cases[loc, nest];
      If[Length@foundDestination != 0, status = noFood; 
       dir = dir + \[Pi]; multiplier = 1;]
      ]
     (pheromoneField[[#[[1]], #[[2]]]] = 
       pheromoneField[[#[[1]], #[[2]]]] + 
        multiplier pheromoneDeposit) &amp;amp; /@ loc;
  
  agent[id, symbol, Last@loc, dir, status]]

update[agentList_List] := 
 Module[{set = update[#] &amp;amp; /@ agentList}, 
  pheromoneField = evaporationRate pheromoneField; 
  If[Mod[ticks, fieldCaptureInterval] == 0, 
   pheromoneHistory = Append[pheromoneHistory, pheromoneField]; 
   foodHistory = Append[foodHistory, foodField];]; ticks++; set]

(*Routines to display the ants in the animate section. Regretably \
can&amp;#039;t be used due to memory leak*)
display[agent[id_, symbol_, location_, direction_, hasFood_]] := 
 Text[Rotate[symbol, direction], location]
display[list_] := Module[{lst = display[#] &amp;amp; /@ list}, Graphics[lst]]

(*initialize ants*)
(*Initialize the colony - in which direction will the ants start \
walking out*)
ants = Table[
   agent[id, antSymbol, nest, 
    RandomVariate[UniformDistribution[{0, 2 \[Pi]}]], noFood], {id, 
    maxAnts}];

antHistory = NestList[update, ants, maxSteps]; // AbsoluteTiming

(*Did the ants eat the food? Check status of the food piles and how \
the pheromone field changed with time*)
foodField[[#[[1]], #[[2]]]] &amp;amp; /@ foodPiles
Manipulate[
 Show[ColorNegate@ImageRotate@Image@pheromoneHistory[[i]], 
  Graphics[{Red, PointSize[Large], Point[nest], PointSize[Medium], 
    Blue, Point[foodPiles]}]], {i, 1, Length@pheromoneHistory, 1}]

[/mcode][img=width: 800px; height: 557px;]/c/portal/getImageAttachment?filename=ants.gif&amp;amp;userId=78214[/img]</description>
    <dc:creator>Diego Zviovich</dc:creator>
    <dc:date>2013-10-12T21:08:11Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2920790">
    <title>Quantile regression 3D examples</title>
    <link>https://community.wolfram.com/groups/-/m/t/2920790</link>
    <description>&amp;amp;[Wolfram Notebook][1]&#xD;
&#xD;
&#xD;
  [1]: https://www.wolframcloud.com/obj/580db34a-30e4-447b-8db2-9df739ad718e</description>
    <dc:creator>Anton Antonov</dc:creator>
    <dc:date>2023-05-17T15:18:40Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2674963">
    <title>The Winning Move for Cutting Corners</title>
    <link>https://community.wolfram.com/groups/-/m/t/2674963</link>
    <description>![enter image description here][1]&#xD;
&#xD;
&amp;amp;[Wolfram Notebook][2]&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Image20221027223559.png&amp;amp;userId=20103&#xD;
  [2]: https://www.wolframcloud.com/obj/2ce060cf-f735-44ef-89d5-2a5de94db174</description>
    <dc:creator>Jindřich Michalik</dc:creator>
    <dc:date>2022-10-27T20:36:50Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/941017">
    <title>Basic example of using ROC with Linear regression</title>
    <link>https://community.wolfram.com/groups/-/m/t/941017</link>
    <description>## Introduction&#xD;
&#xD;
This post is for the package \[[2](https://github.com/antononcube/MathematicaForPrediction/blob/master/ROCFunctions.m)\] that provides *Mathematica* implementations of [Receiver Operating Characteristic](https://en.wikipedia.org/wiki/Receiver_operating_characteristic) (ROC) functions calculation and plotting. The ROC framework is used for analysis and tuning of binary classifiers, \[[3](https://en.wikipedia.org/wiki/Receiver_operating_characteristic)\]. (The classifiers are assumed to classify into a positive/true label or a negative/false label. )&#xD;
&#xD;
The function `ROCFuntions` gives access to the individual ROC functions through string arguments. Those ROC functions are applied to special objects, called ROC Association objects.&#xD;
&#xD;
Each ROC Association object is an `Association` that has the following four keys: &amp;#034;TruePositive&amp;#034;, &amp;#034;FalsePositive&amp;#034;, &amp;#034;TrueNegative&amp;#034;, and &amp;#034;FalseNegative&amp;#034; .&#xD;
&#xD;
Given two lists of actual and predicted labels a ROC Association object can be made with the function `ToROCAssociation` .&#xD;
&#xD;
For more definitions and example of ROC terminology and functions see \[[3](https://en.wikipedia.org/wiki/Receiver_operating_characteristic),[4](https://ccrma.stanford.edu/workshops/mir2009/references/ROCintro.pdf)\].&#xD;
&#xD;
## Minimal example&#xD;
&#xD;
Note that here although we use both of the provided Titanic training and test data, the code is doing only training. The test data is used to find the best tuning parameter (threshold) through ROC analysis.&#xD;
&#xD;
### Get packages&#xD;
&#xD;
These commands load the packages \[[1](https://github.com/antononcube/MathematicaForPrediction/blob/master/MathematicaForPredictionUtilities.m),[2](https://github.com/antononcube/MathematicaForPrediction/blob/master/ROCFunctions.m)\]:&#xD;
&#xD;
    Import[&amp;#034;https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/MathematicaForPredictionUtilities.m&amp;#034;]&#xD;
    Import[&amp;#034;https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/ROCFunctions.m&amp;#034;]&#xD;
&#xD;
### Using Titanic data&#xD;
&#xD;
Here is the summary of the Titanic data used below:&#xD;
&#xD;
    titanicData = (Flatten@*List) @@@ExampleData[{&amp;#034;MachineLearning&amp;#034;, &amp;#034;Titanic&amp;#034;}, &amp;#034;Data&amp;#034;];&#xD;
    columnNames = (Flatten@*List) @@ExampleData[{&amp;#034;MachineLearning&amp;#034;, &amp;#034;Titanic&amp;#034;}, &amp;#034;VariableDescriptions&amp;#034;];&#xD;
    RecordsSummary[titanicData, columnNames]&#xD;
&#xD;
[![Titanic1][1]][1]&#xD;
&#xD;
This variable dependence grid shows the relationships between the variables.&#xD;
&#xD;
    Magnify[#, 0.7] &amp;amp;@VariableDependenceGrid[titanicData, columnNames]&#xD;
&#xD;
[![VariableDependencies][7]][7]&#xD;
&#xD;
### Get training and testing data&#xD;
&#xD;
    data = ExampleData[{&amp;#034;MachineLearning&amp;#034;, &amp;#034;Titanic&amp;#034;}, &amp;#034;TrainingData&amp;#034;];&#xD;
    data = ((Flatten@*List) @@@ data)[[All, {1, 2, 3, -1}]];&#xD;
    trainingData = DeleteCases[data, {___, _Missing, ___}];&#xD;
    Dimensions[trainingData]&#xD;
&#xD;
(* {732, 4} *)&#xD;
&#xD;
    data = ExampleData[{&amp;#034;MachineLearning&amp;#034;, &amp;#034;Titanic&amp;#034;}, &amp;#034;TestData&amp;#034;];&#xD;
    data = ((Flatten@*List) @@@ data)[[All, {1, 2, 3, -1}]];&#xD;
    testData = DeleteCases[data, {___, _Missing, ___}];&#xD;
    Dimensions[testData]&#xD;
&#xD;
(* {314, 4} *)&#xD;
&#xD;
### Replace categorical with numerical values&#xD;
&#xD;
    trainingData = trainingData /. {&amp;#034;survived&amp;#034; -&amp;gt; 1, &amp;#034;died&amp;#034; -&amp;gt; 0, &amp;#034;1st&amp;#034; -&amp;gt; 0, &amp;#034;2nd&amp;#034; -&amp;gt; 1, &amp;#034;3rd&amp;#034; -&amp;gt; 2, &amp;#034;male&amp;#034; -&amp;gt; 0, &amp;#034;female&amp;#034; -&amp;gt; 1};&#xD;
&#xD;
    testData = testData /. {&amp;#034;survived&amp;#034; -&amp;gt; 1, &amp;#034;died&amp;#034; -&amp;gt; 0, &amp;#034;1st&amp;#034; -&amp;gt; 1, &amp;#034;2nd&amp;#034; -&amp;gt; 2, &amp;#034;3rd&amp;#034; -&amp;gt; 3, &amp;#034;male&amp;#034; -&amp;gt; 0, &amp;#034;female&amp;#034; -&amp;gt; 1};&#xD;
&#xD;
### Do linear regression&#xD;
&#xD;
    lfm = LinearModelFit[{trainingData[[All, 1 ;; -2]], trainingData[[All, -1]]}]&#xD;
&#xD;
[![Regression1][2]][2]&#xD;
&#xD;
### Get the predicted values&#xD;
&#xD;
    modelValues = lfm @@@ testData[[All, 1 ;; -2]];&#xD;
&#xD;
    Histogram[modelValues, 20]&#xD;
&#xD;
[![Prediction1][3]][3]&#xD;
&#xD;
RecordsSummary[modelValues]&#xD;
&#xD;
[![Prediction2][4]][4]&#xD;
&#xD;
### Obtain ROC associations over a set of parameter values&#xD;
&#xD;
    testLabels = testData[[All, -1]];&#xD;
&#xD;
    thRange = Range[0.1, 0.9, 0.025];&#xD;
    aROCs = Table[ToROCAssociation[{1, 0}, testLabels, Map[If[# &amp;gt; \[Theta], 1, 0] &amp;amp;, modelValues]], {\[Theta], thRange}];&#xD;
&#xD;
### Evaluate ROC functions for given ROC association&#xD;
&#xD;
    N @ Through[ROCFunctions[{&amp;#034;PPV&amp;#034;, &amp;#034;NPV&amp;#034;, &amp;#034;TPR&amp;#034;, &amp;#034;ACC&amp;#034;, &amp;#034;SPC&amp;#034;, &amp;#034;MCC&amp;#034;}][aROCs[[3]]]]&#xD;
&#xD;
    (* {0.513514, 0.790698, 0.778689, 0.627389, 0.53125, 0.319886} *)&#xD;
&#xD;
### Standard ROC plot&#xD;
&#xD;
    ROCPlot[thRange, aROCs, &amp;#034;PlotJoined&amp;#034; -&amp;gt; Automatic, &amp;#034;ROCPointCallouts&amp;#034; -&amp;gt; True, &amp;#034;ROCPointTooltips&amp;#034; -&amp;gt; True, GridLines -&amp;gt; Automatic]&#xD;
&#xD;
[![ROCPlot1][5]][5]&#xD;
&#xD;
### Plot ROC functions wrt to parameter values&#xD;
&#xD;
    rocFuncs = {&amp;#034;PPV&amp;#034;, &amp;#034;NPV&amp;#034;, &amp;#034;TPR&amp;#034;, &amp;#034;ACC&amp;#034;, &amp;#034;SPC&amp;#034;, &amp;#034;MCC&amp;#034;};&#xD;
    rocFuncTips = Map[# &amp;lt;&amp;gt; &amp;#034;, &amp;#034; &amp;lt;&amp;gt; (ROCFunctions[&amp;#034;FunctionInterpretations&amp;#034;][#]) &amp;amp;, rocFuncs];&#xD;
    ListLinePlot[&#xD;
     MapThread[Tooltip[Transpose[{thRange, #1}], #2] &amp;amp;, {Transpose[Map[Through[ROCFunctions[rocFuncs][#]] &amp;amp;, aROCs]], rocFuncTips}],&#xD;
     Frame -&amp;gt; True, &#xD;
     FrameLabel -&amp;gt; Map[Style[#, Larger] &amp;amp;, {&amp;#034;threshold, \[Theta]&amp;#034;, &amp;#034;rate&amp;#034;}], &#xD;
     PlotLegends -&amp;gt; rocFuncTips, GridLines -&amp;gt; Automatic]&#xD;
&#xD;
[![ROCPlot2][6]][6]&#xD;
&#xD;
### Finding the intersection point of PPV and TPR&#xD;
&#xD;
We want to find a point that provides balanced positive and negative labels success rates. One way to do this is to find the intersection point of the ROC functions PPV (positive predictive value) and TPR (true positive rate).&#xD;
&#xD;
Examining the plot above we can come up with the initial condition for $x$.&#xD;
&#xD;
    ppvFunc = Interpolation[Transpose@{thRange, ROCFunctions[&amp;#034;PPV&amp;#034;] /@ aROCs}];&#xD;
    tprFunc = Interpolation[Transpose@{thRange, ROCFunctions[&amp;#034;TPR&amp;#034;] /@ aROCs}];&#xD;
    FindRoot[ppvFunc[x] - tprFunc[x] == 0, {x, 0.2}]&#xD;
&#xD;
(* {x -&amp;gt; 0.3} *)&#xD;
&#xD;
### Area under the ROC curve&#xD;
&#xD;
The Area Under the ROC curve (AUROC) tells for a given range of the controlling parameter &amp;#034;what is the probability of the classifier to rank a randomly chosen positive instance higher than a randomly chosen negative instance, (assuming &amp;#039;positive&amp;#039; ranks higher than &amp;#039;negative&amp;#039;)&amp;#034;, [3,4]&#xD;
&#xD;
Calculating AUROC is easy using the Trapezoidal quadrature formula:&#xD;
&#xD;
     N@Total[Partition[Sort@Transpose[{ROCFunctions[&amp;#034;FPR&amp;#034;] /@ aROCs, ROCFunctions[&amp;#034;TPR&amp;#034;] /@ aROCs}], 2, 1] &#xD;
       /. {{x1_, y1_}, {x2_, y2_}} :&amp;gt; (x2 - x1) (y1 + (y2 - y1)/2)]&#xD;
&#xD;
     (* 0.474513 *)&#xD;
&#xD;
It is also implemented in \[[2](https://github.com/antononcube/MathematicaForPrediction/blob/master/ROCFunctions.m)\]:&#xD;
&#xD;
    N@ROCFunctions[&amp;#034;AUROC&amp;#034;][aROCs]&#xD;
&#xD;
    (* 0.474513 *)&#xD;
&#xD;
## References&#xD;
&#xD;
\[1\] Anton Antonov, [MathematicaForPrediction utilities](https://github.com/antononcube/MathematicaForPrediction/blob/master/MathematicaForPredictionUtilities.m), (2014), source code [MathematicaForPrediction at GitHub](https://github.com/antononcube/MathematicaForPrediction), package [MathematicaForPredictionUtilities.m](https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/MathematicaForPredictionUtilities.m).&#xD;
&#xD;
\[2\] Anton Antonov, [Receiver operating characteristic functions Mathematica package](https://github.com/antononcube/MathematicaForPrediction/blob/master/ROCFunctions.m), (2016), source code [MathematicaForPrediction at GitHub](https://github.com/antononcube/MathematicaForPrediction), package [ROCFunctions.m](https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/ROCFunctions.m) .&#xD;
&#xD;
\[3\] Wikipedia entry, [Receiver operating characteristic](http://en.wikipedia.org/wiki/Receiver_operating_characteristic).&#xD;
&#xD;
\[4\] Tom Fawcett, [An introduction to ROC analysis](https://ccrma.stanford.edu/workshops/mir2009/references/ROCintro.pdf), (2006), Pattern Recognition Letters, 27, 861-874.&#xD;
&#xD;
[1]:http://i.imgur.com/VTVyV9P.png&#xD;
[2]:http://i.imgur.com/d663I98.png&#xD;
[3]:http://i.imgur.com/bBXsDp2.png&#xD;
[4]:http://i.imgur.com/mzWjhZc.png&#xD;
[5]:https://i.imgur.com/Sam8wX5.png&#xD;
[6]:https://i.imgur.com/lrGRgJp.png&#xD;
[7]:http://i.imgur.com/DSkPQOH.png</description>
    <dc:creator>Anton Antonov</dc:creator>
    <dc:date>2016-10-12T13:21:04Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2333107">
    <title>Using the Gurobi Optimizer in the Wolfram Language</title>
    <link>https://community.wolfram.com/groups/-/m/t/2333107</link>
    <description>&amp;amp;[Wolfram Notebook][1]&#xD;
&#xD;
&#xD;
  [1]: https://www.wolframcloud.com/obj/54323170-e51a-47ca-a4d4-3516daa04d8d</description>
    <dc:creator>Arnoud Buzing</dc:creator>
    <dc:date>2021-08-02T17:06:46Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/3763738">
    <title>[WSRI26] Evaluating Black-Box Physics Through Optical Emulation</title>
    <link>https://community.wolfram.com/groups/-/m/t/3763738</link>
    <description>![Evaluating Black-Box Physics Through Optical Emulation][1]&#xD;
&#xD;
&amp;amp;[Wolfram Notebook][2]&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=bracelet.png&amp;amp;userId=3760415&#xD;
  [2]: https://www.wolframcloud.com/obj/a69cbbc1-44d8-4d3b-a1e1-2029814fd159</description>
    <dc:creator>Hubert Kołcz</dc:creator>
    <dc:date>2026-07-17T12:40:37Z</dc:date>
  </item>
</rdf:RDF>

