In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os.path as ospath

In [2]:
excelfile = ospath.join('..','Serious games','Games','БД4_Лёгкая.xlsm')

In [3]:
Alldata = pd.read_excel(excelfile,sheet_name='Данные')
Games = pd.read_excel(excelfile,sheet_name='Игры')
print(Alldata.columns)
Games.columns


Index(['Game', 'Time', 'Subject', 'Group', 'GrSubject', 'Type', 'Gain',
       'Penalty', 'x', 's1', 's2', 's3', 'AcceptAdvice', 'CalcCount',
       'CalcAdviceCount', 'UseHelp'],
      dtype='object')
Out[3]:
Index(['Session', 'Game', 'Date', 'Place', 'GamersCount', 'R',
       'Parametr1_alfa', 'Parametr2_beta', 'Mechname', 'GameMech',
       'Cooperation', 'talks', 'Name', 'Datafile', 'Sbjfile', 'стимул',
       'Group', 'Курс балла'],
      dtype='object')

In [4]:
YHGames=Games[(Games.Mechname=='yh') & (Games.GameMech=='agree')]
YHExpGames=Games[(Games.Mechname=='yh') & (Games.GameMech=='exp')]

In [6]:
YHData=Alldata[Alldata.Game.isin(YHGames.Game)]
YHEData=Alldata[Alldata.Game.isin(YHExpGames.Game)]

In [7]:
print(YHData.shape,YHEData.shape)


(1035, 16) (75, 16)

In [7]:
GLGames=Games[(Games.Mechname=='gl') & (Games.GameMech=='agree')]
GLData=Alldata[Alldata.Game.isin(GLGames.Game)]

In [8]:
GLEGames=Games[(Games.Mechname=='gl') & (Games.GameMech=='exp')]
GLEData=Alldata[Alldata.Game.isin(GLEGames.Game)]

In [8]:
GLData.shape


Out[8]:
(2847, 16)

In [9]:
from scipy.spatial import distance

In [11]:
distance.cityblock([49,41,25],[38.3,38.3,38.3])


Out[11]:
26.700000000000003

In [ ]:


In [ ]:

График длин игр


In [64]:
gamelength=YHData[['Game','Time']].groupby('Game').max()

In [65]:
a=gamelength.sort_values(by='Time')

In [66]:
a['Game']=range(1,15)

In [67]:
b=a.rename(columns={'Time':'Game length'})

In [68]:
p=b.plot.scatter(x='Game',y='Game length')



In [69]:
p.get_figure().savefig('Gameslen.png',dpi=100)

In [31]:
GLData.axes


Out[31]:
[Int64Index([6573, 6574, 6575, 6576, 6577, 6578, 6579, 6580, 6581, 6582, 6583,
             6584, 6585, 6586, 6587, 6588, 6589, 6590, 6591, 6592, 6593, 6594,
             6595, 6596, 6597, 6598, 6599, 6600, 6601, 6602, 6603, 6604, 6605,
             6606, 6607, 6608, 6609, 6610, 6611, 6612, 6613, 6614, 6615, 6616,
             6617, 6618, 6619, 6620, 6621, 6622, 6623, 6624, 6625, 6626, 6627,
             6628, 6629, 6630, 6631, 6632],
            dtype='int64'),
 Index(['Game', 'Time', 'Subject', 'Group', 'GrSubject', 'Type', 'Gain',
        'Penalty', 'x', 's1', 's2', 's3', 'AcceptAdvice', 'CalcCount',
        'CalcAdviceCount', 'UseHelp'],
       dtype='object')]

In [40]:
GLData[['s1','s2','s3']].values[-1]


Out[40]:
array([35., 35., 45.])

In [23]:
for i,v in zip(GLData['Time'].values,GLData[['s1','s2','s3']].values):
    print(type(v))
    break


<class 'numpy.ndarray'>

In [44]:
GLData['s2'].index


Out[44]:
Int64Index([6573, 6574, 6575, 6576, 6577, 6578, 6579, 6580, 6581, 6582, 6583,
            6584, 6585, 6586, 6587, 6588, 6589, 6590, 6591, 6592, 6593, 6594,
            6595, 6596, 6597, 6598, 6599, 6600, 6601, 6602, 6603, 6604, 6605,
            6606, 6607, 6608, 6609, 6610, 6611, 6612, 6613, 6614, 6615, 6616,
            6617, 6618, 6619, 6620, 6621, 6622, 6623, 6624, 6625, 6626, 6627,
            6628, 6629, 6630, 6631, 6632],
           dtype='int64')

КП


In [8]:
def aheadCB(diter,eps,metric='cityblock'):
    """ return next CB start and stop and remaining iterator """
    from scipy.spatial import distance
    from itertools import chain as mchain
    start,vals = next(diter)
    vals = [ vals ]
    
    prev = start
    for i,v in diter:
        if np.asscalar(max(distance.cdist(vals,[v],metric))) > eps :
            return ((start,prev),mchain([(i,v)],diter))
        else:
            prev = i
            vals.append( v )
    return ((start,prev),diter)

def getCB(data,eps=0,metric='cityblock'): # colon data[0] must be 1,2,3,... to properly work of data[end-1] 
    from itertools import chain as mchain
    dend = data.index[-1]
    (start,end),diter = aheadCB(zip(data.index.values,data.values),eps,metric=metric)
    if start != end :
        cblist = [(start,end)]
        diter = mchain([(end,data.loc[end].values)],diter)
    else :
        cblist = []

    while end != dend :
        ((start,end),diter) = aheadCB(diter,eps)
        if start != end :
            cblist.append((start,end))
            diter = mchain([(end,data.loc[end].values)],diter)
    return cblist

In [23]:
['Game','Time','GrSubject']+(['s2'] if 1 == 2 else ['s1','s2','s3'])


Out[23]:
['Game', 'Time', 'GrSubject', 's1', 's2', 's3']

In [9]:
def OnlySelfBidsOfGame(game): # s2 = sii
    shiftgame = game.copy()
    n = game.columns.get_loc('s1') - 1
    shiftgame.loc[:,'s2']=shiftgame.apply(lambda x: x[n+x['GrSubject']], axis=1)
    return shiftgame

def getCBwithEps(gamesdata, eps=0,dim=1,metric='cityblock'):    
    cols = ['s2'] if dim == 1 else ['s1','s2','s3']
    gr = gamesdata.loc[:,['Game','Time','GrSubject']+cols].groupby(['GrSubject','Game'])
    
    lst = []
    for (s,g),data in gr:
        data = data.set_index('Time')
        glen = data.index.max()
        if dim == 1:
            cb = getCB(data[cols],eps,metric=metric)
        else:
            cb = getCB(data[cols],eps,metric=metric)
        data = pd.DataFrame(cb,columns=['ts','te'])
        data['subject'] = s
        data['game'] = g
        data['gamelength'] = glen
        lst.append(data)
    return pd.concat(lst).reset_index(drop=True)
    
def getCBofAllGames(gamesdata, maxeps=10, dim=1,metric='cityblock'):
    if dim == 1:
        gr = gamesdata.loc[:,['Game','Time','GrSubject','s2']].groupby(['GrSubject','Game'])
    else:
        gr = gamesdata.loc[:,['Game','Time','GrSubject','s1','s2','s3']].groupby(['GrSubject','Game'])
    cbCounts, stepsCounts = [],[]
    for eps in range(maxeps+1):
        lst = []
        for (s,g),data in gr:
            data = data.set_index('Time')
            if dim == 1:
                cb = getCB(data[['s2']],eps,metric=metric)
            else:
                cb = getCB(data[['s1','s2','s3']],eps,metric=metric)
            data = pd.DataFrame(cb,columns=['ts','te'])
            data['subject'] = s
            data['game'] = g
            lst.append(data)
        cb = pd.concat(lst).reset_index(drop=True)
        cbCounts.append(cb.shape[0])
        stepsCounts.append((cb['te']-cb['ts']+1).sum())
    Counts = pd.DataFrame({'CB Count':cbCounts,'Steps Count':stepsCounts})
    Counts.index.name = 'eps'
    return Counts
def getCountsofCB(cbdata):
    pass

In [70]:
gr = YHData.loc[:,['Game','Time','GrSubject','s2']].groupby('Game')

In [72]:
game40_1=gr.get_group(40)
#game40_1 = game40_1[['Time','s2']].set_index('Time')

In [76]:
game40_1.sort_values(by=['Time','GrSubject'])['s2'].iloc[-3:]


Out[76]:
2711    115.0
2709    115.0
2710    115.0
Name: s2, dtype: float64

In [ ]:


In [63]:
for i,v in game40_1.items():
  print(i,v)


s2 Time
1       1.0
2       1.1
3       1.0
4       1.1
5     115.0
6       1.0
7       1.1
8       1.2
9      40.0
10     75.0
11     23.8
12      1.0
13    115.0
14     50.0
15     40.0
16     10.0
17     20.0
18     22.0
19     25.0
20     40.0
21     10.0
22     15.0
23      1.0
24      1.1
25      1.0
26      1.1
27      1.0
28      1.1
29      1.0
30      1.1
31      1.0
32     40.0
33     40.0
34     39.0
35     45.0
36     48.0
37     48.0
38     10.0
39     11.0
40     10.0
41     11.0
42     10.0
43     11.0
44     10.0
45     11.0
46     10.0
47     11.0
48     10.0
49     11.0
50     15.0
51     20.0
52     23.0
53     20.0
54     21.0
55    115.0
56     40.0
57     20.0
58     10.0
59     10.0
60    115.0
Name: s2, dtype: float64

In [44]:
list(getCB(game40_1['s2'],1))


Out[44]:
[(2, 4), (5, 6)]

Доля КП в GL experimental design


In [9]:
GLCounts = getCBofAllGames(GLData,dim=3)
GLCounts['Steps Count %'] = GLCounts['Steps Count']/(2847/100)
GLCounts


Out[9]:
CB Count Steps Count Steps Count %
eps
0 340 1004 35.265191
1 419 1238 43.484370
2 486 1452 51.001054
3 507 1519 53.354408
4 512 1595 56.023885
5 525 1652 58.025992
6 529 1692 59.430980
7 532 1714 60.203723
8 544 1764 61.959958
9 547 1785 62.697576
10 587 1969 69.160520
11 592 2004 70.389884
12 596 2034 71.443625
13 598 2061 72.391992
14 600 2090 73.410608
15 607 2138 75.096593
16 611 2167 76.115209
17 610 2176 76.431331
18 606 2189 76.887952
19 607 2205 77.449947
20 652 2390 83.948015

In [10]:
GLCounts.to_clipboard()

In [52]:
GLECounts = getCBofAllGames(GLEData,dim=3)
GLECounts['Steps Count %'] = GLECounts['Steps Count']/(60/100)
GLECounts


Out[52]:
CB Count Steps Count Steps Count %
eps
0 5 11 18.333333
1 5 11 18.333333
2 6 13 21.666667
3 6 13 21.666667
4 8 17 28.333333
5 9 19 31.666667
6 9 19 31.666667
7 9 19 31.666667
8 8 19 31.666667
9 8 19 31.666667
10 11 26 43.333333

Доля КП


In [53]:
print(YHData.shape,YHEData.shape)


(1035, 16) (75, 16)

In [55]:
Counts = getCBofAllGames(YHData)
Counts['Steps Count %'] = Counts['Steps Count']/(YHData.shape[0]/100)
Counts


Out[55]:
CB Count Steps Count Steps Count %
eps
0 139 468 45.217391
1 189 651 62.898551
2 201 713 68.888889
3 207 752 72.657005
4 212 785 75.845411
5 238 892 86.183575
6 230 890 85.990338
7 223 890 85.990338
8 221 897 86.666667
9 211 893 86.280193
10 211 946 91.400966

In [58]:
Counts.to_clipboard()

In [17]:
fig, axes = plt.subplots(nrows=2, ncols=1)
axes[0].set_title('CB Count')
axes[1].set_title('Steps Count')
Counts['CB Count'].plot(ax=axes[0])
Counts['Steps Count'].plot(ax=axes[1])
fig.tight_layout(h_pad=0.1)
fig.savefig('CB_StepsCount.png',dpi=100)



In [19]:
YHEData.shape


Out[19]:
(75, 16)

In [56]:
CountsExp = getCBofAllGames(YHEData)
CountsExp['Steps Count %'] = CountsExp['Steps Count']/(YHEData.shape[0]/100)
CountsExp


Out[56]:
CB Count Steps Count Steps Count %
eps
0 11 27 36.000000
1 11 28 37.333333
2 12 30 40.000000
3 12 30 40.000000
4 12 30 40.000000
5 17 40 53.333333
6 17 40 53.333333
7 17 40 53.333333
8 17 40 53.333333
9 17 40 53.333333
10 19 51 68.000000

Для графиков числа КП и шагов в них


In [16]:
Meta={'basecount':YHData.shape[0],'expcount':YHEData.shape[0]}

Для статьи "КП итог"


In [27]:
fig, axes = plt.subplots(nrows=2, ncols=2)
axes[0,0].set_title('YH - CB Count')
axes[1,0].set_title('Experim. YH - CB Count')
axes[0,1].set_title('YH - Steps Count (%)')
axes[1,1].set_title('Experim. YH - Steps Count (%)')
CountsExp['CB Count'].plot(ax=axes[1,0])
(CountsExp['Steps Count']/(Meta['expcount']/100)).plot(ax=axes[1,1])
Counts['CB Count'].plot(ax=axes[0,0])
(Counts['Steps Count']/(Meta['basecount']/100)).plot(ax=axes[0,1])
fig.tight_layout(h_pad=0.1)
fig.set_size_inches((10,5))
fig.savefig('YHE_CB_StepsCount.png',dpi=150)


Для презентации на УБС-2018


In [15]:
fig, axes = plt.subplots(nrows=2, ncols=1)
#axes[0,0].set_title('YH - CB Count')
#axes[1,0].set_title('Experim. YH - CB Count')
axes[0].set_title('YH - Steps Count (%)')
axes[1].set_title('Experim. YH - Steps Count (%)')
#CountsExp['CB Count'].plot(ax=axes[1,0])
CountsExp['Steps Count'].plot(ax=axes[1])
#Counts['CB Count'].plot(ax=axes[0,0])
Counts['Steps Count'].plot(ax=axes[0])
fig.tight_layout(h_pad=0.1)
#fig.set_size_inches((10,5))
fig.savefig('YHE_CB_StepsCount.png',dpi=150)



In [82]:
CountsExp['Steps Count']/75


Out[82]:
eps
0     0.360000
1     0.373333
2     0.400000
3     0.400000
4     0.400000
5     0.533333
6     0.533333
7     0.533333
8     0.533333
9     0.533333
10    0.680000
Name: Steps Count, dtype: float64

In [61]:
fig, axes = plt.subplots(nrows=2, ncols=1)
CountsExp['CB Count'].plot(ax=axes[0])
CountsExp['Steps Count'].plot(ax=axes[1])
fig.savefig('YHE_CB_StepsCount.png',dpi=100)



In [64]:
GLData[['Time','x']].iloc[-3:]


Out[64]:
Time x
6411 8 22.133333
6412 8 42.333333
6413 8 50.533333

Распределение, эфф-е по Нэш-торгам

NashOpt - оптимальное распределение ресурсов для максимизации функции торгов Нэша $ \Pi_i (u_i(x_i)-u_i(0)) $ :


In [ ]:
NashOpt=[32.0724,39.1355,43.7921]

In [115]:
gamegroups = GLData.groupby('Game')

a = []
for g,data in gamegroups:
    data.sort_values(by=['Time','GrSubject'])
    a.append( data['x'].iloc[-3:].values )

In [116]:
a


