-
Notifications
You must be signed in to change notification settings - Fork 0
/
similarityCorrelation.py
120 lines (88 loc) · 4.26 KB
/
similarityCorrelation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from utils import startToSimilarMatrix2, matrixCorr, configFilePath
from Markov import MarkovChainAll
#similarity matrix correlation
def corOfSimilarityMatrices(numOrAct,participantNumber1, participantNumber2, totalParticipant):
similar1 = startToSimilarMatrix2(participantNumber1, numOrAct, totalParticipant)
similar2 = startToSimilarMatrix2(participantNumber2, numOrAct, totalParticipant)
return matrixCorr(similar1, similar2)
if __name__ == "__main__":
participantNumber1 = 1
participantNumber2 = 2
totalParticipant = 24
numOrAct = "n"
dropOut = {}
# print(corOfSimilarityMatrices(numOrAct,participantNumber1, participantNumber2, totalParticipant))
fullMatrix = np.array([[5 for i in range(6)] for j in range(6)])
objDisMatrix = fullMatrix - np.array([[i for i in range(6)], [1, 0, 1, 2, 3, 4], [2, 1, 0, 1, 2, 3], [3, 2, 1, 0, 1, 2], [4, 3, 2, 1, 0, 1], [5, 4, 3, 2, 1, 0]])
# print(objDisMatrix)
def subSequenceCorrPlot():
theAnswer = MarkovChainAll(totalParticipant, configFilePath("FOLDER","responseFileFolder"))
recordS = []
for participant in range(1, totalParticipant + 1):
if participant in dropOut:
continue
ma = getattr(theAnswer, "p" + str(participant)).snum.MarkovMatrix
sub = startToSimilarMatrix2(participant, "n", totalParticipant)
recordS.append(matrixCorr(ma, sub)[0])
# print(record)
# plt.bar(range(totalParticipant), record)
plt.hist(recordS, bins = 10, ec = "black", alpha = 0.5, label = "slow")
recordF = []
for participant in range(1, totalParticipant + 1):
if participant in dropOut:
continue
ma = getattr(theAnswer, "p" + str(participant)).fnum.MarkovMatrix
sub = startToSimilarMatrix2(participant, "n", totalParticipant)
recordF.append(matrixCorr(ma, sub)[0])
# print(record)
# plt.bar(range(totalParticipant), record)
plt.hist(recordF, bins = 10, ec = "black", alpha = 0.5, label = "fast")
plt.legend(loc='upper right')
plt.title('Subjective and Markov Matrix Correlation Distribution')
plt.show()
# res = stats.wilcoxon(recordS, recordF)
# print(res)
accuracy = sum(i < j for i, j in zip(recordS, recordF)) / len(recordS)
# accuracy = [i < j for i, j in zip(recordS, recordF)]
print(accuracy)
# subSequenceCorrPlot()
def objSequenceCorrPlot():
theAnswer = MarkovChainAll(totalParticipant, configFilePath("FOLDER","responseFileFolder"))
recordS = []
for participant in range(1, totalParticipant + 1):
if participant in dropOut:
continue
ma = getattr(theAnswer, "p" + str(participant)).snum.MarkovMatrix
recordS.append(matrixCorr(ma, objDisMatrix)[0])
plt.hist(recordS, bins = 10, ec = "black", alpha = 0.5, label = "slow")
recordF = []
for participant in range(1, totalParticipant + 1):
if participant in dropOut:
continue
ma = getattr(theAnswer, "p" + str(participant)).fnum.MarkovMatrix
recordF.append(matrixCorr(ma, objDisMatrix)[0])
plt.hist(recordF, bins = 10, ec = "black", alpha = 0.5, label = "fast")
plt.legend(loc='upper right')
plt.title('Objective and Markov Matrix Correlation Distribution')
plt.show()
# res = stats.wilcoxon(recordS, recordF)
# print(res)
accuracy = sum(i < j for i, j in zip(recordS, recordF)) / len(recordS)
print(accuracy)
objSequenceCorrPlot()
def subObjCorrPlot():
record = []
for participant in range(1, totalParticipant + 1):
if participant in dropOut:
continue
similar1 = startToSimilarMatrix2(participant, numOrAct, totalParticipant)
record.append(matrixCorr(similar1, objDisMatrix)[0])
plt.hist(record, bins = 10, ec = "black", alpha = 0.5)
plt.title('Subjective and Objective Similarity Matrix Correlation Distribution')
plt.show()
# subObjCorrPlot()