I'm working with the Scikit-Learn NMF algorithm and I would like to know if there is any way to use negative values with the algorithm, I need it to work with BVH files.
I'm using python 3.7.5
import numpy as np
import re
from sklearn.decomposition import NMF
with open('01_01.bvh', 'r') as fr:
with open('01_01_NMF.bvh', 'w') as fw:
for line in fr.readlines():
if line[0].isdigit() or line[1].isdigit():
line = re.split('\s+|\n', line)
line.pop()
MOTION = [float(nums) for nums in line]
X = MOTION
print("Original")
print(X)
model = NMF(n_components=96, init='random', random_state=0)
W = model.fit_transform(X)
H = model.components_
print("NMF")
print(W)
OutputMotion = [str(nums) for nums in W]
out = ' '.join(OutputMotion)
fw.write(out + '\n')
else:
fw.write(line)
The code already reads line by line the bvh files and verifies that it is in the Motion section, that section is the one that has to go through the NMF but it usually has many negative values and the algorithm rejects them. Any help is welcome, thank you.
You have to normalize the data, so every parameter value is between 0.0-1.0. see scikit learn https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.NMF.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.