Out[116]:
[array([38.13333333, 44.        , 32.86666667]),
 array([42.06666667, 41.70833333, 31.225     ]),
 array([ 166.66666667,   53.75      , -152.5       ]),
 array([ 0.15, 66.25, 48.6 ]),
 array([33.       , 28.5034256, 53.4965744]),
 array([41., 49., 25.]),
 array([25., 49., 41.]),
 array([41., 25., 49.]),
 array([25., 49., 41.]),
 array([24.83333333, 41.33333333, 48.83333333]),
 array([65.,  0., 50.]),
 array([ 43.33333333, -28.33333333, 100.        ]),
 array([45.  , 45.75, 24.25]),
 array([25., 41., 49.]),
 array([ 0. , 69.5, 45.5]),
 array([34.33333333, 42.        , 38.66666667]),
 array([32.33333333, 32.66666667, 46.66666667]),
 array([47.33333333, 21.66666667, 46.        ]),
 array([25., 49., 41.]),
 array([53.66666667, 26.75      , 34.58333333]),
 array([37.6       , 38.96666667, 38.4       ]),
 array([27.5       , 40.25      , 45.83333333]),
 array([48.33333333, 22.13333333, 44.53333333]),
 array([52.83333333, 38.33333333, 23.5       ]),
 array([46.33333333, 22.33333333, 46.33333333]),
 array([26.66666667, 46.66666667, 41.66666667]),
 array([50.        , 28.33333333, 36.66666667]),
 array([38.33333333, 25.33333333, 35.66666667]),
 array([34.85      , 42.76666667, 37.35      ]),
 array([68.66666667, 11.        , 33.66666667]),
 array([44.9       , 46.        , 24.06666667]),
 array([43.66666667, 47.66666667, 23.66666667]),
 array([23.39166667, 39.50833333, 52.1       ]),
 array([12.        , 89.        ,  9.83333333]),
 array([33.86666667, 49.43333333, 31.7       ]),
 array([34.43333333, 36.73333333, 43.43333333]),
 array([32.525     , 57.45868036, 25.01631964]),
 array([38.75, 49.25, 27.  ]),
 array([56.66666667, 42.5       , 15.83333333]),
 array([42.2919906 , 36.16666667, 36.54134273]),
 array([22.13333333, 42.33333333, 50.53333333])]

In [81]:
from scipy.spatial import distance

In [119]:
npd = distance.cdist(a,[[115/3,115/3,115/3],[49,41,25],[32.0724, 39.1355, 43.7921]],'cityblock')
npd2 = distance.cdist(a,[[115/3,115/3,115/3],[49,41,25],[32.0724, 39.1355, 43.7921]],'euclidean')

[np.mean(npd,axis=0),np.mean(npd2,axis=0)]


Out[119]:
[array([41.02181685, 49.6502236 , 42.39936481]),
 array([26.79171582, 32.52246141, 27.75504135])]

In [96]:
gamegroups = YHData.groupby('Game')

In [97]:
a = []
for g,data in gamegroups:
    data.sort_values(by=['Time','GrSubject'])
    a.append( data['x'].iloc[-3:].values )

In [99]:
npd = distance.cdist(a,[[49,41,25],[22.81,115/3,53.85]],'cityblock')
npd2 = distance.cdist(a,[[49,41,25],[22.81,115/3,53.85]],'euclidean')

In [100]:
np.mean(npd,axis=0)


Out[100]:
array([51.26294136, 53.61308444])

In [101]:
np.mean(npd2,axis=0)


Out[101]:
array([32.4326487 , 34.89020465])

In [98]:
a


Out[98]:
[array([38.33333333, 38.33333333, 38.33333333]),
 array([50.88495575, 40.7079646 , 23.40707965]),
 array([68.69666408, 44.60822343,  1.69511249]),
 array([43.07116105, 22.39700375, 49.53183521]),
 array([24.64285714, 65.71428571, 24.64285714]),
 array([45.72289157, 53.1124498 , 16.16465863]),
 array([  3.74230431,  10.11433597, 101.14335972]),
 array([37.77444254, 39.45111492, 37.77444254]),
 array([ 8.69747899,  9.66386555, 96.63865546]),
 array([37.57523646, 37.87188306, 39.55288048]),
 array([35.63511327, 43.72977346, 35.63511327]),
 array([32.45967742, 46.37096774, 36.16935484]),
 array([27.38095238, 21.9047619 , 65.71428571]),
 array([39.57322552, 37.1967655 , 38.23000898])]

In [ ]:


In [102]:
def f(x,r):
    import math
    return math.sqrt(r+x)-math.sqrt(r)

In [103]:
def Nf(x,r):
    return f(x[0],r[0])*f(x[1],r[1])*f(x[2],r[2])

In [107]:
Nf([22.81,115/3,53.85],[1,9,25])


Out[107]:
58.39938875025514

In [105]:
Nf([20,40,55],[1,9,25])


Out[105]:
56.522610716240145

In [108]:
Nf([115/3,115/3,115/3],[1,9,25])


Out[108]:
60.50607771202381

In [109]:
22.81+115/3+53.85


Out[109]:
114.99333333333334

In [110]:
Nf([32.0724, 39.1355, 43.7921],[1,9,25])


Out[110]:
61.62857193511759

In [114]:
Nf([49,41,25],[1,9,25])


Out[114]:
51.187950266179705

Оценка распределения длин КП


In [10]:
cbs = getCBwithEps(YHData)

In [11]:
notStoppedCbs = cbs[cbs['te']!=cbs['gamelength']]

In [12]:
lengths = (notStoppedCbs['te']-notStoppedCbs['ts'])

In [13]:
lengths.values


Out[13]:
array([1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 3, 8, 3, 5, 1, 1, 1,
       1, 2, 3, 2, 2, 2, 1, 5, 1, 1, 6, 2, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
       4, 2, 5, 1, 1, 1, 1, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1,
       1, 4, 5, 1, 3, 2, 1, 2, 2, 2, 1, 7, 3, 2, 1, 1, 1, 1, 3, 2, 3, 6,
       1, 6, 8, 1, 8, 1, 3, 11, 1, 2, 5, 1, 1, 1, 2, 1, 2, 6, 3, 1, 3, 1,
       2, 4, 1, 1, 4, 1, 3, 2], dtype=object)

In [2]:
from scipy import stats
from scipy.stats import logser
from statsmodels.base.model import GenericLikelihoodModel

In [15]:
class LogFit(GenericLikelihoodModel):
    def __init__(self, endog, exog=None, **kwds):
        if exog is None:
            exog = np.zeros_like(endog)
            
        super(LogFit, self).__init__(endog, exog, **kwds)
    
    def nloglikeobs(self, params):

        return -np.log(logser.pmf(self.endog, p=params[0]))
    
    def fit(self, start_params=None, maxiter=10000, maxfun=5000, **kwds):
        if start_params is None:
            excess_zeros = 0.5 #(self.endog == 0).mean() - stats.poisson.pmf(0, lambda_start)
            
            start_params = np.array([excess_zeros])
            
        return super(LogFit, self).fit(start_params=start_params,
                                                    maxiter=maxiter, maxfun=maxfun, **kwds)

In [20]:
results = LogFit(lengths.values.tolist()).fit()


Optimization terminated successfully.
         Current function value: 1.520917
         Iterations: 14
         Function evaluations: 28

In [21]:
plog = results.params.item()

In [22]:
plog


Out[22]:
0.7646484375000007

In [66]:
notStoppedCbs.shape


Out[66]:
(118, 5)

In [74]:
118*(1-logser.pmf(1,plog)-logser.pmf(2,plog)-logser.pmf(3,plog)-logser.pmf(4,plog)-logser.pmf(5,plog)-logser.pmf(6,plog)) #smallclass


Out[74]:
5.676809626210824

smallclass <~ 5 then use classes 1,2,3,4,5,[6,...]


In [108]:
def myclass(a):
    if a > 4:
        return 5
    else:
        return a

In [96]:
lengths.index = lengths.values

In [109]:
histclasses = lengths.groupby(myclass).count()

In [110]:
histclasses


Out[110]:
1    63
2    21
3    13
4     5
5    16
dtype: int64

In [113]:
expclassesp = [logser.pmf(1,plog),logser.pmf(2,plog),logser.pmf(3,plog),logser.pmf(4,plog)]
expclassesp.append( 1 - np.sum(expclassesp) )

In [114]:
expclasses = np.multiply(118,expclassesp)

In [117]:
stats.chisquare(histclasses.values,expclasses,1)


