def calc_mapping(
        dfile_db,
        mapping=None,
        dcon_db=None,
        target_mos=None,
        target_ci=None,
        pred=None,
        ):
    '''
    Computes mapping between subjective and predicted MOS. 
    '''       
    if dcon_db is not None:
        y = dcon_db[target_mos].to_numpy()        
        y_hat = dfile_db.groupby('con').mean().get(pred).to_numpy()
    else:
        y = dfile_db[target_mos].to_numpy()        
        y_hat = dfile_db[pred].to_numpy()    
        
    if mapping==None:
        b = np.array([0,1,0,0])
        d_map = 0
    elif mapping=='first_order':
        b = fit_first_order(y, y_hat)
        d_map = 1
    elif mapping=='second_order':
        b = fit_second_order(y, y_hat)            
        d_map = 3
    elif mapping=='third_order_not_monotonic':
        b = fit_third_order(y, y_hat)            
        d_map = 4        
    elif mapping=='third_order':
        b = fit_monotonic_third_order(
            dfile_db,
            dcon_db=dcon_db, 
            pred=pred, 
            target_mos=target_mos, 
            target_ci=target_ci,
            mapping='error',
            )
        d_map = 4
    else:
        raise NotImplementedError      
    
    return b, d_map

    Computes mapping between subjective and predicted MOS. 
    
speechscore/scores/nisqa/NISQA_lib.py