def calculate_gamma(P,sigma):
    """
    Calcualte the fraction of the information

    Parameters
    ----------
    P: integer
        The number of the basis function
    sigma: array
        The array obtained from the singular value decomposition
    
    Returns
    ----------
    res : float
        Information carried by the first P basis function
    """

    M = len(sigma)
    sigma_sum = 0
    for i in range(M):
        sigma_sum += sigma[i]*sigma[i]
    P_sum = 0
    for i in range(P+1):
        P_sum += sigma[i]*sigma[i]
    res = P_sum / sigma_sum * 100  # 100 percent
    return res