Out[117]:
Power_divergenceResult(statistic=1.84401018997024, pvalue=0.6054049725007631)

Гипотеза падения выигрышей


In [67]:
arr = np.loadtxt('2.txt')

In [61]:
np.shape(arr)


Out[61]:
(2, 198)

In [46]:
stats.wilcoxon(arr[0],arr[1],zero_method='wilcox')


Out[46]:
WilcoxonResult(statistic=2110.0, pvalue=6.705348674323277e-06)

In [23]:
d=pd.DataFrame(arr[0]-arr[1])

In [25]:
d['abs']=abs(d[0])

In [30]:
dsrt = d.sort_values(by='abs')

In [39]:
dsrtnn = dsrt[dsrt['abs']>0].copy()

In [40]:
dsrtnn['rank'] = range(1,dsrtnn.shape[0]+1)

In [45]:
dsrtnn[dsrtnn[0]<0]['rank'].sum()


Out[45]:
2110

In [51]:
(np.sign(dsrtnn[0])*dsrtnn['rank']).sum()


Out[51]:
3655.0

In [52]:
from math import sqrt

In [53]:
n = 125
sigma = sqrt( n*(n+1)*(2*n+1)/6 )

In [54]:
sigma


Out[54]:
811.7111555227019

In [55]:
sigma*1.96


Out[55]:
1590.9538648244957

In [57]:
2*(1-stats.norm.cdf(3655.0/sigma))


Out[57]:
6.7053486743073876e-06

In [68]:
stats.mannwhitneyu(arr[0],arr[1],alternative='less')


Out[68]:
MannwhitneyuResult(statistic=20470.5, pvalue=0.9997420978922387)

Нэш-торги


In [7]:
YHg=YHData.groupby(['Game','Time'])

In [46]:
YHData.shape


Out[46]:
(1035, 16)

In [32]:
YHg.sum()


Out[32]:
Group GrSubject Type Gain Penalty x s1 s2 s3 AcceptAdvice CalcCount CalcAdviceCount UseHelp
Game Time
40 1 3 6 35.0 6.812121 11.59900 115.0 0.0 215.0 0.0 0.0 0.0 0.0 2.0
2 3 6 35.0 6.808913 11.62040 115.0 0.0 215.1 0.0 0.0 3.0 0.0 3.0
3 3 6 35.0 6.812121 11.59900 115.0 0.0 215.0 0.0 0.0 3.0 0.0 1.0
4 3 6 35.0 15.951731 2.57165 115.0 0.0 102.6 0.0 0.0 6.0 0.0 3.0
5 3 6 35.0 6.833104 14.15300 115.0 0.0 216.5 0.0 0.0 8.0 0.0 2.0
6 3 6 35.0 11.057325 7.45100 115.0 0.0 172.0 0.0 0.0 4.0 0.0 3.0
7 3 6 35.0 15.000859 3.33200 115.0 0.0 121.1 0.0 0.0 3.0 0.0 3.0
8 3 6 35.0 15.015961 3.34400 115.0 0.0 121.2 0.0 0.0 1.0 0.0 4.0
9 3 6 35.0 14.507315 6.40000 115.0 0.0 140.0 0.0 0.0 10.0 0.0 5.0
10 3 6 35.0 13.965651 7.14000 115.0 0.0 151.0 0.0 0.0 22.0 0.0 6.0
11 3 6 35.0 15.947102 4.46180 115.0 0.0 134.8 0.0 0.0 14.0 0.0 9.0
12 3 6 35.0 13.840881 4.69100 115.0 0.0 142.0 0.0 0.0 6.0 0.0 5.0
13 3 6 35.0 2.249649 18.95000 115.0 0.0 245.0 0.0 0.0 3.0 0.0 2.0
14 3 6 35.0 6.857738 14.00000 115.0 0.0 215.0 0.0 0.0 7.0 0.0 4.0
15 3 6 35.0 19.004806 2.00000 115.0 0.0 85.0 0.0 0.0 7.0 0.0 3.0
16 3 6 35.0 19.492161 0.90000 115.0 0.0 60.0 0.0 0.0 3.0 0.0 3.0
17 3 6 35.0 19.242015 1.70000 115.0 0.0 75.0 0.0 0.0 5.0 0.0 5.0
18 3 6 35.0 19.184618 1.81000 115.0 0.0 77.0 0.0 0.0 2.0 0.0 2.0
19 3 6 35.0 19.358979 1.65000 115.0 0.0 75.0 0.0 0.0 9.0 0.0 8.0
20 3 6 35.0 9.501888 10.80000 115.0 0.0 195.0 0.0 0.0 5.0 0.0 4.0
21 3 6 35.0 10.900591 8.65000 115.0 0.0 185.0 0.0 0.0 1.0 0.0 5.0
22 3 6 35.0 19.732647 0.65500 115.0 0.0 56.0 0.0 0.0 6.0 0.0 5.0
23 3 6 35.0 13.439753 4.59100 115.0 0.0 152.0 0.0 0.0 1.0 0.0 4.0
24 3 6 35.0 13.636244 4.77050 115.0 0.0 156.1 0.0 0.0 6.0 0.0 4.0
25 3 6 35.0 5.450615 12.99100 115.0 0.0 227.0 0.0 0.0 2.0 0.0 3.0
26 3 6 35.0 17.776815 1.07150 115.0 0.0 66.1 0.0 0.0 5.0 0.0 2.0
27 3 6 35.0 17.944727 0.86000 115.0 0.0 61.0 0.0 0.0 2.0 0.0 2.0
28 3 6 35.0 17.776815 1.07150 115.0 0.0 66.1 0.0 0.0 1.0 0.0 2.0
29 3 6 35.0 17.742291 1.06500 115.0 0.0 66.0 0.0 0.0 1.0 0.0 1.0
30 3 6 35.0 17.776815 1.07150 115.0 0.0 66.1 0.0 0.0 1.0 0.0 5.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
93 11 6 6 35.0 18.353990 1.58000 115.0 0.0 81.0 0.0 0.0 9.0 0.0 2.0
12 6 6 35.0 16.348287 4.77500 115.0 0.0 120.0 0.0 0.0 4.0 0.0 2.0
13 6 6 35.0 18.106282 3.00000 115.0 0.0 95.0 0.0 0.0 20.0 0.0 1.0
14 6 6 35.0 18.352494 2.67500 115.0 0.0 90.0 0.0 0.0 10.0 0.0 2.0
15 6 6 35.0 17.829075 3.32500 115.0 0.0 100.0 0.0 0.0 4.0 0.0 1.0
16 6 6 35.0 17.216159 3.97500 115.0 0.0 110.0 0.0 0.0 11.0 0.0 1.0
17 6 6 35.0 16.786546 4.37500 115.0 0.0 115.0 0.0 0.0 6.0 0.0 2.0
18 6 6 35.0 17.510346 3.66000 115.0 0.0 107.0 0.0 0.0 20.0 0.0 1.0
19 6 6 35.0 18.812764 2.17500 115.0 0.0 90.0 0.0 0.0 8.0 0.0 1.0
20 6 6 35.0 17.848249 3.20000 115.0 0.0 105.0 0.0 0.0 19.0 0.0 2.0
94 1 9 6 35.0 18.719680 2.20000 115.0 0.0 82.0 0.0 0.0 0.0 0.0 0.0
2 9 6 35.0 14.307001 5.81500 115.0 0.0 146.0 0.0 0.0 4.0 0.0 3.0
3 9 6 35.0 15.672237 5.24000 115.0 0.0 127.0 0.0 0.0 3.0 0.0 3.0
4 9 6 35.0 17.203957 3.90600 115.0 0.0 108.3 0.0 0.0 3.0 0.0 5.0
5 9 6 35.0 14.287087 6.17750 115.0 0.0 143.3 0.0 0.0 2.0 0.0 3.0
6 9 6 35.0 18.472328 2.67500 115.0 0.0 90.0 0.0 0.0 5.0 0.0 5.0
7 9 6 35.0 18.515589 2.66100 115.0 0.0 90.0 0.0 0.0 8.0 0.0 2.0
8 9 6 35.0 18.861407 2.32600 115.0 0.0 85.0 0.0 0.0 2.0 0.0 4.0
9 9 6 35.0 14.976465 5.67600 115.0 0.0 135.0 0.0 0.0 10.0 0.0 3.0
10 9 6 35.0 17.638674 3.46500 115.0 0.0 102.0 0.0 0.0 6.0 0.0 4.0
11 9 6 35.0 17.672526 3.46500 115.0 0.0 102.0 0.0 0.0 7.0 0.0 4.0
12 9 6 35.0 17.751017 3.39500 115.0 0.0 101.0 0.0 0.0 1.0 0.0 1.0
13 9 6 35.0 17.113443 3.95500 115.0 0.0 109.0 0.0 0.0 15.0 0.0 3.0
14 9 6 35.0 15.871124 5.04300 115.0 0.0 124.0 0.0 0.0 23.0 0.0 10.0
15 9 6 35.0 16.596796 4.47300 115.0 0.0 116.0 0.0 0.0 4.0 0.0 2.0
16 9 6 35.0 17.906667 3.25500 115.0 0.0 99.0 0.0 0.0 3.0 0.0 1.0
17 9 6 35.0 17.113443 3.95500 115.0 0.0 109.0 0.0 0.0 11.0 0.0 4.0
18 9 6 35.0 16.866384 4.20693 115.0 0.0 112.4 0.0 0.0 6.0 0.0 3.0
19 9 6 35.0 17.016400 4.06600 115.0 0.0 110.5 0.0 0.0 7.0 0.0 3.0
20 9 6 35.0 16.991428 4.12790 115.0 0.0 111.3 0.0 0.0 15.0 0.0 3.0

