Beispiel #1
0
def shermanMorrison(x, Ainv, m, up=True):
    ''' 
   Does a rank-1 adjustment of Ainv using the Sherman-Morrison formula
   (A + xx^H)^(-1) = A^(-1) - (A^(-1)xx^(H)A^(-1)) / (1 + x^(H)A^(-1)x)
   if (1 + x^(H)A^(-1)x) != 0.
   
   Ainv is a matrix of size m*m
   x is a column vector of length m    
   
   If up == True: A rank update is performed, 
   otherwise we do a rank degrade.
   '''
    factor = 1
    if up != True:
        factor = -1

    xH = x.conjugate()
    Ainvx = mynp.dot(Ainv, x)
    xHAinv = mynp.dot(xH, Ainv)
    xHAinvx = mynp.dot(
        xH, mynp.dot(Ainv, x)
    )  # memory layout impose this product rather than reusing xHAinv (the result here is a scalar)

    numerator = mynp.outer(Ainvx, xHAinv)
    denominator = 1 + factor * xHAinvx
    if abs(denominator) == 0:
        raise Exception('Denominator is 0 in Sherman Morrison formula')

    return Ainv - ((factor / denominator) * numerator)
Beispiel #2
0
def shermanMorrison(x, Ainv, m, up = True):
   ''' 
   Does a rank-1 adjustment of Ainv using the Sherman-Morrison formula
   (A + xx^H)^(-1) = A^(-1) - (A^(-1)xx^(H)A^(-1)) / (1 + x^(H)A^(-1)x)
   if (1 + x^(H)A^(-1)x) != 0.
   
   Ainv is a matrix of size m*m
   x is a column vector of length m    
   
   If up == True: A rank update is performed, 
   otherwise we do a rank degrade.
   ''' 
   factor = 1
   if up != True: 
      factor = -1
   
   xH = x.conjugate()
   Ainvx = mynp.dot(Ainv, x)
   xHAinv = mynp.dot(xH, Ainv)
   xHAinvx = mynp.dot(xH, mynp.dot(Ainv, x)) # memory layout impose this product rather than reusing xHAinv (the result here is a scalar)
   
   numerator = mynp.outer(Ainvx, xHAinv)
   denominator = 1 + factor * xHAinvx
   if abs(denominator) == 0:
      raise Exception('Denominator is 0 in Sherman Morrison formula')
   
   return Ainv - ( (factor/denominator) * numerator )
Beispiel #3
0
 def calcBeamPatternLinearArray(self, w, M, spacing, thetas, steering_angle=0, takePowerAndNormalize=False):
    x_el = np.linspace( -(M-1)/(2.0/spacing), (M-1)/(2.0/spacing), M )
    W_matrix = np.exp(-1j * np.outer(2*np.pi*(np.sin(thetas) - np.sin(steering_angle)), x_el))
    W = np.dot(W_matrix , w)
    if takePowerAndNormalize:
       W = W*W.conj()
       W = W / W.max()
    
    return W
Beispiel #4
0
    def calcBeamPatternLinearArray(self,
                                   w,
                                   M,
                                   spacing,
                                   thetas,
                                   steering_angle=0,
                                   takePowerAndNormalize=False):
        x_el = np.linspace(-(M - 1) / (2.0 / spacing),
                           (M - 1) / (2.0 / spacing), M)
        W_matrix = np.exp(
            -1j *
            np.outer(2 * np.pi *
                     (np.sin(thetas) - np.sin(steering_angle)), x_el))
        W = np.dot(W_matrix, w)
        if takePowerAndNormalize:
            W = W * W.conj()
            W = W / W.max()

        return W
Beispiel #5
0
    def testComplexCholeskySolver(self):

        N = 32
        x = np.random.normal(loc=0.0, scale=1.0, size=(N,)) + 1j * np.random.normal(loc=0.0, scale=1.0, size=(N,))
        A = np.outer(x, x.conj()).astype("complex128")
        A = A + 0.5 * np.eye(N)
        b = np.ones(N, dtype=np.complex128)

        #      A = np.array([[3+0j,5+1j],[5-1j,14+0j]])
        #      b = np.array([1+0j,1+0j])

        yi = mklcSolveCholeskyC(A, b)

        print yi

        print "Numpy reference:"

        C = np.linalg.solve(A, b)
        print C

        print "hello"