Computing Emotional Response Agorithm

 You can compute emotion frequency by first assigning an emotion label to each trial (e.g., participant response, facial-expression model output, or text report about the artwork), then counting how often each emotion occurs and normalizing by the total number of trials.

Basic idea

Assume you have a list of responses to artworks, where each response is already labeled with a discrete emotion such as "happy", "sad", "fear", etc. (these could come from an image emotion detector, a text classifier, or manual coding). You then:

  1. Count how many times each emotion appears.

  2. Divide by the total number of responses to get relative frequencies.

Python code example

python
from collections import Counter import pandas as pd # Example data: each row is a trial (a person viewing an artwork) # artwork_id: which artwork was shown # participant_id: who viewed it # emotion: detected or self-reported emotion label for that trial data = [ {"artwork_id": "A1", "participant_id": "P1", "emotion": "happy"}, {"artwork_id": "A1", "participant_id": "P2", "emotion": "sad"}, {"artwork_id": "A1", "participant_id": "P3", "emotion": "happy"}, {"artwork_id": "A2", "participant_id": "P1", "emotion": "fear"}, {"artwork_id": "A2", "participant_id": "P2", "emotion": "happy"}, {"artwork_id": "A2", "participant_id": "P3", "emotion": "neutral"}, ] df = pd.DataFrame(data) def emotion_frequency_for_artwork(df, artwork_id): # Filter trials for one artwork sub = df[df["artwork_id"] == artwork_id] # Count occurrences of each emotion counts = Counter(sub["emotion"]) # Compute relative frequency (proportion) for each emotion total = len(sub) freqs = {emo: count / total for emo, count in counts.items()} # Return both raw counts and relative frequencies return counts, freqs # Example: frequencies for artwork A1 counts_A1, freqs_A1 = emotion_frequency_for_artwork(df, "A1") print("Counts A1:", counts_A1) print("Frequencies A1:", freqs_A1) # If you want a frequency table for all artworks at once: freq_table = ( df.groupby(["artwork_id", "emotion"]) .size() .groupby(level=0) .apply(lambda x: x / x.sum()) # normalize within each artwork .rename("freq") .reset_index() ) print(freq_table)

This example assumes you already have an "emotion" label per trial; you can get those labels from an emotion-detection model on faces, an EEG classifier, or an emotion classifier on text utterances describing the artwork. If you share how you obtain the emotion labels (facial expressions, self-report, text descriptions, EEG, etc.), a more targeted code example can be provided.

Comments

Popular posts from this blog

Leading Humans in the Trump Era

HiIgh 4-ethyl phenol (4-EP) using activated carbon (AC)

Catalytic Pyrolysis Study