Ejemplo n.º 1
0
def dg_second_moment(u, gauss_mean1, gauss_mean2, support1, support2):
    """
    Missing documentation
    
    Parameters
    ----------
    u : Type
        Description
    gauss_mean1 : Type
        Description
    gauss_mean2 : Type
        Description
    support1 : Type
        Description
    support2 : Type
        Description
    
    Returns
    -------
    Value : Type
        Description
    """
    # subfunction DGSecondMoment: Calculate second Moment of the DG
    # for a given correlation lambda
    #a very, very inefficient function for calculating the second moments of a
    #DG with specified gammas and supports and correlation lambda
    from statsmodels.sandbox.distributions.multivariate import mvnormcdf

    sig = np.array([[1, u], [u, 1]])
    x, y = np.meshgrid(support2, support1)
    xy = x * y

    ps = np.zeros((len(support1), len(support2)))

    for i in range(len(support1)):
        for j in range(len(support2)):
            ps[i, j] = mvnormcdf([gauss_mean1[i], gauss_mean2[j]], [0, 0], sig)

    ps2 = ps.copy()
    for i in range(len(support1)):
        for j in range(len(support2)):
            if i > 0 and j > 0:
                ps2[i, j] = ps[i, j] + ps[i - 1, j - 1] - ps[i - 1,
                                                             j] - ps[i, j - 1]
            elif j > 0 and i == 0:
                ps2[i, j] = ps[i, j] - ps[i, j - 1]
            elif i > 0 and j == 0:
                ps2[i, j] = ps[i, j] - ps[i - 1, j]
            elif i == 0 and j == 0:
                ps2[i, j] = ps[i, j]

    ps2 = np.clip(ps2, 0, ps2.max())
    joint = ps2.copy()
    ps2 = ps2 * xy
    secmom = np.sum(ps2)
    return secmom, joint
Ejemplo n.º 2
0
def dg_second_moment(u, gauss_mean1, gauss_mean2, support1, support2):
    """
    Missing documentation
    
    Parameters
    ----------
    u : Type
        Description
    gauss_mean1 : Type
        Description
    gauss_mean2 : Type
        Description
    support1 : Type
        Description
    support2 : Type
        Description
    
    Returns
    -------
    Value : Type
        Description
    """
    # subfunction DGSecondMoment: Calculate second Moment of the DG
    # for a given correlation lambda
    #a very, very inefficient function for calculating the second moments of a
    #DG with specified gammas and supports and correlation lambda
    from statsmodels.sandbox.distributions.multivariate import mvnormcdf

    sig = np.array([[1, u], [u, 1]])
    x, y = np.meshgrid(support2, support1)
    xy = x * y

    ps = np.zeros((len(support1), len(support2)))

    for i in range(len(support1)):
        for j in range(len(support2)):
            ps[i, j] = mvnormcdf([gauss_mean1[i], gauss_mean2[j]], [0, 0], sig)

    ps2 = ps.copy()
    for i in range(len(support1)):
        for j in range(len(support2)):
            if i > 0 and j > 0:
                ps2[i, j] = ps[i, j] + ps[i - 1, j - 1] - ps[i - 1, j] - ps[i, j - 1]
            elif j > 0 and i == 0:
                ps2[i, j] = ps[i, j] - ps[i, j - 1]
            elif i > 0 and j == 0:
                ps2[i, j] = ps[i, j] - ps[i - 1, j]
            elif i == 0 and j == 0:
                ps2[i, j] = ps[i, j]

    ps2 = np.clip(ps2, 0, ps2.max())
    joint = ps2.copy()
    ps2 = ps2 * xy
    secmom = np.sum(ps2)
    return secmom, joint
Ejemplo n.º 3
0
def maxpdf(x, mu, S):
    s = np.zeros(x.shape[0])
    d = mu.shape[0]
    for i in xrange(d):
        mu_i = mu[i]
        S_ii = S[i, i]
        mu_ni, S_nini = remove(mu, S, i)
        S_ini = np.array(np.bmat([[S[:i, i], S[i+1:, i]]]))
        mu_nii = mu_ni[:, None] + np.dot(S_ini.T, x[None, :] - mu_i) / S_ii
        S_ninii = S_nini - np.dot(S_ini, S_ini.T) / S_ii
        phi_i = norm.pdf(x, loc=mu_i, scale=np.sqrt(S_ii))
        Phi_i = np.array([mvnormcdf(x[j], mu_nii[:, j], S_ninii) 
                          for j in xrange(x.shape[0])])
        s += phi_i * Phi_i
    return s
Ejemplo n.º 4
0
def maxpdf(x, mu, S):
    s = np.zeros(x.shape[0])
    d = mu.shape[0]
    for i in xrange(d):
        mu_i = mu[i]
        S_ii = S[i, i]
        mu_ni, S_nini = remove(mu, S, i)
        S_ini = np.array(np.bmat([[S[:i, i], S[i + 1:, i]]]))
        mu_nii = mu_ni[:, None] + np.dot(S_ini.T, x[None, :] - mu_i) / S_ii
        S_ninii = S_nini - np.dot(S_ini, S_ini.T) / S_ii
        phi_i = norm.pdf(x, loc=mu_i, scale=np.sqrt(S_ii))
        Phi_i = np.array([
            mvnormcdf(x[j], mu_nii[:, j], S_ninii) for j in xrange(x.shape[0])
        ])
        s += phi_i * Phi_i
    return s
Ejemplo n.º 5
0
    def cdf(self, x, **kwds):
        '''cumulative distribution function

        Parameters
        ----------
        x : array_like
            can be 1d or 2d, if 2d, then each row is taken as independent
            multivariate random vector
        kwds : dict
            contains options for the numerical calculation of the cdf

        Returns
        -------
        cdf : float or array
            probability density value of each random vector

        '''
        #lower = -np.inf * np.ones_like(x)
        #return mvstdnormcdf(lower, self.standardize(x), self.corr, **kwds)
        return mvnormcdf(x, self.mean, self.cov, **kwds)
Ejemplo n.º 6
0
    def cdf(self, x, **kwds):
        '''cumulative distribution function

        Parameters
        ----------
        x : array_like
            can be 1d or 2d, if 2d, then each row is taken as independent
            multivariate random vector
        kwds : dict
            contains options for the numerical calculation of the cdf

        Returns
        -------
        cdf : float or array
            probability density value of each random vector

        '''
        #lower = -np.inf * np.ones_like(x)
        #return mvstdnormcdf(lower, self.standardize(x), self.corr, **kwds)
        return mvnormcdf(x, self.mean, self.cov, **kwds)