def construct_3_step_sheaf(): global s3 s3=ps.Sheaf([ps.SheafCell(dimension=0, compactClosure=True, stalkDim=6, metric=distance, # Ignores velocity cofaces=[ps.SheafCoface(index=1, orientation=1, restriction=ps.LinearMorphism(np.array([[1,0,0,0,0,0], [0,1,0,0,0,0], [0,0,1,0,0,0], [0,0,0,1,0,0], [0,0,0,0,1,0]]))), # A->B ps.SheafCoface(index=2, orientation=1, restriction=ps.LinearMorphism(np.array([[1,0,0,0,0,0], [0,1,0,0,0,0], [0,0,1,0,0,0], [0,0,0,2,0,0], [0,0,0,0,1,0]]))), # A->C ], ), ps.SheafCell(dimension=1, compactClosure=True, stalkDim=5, metric=distance, cofaces=[ps.SheafCoface(index=3, orientation=1, restriction=ps.LinearMorphism(np.array([[1,0,0,0,0], [0,1,0,0,0], [0,0,1,0,0], [0,0,0,2,0]]))), # B->D ]), ps.SheafCell(dimension=1, compactClosure=True, stalkDim=5, metric=distance, # Ignores velocity cofaces=[ps.SheafCoface(index=3, orientation=1, restriction=ps.LinearMorphism(np.array([[1,0,0,0,0], [0,1,0,0,0], [0,0,1,0,0], [0,0,0,1,0]]))), # C->D ]), ps.SheafCell(dimension=2, compactClosure=True, stalkDim=4, metric=distance, cofaces=[ps.SheafCoface(index=4, orientation=1, restriction=ps.LinearMorphism(np.array([[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]])))]), ps.SheafCell(dimension=3, compactClosure=True, stalkDim=4, metric=distance, cofaces=[]), ])
def setUp(self): ## From p. 98 Example 4.9: ## Cells=[A,B,C,D,E,F,G] inherit id from index of this list ## Restriction Maps: self.restAD = np.matrix([1,0,0,0]) self.restAG = np.matrix([0,0,1,-1]) self.restBD = np.matrix([1,0,0]) self.restBE = np.matrix([[0,0,3],[0,2,0]]) self.restBF = np.matrix([0,1,0]) self.restCE = np.matrix([[0,0,3,0],[0,0,0,2]]) self.restCF = np.matrix([0,0,0,1]) self.restCG = np.matrix([1,-1,0,0]) ## cofaces self.cofaceAD = ps.SheafCoface(3,1,self.restAD) self.cofaceAG = ps.SheafCoface(6,1,self.restAG) self.cofaceBD = ps.SheafCoface(3,-1,self.restBD) self.cofaceBE = ps.SheafCoface(4,1,self.restBE) self.cofaceBF = ps.SheafCoface(5,1,self.restBF) self.cofaceCE = ps.SheafCoface(4,-1,self.restCE) self.cofaceCF = ps.SheafCoface(5,-1,self.restCF) self.cofaceCG = ps.SheafCoface(6,-1,self.restCG) self.cellA = ps.SheafCell(dimension=0,id=0,stalkDim=4,name='A', cofaces=[self.cofaceAD,self.cofaceAG]) self.cellB = ps.SheafCell(dimension=0,id=1,stalkDim=3,name='B', cofaces=[self.cofaceBD,self.cofaceBE,self.cofaceBF]) self.cellC = ps.SheafCell(dimension=0,id=2,stalkDim=4,name='C', cofaces=[self.cofaceCE,self.cofaceCF,self.cofaceCG]) self.cellD = ps.SheafCell(dimension=1,id=3,stalkDim=1,name='D') self.cellE = ps.SheafCell(dimension=1,id=4,stalkDim=2,name='E') self.cellF = ps.SheafCell(dimension=1,id=5,stalkDim=1,name='F') self.cellG = ps.SheafCell(dimension=1,id=6,stalkDim=1,name='G') self.sheaf = ps.Sheaf([self.cellA,self.cellB,self.cellC,self.cellD,self.cellE,self.cellF,self.cellG])
def setUp(self): self.testSheaf = ps.Sheaf([ ps.SheafCell(dimension=0, stalkDim=1, cofaces=[ ps.SheafCoface(index=1, restriction=np.array([1])), ps.SheafCoface(index=2, restriction=np.array([1])) ]), ps.SheafCell(dimension=1, stalkDim=1), ps.SheafCell(dimension=1, stalkDim=1) ]) self.asg = ps.Section([ ps.SectionCell(support=0, value=0), ps.SectionCell(support=1, value=0), ps.SectionCell(support=2, value=1) ]) self.testSheaf2 = ps.Sheaf([ ps.SheafCell(dimension=0, stalkDim=1, cofaces=[ ps.SheafCoface(index=1, restriction=np.array([1])), ps.SheafCoface(index=2, restriction=np.array([1])) ]), ps.SheafCell(dimension=1, stalkDim=1), ps.SheafCell(dimension=1, stalkDim=1), ps.SheafCell( dimension=0, stalkDim=1, cofaces=[ps.SheafCoface(index=1, restriction=np.array([1]))]) ]) self.asg2 = ps.Section([ ps.SectionCell(support=0, value=0), # A ps.SectionCell(support=1, value=0), # C ps.SectionCell(support=2, value=1), # B ps.SectionCell(support=3, value=0) ]) # D self.asg3 = ps.Section([ ps.SectionCell(support=0, value=0), # A ps.SectionCell(support=1, value=0), # C ps.SectionCell(support=2, value=1), # B ps.SectionCell(support=3, value=1) ]) # D
def setUp(self): self.testSheaf1 = ps.Sheaf([]) # Small sheaf self.testSheaf2 = ps.Sheaf([ ps.SheafCell(dimension=1, stalkDim=1, cofaces=[ ps.SheafCoface(index=2, orientation=np.array(1), restriction=np.array([0.5])) ]), ps.SheafCell(dimension=1, stalkDim=1, cofaces=[ ps.SheafCoface(index=2, orientation=np.array(-1), restriction=np.array([1])) ]), ps.SheafCell(dimension=2, stalkDim=1, cofaces=[]), ps.SheafCell(dimension=0, stalkDim=1, cofaces=[ ps.SheafCoface(index=0, orientation=np.array(1), restriction=np.array([2])), ps.SheafCoface(index=1, orientation=np.array(1), restriction=np.array([1])) ]) ]) self.asg2_1 = ps.Section([ ps.SectionCell(support=0, value=np.array(0.)), ps.SectionCell(support=1, value=np.array(1.)) ]) self.asg2_3 = ps.Section([ ps.SectionCell(support=0, value=np.array(0.)), ps.SectionCell(support=1, value=np.array(1.)), ps.SectionCell(support=2, value=np.array(0.5)), ps.SectionCell(support=3, value=np.array(1. / 3)) ])
consistency_radii=[s1.consistencyRadius(case) for case in input_data] return consistency_radii #Sheaf Construction #sheafcell=self,dimension,cofaces=[],compactClosure=True,stalkDim=None,metric=None) #sheaf coface=(self,index,orientation,restriction) sdim=np.ts.size #number of samples for u & v; n+m. For n or m, use sdim/2 s1=py.Sheaf([py.SheafCell(dimension=1,stalkDim=(sdim/2),cofaces=[]), \ py.SheafCell(dimension=1,stalkDim=(sdim/2),cofaces=[]), \ py.SheafCell(dimension=1,stalkDim=(sdim/2),cofaces=[]), \ py.SheafCell(dimension=1,stalkDim=(sdim/2),cofaces=[]), \ py.SheafCell \ (dimension=0,stalkDim=sdim,cofaces=[py.SheafCoface(index=0, orientation=1, restriction=py.LinearMorphism(pr1(ts))), \ py.SheafCoface(index=1, orientation=1, restriction=py.LinearMorphism(pr2(ts))), \ py.SheafCoface(index=3, orientation=1, restriction=py.SetMorphism(eqn1(ts)))]), \ py.SheafCell \ (dimension=0,stalkDim=sdim,cofaces=[py.SheafCoface(index=0, orientation=-1, restriction=py.LinearMorphism(pr1(ts))), \ py.SheafCoface(index=1, orientation=-1, restriction=py.LinearMorphism(pr2(ts))), \ py.SheafCoface(index=2, orientation=-1, restriction=py.SetMorphism(eqn2(ts)))]), \ py.SheafCell \ (dimension=0,stalkDim=(sdim/2),cofaces=[py.SheafCoface(index=0, orientation=1, restriction=py.LinearMorphism(iden(ts))), \ py.SheafCoface(index=2, orientation=1, restriction=py.LinearMorphism(ddt(ts)))]), \ py.SheafCell \ (dimension=0,stalkDim=(sdim/2),cofaces=[py.SheafCoface(index=1, orientation=1, restriction=py.LinearMorphism(iden(ts))), \ py.SheafCoface(index=3, orientation=-1, restriction=py.LinearMorphism(ddt(ts)))])]) #How to construct? Taken from search_rescue_test.py
# # Copyright (c) 2013-2014, Michael Robinson # Distribution of unaltered copies permitted for noncommercial use only # All other uses require express permission of the author # This software comes with no warrantees express or implied import numpy as np import pysheaf as ps if __name__ == '__main__': # A circle CircSheaf = ps.Sheaf([ ps.SheafCell(dimension=0, cofaces=[ ps.SheafCoface(index=2, orientation=-1, restriction=np.matrix(1)), ps.SheafCoface(index=3, orientation=1, restriction=np.matrix(1)) ]), # Vertex ps.SheafCell(dimension=0, cofaces=[ ps.SheafCoface(index=2, orientation=1, restriction=np.matrix(1)), ps.SheafCoface(index=3, orientation=-1, restriction=np.matrix(1)) ]), # Vertex ps.SheafCell(dimension=1, stalkDim=1), # Edge
# Try to extend sections, based on examples found in Chapter 3 of # "Topological Signal Processing", by Michael Robinson # # Copyright (c) 2013-2014, Michael Robinson # Distribution of unaltered copies permitted for noncommercial use only # All other uses require express permission of the author # This software comes with no warrantees express or implied import numpy as np import pysheaf as ps sh1 = ps.Sheaf([ ps.SheafCell(dimension=0, cofaces=[ ps.SheafCoface(index=2, orientation=-1, restriction=np.matrix(1)) ]), ps.SheafCell(dimension=0, cofaces=[ ps.SheafCoface(index=2, orientation=1, restriction=np.matrix(1)) ]), ps.SheafCell(dimension=1, cofaces=[], stalkDim=1) ]) sec1 = ps.Section([ps.SectionCell(0, 1), ps.SectionCell(1, 1)]) sec2 = ps.Section([ps.SectionCell(0, 1)]) sec3 = ps.Section([ps.SectionCell(0, 1), ps.SectionCell(1, 2)])
# 5: U5 = R^2 (x,y) # 6: V1 = S1 (theta1) # 7: V2 = S1 (theta2) # 8: V3 = R (t) s1 = ps.Sheaf([ ps.SheafCell( dimension=0, compactClosure=True, stalkDim=6, metric=distance_alt, # Ignores velocity cofaces=[ ps.SheafCoface(index=2, orientation=1, restriction=ps.LinearMorphism( np.array([[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0]]))), # X->U2 ps.SheafCoface(index=3, orientation=1, restriction=ps.SetMorphism(A)), # X->U3 ps.SheafCoface(index=4, orientation=1, restriction=ps.SetMorphism(B)), # X->U4 ps.SheafCoface(index=5, orientation=1, restriction=ps.SetMorphism(E)) ]), # X->U5 ps.SheafCell(dimension=2, compactClosure=True,
def construct_sheaf(): global s1 s1 = ps.Sheaf([ ps.SheafCell( dimension=0, compactClosure=True, stalkDim=6, metric=distance_alt, # Ignores velocity cofaces=[ ps.SheafCoface(index=2, orientation=1, restriction=ps.LinearMorphism( np.array([[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0]]))), # X->U2 ps.SheafCoface(index=3, orientation=1, restriction=ps.SetMorphism(A)), # X->U3 ps.SheafCoface(index=4, orientation=1, restriction=ps.SetMorphism(B)), # X->U4 ps.SheafCoface(index=5, orientation=1, restriction=ps.SetMorphism(E)) ], # X->U5 bounds=scene_bounds_0), ps.SheafCell(dimension=2, compactClosure=True, stalkDim=3, metric=distance_alt, cofaces=[]), # U1 ps.SheafCell( dimension=1, compactClosure=True, stalkDim=5, metric=distance_alt, # Ignores velocity cofaces=[ ps.SheafCoface(index=1, orientation=1, restriction=ps.LinearMorphism( np.array([[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0]]))) ]), # U2->U1 ps.SheafCell( dimension=1, compactClosure=True, stalkDim=2, metric=lambda x, y: min(anglemetric(x[0], y[0]), abs(x[1] - y[1])), cofaces=[ ps.SheafCoface(index=6, orientation=1, restriction=ps.LinearMorphism(np.array( [[1, 0]]))), # U3->V1 ps.SheafCoface(index=8, orientation=1, restriction=ps.LinearMorphism(np.array([[0, 1]]))) ], # U3->V3 bounds=[(70, 80), (-pi, pi)]), # U3->V3 ps.SheafCell( dimension=1, compactClosure=True, stalkDim=2, metric=lambda x, y: min(anglemetric(x[0], y[0]), abs(x[1] - y[1])), cofaces=[ ps.SheafCoface(index=8, orientation=-1, restriction=ps.LinearMorphism(np.array( [[0, 1]]))), # U4->V3 ps.SheafCoface(index=7, orientation=1, restriction=ps.LinearMorphism(np.array([[1, 0]]))) ], # U4->V2 bounds=[(60, 70), (-pi, pi)]), # U4->V2 ps.SheafCell( dimension=1, compactClosure=True, stalkDim=2, metric=distance, cofaces=[ ps.SheafCoface(index=6, orientation=-1, restriction=ps.SetMorphism(C)), # U5->V1 ps.SheafCoface(index=7, orientation=-1, restriction=ps.SetMorphism(D)) ], # U5->V2 bounds=[(-55, -75), (40, 50)]), ps.SheafCell(dimension=2, compactClosure=True, stalkDim=1, metric=anglemetric, cofaces=[]), # V1 ps.SheafCell(dimension=2, compactClosure=True, stalkDim=1, metric=anglemetric, cofaces=[]), # V2 ps.SheafCell(dimension=2, compactClosure=True, stalkDim=1, cofaces=[]) ]) # V3
# Try to extend Assignments, based on examples found in Chapter 3 of # "Topological Signal Processing", by Michael Robinson # # Copyright (c) 2013-2014, Michael Robinson # Distribution of unaltered copies permitted for noncommercial use only # All other uses require express permission of the author # This software comes with no warrantees express or implied import numpy as np import pysheaf as ps sh1=ps.Sheaf([ps.SheafCell(dimension=0,cofaces=[ps.SheafCoface(index=2,orientation=-1,restriction=np.matrix(1))]), ps.SheafCell(dimension=0,cofaces=[ps.SheafCoface(index=2,orientation=1,restriction=np.matrix(1))]), ps.SheafCell(dimension=1,cofaces=[],stalkDim=1)]) sec1=ps.Assignment([ps.AssignmentCell(0,1),ps.AssignmentCell(1,1)]) sec2=ps.Assignment([ps.AssignmentCell(0,1)]) sec3=ps.Assignment([ps.AssignmentCell(0,1),ps.AssignmentCell(1,2)]) # Extending Assignment over two vertices to a common coface if sec1.extend(sh1,2) and sec2.extend(sh1,2) and not sec3.extend(sh1,2) and sec2.extend(sh1,1): print "Test 1 passed" else: print "Test 1 failed" sh2=ps.Sheaf([ps.SheafCell(dimension=0,cofaces=[ps.SheafCoface(index=1,orientation=-1,restriction=np.matrix(1))]), ps.SheafCell(dimension=1,cofaces=[],stalkDim=1), ps.SheafCell(dimension=0,cofaces=[ps.SheafCoface(index=1,orientation=1,restriction=np.matrix(-1)), ps.SheafCoface(index=3,orientation=-1,restriction=np.matrix(1))]), ps.SheafCell(dimension=1,cofaces=[],stalkDim=1)])
#U1=F we never actually use this index because diagram commutes #U2=PxF #U3=WxF #U4=WxP #V1=P #V2=F #V3=W #difference between LINEAR morphism and SET morphism s1 = ps.Sheaf([ ps.SheafCell( dimension=0, compactClosure=True, stalkDim=2, #THIS IS THE NUMBER OF COLUMNS ?!?! cofaces=[ ps.SheafCoface(index=4, orientation=1, restriction=ps.LinearMorphism( np.array([[1.0, 0], [0, 1.0]]))), #X>U3 ?!?!?! ps.SheafCoface(index=5, orientation=-1, restriction=ps.LinearMorphism( np.array([[0, 0], [1.0, 0], [0, 1.0], [0, 0]]))) ]), #X>U4 ps.SheafCell( dimension=0, compactClosure=True, stalkDim= 4, #WHICH INDEX OF COLUMNS IS THIS REFERRING TO, THE SEED OR THE FINALS cofaces=[ ps.SheafCoface(index=4, orientation=1, restriction=ps.LinearMorphism(
#ts,alpha,beta,sigma,rho,gamma=tsmade ts, alpha, beta, sigma, rho, gamma = parseddata_quarterly sdim = ts.size #number of samples for u & v; n+m. For n or m, use sdim/2 print "size of time series is " + str(ts.shape) tsu = ts[:sdim / 2] tsv = ts[sdim / 2:] s1=py.Sheaf([py.SheafCell(dimension=1,stalkDim=(sdim/2),cofaces=[]), \ py.SheafCell(dimension=1,stalkDim=(sdim/2),cofaces=[]), \ py.SheafCell(dimension=1,stalkDim=(sdim/2),cofaces=[]), \ py.SheafCell(dimension=1,stalkDim=(sdim/2),cofaces=[]), \ py.SheafCell \ (dimension=0,stalkDim=sdim,cofaces=[py.SheafCoface(index=0, orientation=1, restriction=py.LinearMorphism(pr1(ts))), \ py.SheafCoface(index=1, orientation=1, restriction=py.LinearMorphism(pr2(ts))), \ py.SheafCoface(index=3, orientation=1, restriction=py.SetMorphism(lambda x: eqn1(x,alpha,beta,sigma)))]), \ py.SheafCell \ (dimension=0,stalkDim=sdim,cofaces=[py.SheafCoface(index=0, orientation=-1, restriction=py.LinearMorphism(pr1(ts))), \ py.SheafCoface(index=1, orientation=-1, restriction=py.LinearMorphism(pr2(ts))), \ py.SheafCoface(index=2, orientation=-1, restriction=py.SetMorphism(lambda x:eqn2(x,alpha,gamma,rho)))]), \ py.SheafCell \ (dimension=0,stalkDim=(sdim/2),cofaces=[py.SheafCoface(index=0, orientation=1, restriction=py.LinearMorphism(iden(tsu))), \ py.SheafCoface(index=2, orientation=1, restriction=py.LinearMorphism(ddt(tsu)))]), \ py.SheafCell \ (dimension=0,stalkDim=(sdim/2),cofaces=[py.SheafCoface(index=1, orientation=1, restriction=py.LinearMorphism(iden(tsv))), \ py.SheafCoface(index=3, orientation=-1, restriction=py.LinearMorphism(ddt(tsv)))])]) input_data = [ py.Section([