<jupyter_start><jupyter_text>Speech Convergence Convergence is computed on word pairs. For a word pair to be a convergent one, the acoustic properties of the words for the two speakers must become more similar to each other. ![title](docs/img/Convergence_criteria.png)  Run the notebook<jupyter_code># init
import numpy as np
import os
import warnings
warnings.filterwarnings('ignore')
from IPython.display import clear_output
import seaborn as sns
from matplotlib import pyplot as plt
import pandas as pd
%matplotlib inline

subject_name = ['stella','juliet','shai','ayoub','lucas','simone','henry', 'julien',
                'marion','elvira']
partner_name = ['juliet','stella','ayoub','shai','simone','lucas','julien', 'henry', 
                'elvira','marion']
subject_group_no = [1,1,2,2,3,3,4,4,5,5]

session_name = ['pre','duet1', 'duet2', 'duet3' ,'duet4','duet5','duet6','post']

# load data
duet_scores = pd.read_pickle('data/duet_scores.pkl')
duet_scores  = duet_scores.sort_values(by=['subject','session', 'wordNo'])
duet_scores.head()<jupyter_output><empty_output><jupyter_text>Convergence criteriaCompute the distribution of LLR score difference between own model and partner model. We call it baseline_threshold and we get it for each speaker. We get the 5 , 50 and 95 percentile of this distribution.For test speech we compute the LLR score difference (y) between own model and partner model. Now if:    baseline_threshold(5)< y < baseline_threshold(95) = No change    y <= baseline_threshold(5) = Convergence    y >= baseline_threshold(95) = Divergence<jupyter_code># compute baseline threshold for each subjects with [5 50 95] percentile
session = session_name[7]
print('baseline threshold is computed on the session = '+session)

baseline_threshold = []
for i in range(0,len(subject_name)):
    s=subject_name[i]
    p=partner_name[i]
    a=duet_scores[(duet_scores['session']==session)&
                  (duet_scores['subject']==s)]['GMM_'+s].get_values()

    b=duet_scores[(duet_scores['session']==session)&
                  (duet_scores['subject']==s)]['GMM_'+p].get_values()
    
    baseline_threshold.append((np.percentile(a-b,5),np.percentile(a-b,50),np.percentile(a-b,95)))
baseline_threshold = np.stack(baseline_threshold)    
baseline_threshold    

# convergence computation
def get_convergence(A,baseline_threshold):

    strategies = []
    for i in range(0,A.shape[0]):        
        s = A.iloc[i]['subject']
        s_idx = subject_name.index(s)
        p = partner_name[s_idx]
        
        a = A.iloc[i]['GMM_'+s] - A.iloc[i]['GMM_'+p]
        
        
        NoChange = 0
        Convergence = 0
        Divergence = 0
        score_diff=0
        if(baseline_threshold[s_idx,0]<a<baseline_threshold[s_idx,2]):
            NoChange = 1
        elif(baseline_threshold[s_idx,0]>=a):
            Convergence = 1
        elif(baseline_threshold[s_idx,2]<=a):
            Divergence = 1
            
        aa = np.where(np.asarray(subject_name)==A.iloc[i]['subject'])[0][0]
        
        
        a = pd.DataFrame({'group':subject_group_no[aa]-1,'wordNo':A.iloc[i]['wordNo'],
                          'subject':A.iloc[i]['subject'],
                          'session':session_name.index(A.iloc[i]['session']),
                          'NoChange':[NoChange],'Convergence':Convergence,
                          'Divergence':Divergence,
                          'mean_score_ratio':a / baseline_threshold[s_idx,1]})    
        strategies.append(a)     

    strategies = pd.concat((strategies),axis=0)
    return strategies


strategies = get_convergence(duet_scores,baseline_threshold)
strategies = strategies.melt(['group','wordNo','subject','session','mean_score_ratio'], 
                             var_name='type', value_name='data')
strategies.head()<jupyter_output><empty_output><jupyter_text>Visualize the results<jupyter_code># Plot
sns.set(font_scale=1.5)


f, AX = plt.subplots(figsize=(15,6))

ax = sns.barplot(x="subject", y="data", hue='type',data=strategies)
def change_width(ax, new_value) :
    for patch in ax.patches :
        current_width = patch.get_width()
        diff = current_width - new_value

        # we change the bar width
        patch.set_width(new_value)

        # we recenter the bar
        patch.set_x(patch.get_x() + diff * .5)

#change_width(ax, .65)
_=plt.ylabel('No of times')
#_=plt.xlim([-1,10])<jupyter_output><empty_output>