Esempio n. 1
0
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=[]),
                 ])
Esempio n. 2
0
    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])
Esempio n. 3
0
    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
Esempio n. 4
0
    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))
        ])
Esempio n. 5
0
def BuildConstantSheaf(G, dataDimension=1):
    """Construct a constant sheaf on a graph G with a given dataDimension"""
    shf = ps.Sheaf()

    # Add cells for each node in the graph
    for node in G.nodes():
        shf.AddCell(node, ps.Cell('vector', dataDimension=dataDimension))

    # Add cofaces for each edge in the graph
    for edge in G.edges():
        shf.AddCoface(
            edge[0], edge[1],
            ps.Coface('vector', 'vector',
                      dataTools.LinearMorphism(np.eye(dataDimension))))

    return shf  # BuildConstantSheaf
Esempio n. 6
0
#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

input_data=[py.Section([py.SectionCell(support=0,value=np.array(ts[:(sdim/2)])), # U
                        py.SectionCell(support=1,value=np.array(ts[(sdim/2):]))])] # V

# Exhibit the consistency radius of the partially-filled Section with the input data
Esempio n. 7
0
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
        ps.SheafCell(dimension=1, stalkDim=1)
    ])  # Edge
    print 'Circle Sheaf Betti numbers: ' + str(
        (CircSheaf.cobetti(0), CircSheaf.cobetti(1), CircSheaf.cobetti(2)))

    # A disk
    DiskSheaf = ps.Sheaf([
Esempio n. 8
0
# 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)])

# Extending section 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):
Esempio n. 9
0
    starting_pop = toolbox.population(n=initial_population_size)
    pop, log = algorithms.eaMuPlusLambda(starting_pop,
                                         toolbox,
                                         mu=(3 * initial_population_size),
                                         lambda_=(3 * initial_population_size),
                                         cxpb=0.5,
                                         mutpb=0.5,
                                         ngen=number_of_generations,
                                         stats=stats,
                                         halloffame=mostFitIndividual)

    return mostFitIndividual  # DeapSheafOptimizer


if __name__ == '__main__':
    graph = ps.Sheaf()
    graph.mPreventRedundantExtendedAssignments = False

    TEST_TYPE = "test_type"
    graph.AddCell(
        0,
        ps.Cell(TEST_TYPE,
                CompareScalars,
                serializeAssignmentMethod=SerializeScalars))
    graph.AddCell(
        1,
        ps.Cell(TEST_TYPE,
                CompareScalars,
                serializeAssignmentMethod=SerializeScalars))
    graph.AddCell(
        2,
Esempio n. 10
0
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,
                 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
    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
    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
    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
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
Esempio n. 12
0
#
# Copyright (c) 2017, 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

# Create some cells
cA = ps.SheafCell(name='A', dimension=0, stalkDim=2)
cB = ps.SheafCell(name='B', dimension=0, stalkDim=2)
cAB = ps.SheafCell(name='AB', dimension=1, stalkDim=2)

# Initialize the sheaf structure
s = ps.Sheaf()

# Add two cells, remembering their IDs assigned by the Sheaf
cA_id = s.add_cell(cA)
cAB_id = s.add_cell(cAB)

# Add a coface
s.add_coface((cA_id, cAB_id),
             orientation=1,
             restriction=np.array([[1, 0], [0, 1]]))

# Add another cell and coface
cB_id = s.add_cell(cB)
s.add_coface((cB_id, cAB_id),
             orientation=1,
             restriction=np.array([[0, 1], [1, 0]]))
Esempio n. 13
0
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(
                               np.array([[1.0, 1.0, 0, 0],
                                         [0, 0, 1.0, 1.0]]))),  #X>U3 ?!?!?
            ps.SheafCoface(index=5,
                           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]])))
        ]),  #X>U4
    ps.SheafCell(
        dimension=0,
        compactClosure=True,
        stalkDim=4,  #THIS IS THE NUMBER OF COLUMNS 
        cofaces=[
            ps.SheafCoface(index=5,
                           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]]))),
            ps.SheafCoface(index=6,
                           orientation=-1,
                           restriction=ps.LinearMorphism(
                               np.array([[1.0, 0, 1.0, 0], [0, 1.0, 0, 1.0]])))
        ]),  #V3>V3
    ps.SheafCell(
        dimension=0,
        compactClosure=True,
        stalkDim=2,  #THIS IS THE NUMBER OF COLUMNS 
        cofaces=[
            ps.SheafCoface(index=5,
                           orientation=1,
                           restriction=ps.LinearMorphism(
                               np.array([[1.0, 0], [0, 0], [0, 0],
                                         [0, 1.0]]))),  #X>U4
            ps.SheafCoface(index=6,
                           orientation=-1,
                           restriction=ps.LinearMorphism(
                               np.array([[1.0, 0], [0, 1.0]])))
        ]),  #V3>V3
    ps.SheafCell(
        dimension=1,
        compactClosure=True,
        stalkDim=2,  #THIS IS THE NUMBER OF rows 
        cofaces=[]),
    ps.SheafCell(
        dimension=1,
        compactClosure=True,
        stalkDim=4,  #THIS IS THE NUMBER OF rows 
        cofaces=[]),
    ps.SheafCell(
        dimension=1,
        compactClosure=True,
        stalkDim=2,  #THIS IS THE NUMBER OF rows 
        cofaces=[])
])
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 31 16:16:22 2018

