コード例 #1
0
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    return [vlist[i] for i in range(len(vlist)) if orthogonalize(vlist)[i] * orthogonalize(vlist)[i] > 1e-20]
コード例 #2
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    return [ (1/math.sqrt(x*x)) * x for x in orthogonalize(L)]
コード例 #3
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]

    list1 = [[4, 3, 1, 2], [8, 9, -5, -5], [10, 1, -1, 5]]
    for i in list1:
        list2vec(i)
>>> L = [Vec({0, 1, 2, 3},{0: 4, 1: 3, 2: 1, 3: 2}),Vec({0, 1, 2, 3},{0: 8, 1: 9, 2: -5, 3: -5}),  Vec({0, 1, 2, 3},{0: 10, 1: 1, 2: -1, 3: 5}) ]

>>> from vecutil import *
>>> v1 = list2vec([1,2,3,4])
>>> v2 = list2vec([2,3,4,5])
>>> print(test_format(orthonormalization.orthonormalize([v1, v2])))
[Vec({0.000000, 1.000000, 2.000000, 3.000000}, {0.000000: 0.182574, 1.000000: 0.365148, 2.000000: 0.547723, 3.000000: 0.730297}), Vec({0.000000, 1.000000, 2.000000, 3.000000}, {0.000000: 0.816497, 1.000000: 0.408248, 3.000000: -0.408248})]
>>> v1 = list2vec([1,2,1])
>>> v2 = list2vec([2,2,2])
>>> print(test_format(orthonormalization.orthonormalize([v1, v2])))
[Vec({0.000000, 1.000000, 2.000000}, {0.000000: 0.408248, 1.000000: 0.816497, 2.000000: 0.408248}), Vec({0.000000, 1.000000, 2.000000}, {0.000000: 0.577350, 1.000000: -0.577350, 2.000000: 0.577350})]
>>> v1 = list2vec([.2, .4, .1, .9])
>>> v2 = list2vec([12, 144, 91, 0])
>>> v3 = list2vec([1, 1, 1, 1])
>>> v4 = list2vec([0, 12, 0, 0])
>>> print(test_format(orthonormalization.orthonormalize([v1, v2, v3, v4])))
[Vec({0.000000, 1.000000, 2.000000, 3.000000}, {0.000000: 0.198030, 1.000000: 0.396059, 2.000000: 0.099015, 3.000000: 0.891133}), Vec({0.000000, 1.000000, 2.000000, 3.000000}, {0.000000: -0.009900, 1.000000: 0.747167, 2.000000: 0.538319, 3.000000: -0.389687}), Vec({0.000000, 1.000000, 2.000000, 3.000000}, {0.000000: 0.827563, 1.000000: -0.344536, 2.000000: 0.436070, 3.000000: -0.079228}), Vec({0.000000, 1.000000, 2.000000, 3.000000}, {0.000000: 0.525190, 1.000000: 0.407644, 2.000000: -0.714319, 3.000000: -0.218515})]
    '''
    Ortho_L = orthogonalize(L)

    list1 = []
    for i in Ortho_L:
        list1.append(sqrt(i*i))
    return [v/vnorm for v, vnorm in zip(Ortho_L, list1)]
コード例 #4
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list Lstar of len(L) orthonormal Vecs such that, for all i in range(len(L)),
            Span L[:i+1] == Span Lstar[:i+1]

    >>> from vec import Vec
    >>> D = {'a','b','c','d'}
    >>> L = [Vec(D, {'a':4,'b':3,'c':1,'d':2}), Vec(D, {'a':8,'b':9,'c':-5,'d':-5}), Vec(D, {'a':10,'b':1,'c':-1,'d':5})]
    >>> for v in orthonormalize(L): print(v)
    ... 
    <BLANKLINE>
        a     b     c     d
    -----------------------
     0.73 0.548 0.183 0.365
    <BLANKLINE>
         a     b      c      d
    --------------------------
     0.187 0.403 -0.566 -0.695
    <BLANKLINE>
         a      b      c     d
    --------------------------
     0.528 -0.653 -0.512 0.181
    '''
    vstarlist = orthogonalization.orthogonalize(
        L)  #obrain V* veclist and matrix T
    return [normalize(v)
            for v in vstarlist]  # obtain the Q matrix as a list of vecs
