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

Estimate VAD by weighted average

Does a weighted average of centroids.

If intensity sums to zero for a category, a 'neutral' category is used or 0 if it's not present. I'm not 100% sure this is the best approach, and the name of the "neutral" category perhaps should use some convention?

Note that if there are no categories present, then no VAD (or other dimensional) estimate is returned. It may be better to use the neutral centroid if it's present in this case also.
This commit is contained in:
drevicko 2017-04-04 15:37:07 +01:00 committed by GitHub
parent 1302b0b93c
commit 53138e6942

View File

@ -1,5 +1,6 @@
from senpy.plugins import EmotionConversionPlugin from senpy.plugins import EmotionConversionPlugin
from senpy.models import EmotionSet, Emotion, Error from senpy.models import EmotionSet, Emotion, Error
from collections import defaultdict
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -37,14 +38,22 @@ class CentroidConversion(EmotionConversionPlugin):
def _forward_conversion(self, original): def _forward_conversion(self, original):
"""Sum the VAD value of all categories found.""" """Sum the VAD value of all categories found."""
res = Emotion() res = Emotion()
totalIntensities = defaultdict(float)
for e in original.onyx__hasEmotion: for e in original.onyx__hasEmotion:
category = e.onyx__hasEmotionCategory category = e.onyx__hasEmotionCategory
intensity = e.get("onyx__hasEmotionIntensity",1)
if category in self.centroids: if category in self.centroids:
totalIntensities[category] += intensity
for dim, value in self.centroids[category].items(): for dim, value in self.centroids[category].items():
try: try:
res[dim] += value res[dim] += value * intensity
except Exception: except Exception:
res[dim] = value res[dim] = value * intensity
for dim,intensity in totalIntensities.items():
if intensity != 0:
res[dim] /= intensity
else:
res[dim] = self.centroids.get('neutral', {dim:0})[dim]
return res return res
def _backwards_conversion(self, original): def _backwards_conversion(self, original):