(B2, Y_res, C2, R, n2, m2, lambdax)
return (Y_ij, Y_res, C2)
Compute second order sensitivities.
Compute second order sensitivities.
Compute second order sensitivities .
def _second_order(B2, Y_res, C2, R, n2, m2, lambdax):
    """Compute second order sensitivities."""
    Y_ij = np.zeros((R, n2))      # Initialize 1st order contributions
    T2 = np.zeros((m2, R, n2))    # Initialize T(emporary) matrix - 1st

    # First order individual estimation
    for j in range(n2):
        # Regularized least squares inversion ( minimize || C1 ||_2 )
        B22 = np.matmul(np.transpose(B2[:, :, j]), B2[:, :, j])

        # if it is ill-conditioned matrix, the default value is zero
        if np.all(np.linalg.svd(B22)[1]): # sigma, diagonal matrix, from svd
            T2[:, :, j] = np.linalg.solve(np.add(B22, np.multiply(
                lambdax, np.identity(m2))), np.transpose(B2[:, :, j]))

        C2[:, j] = np.matmul(T2[:, :, j], Y_res).reshape(m2,)
        Y_ij[:, j] = np.matmul(B2[:, :, j], C2[:, j])

    # Now compute second-order terms
    for j in range(n2):
        Y_ij[:, j] = np.matmul(B2[:, :, j], C2[:, j])

        # Subtract each first order term from residuals
        Y_res = np.subtract(Y_res, Y_ij[:, j].reshape(R, 1))

    return (Y_ij, Y_res, C2)
def _second_order ( B2 , Y_res , C2 , R , n2 , m2 , lambdax ) : Y_ij = np . zeros ( ( R , n2 ) ) # Initialize 1st order contributions T2 = np . zeros ( ( m2 , R , n2 ) ) # Initialize T(emporary) matrix - 1st # First order individual estimation for j in range ( n2 ) : # Regularized least squares inversion ( minimize || C1 ||_2 ) B22 = np . matmul ( np . transpose ( B2 [ : , : , j ] ) , B2 [ : , : , j ] ) # if it is ill-conditioned matrix, the default value is zero if np . all ( np . linalg . svd ( B22 ) [ 1 ] ) : # sigma, diagonal matrix, from svd T2 [ : , : , j ] = np . linalg . solve ( np . add ( B22 , np . multiply ( lambdax , np . identity ( m2 ) ) ) , np . transpose ( B2 [ : , : , j ] ) ) C2 [ : , j ] = np . matmul ( T2 [ : , : , j ] , Y_res ) . reshape ( m2 , ) Y_ij [ : , j ] = np . matmul ( B2 [ : , : , j ] , C2 [ : , j ] ) # Now compute second-order terms for j in range ( n2 ) : Y_ij [ : , j ] = np . matmul ( B2 [ : , : , j ] , C2 [ : , j ] ) # Subtract each first order term from residuals Y_res = np . subtract ( Y_res , Y_ij [ : , j ] . reshape ( R , 1 ) ) return ( Y_ij , Y_res , C2 )