コード例 #5
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list Lstar of len(L) orthonormal Vecs such that, for all i in range(len(L)),
            Span L[:i+1] == Span Lstar[:i+1]

    >>> from vec import Vec
    >>> D = {'a','b','c','d'}
    >>> L = [Vec(D, {'a':4,'b':3,'c':1,'d':2}), Vec(D, {'a':8,'b':9,'c':-5,'d':-5}), Vec(D, {'a':10,'b':1,'c':-1,'d':5})]
    >>> for v in orthonormalize(L): print(v)
    ... 
    <BLANKLINE>
        a     b     c     d
    -----------------------
     0.73 0.548 0.183 0.365
    <BLANKLINE>
         a     b      c      d
    --------------------------
     0.187 0.403 -0.566 -0.695
    <BLANKLINE>
         a      b      c     d
    --------------------------
     0.528 -0.653 -0.512 0.181
    '''
    return [v/sqrt(v*v) for v in orthogonalize(L) if 1e-50 < v*v]
コード例 #6
0
def orthonormalize(L):
    """
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    """
    return list(map(lambda v: (1.0 / sqrt(v * v)) * v if v * v > 1e-20 else v, orthogonalize(L)))
コード例 #7
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list Lstar of len(L) orthonormal Vecs such that, for all i in range(len(L)),
            Span L[:i+1] == Span Lstar[:i+1]

    >>> from vec import Vec
    >>> D = {'a','b','c','d'}
    >>> L = [Vec(D, {'a':4,'b':3,'c':1,'d':2}), Vec(D, {'a':8,'b':9,'c':-5,'d':-5}), Vec(D, {'a':10,'b':1,'c':-1,'d':5})]
    >>> for v in orthonormalize(L): print(v)
    ... 
    <BLANKLINE>
        a     b     c     d
    -----------------------
     0.73 0.548 0.183 0.365
    <BLANKLINE>
         a     b      c      d
    --------------------------
     0.187 0.403 -0.566 -0.695
    <BLANKLINE>
         a      b      c     d
    --------------------------
     0.528 -0.653 -0.512 0.181
    '''
    Lstar = orthogonalize(L)
    return [(1/sqrt(v*v)) * v for v in Lstar if not v.is_almost_zero()]
コード例 #8
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    return [normalize(v) for v in orthogonalize(L)]
コード例 #9
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]

    >>> from vec import Vec
    >>> D = {'a','b','c','d'}
    >>> L = [Vec(D, {'a':4,'b':3,'c':1,'d':2}), Vec(D, {'a':8,'b':9,'c':-5,'d':-5}), Vec(D, {'a':10,'b':1,'c':-1,'d':5})]
    >>> for v in orthonormalize(L): print(v)
    ... 
    <BLANKLINE>
    b    a     c     d
    -----------------------
    0.548 0.73 0.183 0.365
    <BLANKLINE>
    b     a      c      d
    --------------------------
    0.403 0.187 -0.566 -0.695
    <BLANKLINE>
    b     a      c     d
    --------------------------
    -0.653 0.528 -0.512 0.181
    '''
    return ( i / sqrt(i**2) for i in orthogonalize(L))
コード例 #10
0
def orthonormalize(L):
    """
    Input: a list L of linearly independent Vecs
    Output: A list Lstar of len(L) orthonormal Vecs such that, for all i in range(len(L)),
            Span L[:i+1] == Span Lstar[:i+1]

    >>> from vec import Vec
    >>> D = {'a','b','c','d'}
    >>> L = [Vec(D, {'a':4,'b':3,'c':1,'d':2}), Vec(D, {'a':8,'b':9,'c':-5,'d':-5}), Vec(D, {'a':10,'b':1,'c':-1,'d':5})]
    >>> for v in orthonormalize(L): print(v)
    ... 
    <BLANKLINE>
        a     b     c     d
    -----------------------
     0.73 0.548 0.183 0.365
    <BLANKLINE>
         a     b      c      d
    --------------------------
     0.187 0.403 -0.566 -0.695
    <BLANKLINE>
         a      b      c     d
    --------------------------
     0.528 -0.653 -0.512 0.181
    """
    vstarlist = orthogonalization.orthogonalize(L)  # obrain V* veclist and matrix T
    return [normalize(v) for v in vstarlist]  # obtain the Q matrix as a list of vecs
コード例 #11
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    return [v / sqrt(v * v) for v in orthogonalize(L)]
コード例 #12
0
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    ''' 
    return [u for u in orthogonalize(vlist) if u * u > 10E-20]
コード例 #13
0
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [i for i in orthogonalize(vlist) if i * i > (10**-20)**0.5]
コード例 #14
0
ファイル: hw7.py プロジェクト: rakeshnbabu/matrix
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [iVec for iVec in orthogonalize(vlist) if iVec * iVec > 10**-20]
コード例 #15
0
ファイル: hw7.py プロジェクト: manishmmulani/python_repo
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return list(filter(lambda v : v*v > 1e-20, orthogonalize(vlist)))
コード例 #16
0
ファイル: hw7.py プロジェクト: airy-beam/online_courses
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [ i for i in orthogonalize(vlist) if not(abs(i * i) < 10**(-20)) ]
コード例 #17
0
ファイル: hw7.py プロジェクト: gregorycook/PythonProjects
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [v for v in orthogonalize(vlist) if v*v >1e-11]
コード例 #18
0
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    return [ vlist[i] for i,x in enumerate(orthogonalize(vlist)) if x*x>1e-20 ]
コード例 #19
0
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [ x for x in orthogonalize(vlist) if x*x>1e-20 ]
コード例 #20
0
ファイル: hw7.py プロジェクト: buptdjd/linearAlgebra-coursera
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    return [vlist[k] for k, v in enumerate(orthogonalize(vlist)) if square_norm(v) > 1E-20]
コード例 #21
0
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return list(filter(lambda v: v * v > 1e-20, orthogonalize(vlist)))
コード例 #22
0
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [v for v in orthogonalize(vlist) if v * v > 1e-11]
コード例 #23
0
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [x for x in orthogonalize(vlist) if x * x > 10**-20]
コード例 #24
0
ファイル: hw7.py プロジェクト: zezei/linearAlgebra-coursera
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [v for v in orthogonalize(vlist) if square_norm(v) > 1E-20]
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    olist = orthogonalize(L)
    return [ o/sqrt(o*o) for o in olist]
コード例 #26
0
ファイル: hw7.py プロジェクト: vasuharish/CodingTheMatrix
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [e for e in orthogonalize(vlist) if e * e > 1e-20]
コード例 #27
0
ファイル: hw7.py プロジェクト: buptdjd/linearAlgebra-coursera
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [v for v in orthogonalize(vlist) if square_norm(v) > 1E-20]
コード例 #28
0
ファイル: hw7.py プロジェクト: fperezlo/matrix
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    return [ i for i in orthogonalize(vlist) if i*i>(10**-20)**0.5 ]
コード例 #29
0
ファイル: hw7.py プロジェクト: peachyo/codingthematrix
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    from vec import dot
    return [v for v in orthogonalize(vlist) if dot(v,v) > 1e-20]
コード例 #30
0
ファイル: hw7.py プロジェクト: enigne/CodingMatrix
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    v_star = orthogonalize(vlist)
    return [vlist[v] for v in range(len(vlist)) if v_star[v]*v_star[v] > 10e-20]
コード例 #31
0
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    O = orthogonalize(vlist)
    return [vlist[x] for x in range(len(vlist)) if O[x] * O[x] > 10**-20]
コード例 #32
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    L_star = orthogonalize(L)
    L_norm = [ sqrt(v*v) for v in L_star ]
    return [ L_star[i]/L_norm[i] for i in range(len(L_star)) ]
コード例 #33
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    from orthogonalization import orthogonalize
    oVecs = orthogonalize(L)
    return [v/(v*v)**(1/2) for v in oVecs]
コード例 #34
0
ファイル: hw7.py プロジェクト: varren/matrix
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    O = orthogonalize(vlist)
    return [vlist[x] for x in range(len(vlist)) if O[x]*O[x] >10**-20 ]
コード例 #35
0
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    olist = orthogonalize(vlist)
    return [o for o in olist if  o*o>1e-20]
コード例 #36
0
ファイル: hw7.py プロジェクト: ruczhangxy/coursera
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    orth_list = orthogonalize(vlist)
    return [v for i, v in enumerate(vlist) if orth_list[i] * orth_list[i] > 10 ** -20]
コード例 #37
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    o = orthogonalize(L)
    l = [sqrt(square_norm(v)) for v in o]
    return [v/l[k] for k, v in enumerate(o)]
コード例 #38
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    orthoL = orthogonalize(L)
    normL = [sqrt(li * li) for li in orthoL]
    return [li / ni for li, ni in zip(orthoL, normL)]
コード例 #39
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    orthoL = orthogonalize(L)
    normL = [sqrt(li*li) for li in orthoL]
    return [li/ni for li,ni in zip(orthoL, normL)]