345 rows × 13 columns

Функции расчёта выигрышей в игре


In [8]:
class Game:
    import numpy as np
    def __init__(self,R,s0,types):
        self.R = R
        self.s0 = np.array(s0)
        self.n = len(s0)
        self.types = np.array(types)
    def u(self,x):
        return self.np.sqrt(self.types+x)
game = Game( 115,(115/3,115/3,115/3), (1,9,25))

In [9]:
class Mechanism:
    def __init__(self,game,params,xfunc,tfunc):
        self.game = game
        for k,v in params.items():
            setattr(self,k,v)
        self.xfunc = xfunc
        self.tfunc = tfunc
        
    def x(self,s):
        return self.xfunc(s,self.game)
    def t(self,s):
        return self.tfunc(s,self.game,self)
    def f(self,s):
        return game.u(self.x(s))-self.t(s)

YHMechanism = Mechanism(game,
                        {'beta':0.0005}, 
                        lambda s,g: s*g.R/s.sum(),
                        lambda s,g,m: m.beta*s*(np.repeat(s.sum(),3)-s))

class GLClass:
    from scipy.spatial import distance
    def __init__(self):
        self.glx = lambda s,g: s.sum(axis=0) / g.n
    def glt(self,s,g,m):
        p = m.beta * self.distance.cdist([self.glx(s,g)],s,'sqeuclidean')
        pmean = m.alfa * p.mean()
        return p - pmean
GL = GLClass()
    
GLMechanism = Mechanism(game,{'beta':0.0005,'alfa':1},
                        GL.glx,
                        GL.glt
                       )

In [104]:
s = np.array([[70,33.248853,11.751147],[26.5,77,11.5],[21.143719,33.856281,60]])
print(GLMechanism.x(s),GLMechanism.t(s),GLMechanism.f(s))


[39.214573   48.03504467 27.75038233] [[ 0.00206069 -0.0767621   0.07470141]] [[6.33943543 7.62891707 7.18824444]]

In [101]:
GLData.iloc[1800:1803]


Out[101]:
Game Time Subject Group GrSubject Type Gain Penalty x s1 s2 s3 AcceptAdvice CalcCount CalcAdviceCount UseHelp
3534 51 8 11 4 3 25.0 7.188244 0.074701 27.750382 21.143719 33.856281 60.000000 1.0 0.0 1.0 NaN
3535 51 8 12 4 1 1.0 6.339435 0.002061 39.214573 70.000000 33.248853 11.751147 1.0 0.0 6.0 NaN
3536 51 8 10 4 2 9.0 7.628917 -0.076762 48.035044 26.500000 77.000000 11.500000 0.0 0.0 0.0 NaN

In [126]:
p=YHData.iloc[21:24]
p.sort_values(by="GrSubject")
print(p)


      Game  Time Subject  Group  GrSubject  Type      Gain  Penalty  \
2553    40     8       6      1          2   9.0  5.228284    1.624   
2554    40     8      10      1          3  25.0  8.397277    1.648   
2555    40     8      11      1          1   1.0  1.390400    0.072   

              x  s1    s2  s3  AcceptAdvice  CalcCount  CalcAdviceCount  \
2553  37.953795 NaN  40.0 NaN           0.0        0.0              0.0   
2554  75.907591 NaN  80.0 NaN           0.0        1.0              0.0   
2555   1.138614 NaN   1.2 NaN           0.0        0.0              0.0   

      UseHelp  
2553      1.0  
2554      1.0  
2555      2.0  

In [11]:
print(YHMechanism.beta)
s = np.array([1.2,40,80])
print(YHMechanism.t(s))
YHMechanism.f(s)


0.0005
[0.072 1.624 1.648]
Out[11]:
array([1.39040003, 5.22828395, 8.39727704])

In [12]:
def Unash(f,f0):
    return (f-f0).prod()

print(YHMechanism.game.s0)

f0 = YHMechanism.game.u([0,0,0])
print(f0)

Unash(f0,s)


[38.33333333 38.33333333 38.33333333]
[1. 3. 5.]
Out[12]:
-554.9999999999999

In [115]:
import itertools
res = []
for name,group in YHg:
    group = group.sort_values(by='GrSubject')
    if name[1] == 1 :
        curname = name[0]
        prevg = group
        continue
    
    fprev = prevg['Gain'].values
    sprev = prevg['s2'].values
    s = group['s2'].values
    s1, s2, s3 = sprev.copy(), sprev.copy(), sprev.copy()
    s1[0] = s[0]
    s2[1] = s[1]
    s3[2] = s[2]
    f1 = YHMechanism.f(s1)
    f2 = YHMechanism.f(s2)
    f3 = YHMechanism.f(s3)
    U = Unash(fprev,f0)
    U1 = Unash(f1,f0)
    U2 = Unash(f2,f0)
    U3 = Unash(f3,f0)
    Unew = Unash(YHMechanism.f(s),f0)
    res.append( [a for a in itertools.chain(name,[U1>U,U2>U,U3>U,Unew>U,U,U1,U2,U3,Unew])] )
    prevg = group
    #print(name,prev['Gain'])

In [116]:
a = np.vstack(res)

In [117]:
pda = pd.DataFrame(a); pda


