<jupyter_start><jupyter_text>Sampling GFG parametersFaces from the GFG platform can be parameterized with specific configurations of action units (AUs) and temporal/onset parameters. This notebook describes how we sample these parameters. 1. Sampling of AUsIn previous articles ([Jack et al., 2016](http://psycnet.apa.org/journals/xge/145/6/708.html?uid=2016-17953-001), [Delis et al., 2016](http://jov.arvojournals.org/article.aspx?articleid=2529071)), AU samples were generated by sampling a combination of AUs from a binomial distribution which was parameterized as follows:\begin{align}B(n, p)\end{align}In which $n$ refers to the number of "trials" and $p$ to the probability of "success" for a given trial. In the aforementioned articles, the authors use $n=5$ and $p=0.6$ and limit the range from $1$ to $6$. While setting the minimum to 1 makes sense (you want at least one AU to animate the face), setting the maximum to 6 is unnecessary because with $n=5$ the maximum is 5. Also, the articles mention that the median number of AUs is 3, which makes sense because the median of a binomial distribution with parameters $n$ and $p$ is $np$ ($5 \times 0.6 = 3$).Anyway, let's acutally implement such a sampling scheme. First, let's load in the choices of AU available to us:<jupyter_code>from scipy.io import loadmat
au_labels = loadmat('../GFG_python/au_labels.mat')['au_labels'][0]
au_labels = [au[0] for au in au_labels]

print("Number of AUs: %i" % len(au_labels))
print(au_labels)<jupyter_output>Number of AUs: 42
['AU1', 'AU1-2', 'AU2', 'AU2L', 'AU4', 'AU5', 'AU6', 'AU6L', 'AU6R', 'AU7L', 'AU7R', 'AU9', 'AU10Open', 'AU10LOpen', 'AU10ROpen', 'AU11L', 'AU11R', 'AU12', 'AU25-12', 'AU12L', 'AU12R', 'AU13', 'AU14', 'AU14L', 'AU14R', 'AU15', 'AU16Open', 'AU17', 'AU20', 'AU20L', 'AU20R', 'AU22', 'AU23', 'AU24', 'AU25', 'AU26', 'AU27i', 'AU38', 'AU39', 'AU43', 'AU7', 'AU12-6']<jupyter_text>Now, let's define a function that randomly samples a number of AUs, which is determined by a draw from a binomial distribution with $n=5$ and $p=0.6$:<jupyter_code>import numpy as np

def sample_AUs(au_labels, n=5, p=0.6):
    """ Draws a random sample of AUs.
    
    Parameters
    ----------
    au_labels : numpy array
        Array with AU-labels
    n : int
        Parameter n of binomial distribution
    p : float
        Parameter p of binomial distribution
        
    Returns
    -------
    these_AUs : numpy array
        Array with selected AUs.
    """
    this_n = np.random.binomial(n=5, p=0.6)
    while this_n == 0:  # Resample if number of AUs to draw is 0
        this_n = np.random.binomial(n=5, p=0.6)
    
    these_AUs = np.random.choice(au_labels, size=this_n, replace=False)
    return these_AUs

print("Selected AUs: %s" % (sample_AUs(au_labels),))<jupyter_output>Selected AUs: ['AU14R' 'AU6' 'AU10ROpen']
{'fraction_non_alphanumeric': 0.13605921748325697, 'fraction_numerical': 0.05181529784984138, 'mean_word_length': 4.132007233273056, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '145897', 'license': 'MIT', 'n_tokens_mistral': 1060, 'n_tokens_neox': 967, 'n_words': 343, 'path': 'notebooks/sampling_GFG_parameters.ipynb', 'repo_name': 'lukassnoek/GFG_python', 'size': '2837'}