# 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__': targ1=ps.DirectedGraph([(None,1),(1,2),(2,None),(None,3),(3,4),(4,None)]) fs1=ps.FlowSheaf(targ1) targ2=ps.DirectedGraph([(None,1),(None,1),(1,2),(2,None),(2,None)]) targ3=ps.DirectedGraph([(None,1),(None,1),(1,2),(2,None)]) map1=[(0,0),(1,2),(2,3),(3,1),(4,2),(5,4),(6,5),(7,6),(8,5),(9,6)] map2=[(0,0),(1,1),(2,2),(3,3),(4,3),(5,4)] print 'Ready to compute!' pf1,pf1m=fs1.pushForward(targ2,map1) print 'pushforward FS 1 induced map ' + str(ps.inducedMap(pf1,fs1,pf1m,0)) fs2,fsm2=pf1.flowCollapse() print 'collapse 1 induced map ' + str(ps.inducedMap(pf1,fs2,fsm2,0)) pf2,pf2m=fs2.pushForward(targ3,map2) print 'pushforward FS 2 induced map ' + str(ps.inducedMap(pf2,fs2,pf2m,0)) fs3,fsm3=pf2.flowCollapse() print 'collapse 2 induced map ' + str(ps.inducedMap(pf2,fs3,fsm3,0)) persh=ps.PersistenceSheaf([fs1,pf1,fs2,pf2,fs3],[(1,0,pf1m),(1,2,fsm2),(3,2,pf2m),(3,4,fsm3)],0) print 'Persistence Betti 0=' + str(persh.betti(0))
print 'S^2 Sheaf Betti numbers: ' + str( (SphSheaf.cobetti(0), SphSheaf.cobetti(1), SphSheaf.cobetti(2))) MorCirDisk = ps.SheafMorphism([ ps.SheafMorphismCell(destinations=[0, 1, 2], maps=[ ps.LinearMorphism(np.matrix(1)), ps.LinearMorphism(np.matrix(1)), ps.LinearMorphism(np.matrix(1)) ]), ps.SheafMorphismCell(destinations=[3], maps=[ps.LinearMorphism(np.matrix(1))]), ps.SheafMorphismCell(destinations=[], maps=[]) ]) print 'degree 0 induced map S^1->D^2: ' + str( ps.inducedMap(DiskSheaf, CircSheaf, MorCirDisk, 0)) print 'degree 1 induced map S^1->D^2:' + str( ps.inducedMap(DiskSheaf, CircSheaf, MorCirDisk, 1)) print 'degree 2 induced map S^1->D^2:' + str( ps.inducedMap(DiskSheaf, CircSheaf, MorCirDisk, 2)) # Sheaf over a graph with an undirected loop LoopSheaf = ps.Sheaf([ ps.SheafCell(dimension=0, cofaces=[ ps.SheafCoface(2, 1, np.matrix([1, 0])), ps.SheafCoface(3, 1, np.matrix([0, 0])), ps.SheafCoface(4, -1, np.matrix([1, 1])) ]), ps.SheafCell(dimension=0, cofaces=[
# 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__': targ1=ps.DirectedGraph([(None,1),(1,2),(2,None),(None,3),(3,4),(4,None)]) fs1=ps.FlowSheaf(targ1) targ2=ps.DirectedGraph([(None,1),(None,1),(1,2),(2,None),(2,None)]) targ3=ps.DirectedGraph([(None,1),(None,1),(1,2),(2,None)]) map1=[(0,0),(1,2),(2,3),(3,1),(4,2),(5,4),(6,5),(7,6),(8,5),(9,6)] map2=[(0,0),(1,1),(2,2),(3,3),(4,3),(5,4)] print 'Ready to compute!' pf1,pf1m=fs1.pushForward(targ2,map1) print 'pushforward FS 1 induced map ' + str(ps.inducedMap(pf1,fs1,pf1m,0)) fs2,fsm2=pf1.flowCollapse() print 'collapse 1 induced map ' + str(ps.inducedMap(pf1,fs2,fsm2,0)) pf2,pf2m=fs2.pushForward(targ3,map2) print 'pushforward FS 2 induced map ' + str(ps.inducedMap(pf2,fs2,pf2m,0)) fs3,fsm3=pf2.flowCollapse() print 'collapse 2 induced map ' + str(ps.inducedMap(pf2,fs3,fsm3,0)) persh=ps.PersistenceSheaf([fs1,pf1,fs2,pf2,fs3],[(1,0,pf1m),(1,2,fsm2),(3,2,pf2m),(3,4,fsm3)],0) print 'Persistence Sheaf Betti 0=' + str(persh.cobetti(0))
# A 2-sphere SphSheaf=ps.Sheaf([ps.SheafCell(dimension=0,cofaces=[ ps.SheafCoface(1,-1,np.matrix(1)), ps.SheafCoface(1,1,np.matrix(1))]), ps.SheafCell(dimension=1,cofaces=[ ps.SheafCoface(2,-1,np.matrix(1)), ps.SheafCoface(3,1,np.matrix(1))]), ps.SheafCell(dimension=2,stalkDim=1), ps.SheafCell(dimension=2,stalkDim=1)]) print 'S^2 Betti numbers: ' + str((SphSheaf.betti(0),SphSheaf.betti(1),SphSheaf.betti(2))) MorCirDisk=ps.SheafMorphism([ps.SheafMorphismCell(destinations=[0,1,2],maps=[ps.LinearMorphism(np.matrix(1)),ps.LinearMorphism(np.matrix(1)),ps.LinearMorphism(np.matrix(1))]), ps.SheafMorphismCell(destinations=[3],maps=[ps.LinearMorphism(np.matrix(1))]), ps.SheafMorphismCell(destinations=[],maps=[])]) print 'degree 0 induced map S^1->D^2: ' + str(ps.inducedMap(DiskSheaf,CircSheaf,MorCirDisk,0)) print 'degree 1 induced map S^1->D^2:' + str(ps.inducedMap(DiskSheaf,CircSheaf,MorCirDisk,1)) print 'degree 2 induced map S^1->D^2:' + str(ps.inducedMap(DiskSheaf,CircSheaf,MorCirDisk,2)) # Sheaf over a graph with an undirected loop LoopSheaf=ps.Sheaf([ps.SheafCell(dimension=0,cofaces=[ ps.SheafCoface(2,1,np.matrix([1,0])), ps.SheafCoface(3,1,np.matrix([0,0])), ps.SheafCoface(4,-1,np.matrix([1,1]))]), ps.SheafCell(dimension=0,cofaces=[ ps.SheafCoface(2,-1,np.matrix([1,0])), ps.SheafCoface(3,-1,np.matrix([0,1])), ps.SheafCoface(5,1,np.matrix([1,1]))]), ps.SheafCell(dimension=1,stalkDim=1), ps.SheafCell(dimension=1,stalkDim=1), ps.SheafCell(dimension=1,compactClosure=False,stalkDim=1),
# A 2-sphere SphSheaf=ps.Sheaf([ps.SheafCell(dimension=0,cofaces=[ ps.SheafCoface(1,-1,np.matrix(1)), ps.SheafCoface(1,1,np.matrix(1))]), ps.SheafCell(dimension=1,cofaces=[ ps.SheafCoface(2,-1,np.matrix(1)), ps.SheafCoface(3,1,np.matrix(1))]), ps.SheafCell(dimension=2,stalkDim=1), ps.SheafCell(dimension=2,stalkDim=1)]) print 'S^2 Betti numbers: ' + str((SphSheaf.betti(0),SphSheaf.betti(1),SphSheaf.betti(2))) MorCirDisk=[ps.SheafMorphismCell(destinations=[0,1,2],maps=[np.matrix(1),np.matrix(1),np.matrix(1)]), ps.SheafMorphismCell(destinations=[3],maps=[np.matrix(1)]), ps.SheafMorphismCell(destinations=[],maps=[])] print 'degree 0 induced map S^1->D^2: ' + str(ps.inducedMap(DiskSheaf,CircSheaf,MorCirDisk,0)) print 'degree 1 induced map S^1->D^2:' + str(ps.inducedMap(DiskSheaf,CircSheaf,MorCirDisk,1)) print 'degree 2 induced map S^1->D^2:' + str(ps.inducedMap(DiskSheaf,CircSheaf,MorCirDisk,2)) # Sheaf over a graph with an undirected loop LoopSheaf=ps.Sheaf([ps.SheafCell(dimension=0,cofaces=[ ps.SheafCoface(2,1,np.matrix([1,0])), ps.SheafCoface(3,1,np.matrix([0,0])), ps.SheafCoface(4,-1,np.matrix([1,1]))]), ps.SheafCell(dimension=0,cofaces=[ ps.SheafCoface(2,-1,np.matrix([1,0])), ps.SheafCoface(3,-1,np.matrix([0,1])), ps.SheafCoface(5,1,np.matrix([1,1]))]), ps.SheafCell(dimension=1,stalkDim=1), ps.SheafCell(dimension=1,stalkDim=1), ps.SheafCell(dimension=1,compactClosure=False,stalkDim=1),