FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python_prosodizer/pdfFromClusters.py at master · dipack95/python_prosodizer · GitHub
This repository was archived by the owner on Oct 13, 2018. It is now read-only.
dipack95
/
python_prosodizer
Public archive
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python_prosodizer
/
pdfFromClusters.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
88 lines (67 loc) · 2.87 KB
Breadcrumbs
python_prosodizer
/
pdfFromClusters.py
Copy path
File metadata and controls
88 lines (67 loc) · 2.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
numpy
as
np
import
pandas
as
pd
import
os
def
main
():
data
=
np
.
array
(
pd
.
read_csv
(
"Docs/labelsAndPredictedLabels.csv"
,
header
=
None
,
sep
=
' '
))
printToFile
=
"Docs/trainingPDF.csv"
if
os
.
path
.
isfile
(
printToFile
):
os
.
remove
(
printToFile
)
printToFileObj
=
open
(
printToFile
,
"a+"
)
# In Milliseconds
frameLength
=
25
blockLength
=
1000
jump
=
250
numOfFrames
=
blockLength
//
frameLength
startIndex
=
0
endIndex
=
numOfFrames
jumpIndex
=
jump
//
frameLength
numOfBlocks
=
np
.
ceil
(
data
.
shape
[
0
]
/
jumpIndex
-
(
numOfFrames
//
jumpIndex
))
#numOfBlocks = np.ceil(data.shape[0] / numOfFrames)
weightOfEmotions
=
{}
clustersForEmotions
=
{}
for
_
in
range
(
np
.
int
(
numOfBlocks
)):
'''
# NOTE: If the frames are not divisible by the numOfFrames,
# When it reaches the last block, since it is not of the exact size, it just takes how many ever values it can find,
# creating a block of less than the size that we want
'''
#print (startIndex, endIndex)
dataBlock
=
data
[
startIndex
:
endIndex
, :]
dataBlockLabels
=
dataBlock
[:,
0
]
dataBlockClusters
=
dataBlock
[:,
1
]
emotions
,
emotionsCount
=
np
.
lib
.
arraysetops
.
unique
(
dataBlockLabels
,
return_counts
=
True
)
clusters
,
clustersCount
=
np
.
lib
.
arraysetops
.
unique
(
dataBlockClusters
,
return_counts
=
True
)
percentagesOfEmotions
=
{}
for
i
in
range
(
len
(
emotionsCount
)):
percentagesOfEmotions
[
emotions
[
i
]]
=
(
emotionsCount
[
i
]
/
numOfFrames
)
*
100
if
emotions
[
i
]
not
in
list
(
weightOfEmotions
.
keys
()):
weightOfEmotions
[
emotions
[
i
]]
=
percentagesOfEmotions
[
emotions
[
i
]]
else
:
weightOfEmotions
[
emotions
[
i
]]
+=
percentagesOfEmotions
[
emotions
[
i
]]
percentagesOfClusters
=
{}
for
i
in
range
(
len
(
clustersCount
)):
percentagesOfClusters
[
clusters
[
i
]]
=
(
clustersCount
[
i
]
/
numOfFrames
)
*
100
for
i
in
range
(
len
(
emotions
)):
for
j
in
range
(
len
(
clusters
)):
val
=
(
percentagesOfEmotions
[
emotions
[
i
]])
*
percentagesOfClusters
[
clusters
[
j
]]
tempKey
=
emotions
[
i
]
+
'_'
+
str
(
clusters
[
j
])
if
tempKey
not
in
list
(
clustersForEmotions
.
keys
()):
clustersForEmotions
[
tempKey
]
=
val
else
:
clustersForEmotions
[
emotions
[
i
]
+
'_'
+
str
(
clusters
[
j
])]
+=
val
# print(emotions[i], clusters[j], val)
# print(percentagesOfEmotions, percentagesOfClusters)
# print("------------NEXT BLOCK---------")
#startIndex += numOfFrames
#endIndex += numOfFrames
startIndex
+=
jumpIndex
endIndex
=
startIndex
+
numOfFrames
# print(weightOfEmotions, clustersForEmotions)
for
tempEmote
in
list
(
weightOfEmotions
.
keys
()):
for
tempEmotionCluster
in
list
(
clustersForEmotions
.
keys
()):
if
tempEmote
in
tempEmotionCluster
:
stdWeight
=
clustersForEmotions
[
tempEmotionCluster
]
/
weightOfEmotions
[
tempEmote
]
print
(
tempEmotionCluster
,
stdWeight
,
file
=
printToFileObj
)
printToFileObj
.
close
()
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL