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')
Alldata = pd.read_excel(excelfile,sheet_name='Данные')
print(Alldata.columns)
Games = pd.read_excel(excelfile,sheet_name='Игры')
Games.columns
Out[2]:
In [3]:
YHGames=Games[(Games.Mechname=='yh') & (Games.GameMech=='agree')]
YHExpGames=Games[(Games.Mechname=='yh') & (Games.GameMech=='exp')]
YHData=Alldata[Alldata.Game.isin(YHGames.Game)]
YHEData=Alldata[Alldata.Game.isin(YHExpGames.Game)]
print(YHData.shape,YHEData.shape)
In [4]:
GLGames=Games[(Games.Mechname=='gl') & (Games.GameMech=='agree')]
GLData=Alldata[Alldata.Game.isin(GLGames.Game)]
GLEGames=Games[(Games.Mechname=='gl') & (Games.GameMech=='exp')]
GLEData=Alldata[Alldata.Game.isin(GLEGames.Game)]
GLData.shape
Out[4]:
In [4]:
from scipy.spatial import distance
In [5]:
distance.cityblock([49,41,25],[38.3,38.3,38.3])
Out[5]:
In [5]:
csvfile = ospath.join('..','Serious games','YHBRdata.csv')
BRdata = pd.read_csv(csvfile,header=None)
BRdata.columns = ['Game','Time','g1','g2','g3','br1','br2','br3']
br1 = BRdata[['Game','Time','g1','br1']].copy()
br1.columns = ['Game','Time','g','br']
br1['GrSubject'] = 1
#br1.insert(br1.shape[1],'GrSubject',1)
br2 = BRdata[['Game','Time','g2','br2']].copy()
br2.columns = ['Game','Time','g','br']
br2['GrSubject'] = 2
#br2.insert(br2.shape[1],'GrSubject',2)
br3 = BRdata[['Game','Time','g3','br3']].copy()
br3.columns = ['Game','Time','g','br']
br3['GrSubject'] = 3
#br3.insert(br3.shape[1],'GrSubject',3)
BRdata=pd.concat([br1,br2,br3])
BRdata.head()
Out[5]:
In [6]:
YHData = pd.merge(YHData, BRdata, on=['Game', 'Time','GrSubject'], how='outer')
YHData.head()
Out[6]:
In [7]:
c1,c2 = YHData['s2'],YHData['br']
YHData['br0'] = ((c1-c2).abs() < 0.01).astype('float64')
YHData['br0.5'] = ((c1-c2).abs() < 0.51).astype('float64')
YHData['br1'] = ((c1-c2).abs() < 1.01).astype('float64')
YHData['twbr'] = (YHData['g'] > 0).astype('float64')
In [8]:
YHData.head()
Out[8]:
In [9]:
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 [10]:
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
def DataWoCB(gamedata, CBdata, cbeps=0):
"""Game data without constant steps: it takes first steps of an each cb and drops out each other steps from game data."""
if not CBdata is None:
CBdata = getCBwithEps(gamedata,cbeps)
wd = gamedata.copy()
for row in CBdata.itertuples(False):
wd = wd[(wd['Game']!=row.game) | (wd['GrSubject']!=row.subject) | (wd['Time']<=row.ts) | (wd['Time']>row.te)]
return wd
def DataMarkedCB(gamedata, cb, column='iscb'):
"""Game data with constant steps: it marks steps of game with "it's CB of the player i" or not."""
res = []
for row in gamedata.itertuples(False):
rowcb = cb[(cb['game']==row.Game) & (cb['subject']==row.GrSubject) & (cb['ts']<row.Time) & (row.Time<=cb['te'])]
cbflag = 1.0 if rowcb.shape[0] > 0 else 0.0
res.append( list(row)+[cbflag])
return pd.DataFrame(res,columns=list(gamedata.columns)+[column])
In [51]:
gr = YHData.loc[:,['Game','Time','GrSubject','s2']].groupby('Game')
In [52]:
game40_1=gr.get_group(41)
#game40_1 = game40_1[['Time','s2']].set_index('Time')
In [11]:
game40_1.sort_values(by=['Time','GrSubject'])[['s2','GrSubject']].head()
In [67]:
game40_1 = game40_1.set_index('Time')
In [73]:
list(getCB(game40_1.groupby('GrSubject').get_group(1)[['s2']],1))
Out[73]:
In [11]:
# Считает несколько секунд
cb = getCBwithEps(YHData,eps=0)
YHData = DataMarkedCB(YHData,cb,'iscb0')
cb = getCBwithEps(YHData,eps=0.51)
YHData = DataMarkedCB(YHData,cb,'iscb0.5')
cb = getCBwithEps(YHData,eps=1.01)
YHData = DataMarkedCB(YHData,cb,'iscb1')
del cb
In [12]:
YHData.head()[['Game','Time','s2','iscb0','iscb0.5','iscb1']]
Out[12]:
In [13]:
def Unash(f,f0):
df = f-f0
return (np.fabs(df)).prod() * np.min(np.sign(df)) # если хоть по одной ЦФ было уменьшение то отрицательна
In [14]:
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))
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 [15]:
s = np.array([1.2,40,80])
print(YHMechanism.t(s),YHMechanism.f(s))
In [16]:
print(YHMechanism.game.s0)
f0 = YHMechanism.game.u([0,0,0])
print(f0)
Unash(f0,s)
Out[16]:
In [17]:
# Функция получения исходных данных для Нэш-торгов
def NashData(Data):
import itertools
prec = 0.000001
res = []
GroupedData = Data.groupby(['Game','Time'])
for name,group in GroupedData:
group = group.sort_values(by='GrSubject')
if name[1] == 1 :
curname = name[0]
prevg = group
continue
#fprev = prevg['Gain'].values
fprev = YHMechanism.f(prevg['s2'].values)
U = Unash(fprev,f0)
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)
U1 = Unash(f1,f0)
U1moreU = 1.0 if U1>U+prec else 0.0
f2 = YHMechanism.f(s2)
U2 = Unash(f2,f0)
U2moreU = 1.0 if U2>U+prec else 0.0
f3 = YHMechanism.f(s3)
U3 = Unash(f3,f0)
U3moreU = 1.0 if U3>U+prec else 0.0
fnew = YHMechanism.f(s)
FmoreFprev = 1.0 if (fnew>fprev).all() else 0.0
Unew = Unash(fnew,f0)
UNewmoreU = 1.0 if Unew>U else 0.0
res.append( [a for a in itertools.chain(name,[U1moreU,U2moreU,U3moreU,UNewmoreU,FmoreFprev,U,U1,U2,U3,Unew],s)] )
prevg = group
#print(name,prev['Gain'])
data_a = pd.DataFrame(np.vstack(res),
columns=['Game','Time','U1>U','U2>U','U3>U','Unew>U','Fnew>F','U','U1','U2','U3','Unew','s1','s2','s3'])
return data_a
In [18]:
nbdata = NashData(YHData)
nbdata.head()
Out[18]:
In [19]:
nb1 = nbdata[['Game','Time','U1>U','Unew>U','Fnew>F','U1','Unew','U']].copy()
nb1.columns = ['Game','Time','Ui>U','Unew>U','Fnew>F','Ui','Unew','U']
nb1['GrSubject'] = 1
nb2 = nbdata[['Game','Time','U2>U','Unew>U','Fnew>F','U2','Unew','U']].copy()
nb2.columns = ['Game','Time','Ui>U','Unew>U','Fnew>F','Ui','Unew','U']
nb2['GrSubject'] = 2
nb3 = nbdata[['Game','Time','U3>U','Unew>U','Fnew>F','U3','Unew','U']].copy()
nb3.columns = ['Game','Time','Ui>U','Unew>U','Fnew>F','Ui','Unew','U']
nb3['GrSubject'] = 3
selfnbdata = pd.concat([nb1,nb2,nb3])
selfnbdata.head()
Out[19]:
In [20]:
YHData = pd.merge(YHData, selfnbdata, on=['Game', 'Time','GrSubject'], how='outer')
YHData.head()
Out[20]:
In [21]:
YHData.to_csv('YH_BR_CB_NB_data.csv')
In [23]:
res = []
for name,group in YHData.groupby('Game'):
t = group.copy()
t['Time'] = t.Time.copy() - t['Time'].max()
res.append(t)
timegrp = pd.concat(res).groupby('Time')
In [24]:
def bhvrcount(x):
return pd.Series([x[x['br0.5']>0].shape[0], x[x.twbr>0].shape[0],x[x['iscb0.5']>0].shape[0],x[x['Ui>U']>0].shape[0]],
index=['br0.5','twbr','cb0.5','twNB'])
In [25]:
endbhvr = timegrp.apply(bhvrcount).sort_index(ascending=False)
endbhvr.to_csv('EndBehavior.csv')
endbhvr.plot();
In [27]:
endbhvrLenMore2 = timegrp.filter(lambda x: x.Time.max() < -1).groupby('Time').apply(bhvrcount)
endbhvrLenMore2.to_csv('EndBehavior,gamelen more 2.csv')
endbhvrLenMore2.plot();
In [28]:
endbhvrLenMore6 = timegrp.filter(lambda x: x.Time.max() < -5).groupby('Time').apply(bhvrcount)
endbhvrLenMore6.to_csv('EndBehavior,gamelen more 6.csv')
endbhvrLenMore6.plot();
In [89]:
timegrp.filter(lambda x: x.Time.max() < -5).Game.unique()
Out[89]:
In [24]:
lastSteps=YHData[['Game','Time']].groupby('Game').max(); lastSteps
Out[24]:
In [29]:
YHData.columns
Out[29]:
In [ ]:
tg = YHData.groupby(['Game','Time'])
In [32]:
cnt = 0
for name,group in tg:
if (group['Unew>U']>0).all() and (group['iscb1']>0).all(): cnt += 1
cnt
Out[32]:
In [36]:
cnt = 0
for name,group in tg:
if (group['twbr']>0).all(): cnt += 1
cnt
Out[36]:
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]:
In [9]:
GLCounts = getCBofAllGames(GLData,dim=3)
GLCounts['Steps Count %'] = GLCounts['Steps Count']/(2847/100)
GLCounts
Out[9]:
In [10]:
GLCounts.to_clipboard()
In [15]:
GLECounts = getCBofAllGames(GLEData,dim=3)
GLECounts['Steps Count %'] = GLECounts['Steps Count']/(60/100)
GLECounts
Out[15]:
In [16]:
print(YHData.shape,YHEData.shape)
In [67]:
YHCB = getCBwithEps(YHData,eps=0.5)
YHCB.sort_values(by=['game','ts']).head()
Out[67]:
In [55]:
(YHCB['te']-YHCB['ts']).sum()
In [10]:
def cbStepsCount(cbdata,sh=0):
return (cbdata['te']-cbdata['ts']+sh).sum()
In [11]:
pd.DataFrame(data=[cbStepsCount(getCBwithEps(YHData,e),0) for e in [0,0.5,1]],
columns=['Steps count'], index=['CB(0)','CB(0.5)','CB(1)'])
Out[11]:
In [43]:
YHCB.shape
Out[43]:
In [68]:
dcb = DataMarkedCB(YHData,YHCB)
In [35]:
%store dcb
In [70]:
dcb.head(6)
Out[70]:
In [45]:
dcb[dcb['iscb']>0].count()
Out[45]:
In [36]:
dcb[dcb['iscb']<1].count()
Out[36]:
In [10]:
YHData.columns
Out[10]:
In [11]:
YHData[(YHData['Game']==40) & (YHData['GrSubject']==1) & (YHData['Time']>=31) & (YHData['Time']<=34)]
Out[11]:
In [44]:
(YHCB['te']-YHCB['ts']).sum()
Out[44]:
In [28]:
Counts = getCBofAllGames(YHData)
Counts['Steps Count %'] = Counts['Steps Count']/(YHData.shape[0]/100)
Counts
Out[28]:
In [19]:
YHData.shape
Out[19]:
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]:
In [56]:
CountsExp = getCBofAllGames(YHEData)
CountsExp['Steps Count %'] = CountsExp['Steps Count']/(YHEData.shape[0]/100)
CountsExp
Out[56]:
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)
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]:
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]:
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]:
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]:
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]:
In [101]:
np.mean(npd2,axis=0)
Out[101]:
In [98]:
a
Out[98]:
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]:
In [105]:
Nf([20,40,55],[1,9,25])
Out[105]:
In [108]:
Nf([115/3,115/3,115/3],[1,9,25])
Out[108]:
In [109]:
22.81+115/3+53.85
Out[109]:
In [110]:
Nf([32.0724, 39.1355, 43.7921],[1,9,25])
Out[110]:
In [114]:
Nf([49,41,25],[1,9,25])
Out[114]:
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]:
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()
In [21]:
plog = results.params.item()
In [22]:
plog
Out[22]:
In [66]:
notStoppedCbs.shape
Out[66]:
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]:
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]:
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]:
In [67]:
arr = np.loadtxt('2.txt')
In [61]:
np.shape(arr)
Out[61]:
In [46]:
stats.wilcoxon(arr[0],arr[1],zero_method='wilcox')
Out[46]:
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]:
In [51]:
(np.sign(dsrtnn[0])*dsrtnn['rank']).sum()
Out[51]:
In [52]:
from math import sqrt
In [53]:
n = 125
sigma = sqrt( n*(n+1)*(2*n+1)/6 )
In [54]:
sigma
Out[54]:
In [55]:
sigma*1.96
Out[55]:
In [57]:
2*(1-stats.norm.cdf(3655.0/sigma))
Out[57]:
In [68]:
stats.mannwhitneyu(arr[0],arr[1],alternative='less')
Out[68]:
In [25]:
totYHdata['g'].nlargest(10)
Out[25]:
In [23]:
"br"
brcnt=totYHdata[(totYHdata['s2']>totYHdata['br']-1) & (totYHdata['s2']<totYHdata['br']+1)]
brcnt.shape
Out[23]:
In [28]:
"twBR"
twbrcnt = totYHdata[totYHdata['g']>0]
twbrcnt.shape
Out[28]:
In [52]:
"twBR общие шаги"
commtwbr = totYHdata.groupby(by=['Game','Time'])
cnt = 0
for name,group in commtwbr:
if (group['g']>0).all(): cnt += 1
print(cnt)
allcnt = 0
for _ in YHData.groupby(['Game','Time']):
allcnt+=1
print(allcnt)
In [ ]:
"CB общие шаги"
In [68]:
YHCB = getCBwithEps(YHData,eps=1)
In [69]:
dcb = DataMarkedCB(totYHData,YHCB)
dcb[dcb['iscb']>0].shape
Out[69]:
In [70]:
commCB = dcb.groupby(['Game','Time'])
cnt = 0
for name,group in commCB:
if (group['iscb']>0).all(): cnt += 1
print(cnt)
In [61]:
dcb.columns
Out[61]:
In [72]:
%store dcb
In [ ]: