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]
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)]
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)]
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
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]
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)))
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()]
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)]
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))
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
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)]
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]
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]
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]
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)))
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)) ]
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]
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 ]
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 ]
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]
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)))
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]
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]
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]
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]
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 ]
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]
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]
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]
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)) ]
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]
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 ]
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]
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]
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)]
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)]
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)]
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) ) ]
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)]
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]
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)]
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)))
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)]
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 ]
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]
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 ]
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 ]
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]
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
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
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
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))]
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
def subset_basis(vlist): return [ vlist[i] for i, e in enumerate(orthogonalize(vlist)) if e * e > 1e-20 ]
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]
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()
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})]