@author: mrobinson
"""

import pysheaf as ps

shf=ps.Sheaf()

shf.AddCell('A',ps.Cell('Scalar'))
shf.AddCell('B',ps.Cell('Scalar'))
shf.AddCell('C',ps.Cell('Scalar'))

shf.AddCoface('A','C',ps.Coface('Scalar','Scalar',lambda x: x))
shf.AddCoface('B','C',ps.Coface('Scalar','Scalar',lambda x: x))
shf.GetCell('A').SetDataAssignment(ps.Assignment('Scalar',0))
shf.GetCell('B').SetDataAssignment(ps.Assignment('Scalar',1))
shf.GetCell('C').SetDataAssignment(ps.Assignment('Scalar',0.25))

shf.mPreventRedundantExtendedAssignments=False

shf.MaximallyExtendCell('A')
shf.MaximallyExtendCell('B')
shf.MaximallyExtendCell('C')

print('Consistency radius : {}'.format(shf.ComputeConsistencyRadius()))

for thres in [0., 0.2, 0.3, 0.8]:
    print('Consistent stars at {} : {}'.format(thres,shf.ConsistentStarCollection(thres)))
Esempio n. 15
0
        SetMorphism.__init__(self, lambda x: np.dot(matrix, x))

    def __mul__(self, other):  # Composition of morphisms
        try:  # Try to multiply matrices.  This might fail if the other morphism isn't a LinearMorphism
            return LinearMorphism(np.dot(self.matrix, other.matrix))
        except AttributeError:
            return SetMorphism.__mul__(self, other)


if __name__ == '__main__':

    print("+-+-+-+-+-+-+-+-+-+-+")
    print("+-Search and rescue-+")
    print("+-+-+-+-+-+-+-+-+-+-+")

    sheaf = ps.Sheaf()

    POSITION = "lat_lon_degrees"
    POSITION_3D_VELOCITY = "lat_lon_degrees_alt_meters_velocity_kilometers_per_hour_type"
    POSITION_3D_VELOCITY_TIME = "lat_lon_degrees_alt_meters_velocity_kilometers_per_hour_time_hours_type"
    POSITION_3D = "lat_lon_alt_degrees_meters_type"
    TIME_HOURS = "time_hours"
    BEARING_DEGREES = "bearing_degrees"
    BEARING_DEGREES_AND_TIME_HOURS = "bearing_degrees_and_time_hours"

    sheaf.AddCell(
        "X",
        ps.Cell(POSITION_3D_VELOCITY_TIME, DistanceLatLongAlt,
                dataDimension=6))
    sheaf.AddCell("U1",
                  ps.Cell(POSITION_3D, DistanceLatLongAlt, dataDimension=3))
Esempio n. 16
0
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([
        py.SectionCell(support=0, value=tsu),  # U
        py.SectionCell(support=1, value=tsv),  #V
        py.SectionCell(support=4, value=ts),  #(U,V)
        py.SectionCell(support=5, value=ts),  #(U,V)