Out[117]:
0 1 2 3 4 5 6 7 8 9 10
0 40.0 2.0 1.0 0.0 0.0 1.0 0.166445 0.182068 0.166445 0.166445 0.182068
1 40.0 3.0 0.0 1.0 1.0 0.0 0.182068 0.166445 0.182068 0.182068 0.166445
2 40.0 4.0 1.0 1.0 0.0 1.0 0.166445 0.182068 0.663205 0.141136 4.637448
3 40.0 5.0 0.0 0.0 1.0 0.0 4.637448 2.334728 4.523720 4.758127 2.365943
4 40.0 6.0 1.0 0.0 0.0 0.0 2.365943 4.312664 -42.795611 -2.119715 0.061842
5 40.0 7.0 1.0 1.0 0.0 1.0 0.061842 0.064509 2.568412 0.061842 2.765782
6 40.0 8.0 1.0 1.0 1.0 1.0 2.765782 2.955366 2.765782 2.765782 2.955366
7 40.0 9.0 0.0 0.0 1.0 1.0 2.955366 1.349725 2.955366 5.147459 5.049548
8 40.0 10.0 0.0 1.0 1.0 0.0 5.049548 -0.238005 6.277598 11.369736 0.827750
9 40.0 11.0 1.0 0.0 1.0 1.0 0.827750 22.653564 0.456697 3.488995 3.342179
10 40.0 12.0 0.0 0.0 0.0 0.0 3.342179 1.879508 3.342179 -0.429276 0.822057
11 40.0 13.0 0.0 1.0 0.0 0.0 0.822057 -20.790588 1.503424 0.822057 -8.576736
12 40.0 14.0 1.0 0.0 1.0 1.0 -8.576736 -0.789690 -70.726083 -8.576736 0.096981
13 40.0 15.0 0.0 1.0 0.0 1.0 0.096981 -0.343730 4.178133 -0.509597 9.742060
14 40.0 16.0 1.0 1.0 1.0 1.0 9.742060 18.127277 9.742060 14.618917 26.487439
15 40.0 17.0 0.0 1.0 1.0 1.0 26.487439 24.755714 26.487439 29.869838 28.245983
16 40.0 18.0 0.0 0.0 0.0 0.0 28.245983 27.229603 28.245983 28.245983 27.229603
17 40.0 19.0 0.0 0.0 0.0 0.0 27.229603 25.544806 27.229603 23.837908 22.339399
18 40.0 20.0 0.0 0.0 0.0 0.0 22.339399 14.618917 22.339399 0.109906 -0.011539
19 40.0 21.0 1.0 0.0 1.0 0.0 -0.011539 1.428371 -30.885469 5.049548 -1.353537
20 40.0 22.0 0.0 1.0 1.0 1.0 -1.353537 -1.432622 14.738696 0.315421 4.688317
21 40.0 23.0 0.0 0.0 0.0 0.0 4.688317 1.763637 4.688317 1.367518 0.811101
22 40.0 24.0 1.0 0.0 1.0 0.0 0.811101 0.872280 0.343788 7.132009 0.065471
23 40.0 25.0 0.0 0.0 1.0 1.0 0.065471 0.064039 0.065471 0.374285 0.343788
24 40.0 26.0 1.0 1.0 1.0 1.0 0.343788 0.374285 0.811101 0.449728 9.907318
25 40.0 27.0 0.0 1.0 1.0 0.0 9.907318 9.234410 9.907318 10.370478 9.673695
26 40.0 28.0 1.0 1.0 0.0 1.0 9.673695 10.370478 9.673695 9.234410 9.907318
27 40.0 29.0 0.0 1.0 1.0 0.0 9.907318 9.234410 9.907318 9.907318 9.234410
28 40.0 30.0 1.0 0.0 0.0 1.0 9.234410 9.907318 9.234410 9.234410 9.907318
29 40.0 31.0 0.0 1.0 1.0 0.0 9.907318 9.234410 9.907318 9.907318 9.234410
... ... ... ... ... ... ... ... ... ... ... ...
301 93.0 10.0 0.0 0.0 0.0 0.0 11.019402 8.904934 11.019402 2.090976 1.148829
302 93.0 11.0 1.0 0.0 1.0 1.0 1.148829 3.311675 1.006632 6.937478 3.097994
303 93.0 12.0 1.0 1.0 0.0 1.0 3.097994 3.659645 11.510484 2.538654 10.931471
304 93.0 13.0 1.0 0.0 1.0 1.0 10.931471 19.565361 10.931471 14.255867 23.908020
305 93.0 14.0 1.0 1.0 1.0 1.0 23.908020 27.216191 23.908020 23.908020 27.216191
306 93.0 15.0 0.0 0.0 0.0 0.0 27.216191 20.533396 27.216191 27.216191 20.533396
307 93.0 16.0 0.0 1.0 1.0 0.0 20.533396 14.255867 20.533396 20.533396 14.255867
308 93.0 17.0 1.0 1.0 0.0 0.0 14.255867 14.255867 14.255867 12.646727 12.646727
309 93.0 18.0 0.0 1.0 1.0 1.0 12.646727 10.050396 14.775667 15.098183 14.316779
310 93.0 19.0 0.0 1.0 0.0 0.0 14.316779 11.607162 16.145505 13.467758 12.508615
311 93.0 20.0 0.0 1.0 1.0 0.0 12.508615 10.406345 12.508615 14.384584 11.804666
312 94.0 2.0 0.0 1.0 0.0 0.0 32.159880 29.128283 32.827630 5.653954 4.619464
313 94.0 3.0 0.0 0.0 1.0 1.0 4.619464 1.431338 4.398269 16.995343 9.212563
314 94.0 4.0 1.0 0.0 1.0 1.0 9.212563 11.568157 6.994575 16.940084 16.889642
315 94.0 5.0 1.0 0.0 0.0 0.0 16.889642 21.191311 16.889642 3.149017 5.086209
316 94.0 6.0 0.0 1.0 1.0 1.0 5.086209 4.497737 5.995839 24.779899 25.518472
317 94.0 7.0 0.0 1.0 1.0 0.0 25.518472 24.120655 25.518472 25.954410 24.547687
318 94.0 8.0 1.0 1.0 1.0 1.0 24.547687 24.547687 24.547687 24.830627 24.830627
319 94.0 9.0 1.0 1.0 0.0 0.0 24.830627 24.830627 24.830627 7.220162 7.220162
320 94.0 10.0 0.0 1.0 1.0 1.0 7.220162 6.130362 8.180416 20.547975 20.167856
321 94.0 11.0 0.0 0.0 1.0 0.0 20.167856 20.167856 18.620872 21.395717 19.802233
322 94.0 12.0 0.0 0.0 1.0 1.0 19.802233 19.802233 19.802233 20.174691 20.174691
323 94.0 13.0 1.0 1.0 0.0 0.0 20.174691 20.174691 20.174691 16.953616 16.953616
324 94.0 14.0 1.0 0.0 0.0 0.0 16.953616 18.176515 14.453028 11.941420 10.803647
325 94.0 15.0 0.0 0.0 1.0 1.0 10.803647 9.858043 9.957934 15.590065 13.465462
326 94.0 16.0 0.0 1.0 1.0 1.0 13.465462 13.465462 16.953616 17.012375 20.876242
327 94.0 17.0 0.0 0.0 0.0 0.0 20.876242 20.876242 20.876242 16.953616 16.953616
328 94.0 18.0 0.0 0.0 0.0 0.0 16.953616 16.892946 15.301364 16.953616 15.243520
329 94.0 19.0 0.0 1.0 1.0 1.0 15.243520 14.440058 16.892946 15.243520 16.049603
330 94.0 20.0 0.0 0.0 1.0 0.0 16.049603 15.751435 14.440058 17.273399 15.311141

331 rows × 11 columns


In [109]:
pda = pda[[2,3,4,5]]

YH

Игры с механизмом YH и механизмом остановки "по договорённости" - никто не поменял заявок. Всего шагов 1035, если брать для каждого игрока в отдельности, то 3105 = 1035 * 3

Функция Нэша: $ U(f,f^0)=\prod_{i} (f_i -f_i^0) $

Базовые выигрыши: $ f^0 = u(0,0,0) $

Определения для текущего шага $t>1$: $$ U_{prev} = U(f(s^{t-1}),f^0) $$ $$ U_i =U(f(s_i^t,s_{-i}^{t-1}),f^0) $$ $$ U_{new}=U(f(s^t),f^0) $$


In [118]:
pda[pda[2]>0]


