def ex1():
    n = 10
    eps = np.finfo(float).eps
    u = np.linspace(0 + eps, 1 - eps, n)
    UU = np.meshgrid(u, u)
    U2 = np.reshape(UU[0], (UU[0].shape[0] * UU[0].shape[1], 1))
    U3 = np.reshape(UU[1], (UU[1].shape[0] * UU[1].shape[1], 1))
    U1 = np.ones(U2.shape) * (1 - eps)
    U = np.concatenate((U1, U2, U3), axis=1)

    R1 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    R2 = np.array([[1, 0.6, -0.3], [0.6, 1, 0.4], [-0.3, 0.4, 1]])

    C1_twomarginal = copulacdf.copulacdf('Gaussian', U, R1)
    C2_twomarginal = copulacdf.copulacdf('Gaussian', U, R2)

    #X = UU[0]
    #Y = UU[1]
    #Z = np.reshape(C1_twomarginal,UU[0].shape)
    #plot_utils.plot_3d(X,Y,Z, 'C1 Two-Marginal')

    # compute error between C1_twomarginal and C2_twomarginal
    sq_err_vec = (C2_twomarginal - C1_twomarginal)**2

    X = UU[0]
    Y = UU[1]
    Z = np.reshape(sq_err_vec, UU[0].shape)
    plot_utils.plot_3d(X, Y, Z, 'Two-Marginal Error')
def ex1():
    n = 10
    eps = np.finfo(float).eps
    u = np.linspace(0+eps,1-eps,n)
    UU = np.meshgrid(u,u)
    U2 = np.reshape(UU[0], (UU[0].shape[0]*UU[0].shape[1], 1))
    U3 = np.reshape(UU[1], (UU[1].shape[0]*UU[1].shape[1], 1))
    U1 = np.ones(U2.shape)*(1-eps)
    U = np.concatenate((U1,U2,U3),axis=1)
    
    R1 = np.array([[1,0,0],[0,1,0],[0,0,1]])
    R2 = np.array([[1,0.6,-0.3],[0.6,1,0.4],[-0.3,0.4,1]])
    
    C1_twomarginal = copulacdf.copulacdf('Gaussian',U,R1)
    C2_twomarginal = copulacdf.copulacdf('Gaussian',U,R2)
    
    #X = UU[0]
    #Y = UU[1]
    #Z = np.reshape(C1_twomarginal,UU[0].shape)
    #plot_utils.plot_3d(X,Y,Z, 'C1 Two-Marginal')
    
    # compute error between C1_twomarginal and C2_twomarginal
    sq_err_vec = (C2_twomarginal-C1_twomarginal)**2
    
    X = UU[0]
    Y = UU[1]
    Z = np.reshape(sq_err_vec,UU[0].shape)
    plot_utils.plot_3d(X,Y,Z, 'Two-Marginal Error')
def _gumbel(u1v1, u1v2, u2v1, u2v2, alpha):
    
    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('Gumbel', u2v2, alpha) - \
           copulacdf('Gumbel', u2v1, alpha) - \
           copulacdf('Gumbel', u1v2, alpha) + \
           copulacdf('Gumbel', u1v1, alpha) 
    
    return cvol
def _frank(u1v1, u1v2, u2v1, u2v2, alpha):
    
    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('Frank', u2v2, alpha) - \
           copulacdf('Frank', u2v1, alpha) - \
           copulacdf('Frank', u1v2, alpha) + \
           copulacdf('Frank', u1v1, alpha) 
    
    return cvol
def _clayton(u1v1, u1v2, u2v1, u2v2, alpha):
    
    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('Clayton', u2v2, alpha) - \
           copulacdf('Clayton', u2v1, alpha) - \
           copulacdf('Clayton', u1v2, alpha) + \
           copulacdf('Clayton', u1v1, alpha) 
    
    return cvol
Example #6
0
def _gumbel(u1v1, u1v2, u2v1, u2v2, alpha):

    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('Gumbel', u2v2, alpha) - \
           copulacdf('Gumbel', u2v1, alpha) - \
           copulacdf('Gumbel', u1v2, alpha) + \
           copulacdf('Gumbel', u1v1, alpha)

    return cvol
Example #7
0
def _frank(u1v1, u1v2, u2v1, u2v2, alpha):

    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('Frank', u2v2, alpha) - \
           copulacdf('Frank', u2v1, alpha) - \
           copulacdf('Frank', u1v2, alpha) + \
           copulacdf('Frank', u1v1, alpha)

    return cvol
Example #8
0
def _clayton(u1v1, u1v2, u2v1, u2v2, alpha):

    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('Clayton', u2v2, alpha) - \
           copulacdf('Clayton', u2v1, alpha) - \
           copulacdf('Clayton', u1v2, alpha) + \
           copulacdf('Clayton', u1v1, alpha)

    return cvol
def _gaussian(u1v1, u1v2, u2v1, u2v2, r):
    # generate the Rho matrix from r
    Rho = np.ones((2,2))
    Rho[0][1] = r
    Rho[1][0] = r
    
    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('Gaussian', u2v2, Rho) - \
           copulacdf('Gaussian', u2v1, Rho) - \
           copulacdf('Gaussian', u1v2, Rho) + \
           copulacdf('Gaussian', u1v1, Rho) 
    
    return cvol
