1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-22 00:02:28 +00:00

Implements Fernando's suggestion in #31

I've added a neutral point definition (in the converters senpy file) as used in pull request #29
This commit is contained in:
drevicko 2017-05-29 12:13:21 +01:00 committed by GitHub
parent 8d56a0b630
commit 65d6e47513

View File

@ -49,18 +49,15 @@ class CentroidConversion(EmotionConversionPlugin):
def _backwards_conversion(self, original):
"""Find the closest category"""
dimensions = list(self.centroids.values())[0]
dimensions = set(k.keys() for i in centroids.values())
neutralPoint = self.get("origin", None)
neutralPoint = {k:neutralPoint[k] if k in neturalPoint else 0}
def distance(e1, e2):
return sum((e1[k] - e2.get(k, 0)**2) for k in dimensions)
def distance(centroid):
return sum((centroid.get(k, neutralPoint[k]) - original.get(k, neutralPoint[k]))**2 for k in dimensions)
emotion = min(centroids, key=lambda x: distance(centroids[x])
emotion = ''
mindistance = 10000000000000000000000.0
for state in self.centroids:
d = distance(self.centroids[state], original)
if d < mindistance:
mindistance = d
emotion = state
result = Emotion(onyx__hasEmotionCategory=emotion)
return result