-
Notifications
You must be signed in to change notification settings - Fork 0
/
positionSynthesis.py
386 lines (360 loc) · 23.2 KB
/
positionSynthesis.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
import numpy as np
import pandas as pd
import json
import enum
from sklearn.metrics.pairwise import euclidean_distances
from scipy.ndimage import convolve1d
from positionAnalysis import positionDataPreproc, positionJsonDataParser, positionDataToPandasDf, setHipAsOrigin, rollingWindowSegRetrieve, jointsNames
'''
目標: 從輸入的DB motion當中找到與輸入motion最相似的motion,
使用KNN尋找k個最相似的DB motions,
最後需要將DB motion preprocessing後的結果儲存, 減少計算所需時間
'''
positionsJointCount = 7 # 用於比對motion similarity的joint數量(Upper leg*2, knee*2, foot*2, hip)
fullPositionsJointCount = 17 # 用於做motion synthesis的joint數量
rollingWinSize = 10
kSimilar = 5
# kSimilar = 1
augmentationRatio = [0.5, 0.7, 1, 1.3, 1.5]
EWMAWeight = 0.7
def findKSimilarFeatureVectors(aJointDBFeatVecs, aJointMappedFeatVecs, k):
'''
計算與mapped feature vectors最相似的k個DB feature vectors, 這些feature vectors都代表相同joint卻又不同的window
理論上DB feature數量是mapped feature vector的n倍, n是augment ratio的種類數量
'''
# print(aJointMappedFeatVecs.shape)
# print(aJointDBFeatVecs.shape)
l2BtwDBAndMapped = euclidean_distances(aJointMappedFeatVecs, aJointDBFeatVecs) # 每個row都是與某個mapped feature vector與所有DB feature vectors的l2距離
# print(l2BtwDBAndMapped.shape)
kSimilarL2Idx = np.argsort(l2BtwDBAndMapped, axis=1)
kSimilarL2Dist = np.sort(l2BtwDBAndMapped, axis=1)
return kSimilarL2Idx[:, :k], kSimilarL2Dist[:, :k]
def augFeatVecToPos(aJointAugFeatVec, winSize):
'''
將augment後的某個joint的feature vector轉換為只有3D position的DataFrame(或是np.array)
Input:
:aJointAugFeatVec: 某個joint augment後的Feature vectors
'''
return aJointAugFeatVec[:, [winSize-1, winSize*2-1, winSize*3-1]]
def kSimilarFeatureVectorsBlending(mainDBJointPos, kSimilarFeatVecsIdx, kSimilarFeatVecsDists):
'''
將多個feature vectors做blending
Input:
輸入的Feature vector不需要augment過(也不需要velocity, acceralation),
因為synthesis只需要目標位置的3D position(X, Y, Z)
:mainDBJointPos: 目標要synthesis的joint, 在所有time point的3D position
:kSimilarFeatVecsIdx: (某個reference joint的)所有時間點, 每一個時間點有k個相似的feature vectors的time point/index
:kSimilarFeatVecsDists: (某個reference joint的)與k個相似的feature vectors的距離(作為weight使用)
每個row都是一個time point, 內含前k個相似的DB poses
Output:
:blendPos: 所有時間點的motion synthesis的結果, dimension為(輸入的時間點數量, 3)
'''
blendPos = np.zeros((kSimilarFeatVecsIdx.shape[0], 3))
# print(mainDBJointPos.shape)
# print(kSimilarFeatVecsIdx.shape)
# print(kSimilarFeatVecsDists.shape)
for t in range(kSimilarFeatVecsIdx.shape[0]):
# 某個time point下, 最相似的k個3D positions
kSimilarPositions = mainDBJointPos[kSimilarFeatVecsIdx[t, :], :]
# print(kSimilarPositions)
# l2 distance的倒數作為weight
weights = kSimilarFeatVecsDists[t, :]
weights = 1/weights
weights = weights/np.sum(weights)
weights = weights[:, np.newaxis]
# weighted mean/sum
weightedResult = kSimilarPositions*weights
weightedResult = np.sum(weightedResult, axis=0)
# print(weightedResult)
blendPos[t, :] = weightedResult
return blendPos
def blendingResultToJson(blendingResultList):
'''
將motion blend的結果轉換成json格式的dict,
[{'time': 0, 'data': [{'x': 0, 'y': 0', 'z': 0}, ...]}, ...]
'''
jointsCount = len(blendingResultList)
outputdata = [{'time': i, 'data': [{k: 0 for k in ['x', 'y', 'z']} for j in range(jointsCount)]} for i in range(blendingResultList[0].shape[0])]
for aJointIdx in range(jointsCount):
for aTimePoint in range(blendingResultList[0].shape[0]):
for aAxisI, aAxis in enumerate(['x', 'y', 'z']):
outputdata[aTimePoint]['data'][aJointIdx][aAxis] = \
blendingResultList[aJointIdx][aTimePoint, aAxisI]
return outputdata
def EWMAToPositions(posArr, weight):
'''
aplly EWMA到blending後的positions資料上
Input:
:posArr: 儲存blending完後的positions資料, 維度為(時間點數量, 3)
:weight: p_t = p_t*weight + p_{t-1}*(1-weight)
'''
return convolve1d(posArr, weights=[weight, 1-weight], axis=0) # 注意: weight在做conv十是顛倒過來的
# For test 全身joint的preprocessing結果
if __name__=='__main01__':
positionsJointCount = 16
# Read position data
DBFileName = './positionData/fromDB/leftFrontKickPositionFullJoints.json'
## Read Position data in DB
posDBDf = None
with open(DBFileName, 'r') as fileIn:
jsonStr=json.load(fileIn)
positionsDB = positionJsonDataParser(jsonStr, positionsJointCount)
posDBDf = positionDataToPandasDf(positionsDB, positionsJointCount)
DBPreproc = positionDataPreproc(posDBDf, positionsJointCount, rollingWinSize, True, augmentationRatio)
print(len(DBPreproc))
print(DBPreproc[0].shape) # (595, 81)
DBPosNoAug = [augFeatVecToPos(i.values, rollingWinSize) for i in DBPreproc]
print(len(DBPosNoAug))
print(DBPosNoAug[0].shape) # (595, 3)
if __name__=='__main__':
# Read position data
# DBFileName = './positionData/fromDB/leftFrontKickPosition.json'
# DBFileName = './positionData/fromDB/leftFrontKickPositionFullJointsWithHead.json'
DBFileName = './positionData/fromDB/genericAvatar/leftFrontKickPositionFullJointsWithHead_withoutHip.json'
# DBFileName = './positionData/fromDB/leftSideKickPositionFullJointsWithHead.json'
# DBFileName = './positionData/fromDB/walkCrossoverPositionFullJointsWithHead.json'
# DBFileName = './positionData/fromDB/walkInjuredPositionFullJointsWithHead.json'
# DBFileName = './positionData/fromDB/runSprintPositionFullJointsWithHead.json'
# DBFileName = './positionData/fromDB/genericAvatar/leftSideKickPositionFullJointsWithHead.json'
# DBFileName = './positionData/fromDB/genericAvatar/runSprintPositionFullJointsWithHead0.5_withoutHip.json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/leftFrontKickCombinations/leftFrontKick(True, False, False, False, True, True).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/leftFrontKickStreamLinearMappingCombinations/leftFrontKick(True, False, False, True, True, True).json'
AfterMappingFileName = \
'./positionData/fromAfterMappingHand/leftFrontKickStreamLinearMapping/leftFrontKick(True, False, False, True, True, True).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/leftFrontKickStreamLinearMapping_TFFTTT.json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/leftSideKickCombinations/leftSideKick(True, True, True, False, False, False).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/leftSideKickLinearMappingCombinations/leftSideKick(True, True, True, False, False, False).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/generic/leftSideKickLinearMappingCombinations/leftSideKick(True, True, True, False, False, False).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/generic/runSprintLinearMappingCombinations/runSprint(True, True, True, True, True, True).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/walkCrossoverCombinations/walkCrossover(True, True, True, False, True, True).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/walkInjuredCombinations/walkInjured(True, True, True, False, False, False).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/runSprintCombinations/runSprint(True, False, True, True, False, True).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/runSprintLinearMappingCombinations/runSprint(True, False, True, True, False, True).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/runSprintStreamLinearMappingCombinations/runSprint(False, True, True, True, True, True).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/leftFrontKickStreamLinearMappingCombinations/leftFrontKick(True, True, False, True, True, True).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/leftSideKickStreamLinearMappingCombinations/leftSideKick(False, True, True, False, True, False).json'
# AfterMappingFileName = \
# './positionData/fromAfterMappingHand/generic/walkLinearMappingCombinations/walk(True, True, True, True, True, True).json'
## Read Position data in DB
posDBDf = None
AfterMapDf = None
with open(DBFileName, 'r') as fileIn:
jsonStr=json.load(fileIn)
positionsDB = positionJsonDataParser(jsonStr, positionsJointCount)
posDBDf = positionDataToPandasDf(positionsDB, positionsJointCount)
with open(AfterMappingFileName, 'r') as fileIn:
jsonStr=json.load(fileIn)
positionsDB = positionJsonDataParser(jsonStr, positionsJointCount)
AfterMapDf = positionDataToPandasDf(positionsDB, positionsJointCount)
## Preprocessing
## 現在每個joint都有自己的windows/segments組成的DataFrame,
## 維度為(windows數量, (XX...| YY...| ZZ...| speed_x...| speed_y...| speed_z...| acc_x...| acc_y...| acc_z...))
## windows數量為原始windows數量*(變化速度數量)
DBPreproc = positionDataPreproc(posDBDf, positionsJointCount, rollingWinSize, True, augmentationRatio)
AfterMapPreproc = positionDataPreproc(AfterMapDf, positionsJointCount, rollingWinSize, False, augmentationRatio, False)
## Find k similar motions depends on different leg's motions(left leg and right leg)
## 左右腿的比較可以結合knee, foot, displacement between upper leg and foot
## 可以再加上左右腿綜合的joint pairs displacement比較(optional)
## Thus, k_left and k_right motions is found in each time point
## upper leg 以及 hip的比對就不需要了,因為這兩種joint幾乎不會有位移(位移都是noise)
## 每個joint都先找出最相似的k個motions,在考慮如何結合多個joints找到的相似motions
# 與每個mapped feature vec前k個相似的DB feature vectors
# 對指定的多個joints尋找前k個相似的DB feature vectors
jointsInUsedToSyhthesis = [
jointsNames.LeftLowerLeg, jointsNames.LeftFoot, jointsNames.RightLowerLeg, jointsNames.RightFoot
]
multiJointsKSimilarDBIdx = [None for i in range(len(jointsNames))]
multiJointskSimilarDBDist = [None for i in range(len(jointsNames))]
for i in jointsInUsedToSyhthesis:
kSimilarDBIdx, kSimilarDBDist = findKSimilarFeatureVectors(DBPreproc[i].values, AfterMapPreproc[i].values, kSimilar)
multiJointsKSimilarDBIdx[i] = kSimilarDBIdx
multiJointskSimilarDBDist[i] = kSimilarDBDist
# print(kSimilarDBIdx[:30, :])
kSimilarDBIdx, kSimilarDBDist = findKSimilarFeatureVectors(DBPreproc[2].values, AfterMapPreproc[2].values, kSimilar)
print(kSimilarDBIdx[-100:, :])
# print(kSimilarDBDist[-30:, :])
# print(kSimilarDBIdx.shape)
# Feature Vector轉換為原始的joint point(X, Y, Z)
# 接下來在做motion synthesis時, 不會使用到速度與其他的augmentation
# 轉換的方式為選取最後一個X, Y, Z數值,作為synthesis使用的數值
DBPosNoAug = [augFeatVecToPos(i.values, rollingWinSize) for i in DBPreproc]
# DBPosNoAug = augFeatVecToPos(DBPreproc[1].values, rollingWinSize)
print('DBPosNoAug len: ', len(DBPosNoAug))
print('after preproc: ', DBPreproc[1].shape)# (595, 81), 595=119*5
print('before preproc: ', posDBDf.shape)#(601, 21)
print('after De-augment: ', DBPosNoAug[1].shape)# (595, 3)
# 讀取所有DB joints的position資訊,用於motion synthesis。
# 前面讀取的是部分joints的position資訊,用於找到前k個相似的DB poses
# Read position data
DBFFullJointsFileName = './positionData/fromDB/leftFrontKickPositionFullJointsWithHead.json'
# DBFFullJointsFileName = './positionData/fromDB/leftSideKickPositionFullJointsWithHead.json'
# DBFFullJointsFileName = './positionData/fromDB/genericAvatar/leftSideKickPositionFullJointsWithHead_withHip.json'
# DBFFullJointsFileName = './positionData/fromDB/genericAvatar/runSprintPositionFullJointsWithHead_withHip.json'
# DBFFullJointsFileName = './positionData/fromDB/walkCrossoverPositionFullJointsWithHead.json'
# DBFFullJointsFileName = './positionData/fromDB/walkInjuredPositionFullJointsWithHead.json'
# DBFFullJointsFileName = './positionData/fromDB/runSprintPositionFullJointsWithHead.json'
## Read Position data in DB
posDBFullJointsDf = None
with open(DBFFullJointsFileName, 'r') as fileIn:
jsonStr=json.load(fileIn)
positionsDB = positionJsonDataParser(jsonStr, fullPositionsJointCount)
posDBFullJointsDf = positionDataToPandasDf(positionsDB, fullPositionsJointCount)
DBFullJointsPreproc = positionDataPreproc(posDBFullJointsDf, fullPositionsJointCount, rollingWinSize, True, augmentationRatio)
DBFullJointsPosNoAug = [augFeatVecToPos(i.values, rollingWinSize) for i in DBFullJointsPreproc]
# 需要決定要參考哪一些joints的motions,以及跨joint之間的blending weight該如何決定
# 前k個相似的瞬時motion做blending
# 這邊需要區分哪一個joint,因為不同joint會使用不同的blending策略
# e.g. 左腳: 只使用左腳的前k個相似poses, 右膝: 只使用右腳的前k個相似poses, 左手: 使用所有joint得到的相似poses做blending
# jointsBlendingRef = {
# # jointsNames.LeftUpperLeg: {jointsNames.LeftFoot: 0.9, jointsNames.LeftLowerLeg: 0.1},
# # jointsNames.LeftLowerLeg: {jointsNames.LeftFoot: 0.9, jointsNames.LeftLowerLeg: 0.1},
# jointsNames.LeftUpperLeg: {jointsNames.LeftFoot: 1.0},
# jointsNames.LeftLowerLeg: {jointsNames.LeftFoot: 1.0},
# jointsNames.LeftFoot: {jointsNames.LeftFoot: 1.0},
# # jointsNames.RightUpperLeg: {jointsNames.RightFoot: 0.9, jointsNames.RightLowerLeg: 0.1},
# # jointsNames.RightLowerLeg: {jointsNames.RightFoot: 0.9, jointsNames.RightLowerLeg: 0.1},
# jointsNames.RightUpperLeg: {jointsNames.RightFoot: 1.0},
# jointsNames.RightLowerLeg: {jointsNames.RightFoot: 1.0},
# jointsNames.RightFoot: {jointsNames.RightFoot: 1.0},
# jointsNames.Spine: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5},
# jointsNames.Chest: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5},
# jointsNames.UpperChest: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5},
# jointsNames.LeftUpperArm: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5},
# jointsNames.LeftLowerArm: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5},
# jointsNames.LeftHand: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5},
# # jointsNames.LeftHand: {jointsNames.LeftFoot: 1.0},
# jointsNames.RightUpperArm: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5},
# jointsNames.RightLowerArm: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5},
# jointsNames.RightHand: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5},
# # jointsNames.RightHand: {jointsNames.LeftFoot: 1.0},
# jointsNames.Head: {jointsNames.LeftFoot: 0.5, jointsNames.RightFoot: 0.5}
# } # 第一層的key是main joint, 第二層的key是reference joints, 第二層value是reference joints之間的weight
jointsBlendingRef = {
# jointsNames.LeftUpperLeg: {jointsNames.LeftFoot: 0.9, jointsNames.LeftLowerLeg: 0.1},
# jointsNames.LeftLowerLeg: {jointsNames.LeftFoot: 0.9, jointsNames.LeftLowerLeg: 0.1},
jointsNames.LeftUpperLeg: {jointsNames.LeftFoot: 1.0},
jointsNames.LeftLowerLeg: {jointsNames.LeftFoot: 1.0},
jointsNames.LeftFoot: {jointsNames.LeftFoot: 1.0},
# jointsNames.RightUpperLeg: {jointsNames.RightFoot: 0.9, jointsNames.RightLowerLeg: 0.1},
# jointsNames.RightLowerLeg: {jointsNames.RightFoot: 0.9, jointsNames.RightLowerLeg: 0.1},
jointsNames.RightUpperLeg: {jointsNames.LeftFoot: 1.0},
jointsNames.RightLowerLeg: {jointsNames.LeftFoot: 1.0},
jointsNames.RightFoot: {jointsNames.LeftFoot: 1.0},
jointsNames.Spine: {jointsNames.LeftFoot: 1.0},
jointsNames.Chest: {jointsNames.LeftFoot: 1.0},
jointsNames.UpperChest: {jointsNames.LeftFoot: 1.0},
jointsNames.LeftUpperArm: {jointsNames.LeftFoot: 1.0},
jointsNames.LeftLowerArm: {jointsNames.LeftFoot: 1.0},
jointsNames.LeftHand: {jointsNames.LeftFoot: 1.0},
# jointsNames.LeftHand: {jointsNames.LeftFoot: 1.0},
jointsNames.RightUpperArm: {jointsNames.LeftFoot: 1.0},
jointsNames.RightLowerArm: {jointsNames.LeftFoot: 1.0},
jointsNames.RightHand: {jointsNames.LeftFoot: 1.0},
# jointsNames.RightHand: {jointsNames.LeftFoot: 1.0},
jointsNames.Head: {jointsNames.LeftFoot: 1.0},
} # 第一層的key是main joint, 第二層的key是reference joints, 第二層value是reference joints之間的weight
# jointsBlendingRef = {
# # jointsNames.LeftUpperLeg: {jointsNames.LeftFoot: 0.9, jointsNames.LeftLowerLeg: 0.1},
# # jointsNames.LeftLowerLeg: {jointsNames.LeftFoot: 0.9, jointsNames.LeftLowerLeg: 0.1},
# jointsNames.LeftUpperLeg: {jointsNames.RightFoot: 1.0},
# jointsNames.LeftLowerLeg: {jointsNames.RightFoot: 1.0},
# jointsNames.LeftFoot: {jointsNames.RightFoot: 1.0},
# # jointsNames.RightUpperLeg: {jointsNames.RightFoot: 0.9, jointsNames.RightLowerLeg: 0.1},
# # jointsNames.RightLowerLeg: {jointsNames.RightFoot: 0.9, jointsNames.RightLowerLeg: 0.1},
# jointsNames.RightUpperLeg: {jointsNames.RightFoot: 1.0},
# jointsNames.RightLowerLeg: {jointsNames.RightFoot: 1.0},
# jointsNames.RightFoot: {jointsNames.RightFoot: 1.0},
# jointsNames.Spine: {jointsNames.RightFoot: 1.0},
# jointsNames.Chest: {jointsNames.RightFoot: 1.0},
# jointsNames.UpperChest: {jointsNames.RightFoot: 1.0},
# jointsNames.LeftUpperArm: {jointsNames.RightFoot: 1.0},
# jointsNames.LeftLowerArm: {jointsNames.RightFoot: 1.0},
# jointsNames.LeftHand: {jointsNames.RightFoot: 1.0},
# # jointsNames.LeftHand: {jointsNames.LeftFoot: 1.0},
# jointsNames.RightUpperArm: {jointsNames.RightFoot: 1.0},
# jointsNames.RightLowerArm: {jointsNames.RightFoot: 1.0},
# jointsNames.RightHand: {jointsNames.RightFoot: 1.0},
# # jointsNames.RightHand: {jointsNames.LeftFoot: 1.0},
# jointsNames.Head: {jointsNames.RightFoot: 1.0},
# } # 第一層的key是main joint, 第二層的key是reference joints, 第二層value是reference joints之間的weight
blendingResults = []
for aBlendingRef in jointsBlendingRef:
mainJoint = aBlendingRef # 要synthesis的joint
refJoints = jointsBlendingRef[mainJoint].keys() # 做為參考找出k個similar vectors的joint(等同找到time point)
refJointsWeights = jointsBlendingRef[mainJoint].values()
refJointsWeights = list(refJointsWeights)
multiRefJointsResults = []
for aRefJoint in refJoints:
# print(aRefJoint)
multiRefJointsResults.append(
kSimilarFeatureVectorsBlending(
DBFullJointsPosNoAug[mainJoint],
multiJointsKSimilarDBIdx[aRefJoint], multiJointskSimilarDBDist[aRefJoint]
)
)
for i, w in enumerate(refJointsWeights):
multiRefJointsResults[i] = multiRefJointsResults[i]*refJointsWeights[i]
multiRefJointsResults = sum(multiRefJointsResults)
blendingResults.append(multiRefJointsResults)
# if mainJoint == jointsNames.LeftLowerLeg:
# break
print(len(blendingResults))
print(blendingResults[0])
print(blendingResults[0].shape)
# Single main joint syhthesis(obsolete)
# blendResult = kSimilarFeatureVectorsBlending(DBPosNoAug[2], kSimilarDBIdx, kSimilarDBDist)
# print(blendResult)
# print(blendResult.shape)
# Implement CoolMoves使用的Exponential Weighted Moving Average (EWMA)
# 𝑝_𝑡 = (𝑤_𝑡)𝑝_𝑡 + (1 − 𝑤_𝑡)𝑝_{𝑡−1}
# w_t是在t時的global match weight
blendingResultsEWMA = [None for i in range(len(blendingResults))]
for i in range(len(blendingResults)):
# print(blendingResults[i][-10:, :])
# print(blendingResults[i].shape)
blendingResultsEWMA[i] = EWMAToPositions(blendingResults[i], EWMAWeight)
# print(blendingResultsEWMA[i][-10:, :])
# print(blendingResultsEWMA[i].shape)
# Obsolete --> 改到plotMotionIn3D.py實作
# Check min max in the origin data, and the blended data
# 確認最大最小值在原始的資料以及blending後的資料上是否一樣
# 每一個joint各有自己的minmum and maximum value
# 檢查結果是沒問題
# tmpRefJoint = [aBlendingRef for aBlendingRef in jointsBlendingRef]
# print(tmpRefJoint)
# for i, j in enumerate(tmpRefJoint):
# print('origin max, min: ', DBFullJointsPosNoAug[j].max(axis=0), ', ', DBFullJointsPosNoAug[j].min(axis=0))
# print('blended max, min: ', blendingResults[i].max(axis=0), ', ', blendingResults[i].min(axis=0))
# print('blended max, min: ', blendingResultsEWMA[i].max(axis=0), ', ', blendingResultsEWMA[i].min(axis=0))
# 輸出blending完之後的整段motions
# blendingResultJson = blendingResultToJson(blendingResults)
blendingResultJson = blendingResultToJson(blendingResultsEWMA)
# with open('./positionData/afterSynthesis/leftFrontKick_EWMA.json', 'w') as WFile:
with open('./positionData/afterSynthesis/leftFrontKickStreamLinearMapping_TFFTTT_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/leftSideKick_generic_TTTFFF_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/leftSideKickLinearMapping_generic_TTTFFF_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/leftSideKickLinearMapping_TTTTTT_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/leftSideKickLinearMapping_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/leftSideKickStreamLinearMapping_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/walkCrossover_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/walkInjured_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/runSprint_TTTTTT_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/runSprintLinearMapping_TFTTFT_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/runSprintLinearMapping_generic_allLeft_TTTTTT_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/runSprintLinearMapping_EWMA.json', 'w') as WFile:
# with open('./positionData/afterSynthesis/runSprintStreamLinearMapping_EWMA.json', 'w') as WFile:
json.dump(blendingResultJson, WFile)