# Sampling GFG parameters
Faces 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 AUs
In 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:


```python
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)
```

    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']


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$:


```python
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),))
```

    Selected AUs: ['AU14R' 'AU6' 'AU10ROpen']


## 2. Sampling of 

ipynb
5e57c02e0cba34cd4d85599699cfd2d610b71ce0
Jupyter Notebook
2020-02-19T03:46:27.000Z
2020-02-19T03:46:27.000Z
68d7b72057cb46e11b7c7ffd30011e50326185c0
MIT
lukassnoek/GFG_python
notebooks/sampling_GFG_parameters.ipynb
68d7b72057cb46e11b7c7ffd30011e50326185c0
2018-11-13T10:19:25.000Z
2018-11-13T10:19:21.000Z
MIT
lukassnoek/GFG_python
notebooks/sampling_GFG_parameters.ipynb
68d7b72057cb46e11b7c7ffd30011e50326185c0
MIT
lukassnoek/GFG_python
notebooks/sampling_GFG_parameters.ipynb
2022-03-07T12:33:54.000Z
2021-08-13T07:18:05.000Z