def ana_dyads(connectivity):
    """
        Calculate proportion symmetric dyads (PTCMUT), asymmetric dyads (PTCASY) and mutuality index (RHO2).
    """
    nodes = connectivity.shape[0]
    mutual_d = 0
    asym_d = 0
    out_degrees = []

    # count out_degree connections per individual and mutual and asymmetrix connections whole network
    for i in range(connectivity.shape[0]) :
        out_degree = 0
        for j in range(connectivity.shape[1]) :
            if connectivity[i][j] == 1 :
                out_degree += 1
                if connectivity[j][i] == 1 :
                    mutual_d += 0.5
                elif connectivity[j][i] != 1 :
                    asym_d += 1
        out_degrees.append(out_degree)

    total_d = mutual_d + asym_d

    # calculate proportion symmetric dyads (PTCMUT) and asymmetric dyads (PTCASY)
    PTCMUT = mutual_d / total_d
    PTCASY = asym_d / total_d

    # calculate mutuality index (RHO2) (according to Katz and Powell’s (1955))
    sum_out_degrees = sum(out_degrees)
    mean_out_degrees = sum_out_degrees / len(out_degrees)
    sum_squares_out = 0
    for i in range(len(out_degrees)) :
        sum_squares_out += (mean_out_degrees - out_degrees[i]) ** 2
    RHO2 = (2 * (nodes - 1) ** 2 * mutual_d - sum_out_degrees ** 2 + sum_squares_out) / (
                sum_out_degrees * (nodes - 1) ** 2 - sum_out_degrees ** 2 + sum_squares_out)

    return PTCMUT, PTCASY, RHO2