Out[118]:
0 1 2 3 4 5 6 7 8 9 10
0 40.0 2.0 1.0 0.0 0.0 1.0 0.166445 0.182068 0.166445 0.166445 0.182068
2 40.0 4.0 1.0 1.0 0.0 1.0 0.166445 0.182068 0.663205 0.141136 4.637448
4 40.0 6.0 1.0 0.0 0.0 0.0 2.365943 4.312664 -42.795611 -2.119715 0.061842
5 40.0 7.0 1.0 1.0 0.0 1.0 0.061842 0.064509 2.568412 0.061842 2.765782
6 40.0 8.0 1.0 1.0 1.0 1.0 2.765782 2.955366 2.765782 2.765782 2.955366
9 40.0 11.0 1.0 0.0 1.0 1.0 0.827750 22.653564 0.456697 3.488995 3.342179
12 40.0 14.0 1.0 0.0 1.0 1.0 -8.576736 -0.789690 -70.726083 -8.576736 0.096981
14 40.0 16.0 1.0 1.0 1.0 1.0 9.742060 18.127277 9.742060 14.618917 26.487439
19 40.0 21.0 1.0 0.0 1.0 0.0 -0.011539 1.428371 -30.885469 5.049548 -1.353537
22 40.0 24.0 1.0 0.0 1.0 0.0 0.811101 0.872280 0.343788 7.132009 0.065471
24 40.0 26.0 1.0 1.0 1.0 1.0 0.343788 0.374285 0.811101 0.449728 9.907318
26 40.0 28.0 1.0 1.0 0.0 1.0 9.673695 10.370478 9.673695 9.234410 9.907318
28 40.0 30.0 1.0 0.0 0.0 1.0 9.234410 9.907318 9.234410 9.234410 9.907318
30 40.0 32.0 1.0 0.0 0.0 1.0 9.234410 16.132933 9.234410 9.234410 16.132933
32 40.0 34.0 1.0 0.0 0.0 0.0 12.676739 13.202761 11.741882 12.676739 12.246920
35 40.0 37.0 1.0 1.0 0.0 0.0 5.771193 5.771193 5.771193 0.340359 0.340359
36 40.0 38.0 1.0 0.0 1.0 1.0 0.340359 0.653560 -55.461912 5.771193 1.145178
39 40.0 41.0 1.0 1.0 1.0 1.0 18.127277 18.231286 18.127277 18.127277 18.231286
41 40.0 43.0 1.0 0.0 0.0 0.0 29.703447 30.054109 8.532591 29.703447 8.526135
42 40.0 44.0 1.0 1.0 1.0 1.0 8.526135 8.532591 8.526135 8.526135 8.532591
45 40.0 47.0 1.0 1.0 1.0 1.0 0.280727 0.337738 1.811707 1.287904 0.310764
46 40.0 48.0 1.0 1.0 1.0 1.0 0.310764 0.315421 4.821864 0.376538 29.703447
47 40.0 49.0 1.0 0.0 0.0 0.0 29.703447 30.054109 29.703447 28.033631 28.370345
48 40.0 50.0 1.0 0.0 1.0 0.0 28.370345 28.412075 21.823612 28.370345 21.708770
51 40.0 53.0 1.0 0.0 0.0 0.0 11.965204 13.044795 11.500736 0.273401 0.184216
52 40.0 54.0 1.0 0.0 1.0 1.0 0.184216 0.227624 -1.210817 7.538718 0.590811
55 40.0 57.0 1.0 0.0 0.0 1.0 -0.329101 0.652287 -0.329101 -0.329101 0.652287
56 40.0 58.0 1.0 1.0 0.0 1.0 0.652287 1.145178 16.617708 0.206742 4.809329
57 40.0 59.0 1.0 1.0 0.0 0.0 4.809329 4.809329 4.809329 1.428371 1.428371
59 41.0 2.0 1.0 0.0 0.0 1.0 0.195423 2.928457 -0.259158 -0.385351 7.398591
... ... ... ... ... ... ... ... ... ... ... ...
267 61.0 10.0 1.0 0.0 1.0 0.0 0.256614 0.256614 -0.050234 0.256614 -0.050234
269 61.0 12.0 1.0 0.0 1.0 1.0 10.681631 10.681631 10.280405 15.262984 14.787099
270 61.0 13.0 1.0 1.0 1.0 1.0 14.787099 14.787099 14.787099 14.904347 14.904347
271 61.0 14.0 1.0 0.0 1.0 0.0 14.904347 14.904347 13.948212 15.254722 14.288263
272 61.0 15.0 1.0 0.0 0.0 0.0 14.288263 14.288263 13.327028 13.948212 12.997630
273 62.0 2.0 1.0 1.0 1.0 1.0 9.181176 9.181176 9.181176 9.181176 9.181176
274 92.0 2.0 1.0 1.0 0.0 1.0 4.661946 6.883776 5.643745 3.964402 7.108376
276 92.0 4.0 1.0 0.0 0.0 1.0 4.887415 8.857505 2.754475 4.404031 5.420046
278 92.0 6.0 1.0 0.0 1.0 0.0 17.040089 18.843305 11.702339 17.919545 14.113573
280 92.0 8.0 1.0 0.0 1.0 0.0 13.617655 14.759380 7.203388 15.521701 9.578957
281 92.0 9.0 1.0 1.0 1.0 1.0 9.578957 12.019140 16.738879 11.040646 21.876681
285 92.0 13.0 1.0 0.0 0.0 0.0 23.026566 28.855323 18.424918 20.567738 20.038725
286 92.0 14.0 1.0 0.0 0.0 0.0 20.038725 21.808118 20.038725 13.364928 14.570646
289 92.0 17.0 1.0 1.0 0.0 0.0 14.163552 17.231876 14.163552 9.448355 11.479247
291 92.0 19.0 1.0 1.0 1.0 1.0 16.696433 18.329844 16.696433 17.931983 19.693373
293 93.0 2.0 1.0 1.0 1.0 1.0 2.600666 2.600666 2.600666 17.438164 17.438164
295 93.0 4.0 1.0 1.0 0.0 0.0 16.330616 16.330616 22.322645 7.614089 12.852322
297 93.0 6.0 1.0 1.0 1.0 1.0 0.126117 5.920307 0.684981 1.030050 10.931471
299 93.0 8.0 1.0 1.0 1.0 1.0 1.649764 1.649764 1.649764 13.502393 13.502393
302 93.0 11.0 1.0 0.0 1.0 1.0 1.148829 3.311675 1.006632 6.937478 3.097994
303 93.0 12.0 1.0 1.0 0.0 1.0 3.097994 3.659645 11.510484 2.538654 10.931471
304 93.0 13.0 1.0 0.0 1.0 1.0 10.931471 19.565361 10.931471 14.255867 23.908020
305 93.0 14.0 1.0 1.0 1.0 1.0 23.908020 27.216191 23.908020 23.908020 27.216191
308 93.0 17.0 1.0 1.0 0.0 0.0 14.255867 14.255867 14.255867 12.646727 12.646727
314 94.0 4.0 1.0 0.0 1.0 1.0 9.212563 11.568157 6.994575 16.940084 16.889642
315 94.0 5.0 1.0 0.0 0.0 0.0 16.889642 21.191311 16.889642 3.149017 5.086209
318 94.0 8.0 1.0 1.0 1.0 1.0 24.547687 24.547687 24.547687 24.830627 24.830627
319 94.0 9.0 1.0 1.0 0.0 0.0 24.830627 24.830627 24.830627 7.220162 7.220162
323 94.0 13.0 1.0 1.0 0.0 0.0 20.174691 20.174691 20.174691 16.953616 16.953616
324 94.0 14.0 1.0 0.0 0.0 0.0 16.953616 18.176515 14.453028 11.941420 10.803647

177 rows × 11 columns


In [110]:
a = (pda[pda>0].count()).values

In [113]:
pd.DataFrame({'Критерии':['U1 > Uprev','U2 > Uprev','U3 > Uprev','U1>Uprev & U2>Uprev & U3>Uprev',
                          'U1>Uprev & U2>Uprev & U3>Uprev & Unew > Uprev','Unew > Uprev',
                          'Unew > Uprev & Exist Ui < Uprev','Unew > Uprev & All Ui < Uprev'],
              'Число подходящих ходов':[a[0],a[1],a[2],pda[(pda[2]*pda[3]*pda[4]==1)].shape[0],
                                       pda[pda[2]*pda[3]*pda[4]*pda[5]==1].shape[0],
                                       pda[pda[5]==1].shape[0],pda[(pda[5]==1) & (pda[2]*pda[3]*pda[4]==0)].shape[0],
                                       pda[(pda[5]==1) & (pda[2]+pda[3]+pda[4]==0)].shape[0]
                                       ]
             })


Out[113]:
Критерии Число подходящих ходов
0 U1 > Uprev 177
1 U2 > Uprev 179
2 U3 > Uprev 189
3 U1>Uprev & U2>Uprev & U3>Uprev 63
4 U1>Uprev & U2>Uprev & U3>Uprev & Unew > Uprev 63
5 Unew > Uprev 165
6 Unew > Uprev & Exist Ui < Uprev 102
7 Unew > Uprev & All Ui < Uprev 0