コード例 #40
0
ファイル: hw7.py プロジェクト: airy-beam/online_courses
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    v_star = orthogonalize(vlist)
    return [ vlist[i] for i in range(len(vlist)) if not( abs(v_star[i] * v_star[i]) < 10**(-20) ) ]
コード例 #41
0
ファイル: orthonormalization.py プロジェクト: danila99/Edu
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    l = orthogonalize(L)
    norms = [sqrt(x*x) for x in l]
    return [l/n for n,l in zip(norms, l)]
コード例 #42
0
ファイル: hw7.py プロジェクト: peachyo/codingthematrix
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist[v]
    '''
    from vec import dot
    return [y for (x,y) in zip(orthogonalize(vlist),vlist) if dot(x,x)>1e-20]
コード例 #43
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    orths = orthogonalize(L)
    norms = [sqrt(v*v) for v in orths]
    return [(1/norms[i])*vec for i, vec in enumerate(orths)]
コード例 #44
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    return list(
        map(lambda v: (1.0 / sqrt(v * v)) * v if v * v > 1e-20 else v,
            orthogonalize(L)))
コード例 #45
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    o = orthogonalize(L)
    l = [sqrt(square_norm(v)) for v in o]
    return [v / l[k] for k, v in enumerate(o)]
コード例 #46
0
ファイル: hw7.py プロジェクト: vasuharish/CodingTheMatrix
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    return [
        vlist[i] for i, e in enumerate(orthogonalize(vlist)) if e * e > 1e-20
    ]
コード例 #47
0
ファイル: hw7.py プロジェクト: lfcunha/coding_the_matrix
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    aa = []
    o = orthogonalize(vlist)

    return [vlist[i] for i, o in enumerate(o) if o * o > 1e-20]
コード例 #48
0
ファイル: hw7.py プロジェクト: zezei/linearAlgebra-coursera
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    return [
        vlist[k] for k, v in enumerate(orthogonalize(vlist))
        if square_norm(v) > 1E-20
    ]
コード例 #49
0
ファイル: hw7.py プロジェクト: ruczhangxy/coursera
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    orth_list = orthogonalize(vlist)
    return [
        v for i, v in enumerate(vlist) if orth_list[i] * orth_list[i] > 10**-20
    ]
コード例 #50
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    from orthogonalization import orthogonalize
    from math import sqrt

    L_star = orthogonalize(L)
    return [v / sqrt(v * v) for v in L_star]
コード例 #51
0
ファイル: hw7.py プロジェクト: Shubashree/matrix_coding
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    oVecs = orthogonalize(vlist)
    vecs = vlist[:]
    for i in range(len(oVecs)):
        norm = sum([oVecs[i][k]**2 for k in oVecs[i].D])**(1 / 2)
        if norm**2 <= 10**-20:
            vecs.remove(vlist[i])
    return vecs
コード例 #52
0
ファイル: hw7.py プロジェクト: murphytalk/math
def subset_basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - linearly independent subset of vlist with the same span as vlist
    '''
    r = []
    i = 0
    for v in orthogonalize(vlist):        
        if (v*v) > 1e-12:
            r.append(vlist[i])
        i = i+1
    return r
コード例 #53
0
ファイル: hw7.py プロジェクト: Shubashree/matrix_coding
def basis(vlist):
    '''
    Input:
        - vlist: a list of Vecs
    Output:
        - a list of linearly independent Vecs with equal span to vlist
    '''
    orthoVecs = orthogonalize(vlist)
    basis = []
    for v in orthoVecs:
        norm = sum([v[k]**2 for k in v.D])**(1 / 2)
        if norm**2 > 10**-20:
            basis.append(v)
    return basis
