print '0-Persistent degree 0 Sheaf Betti number ' + str( PerSheaf0.cobetti(0)) print '0-Persistent degree 1 Sheaf Betti number ' + str( PerSheaf0.cobetti(1)) PerSheaf1 = ps.PersistenceSheaf([ColLoopSheaf, LineSheaf, LoopSheaf], [(0, 1, MorColLine), (0, 2, MorColLoop)], 1) print '1-Persistent degree 0 Sheaf Betti number ' + str( PerSheaf1.cobetti(0)) print '1-Persistent degree 1 Sheaf Betti number ' + str( PerSheaf1.cobetti(1)) fs = ps.FlowSheaf( ps.DirectedGraph([(None, 1), (None, 1), (1, 2), (1, None), (None, 2), (2, None)])) print 'Flow sheaf degree 0 Sheaf Betti number ' + str(fs.cobetti(0)) fs2 = fs.star([6]) print 'Flow sheaf degree 0 Sheaf Betti number ' + str(fs2.cobetti(0)) fs3 = fs.star([7]) print 'Flow sheaf degree 0 Sheaf Betti number ' + str(fs3.cobetti(0)) print 'Dimension of local sections over a single edge ' + str( fs.localSectional([0])[0].cobetti(0)) print 'Dimension of local sections over two edges ' + str( fs.localSectional([0, 1])[0].cobetti(0)) print 'Dimension of local sections over three edges ' + str( fs.localSectional([0, 1, 2])[0].cobetti(0)) print 'Dimension of local sections over three edges and a common vertex ' + str(
restriction=np.matrix(1)) ]), ps.SheafCell(dimension=1, cofaces=[], stalkDim=1) ]) sec4 = ps.Section([ps.SectionCell(0, 1)]) # Extending along a line if sec4.extend(sh2, 1) and sec4.extend(sh2, 2) and sec4.extend(sh2, 3): print[s.value for s in sec4.sectionCells] print "Test 2 passed" else: print "Test 2 failed" # Mayer-Vietoris example from tspbook sh3 = ps.FlowSheaf( ps.DirectedGraph([(None, 0), (None, 0), (0, None), (0, 1), (None, 1), (1, None)])) sec5 = ps.Section([ ps.SectionCell(0, 3), ps.SectionCell(1, 2), ps.SectionCell(2, 1), ps.SectionCell(4, 3), ps.SectionCell(5, 8) ]) sec6 = ps.Section([ ps.SectionCell(0, 3), ps.SectionCell(1, 2), ps.SectionCell(2, 1), ps.SectionCell(4, 3), ps.SectionCell(5, 7) ]) sec7 = ps.Section([ps.SectionCell(1, 2), ps.SectionCell(4, 3)])
# Test transmission line sheaves # # 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 pysheaf as ps import numpy as np f = 900e6 # Operating frequency ft2m = 12 * 0.0254 # Conversion feet to meters wavenumber = 2 * np.pi * f / 3e8 dg = ps.DirectedGraph([(None, 1), (None, 2), (None, 3), (1, 2), (2, 3), (3, 1)]) dg.cells[3].length = 70 * ft2m # Edge e3 dg.cells[4].length = (150 + 70) * ft2m # Edge e1 dg.cells[5].length = 150 * ft2m # Edge e2 tl = ps.TransLineSheaf(dg, wavenumber) print tl.cohomology(0) sec = np.sum(tl.cohomology(0), 1) if np.allclose( np.dot(tl.cells[6].cofaces[1].corestriction, sec[0:3]), np.dot(tl.cells[7].cofaces[1].corestriction, sec[3:6])) and np.allclose( np.dot(tl.cells[6].cofaces[2].corestriction, sec[0:3]), np.dot(tl.cells[8].cofaces[2].corestriction,
def setUp(self): self.dg = ps.DirectedGraph([(0,1),(1,2),(1,2),(0,2)])
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)]) sec4=ps.Assignment([ps.AssignmentCell(0,1)]) # Extending along a line if sec4.extend(sh2,1) and sec4.extend(sh2,2) and sec4.extend(sh2,3): print [s.value for s in sec4.assignmentCells] print "Test 2 passed" else: print "Test 2 failed" # Mayer-Vietoris example from tspbook sh3=ps.FlowSheaf(ps.DirectedGraph([(None,0),(None,0),(0,None),(0,1),(None,1),(1,None)])) sec5=ps.Assignment([ps.AssignmentCell(0,3), ps.AssignmentCell(1,2), ps.AssignmentCell(2,1), ps.AssignmentCell(4,3), ps.AssignmentCell(5,8)]) sec6=ps.Assignment([ps.AssignmentCell(0,3), ps.AssignmentCell(1,2), ps.AssignmentCell(2,1), ps.AssignmentCell(4,3), ps.AssignmentCell(5,7)]) sec7=ps.Assignment([ps.AssignmentCell(1,2), ps.AssignmentCell(4,3)]) sec8=ps.Assignment([ps.AssignmentCell(1,2), ps.AssignmentCell(4,3)])
print 'degree 0 induced map Collapsed->Line: ' + str(ps.inducedMap(ColLoopSheaf,LineSheaf,MorColLine,0)) print 'degree 1 induced map Collapsed->Line: ' + str(ps.inducedMap(ColLoopSheaf,LineSheaf,MorColLine,1)) print 'degree 2 induced map Collapsed->Line: ' + str(ps.inducedMap(ColLoopSheaf,LineSheaf,MorColLine,2)) PerSheaf0=ps.PersistenceSheaf([ColLoopSheaf,LineSheaf,LoopSheaf],[(0,1,MorColLine),(0,2,MorColLoop)],0) print '0-Persistent degree 0 Betti number ' + str(PerSheaf0.betti(0)) print '0-Persistent degree 1 Betti number ' + str(PerSheaf0.betti(1)) PerSheaf1=ps.PersistenceSheaf([ColLoopSheaf,LineSheaf,LoopSheaf],[(0,1,MorColLine),(0,2,MorColLoop)],1) print '1-Persistent degree 0 Betti number ' + str(PerSheaf1.betti(0)) print '1-Persistent degree 1 Betti number ' + str(PerSheaf1.betti(1)) fs=ps.FlowSheaf(ps.DirectedGraph([(None,1),(None,1),(1,2),(1,None),(None,2),(2,None)])) print 'Flow sheaf degree 0 Betti number ' + str(fs.betti(0)) fs2=fs.star([6]) print 'Flow sheaf degree 0 Betti number ' + str(fs2.betti(0)) fs3=fs.star([7]) print 'Flow sheaf degree 0 Betti number ' + str(fs3.betti(0)) print 'Dimension of local sections over a single edge ' + str(fs.localSectional([0])[0].betti(0)) print 'Dimension of local sections over two edges ' + str(fs.localSectional([0,1])[0].betti(0)) print 'Dimension of local sections over three edges ' + str(fs.localSectional([0,1,2])[0].betti(0)) print 'Dimension of local sections over three edges and a common vertex ' + str(fs.localSectional([0,1,2,6])[0].betti(0)) print 'Induced map on local sections from 3 edges to 2 edges ' + str(fs.localRestriction([0,1,2],[0,1])) print 'Induced map on local sections from 3 edges and common vertex to 3 edges ' + str(fs.localRestriction([0,1,2,6],[0,1,2]))
# Unit test for poset chain methods # # 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 pysheaf as ps import numpy as np poset = ps.Poset([ ps.Cell(0, True, [ps.Coface(1, 1), ps.Coface(2, 1)]), ps.Cell(1, True, [ps.Coface(3, 1), ps.Coface(4, 1)]), ps.Cell(1, True, [ps.Coface(3, 1)]), ps.Cell(2, True, [ps.Coface(5, 1)]), ps.Cell(2, True, []), ps.Cell(3, True, []) ]) print poset.maximalChains(0) dg = ps.DirectedGraph([(0, 1), (1, 2), (1, 2), (0, 2)]) print dg.maxFlow(4, 6)
# Sample persistence sheaf calculation # # 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__': 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)