In [13]:
YH40 = YHData[YHData['Game']==40].groupby(['Game','Time'])

In [15]:
YH40.sum()


Out[15]:
Group GrSubject Type Gain Penalty x s1 s2 s3 AcceptAdvice CalcCount CalcAdviceCount UseHelp
Game Time
40 1 3 6 35.0 6.812121 11.59900 115.0 0.0 215.0 0.0 0.0 0.0 0.0 2.0
2 3 6 35.0 6.808913 11.62040 115.0 0.0 215.1 0.0 0.0 3.0 0.0 3.0
3 3 6 35.0 6.812121 11.59900 115.0 0.0 215.0 0.0 0.0 3.0 0.0 1.0
4 3 6 35.0 15.951731 2.57165 115.0 0.0 102.6 0.0 0.0 6.0 0.0 3.0
5 3 6 35.0 6.833104 14.15300 115.0 0.0 216.5 0.0 0.0 8.0 0.0 2.0
6 3 6 35.0 11.057325 7.45100 115.0 0.0 172.0 0.0 0.0 4.0 0.0 3.0
7 3 6 35.0 15.000859 3.33200 115.0 0.0 121.1 0.0 0.0 3.0 0.0 3.0
8 3 6 35.0 15.015961 3.34400 115.0 0.0 121.2 0.0 0.0 1.0 0.0 4.0
9 3 6 35.0 14.507315 6.40000 115.0 0.0 140.0 0.0 0.0 10.0 0.0 5.0
10 3 6 35.0 13.965651 7.14000 115.0 0.0 151.0 0.0 0.0 22.0 0.0 6.0
11 3 6 35.0 15.947102 4.46180 115.0 0.0 134.8 0.0 0.0 14.0 0.0 9.0
12 3 6 35.0 13.840881 4.69100 115.0 0.0 142.0 0.0 0.0 6.0 0.0 5.0
13 3 6 35.0 2.249649 18.95000 115.0 0.0 245.0 0.0 0.0 3.0 0.0 2.0
14 3 6 35.0 6.857738 14.00000 115.0 0.0 215.0 0.0 0.0 7.0 0.0 4.0
15 3 6 35.0 19.004806 2.00000 115.0 0.0 85.0 0.0 0.0 7.0 0.0 3.0
16 3 6 35.0 19.492161 0.90000 115.0 0.0 60.0 0.0 0.0 3.0 0.0 3.0
17 3 6 35.0 19.242015 1.70000 115.0 0.0 75.0 0.0 0.0 5.0 0.0 5.0
18 3 6 35.0 19.184618 1.81000 115.0 0.0 77.0 0.0 0.0 2.0 0.0 2.0
19 3 6 35.0 19.358979 1.65000 115.0 0.0 75.0 0.0 0.0 9.0 0.0 8.0
20 3 6 35.0 9.501888 10.80000 115.0 0.0 195.0 0.0 0.0 5.0 0.0 4.0
21 3 6 35.0 10.900591 8.65000 115.0 0.0 185.0 0.0 0.0 1.0 0.0 5.0
22 3 6 35.0 19.732647 0.65500 115.0 0.0 56.0 0.0 0.0 6.0 0.0 5.0
23 3 6 35.0 13.439753 4.59100 115.0 0.0 152.0 0.0 0.0 1.0 0.0 4.0
24 3 6 35.0 13.636244 4.77050 115.0 0.0 156.1 0.0 0.0 6.0 0.0 4.0
25 3 6 35.0 5.450615 12.99100 115.0 0.0 227.0 0.0 0.0 2.0 0.0 3.0
26 3 6 35.0 17.776815 1.07150 115.0 0.0 66.1 0.0 0.0 5.0 0.0 2.0
27 3 6 35.0 17.944727 0.86000 115.0 0.0 61.0 0.0 0.0 2.0 0.0 2.0
28 3 6 35.0 17.776815 1.07150 115.0 0.0 66.1 0.0 0.0 1.0 0.0 2.0
29 3 6 35.0 17.742291 1.06500 115.0 0.0 66.0 0.0 0.0 1.0 0.0 1.0
30 3 6 35.0 17.776815 1.07150 115.0 0.0 66.1 0.0 0.0 1.0 0.0 5.0
31 3 6 35.0 17.742291 1.06500 115.0 0.0 66.0 0.0 0.0 2.0 0.0 3.0
32 3 6 35.0 17.598476 3.60000 115.0 0.0 105.0 0.0 0.0 2.0 0.0 3.0
33 3 6 35.0 17.116473 4.05500 115.0 0.0 112.0 0.0 0.0 11.0 0.0 4.0
34 3 6 35.0 17.042679 4.11100 115.0 0.0 113.0 0.0 0.0 10.0 0.0 9.0
35 3 6 35.0 16.707016 4.48500 115.0 0.0 118.0 0.0 0.0 4.0 0.0 4.0
36 3 6 35.0 18.194570 2.78400 115.0 0.0 101.0 0.0 0.0 2.0 0.0 3.0
37 3 6 35.0 7.160956 13.34400 115.0 0.0 211.0 0.0 0.0 2.0 0.0 3.0
38 3 6 35.0 17.310031 1.77500 115.0 0.0 130.0 0.0 0.0 4.0 0.0 4.0
39 3 6 35.0 19.647432 0.69500 115.0 0.0 56.0 0.0 0.0 1.0 0.0 2.0
40 3 6 35.0 19.609865 0.65000 115.0 0.0 55.0 0.0 0.0 1.0 0.0 3.0
41 3 6 35.0 19.647432 0.69500 115.0 0.0 56.0 0.0 0.0 4.0 0.0 3.0
42 3 6 35.0 18.736173 1.65000 115.0 0.0 75.0 0.0 0.0 3.0 0.0 2.0
43 3 6 35.0 16.748558 3.15500 115.0 0.0 116.0 0.0 0.0 17.0 0.0 3.0
44 3 6 35.0 16.771674 3.05000 115.0 0.0 115.0 0.0 0.0 2.0 0.0 2.0
45 3 6 35.0 18.235891 1.33500 115.0 0.0 96.0 0.0 0.0 1.0 0.0 4.0
46 3 6 35.0 8.222200 11.15000 115.0 0.0 205.0 0.0 0.0 2.0 0.0 4.0
47 3 6 35.0 17.645870 1.39100 115.0 0.0 127.0 0.0 0.0 4.0 0.0 3.0
48 3 6 35.0 18.736173 1.65000 115.0 0.0 75.0 0.0 0.0 4.0 0.0 3.0
49 3 6 35.0 18.439013 1.97000 115.0 0.0 81.0 0.0 0.0 5.0 0.0 3.0
50 3 6 35.0 17.845657 2.70000 115.0 0.0 95.0 0.0 0.0 9.0 0.0 3.0
51 3 6 35.0 17.467103 3.20000 115.0 0.0 105.0 0.0 0.0 3.0 0.0 4.0
52 3 6 35.0 17.016574 3.69500 115.0 0.0 113.0 0.0 0.0 5.0 0.0 4.0
53 3 6 35.0 8.684344 11.21000 115.0 0.0 201.0 0.0 0.0 6.0 0.0 4.0
54 3 6 35.0 16.693816 3.09500 115.0 0.0 141.0 0.0 0.0 1.0 0.0 3.0
55 3 6 35.0 15.910112 4.60000 115.0 0.0 155.0 0.0 0.0 3.0 0.0 2.0
56 3 6 35.0 15.000396 5.37500 115.0 0.0 160.0 0.0 0.0 6.0 0.0 4.0
57 3 6 35.0 16.766597 2.97500 115.0 0.0 140.0 0.0 0.0 5.0 0.0 3.0
58 3 6 35.0 19.583079 0.45000 115.0 0.0 51.0 0.0 0.0 3.0 0.0 4.0
59 3 6 35.0 13.000197 6.15000 115.0 0.0 165.0 0.0 0.0 2.0 0.0 3.0
60 3 6 35.0 -18.565224 39.67500 115.0 0.0 345.0 0.0 0.0 6.0 0.0 3.0