コード例 #54
0
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list T of orthonormal Vecs such that for all i in [1, len(L)],
            Span L[:i] == Span T[:i]
    '''
    L1 = orthogonalize(L)
    L2 = []
    for i in L1:
        temp = 0
        for j in i.D:
            temp += i[j] ** 2
        L2.append(temp)
    return [L1[i] / sqrt(L2[i]) for i in range(len(L1))]
コード例 #55
0
def aug_orthonormalize(L):
    '''
    Input:
        - L: a list of Vecs
    Output:
        - A pair Qlist, Rlist such that:
            * coldict2mat(L) == coldict2mat(Qlist) * coldict2mat(Rlist)
            * Qlist = orthonormalize(L)
    '''
    def adjust(v,multipliers):
        return Vec(v.D,{i: v.f[i]*multipliers[i] if i in v.f else 0 for i in v.D})
    
    q,r = aug_orthogonalize(L)
    Qlist = orthonormalize(q)
    Rlist = [ adjust(v,[ sqrt(v*v) for v in orthogonalize(L) ]) for v in r ]
    return Qlist,Rlist
コード例 #56
0
def subset_basis(vlist):
    return [
        vlist[i] for i, e in enumerate(orthogonalize(vlist)) if e * e > 1e-20
    ]
コード例 #57
0
def basis(vlist):

    a = orthogonalize(vlist)

    #print(np.linalg.norm(list(a[0].f.values()),2))
    return [e for e in orthogonalize(vlist) if e * e > 1e-20]
コード例 #58
0
def main():

    # Constants for Now - Should Read In
    t = 1
    U = 0.0
    size = 4
    delta_tau = .01
    n_up = 2
    n_down = 2
    total_steps = 10000
    steps_orthog = 10
    steps_measure = 20

    # Matrices Needed Throughout Simulation
    one_body_matrix = np.zeros((size, size))
    one_body_propagator = np.zeros((size, size))
    neighbors = np.zeros((size, 2))
    trial_wf_up = np.zeros((size, n_up))
    trial_wf_down = np.zeros((size, n_down))
    wf_up = np.zeros((size, n_up))
    wf_down = np.zeros((size, n_down))

    # Form the One Body Portion of the Hamiltonian
    ob.form_one_body_matrix(one_body_matrix, neighbors, size, t)

    # Exponentiate That One Body Portion of the Hamiltonian So You Can Propagate
    ob.exponentiate_one_body(one_body_propagator, one_body_matrix, trial_wf_up,
                             trial_wf_down, size, n_up, n_down, delta_tau)

    # Copy Trial Wave Function to Current Wave Function For Propagattion Loop
    wf_up = trial_wf_up
    wf_down = trial_wf_down

    # Propagate By Looping Over Products of One and Two Body Propagators
    for steps in range(total_steps):

        # First Propagate by Half of One Body Term
        ob.propagate_one_body(one_body_propagator, wf_up, wf_down, size, n_up,
                              n_down)

        # Then Propagate By Two Body Term
        tb.propagate_two_body(wf_up, wf_down, size, n_up, n_down, U, delta_tau)

        # Lastly Propagate by Half of One Body Term
        ob.propagate_one_body(one_body_propagator, wf_up, wf_down, size, n_up,
                              n_down)

        # Orthogonalize the Wave Functions to Ensure No Collapse
        if (steps % steps_orthog == 0):
            og.orthogonalize(wf_up, wf_down, size, n_up, n_down)

        # Measure Observables Like the Energy Every So Often
        if (steps % steps_measure == 0):
            current_energy = ms.measure_total_energy(wf_up, wf_down,
                                                     trial_wf_up,
                                                     trial_wf_down, neighbors,
                                                     size, n_up, n_down, U, t)

            print current_energy

            # Append File with Values
            f = open("energy.dat", "a+")
            f.write("%i %5.2f\n" % (steps, current_energy))

    f.close()
コード例 #59
0
ortho_compl_generators_2 = [project_orthogonal(v, U_vecs_2) for v in W_vecs_2]

U_vecs_3 = [list2vec(v) for v in [[-4,3,1,-2],[-2,2,3,-1]]]
W_vecs_3 = [list2vec(v) for v in [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]]

# Give a list of Vecs
ortho_compl_generators_3 = [project_orthogonal(v, U_vecs_3) for v in W_vecs_3]



## 2: (Problem 9.11.3) Basis for null space
# Your solution should be a list of Vecs
rows_A  = [list2vec(v) for v in [[-4,-1,-3,-2], [0,4,0,-1]]]
r_basis = [list2vec(v) for v in [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]]
L       = rows_A + r_basis
Lstar   = orthogonalize(L)

null_space_basis = [v for v in Lstar if not v.is_almost_zero()]



## 3: (Problem 9.11.9) Orthonormalize(L)
def orthonormalize(L):
    '''
    Input: a list L of linearly independent Vecs
    Output: A list Lstar of len(L) orthonormal Vecs such that, for all i in range(len(L)),
            Span L[:i+1] == Span Lstar[:i+1]

    >>> from vec import Vec
    >>> D = {'a','b','c','d'}
    >>> L = [Vec(D, {'a':4,'b':3,'c':1,'d':2}), Vec(D, {'a':8,'b':9,'c':-5,'d':-5}), Vec(D, {'a':10,'b':1,'c':-1,'d':5})]