Advertisement
Guest User

Tõnis.py

a guest
Apr 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import matplotlib.patches as mpatches
  4. import pandas as pd
  5. from os import listdir
  6. from collections import defaultdict
  7.  
  8. dir = 'C:/KatseAndmed/'
  9.  
  10. experiments = [f for f in listdir(dir) if(f.endswith('trial_data.csv'))]
  11.  
  12. allTrials = None
  13.  
  14. #Loen kõikide katsete andmed ühte objekti
  15. for e in experiments:
  16. fail = pd.read_csv(dir+e, sep=';', index_col=False);
  17. allTrials = pd.concat([allTrials, fail], ignore_index=True)
  18.  
  19.  
  20. #Kogu täpsus
  21. acc = allTrials.get('TARGET_SHOWN').sum()/len(allTrials.get('TARGET_SHOWN'))
  22. print('Kogu täpsus = ' + str(acc*100)+"%")
  23.  
  24. #Valin eraldi 2cpd ja 4cpd trialid kus näidati stiimulit (st kysiti kysimusi ka)
  25. _2cpdTrials = allTrials.loc[allTrials['CPD']=='2cpd']
  26. _2cpdTrials = _2cpdTrials.loc[_2cpdTrials['TARGET_SHOWN']==True]
  27.  
  28. _4cpdTrials = allTrials.loc[allTrials['CPD']=='4cpd']
  29. _4cpdTrials = _4cpdTrials.loc[_4cpdTrials['TARGET_SHOWN']==True]
  30.  
  31. _2cpdStandardLeft = _2cpdTrials.loc[_2cpdTrials['LEFT_STIMULUS_CONTRAST'] == 0.245000]
  32.  
  33. _2cpdStandardRight = _2cpdTrials.loc[_2cpdTrials['RIGHT_STIMULUS_CONTRAST'] == 0.245000]
  34.  
  35. _4cpdStandardLeft = _4cpdTrials.loc[_4cpdTrials['LEFT_STIMULUS_CONTRAST'] == 0.245000]
  36.  
  37. _4cpdStandardRight = _4cpdTrials.loc[_4cpdTrials['RIGHT_STIMULUS_CONTRAST'] == 0.245000]
  38.  
  39. testContrasts = _2cpdStandardLeft['RIGHT_STIMULUS_CONTRAST'].unique() #kasutatud testkontrasti väärtused
  40.  
  41. #Mitmel protsendil kordadest, kui standardkontrast oli vasakul, vastas katseisik, et parempoolne on kontrastsem
  42. #Iga erineva testkontrasti väärtuse jaoks arvutan, mitmel protsendil juhtudest kui seda testkontrasti näidati vastas katseisik et test on kontrastsem
  43. countLeft = defaultdict(int)
  44. rightAnswers = _4cpdStandardLeft.loc[_4cpdStandardLeft['WHAT_SIDE_WAS_MORE_CONTRASTY']=='right']
  45. for cont in testContrasts:
  46. countLeft[cont] = len(rightAnswers.loc[rightAnswers['RIGHT_STIMULUS_CONTRAST']==cont])/len(_4cpdStandardLeft.loc[_4cpdStandardLeft['RIGHT_STIMULUS_CONTRAST']==cont])
  47.  
  48. #Mitmel protsendil kordadest, kui standardkontrast oli paremal, vastas katseisik, et vasakpoolne on kontrastsem
  49. countRight = defaultdict(int)
  50. leftAnswers = _4cpdStandardRight .loc[_4cpdStandardRight['WHAT_SIDE_WAS_MORE_CONTRASTY']=='left']
  51. for cont in testContrasts:
  52. countRight[cont] = len(leftAnswers.loc[leftAnswers['LEFT_STIMULUS_CONTRAST']==cont])/len(_4cpdStandardRight.loc[_4cpdStandardRight['LEFT_STIMULUS_CONTRAST']==cont])
  53.  
  54. #Plotin väärtused, enne muudan protsentideks
  55. xValues = []
  56. yValues=[]
  57. keys = sorted(countLeft.keys())
  58. for k in keys:
  59. xValues.append(k*100)
  60. yValues.append(countLeft[k]*100)
  61. plt.plot(xValues, yValues, 'bo--')
  62.  
  63. xValues = []
  64. yValues=[]
  65. keys = sorted(countRight.keys())
  66. for k in keys:
  67. xValues.append(k * 100)
  68. yValues.append(countRight[k] * 100)
  69. plt.plot(xValues, yValues, 'ro--')
  70.  
  71. #Joonise atribuudid
  72. red = mpatches.Patch(color='red', label='Standard contrast mirrored')
  73. blue = mpatches.Patch(color='blue', label='Standard contrast behind hand')
  74. plt.legend(handles=[blue, red])
  75. plt.title("4 cpd")
  76. plt.ylabel("Perceived contrast of test > standard (%)")
  77. plt.xlabel("Contrast of test stimulus (%)")
  78. plt.axis([0, 100, 0, 100])
  79. plt.show()
  80.  
  81. #Teen sama asja aga 2cpd'ga. Copy-paste
  82. countLeft = defaultdict(int)
  83. rightAnswers = _2cpdStandardLeft.loc[_2cpdStandardLeft['WHAT_SIDE_WAS_MORE_CONTRASTY']=='right']
  84. for cont in testContrasts:
  85. countLeft[cont] = len(rightAnswers.loc[rightAnswers['RIGHT_STIMULUS_CONTRAST']==cont])/len(_2cpdStandardLeft.loc[_2cpdStandardLeft['RIGHT_STIMULUS_CONTRAST']==cont])
  86.  
  87. countRight = defaultdict(int)
  88. leftAnswers = _2cpdStandardRight .loc[_2cpdStandardRight['WHAT_SIDE_WAS_MORE_CONTRASTY']=='left']
  89. for cont in testContrasts:
  90. countRight[cont] = len(leftAnswers.loc[leftAnswers['LEFT_STIMULUS_CONTRAST']==cont])/len(_2cpdStandardRight.loc[_2cpdStandardRight['LEFT_STIMULUS_CONTRAST']==cont])
  91.  
  92.  
  93. xValues = []
  94. yValues=[]
  95. keys = sorted(countLeft.keys())
  96. for k in keys:
  97. xValues.append(k*100)
  98. yValues.append(countLeft[k]*100)
  99. plt.plot(xValues, yValues, 'bo--')
  100.  
  101. xValues = []
  102. yValues=[]
  103. keys = sorted(countRight.keys())
  104. for k in keys:
  105. xValues.append(k * 100)
  106. yValues.append(countRight[k] * 100)
  107. plt.plot(xValues, yValues, 'ro--')
  108.  
  109. red = mpatches.Patch(color='red', label='Standard contrast mirrored')
  110. blue = mpatches.Patch(color='blue', label='Standard contrast behind hand')
  111. plt.legend(handles=[blue, red])
  112. plt.title("2 cpd")
  113. plt.ylabel("Perceived contrast of test > standard (%)")
  114. plt.xlabel("Contrast of test stimulus (%)")
  115. plt.axis([0, 100, 0, 100])
  116. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement