Example #1
0
def Berryfrac(xst, xf, yst, yf):
    berrynumtorx = (mlt(Hy[xst:xf, yst:yf, :], Hxx[xst:xf, yst:yf, :]) - 
                    mlt(Hx[xst:xf, yst:yf, :], Hyx[xst:xf, yst:yf, :]))
    
    berrynumtory = (mlt(Hy[xst:xf, yst:yf, :], Hxy[xst:xf, yst:yf, :]) - 
                    mlt(Hx[xst:xf, yst:yf, :], Hyy[xst:xf, yst:yf, :]))
    
    berrynumtorz = (mlt(Hy[xst:xf, yst:yf, :], Hxz[xst:xf, yst:yf, :]) - 
                    mlt(Hx[xst:xf, yst:yf, :], Hyz[xst:xf, yst:yf, :]))
    
    berrydenomtor1 = 1 + Hz[xst:xf, yst:yf, :]
    
    berrydenomtor2 = 1 - Hz[xst:xf, yst:yf, :]
    
    return [berrynumtorx, berrynumtory, berrynumtorz, 
            berrydenomtor1, berrydenomtor2]
Example #2
0
def constrainedflexibleleastsquare(X,
                                   y,
                                   lamb,
                                   W1,
                                   W2,
                                   Phi,
                                   D,
                                   d,
                                   smallG,
                                   a,
                                   b):
    r"""
    
    .. math::
       :nowrap:

       \begin{eqnarray*}
       \arg_{\beta_t,\forall t}\min\sum_{t = 1}^m (y_t - X^T_t \beta_t)^T W_1 (y_t - X^T_t \beta_t) +& \sum_{t=1}^{m-1}\lambda (\beta_{t+1} - \Phi \beta_t)^T W_2 (\beta_{t+1} - \Phi \beta_t)\\
       G \beta_t & \geq g, \quad \forall t\\
       D \beta_t & = d, \quad \forall t
       \end{eqnarray*}

    """
    t, n = scipy.shape(X)
    P = scipy.empty( (t * n, t * n))
    G = scipy.empty( (2*n, n))
    G[0:n, 0:n] = smallG
    G[n: 2*n, 0:n] = -smallG
    g = scipy.empty( (2*n, 1))
    g[0:n] = b
    g[n:2*n] = -a
####P#####
    for i in xrange(t):
        if i == 0:
            p = 2* W1* mlt(X[i].T, X[i]) + lamb * Phi.T * W2 * Phi
        elif i == t-1:
            p = 2* W1* mlt(X[i].T, X[i])
        else:
            p = 2* W1* mlt(X[i].T, X[i]) + lamb * (Phi.T * W2 * Phi + W2)
        if i < t-1:
            P[(i)*n:(i+1)*n, (i+1)*n:(i+2)*n] = -2 * lamb * Phi.T  *W2
            P[(i+1)*n:(i+2)*n, (i)*n:(i+1)*n] = -2 * lamb * W2 * Phi
        P[i*n:i*n+n, i*n:i*n+n] = p.copy()

##q##
    q = scipy.empty((t*n, 1))
    for i in xrange(t):
        q[i*n:(i+1)*n] = -2 * X[i].T * W1 * y[i]
#q = (-2 * W1 * y)
##bigG##
    gr, gc = scipy.shape(G)
    bigG = scipy.empty((gr*t, gc*t))
        
    for i in xrange(t):
        bigG[i*gr:(i+1)*gr, i*gc:(i+1)*gc] = G

    bigg = scipy.empty((gr*t, 1))
    for i in xrange(t):
        bigg[i*gr:(i+1)*gr] = g
                
    dr, dc = scipy.shape(D)
    A = scipy.empty((t* dr, t* dc))
    for i in xrange(t):
        A[i*dr: (i+1) * dr, i*dc:(i+1)*dc] = D
        b = scipy.empty((t, 1))
    for i in xrange(t):
        b[i:(i+1)] = d

    paraset = map(cvxopt.matrix, (P, q, bigG, bigg, A, b))
    beta =  mat(qp(*paraset)['x']).reshape(t, n).tolist()
    return beta
Example #3
0
D = scipy.ones((1, n))
d = scipy.matrix(1.)
smallG = scipy.identity(n)
a = scipy.zeros((n, 1))
c = scipy.ones((n, 1))

G = scipy.empty((2 * n, n))
G[0:n, 0:n] = smallG
G[n:2 * n, 0:n] = -smallG
g = scipy.empty((2 * n, 1))
g[0:n] = c
g[n:2 * n] = -a
####P#####
for i in xrange(t):
    if i == 0:
        p = 2 * W1 * mlt(X[i].T, X[i]) + lamb * Phi.T * W2 * Phi
    elif i == t - 1:
        p = 2 * W1 * mlt(X[i].T, X[i])
    else:
        p = 2 * W1 * mlt(X[i].T, X[i]) + lamb * (Phi.T * W2 * Phi + W2)
    if i < t - 1:
        P[(i) * n:(i + 1) * n,
          (i + 1) * n:(i + 2) * n] = -2 * lamb * Phi.T * W2
        P[(i + 1) * n:(i + 2) * n, (i) * n:(i + 1) * n] = -2 * lamb * W2 * Phi
    P[i * n:i * n + n, i * n:i * n + n] = p.copy()

##q##
q = scipy.empty((t * n, 1))
for i in xrange(t):
    q[i * n:(i + 1) * n] = -2 * X[i].T * W1 * y[i]
#q = (-2 * W1 * y)
Example #4
0
Nz = params.Nz 

kx = np.linspace(0, 2*pi, Nx)
ky = np.linspace(0, 2*pi, Ny)
kz = np.linspace(0, 2*pi, Nz)

# Cartesian coordinates, indexing for correct order x,y,z (not y,x,z)
[kkx, kky, kkz] = np.meshgrid(kx, ky, kz, indexing = 'ij')

# Coefficients in front of sigma_x,y,z in Hopf Hamiltonian
lamb = np.divide(1, np.power(np.sin(kkx), 2) + np.power(np.sin(kky), 2) + 
                 np.power(np.sin(kkz), 2) + 
                 np.power(np.cos(kkx) + np.cos(kky) + np.cos(kkz) + h, 2))

Hx = mlt(2 * lamb, mlt(np.sin(kkx), np.sin(kkz)) + 
                 t*mlt(np.sin(kky), (np.cos(kkx) + np.cos(kky) + 
                                             np.cos(kkz) + h)))
Hy = mlt(2 * lamb, t*mlt(np.sin(kky), np.sin(kkz)) -
                 mlt(np.sin(kkx), (np.cos(kkx) + np.cos(kky) + 
                                           np.cos(kkz) + h)))
Hz = mlt(lamb, (np.power(np.sin(kkx), 2) + 
                        t**2 * np.power(np.sin(kky), 2) - 
                        np.power(np.sin(kkz), 2) - 
                        np.power((np.cos(kkx) + np.cos(kky) + 
                                  np.cos(kkz) + h), 2)))

# Constract partial derivatives, Hxy = d_yH_x
Hxx = Hx[1:Nx, 0:Ny-1, 0:Nz-1] - Hx[0:Nx-1, 0:Ny-1, 0:Nz-1]
Hxy = Hx[0:Nx-1, 1:Ny, 0:Nz-1] - Hx[0:Nx-1, 0:Ny-1, 0:Nz-1]
Hxz = Hx[0:Nx-1, 0:Ny-1, 1:Nz] - Hx[0:Nx-1, 0:Ny-1, 0:Nz-1]
Example #5
0
D = scipy.ones((1,n))
d = scipy.matrix(1.)
smallG = scipy.identity(n)
a = scipy.zeros((n,1))
c = scipy.ones((n,1))

G = scipy.empty( (2*n, n))
G[0:n, 0:n] = smallG
G[n: 2*n, 0:n] = -smallG
g = scipy.empty( (2*n, 1))
g[0:n] = c
g[n:2*n] = -a
####P#####
for i in xrange(t):
    if i == 0:
        p = 2* W1* mlt(X[i].T, X[i]) + lamb * Phi.T * W2 * Phi
    elif i == t-1:
        p = 2* W1* mlt(X[i].T, X[i])
    else:
        p = 2* W1* mlt(X[i].T, X[i]) + lamb * (Phi.T * W2 * Phi + W2)
    if i < t-1:
        P[(i)*n:(i+1)*n, (i+1)*n:(i+2)*n] = -2 * lamb * Phi.T  *W2
        P[(i+1)*n:(i+2)*n, (i)*n:(i+1)*n] = -2 * lamb * W2 * Phi
    P[i*n:i*n+n, i*n:i*n+n] = p.copy()

##q##
q = scipy.empty((t*n, 1))
for i in xrange(t):
    q[i*n:(i+1)*n] = -2 * X[i].T * W1 * y[i]
#q = (-2 * W1 * y)
##bigG##