Example #10
0
def _gaussian(u1v1, u1v2, u2v1, u2v2, r):
    # generate the Rho matrix from r
    Rho = np.ones((2, 2))
    Rho[0][1] = r
    Rho[1][0] = r

    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('Gaussian', u2v2, Rho) - \
           copulacdf('Gaussian', u2v1, Rho) - \
           copulacdf('Gaussian', u1v2, Rho) + \
           copulacdf('Gaussian', u1v1, Rho)

    return cvol
def _t(u1v1, u1v2, u2v1, u2v2, r, nu):
    # generate the Rho matrix from r
    Rho = np.ones((2,2))
    Rho[0][1] = r
    Rho[1][0] = r
    
    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('T', u2v2, Rho, nu) - \
           copulacdf('T', u2v1, Rho, nu) - \
           copulacdf('T', u1v2, Rho, nu) + \
           copulacdf('T', u1v1, Rho, nu) 
    
    return cvol
    
    return None
Example #12
0
def _t(u1v1, u1v2, u2v1, u2v2, r, nu):
    # generate the Rho matrix from r
    Rho = np.ones((2, 2))
    Rho[0][1] = r
    Rho[1][0] = r

    # this is the equation for C Volume as defined by Nelsen
    cvol = copulacdf('T', u2v2, Rho, nu) - \
           copulacdf('T', u2v1, Rho, nu) - \
           copulacdf('T', u1v2, Rho, nu) + \
           copulacdf('T', u1v1, Rho, nu)

    return cvol

    return None
Example #13
0
def _gumbel(U, alpha):
    n = U.shape[0]
    d = U.shape[1]
    if (d > 2):
        raise ValueError(
            'Maximum dimensionality supported is 2 for the Gumbel Copula Family'
        )

    if (alpha < 1):
        raise ValueError('Bad dependency parameter for Gumbel copula')
    elif alpha == 1:
        y = np.ones((n, 1))
    else:
        # below is the closed form of d2C/dudv of the Gumbel copula
        C = copulacdf('Gumbel', U, alpha)
        u = U[:, 0]
        v = U[:, 1]
        p1 = C * 1.0 / (u * v) * np.power(
            np.power(-1 * np.log(u), alpha) + np.power(-1 * np.log(v), alpha),
            -2.0 + 2.0 / alpha) * np.power(np.log(u) * np.log(v), alpha - 1.0)
        p2 = 1.0 + (alpha - 1.0) * np.power(
            np.power(-1 * np.log(u), alpha) + np.power(-1 * np.log(v), alpha),
            -1.0 / alpha)
        y = p1 * p2
    return y
def ex2():
    n = 10
    eps = np.finfo(float).eps
    u = np.linspace(0 + eps, 1 - eps, n)
    UU = np.meshgrid(u, u)
    U3 = np.reshape(UU[1], (UU[1].shape[0] * UU[1].shape[1], 1))
    U1 = np.ones(U3.shape) * (1 - eps)
    U2 = np.ones(U3.shape) * (1 - eps)
    U = np.concatenate((U1, U2, U3), axis=1)

    R1 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    R2 = np.array([[1, 0.6, -0.3], [0.6, 1, 0.4], [-0.3, 0.4, 1]])

    C1_onemarginal = copulacdf.copulacdf('Gaussian', U, R1)
    C2_onemarginal = copulacdf.copulacdf('Gaussian', U, R2)
    sq_err_vec = (C2_onemarginal - C1_onemarginal)**2

    X = UU[0]
    Y = UU[1]
    Z = np.reshape(sq_err_vec, UU[0].shape)
    plot_utils.plot_3d(X, Y, Z, 'One-Margin Error')
def ex2():
    n = 10
    eps = np.finfo(float).eps
    u = np.linspace(0+eps,1-eps,n)
    UU = np.meshgrid(u,u)
    U3 = np.reshape(UU[1], (UU[1].shape[0]*UU[1].shape[1], 1))
    U1 = np.ones(U3.shape)*(1-eps)
    U2 = np.ones(U3.shape)*(1-eps)
    U = np.concatenate((U1,U2,U3),axis=1)
    
    R1 = np.array([[1,0,0],[0,1,0],[0,0,1]])
    R2 = np.array([[1,0.6,-0.3],[0.6,1,0.4],[-0.3,0.4,1]])
    
    C1_onemarginal = copulacdf.copulacdf('Gaussian',U,R1)
    C2_onemarginal = copulacdf.copulacdf('Gaussian',U,R2)
    sq_err_vec = (C2_onemarginal-C1_onemarginal)**2
    
    X = UU[0]
    Y = UU[1]
    Z = np.reshape(sq_err_vec,UU[0].shape)
    plot_utils.plot_3d(X,Y,Z, 'One-Margin Error')
def _gumbel(U, alpha):
    n = U.shape[0]
    d = U.shape[1]
    if(d>2):
        raise ValueError('Maximum dimensionality supported is 2 for the Gumbel Copula Family')
    
    if(alpha < 1):
        raise ValueError('Bad dependency parameter for Gumbel copula')
    elif alpha==1:
        y = np.ones((n,1))
    else:
        # below is the closed form of d2C/dudv of the Gumbel copula
        C = copulacdf('Gumbel', U, alpha)
        u = U[:,0]
        v = U[:,1]
        p1 = C*1.0/(u*v)*np.power(np.power(-1*np.log(u),alpha) + np.power(-1*np.log(v),alpha), -2.0 + 2.0/alpha)*np.power(np.log(u)*np.log(v),alpha-1.0)
        p2 = 1.0 + (alpha - 1.0)*np.power(np.power(-1*np.log(u),alpha) + np.power(-1*np.log(v),alpha), -1.0/alpha )
        y = p1*p2
    return y