Exemplo n.º 1
0
    def testSerializationModLinearBoundingBox(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid

        factory = Grid.createModLinearGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        boundingBox = factory.getBoundingBox()
        tempBound = boundingBox.getBoundary(0)
        tempBound.leftBoundary = 0.0
        tempBound.rightBoundary = 100.0
        tempBound.bDirichletLeft = False
        tempBound.bDirichletRight = False
        boundingBox.setBoundary(0, tempBound)

        str = factory.serialize()
        self.assert_(len(str) > 0)

        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)

        self.assertEqual(factory.getStorage().size(),
                         newfac.getStorage().size())

        boundingBox = newfac.getBoundingBox()
        tempBound = boundingBox.getBoundary(0)
        self.assertEqual(0.0, tempBound.leftBoundary)
        self.assertEqual(100.0, tempBound.rightBoundary)
        self.assertEqual(False, tempBound.bDirichletLeft)
        self.assertEqual(False, tempBound.bDirichletRight)
Exemplo n.º 2
0
    def testSerializationModLinearBoundingBox(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        factory = Grid.createModLinearGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        boundingBox = factory.getBoundingBox()
        tempBound = boundingBox.getBoundary(0)
        tempBound.leftBoundary = 0.0
        tempBound.rightBoundary = 100.0
        tempBound.bDirichletLeft = False;
        tempBound.bDirichletRight = False;
        boundingBox.setBoundary(0, tempBound)

        str = factory.serialize()
        self.assert_(len(str) > 0)
        
        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)
        
        self.assertEqual(factory.getStorage().size(), newfac.getStorage().size())
        
        boundingBox = newfac.getBoundingBox()
        tempBound = boundingBox.getBoundary(0)
        self.assertEqual(0.0, tempBound.leftBoundary)
        self.assertEqual(100.0, tempBound.rightBoundary)
        self.assertEqual(False, tempBound.bDirichletLeft)
        self.assertEqual(False, tempBound.bDirichletRight)
Exemplo n.º 3
0
    def testSerializationModLinearWithLeaf(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid

        srcLeaf = []
        factory = Grid.createModLinearGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        for i in xrange(factory.getStorage().size()):
            srcLeaf.append(factory.getStorage().get(i).isLeaf())

        str = factory.serialize()
        self.assert_(len(str) > 0)

        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)

        self.assertEqual(factory.getStorage().size(),
                         newfac.getStorage().size())

        for i in xrange(factory.getStorage().size()):
            self.failUnlessEqual(newfac.getStorage().get(i).isLeaf(),
                                 srcLeaf[i])
 def testHierarchisation1DModLinear(self):
     from pysgpp import Grid
     
     dim = 1
     level = 5
     function = buildParable(dim)
     grid = Grid.createModLinearGrid(dim)
     testHierarchisationDehierarchisation(self, grid, level, function)
Exemplo n.º 5
0
    def testHierarchisationDModLinearWithBoundary(self):
        from pysgpp import Grid

        dim = 3
        level = 5
        function = buildParableBoundary(dim)
        grid = Grid.createModLinearGrid(dim)
        testHierarchisationDehierarchisation(self, grid, level, function)
Exemplo n.º 6
0
    def testHierarchisation1DModLinear(self):
        from pysgpp import Grid

        dim = 1
        level = 5
        function = buildParable(dim)
        grid = Grid.createModLinearGrid(dim)
        testHierarchisationDehierarchisation(self, grid, level, function)
    def testHierarchisationDModLinearWithBoundary(self):
        from pysgpp import Grid

        dim = 3
        level = 5
        function = buildParableBoundary(dim)
        grid = Grid.createModLinearGrid(dim)
        testHierarchisationDehierarchisation(self, grid, level, function)
Exemplo n.º 8
0
    def testHatRegular1D(self):
        from pysgpp import Grid
        
        factory = Grid.createModLinearGrid(1)

        m = generateLaplaceMatrix(factory, 5)
        m_ref = readReferenceMatrix(self, factory.getStorage(), 'data/C_laplace_phi_li_ausgeklappt_dim_1_nopsgrid_31_float.dat.gz')

        # compare
        compareStiffnessMatrices(self, m, m_ref)
Exemplo n.º 9
0
    def testHatRegulardD_two(self):
        from pysgpp import Grid
        
        factory = Grid.createModLinearGrid(3)
        training = buildTrainingVector(readDataVector('../datasets/BT_BBT/data_dim_3_nops_512_float.arff.gz'))
        level = 4
        gen = factory.getGenerator()
        gen.regular(level)

        m = generateBTMatrix(factory, training)
        m_ref = readReferenceMatrix(self, factory.getStorage(), '../datasets/BT_BBT/BT_phi_li_ausgeklappt_dim_3_nopsgrid_111_float.dat.gz')

        # compare
        compareBTMatrices(self, m, m_ref) 
Exemplo n.º 10
0
    def testHatRegular1D_two(self):
        from pysgpp import Grid
        
        factory = Grid.createModLinearGrid(1)
        training = buildTrainingVector(readDataVector('data/data_dim_1_nops_8_float.arff.gz'))
        level = 5
        gen = factory.createGridGenerator()
        gen.regular(level)

        m = generateBTMatrix(factory, training)
        m_ref = readReferenceMatrix(self, factory.getStorage(), 'data/BT_phi_li_ausgeklappt_dim_1_nopsgrid_31_float.dat.gz')

        # compare
        compareBTMatrices(self, m, m_ref) 
Exemplo n.º 11
0
    def testHatRegulardD_two(self):
        from pysgpp import Grid

        factory = Grid.createModLinearGrid(3)
        training = buildTrainingVector(readDataVector('data/data_dim_3_nops_512_float.arff.gz'))
        level = 4
        gen = factory.createGridGenerator()
        gen.regular(level)

        m = generateBBTMatrix(factory, training)
        m_ref = readReferenceMatrix(self, factory.getStorage(), 'data/BBT_phi_li_ausgeklappt_dim_3_nopsgrid_111_float.dat.gz')

        # compare
        compareBBTMatrices(self, m, m_ref)
Exemplo n.º 12
0
    def testSerializationModLinear(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        factory = Grid.createModLinearGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        str = factory.serialize()
        self.assert_(len(str) > 0)
        
        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)
        
        self.assertEqual(factory.getStorage().size(), newfac.getStorage().size())
Exemplo n.º 13
0
    def testSerializationModLinear(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid

        factory = Grid.createModLinearGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        str = factory.serialize()
        self.assert_(len(str) > 0)

        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)

        self.assertEqual(factory.getStorage().size(),
                         newfac.getStorage().size())
Exemplo n.º 14
0
    def testSerializationModLinearWithLeaf(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        srcLeaf = []
        factory = Grid.createModLinearGrid(2)
        self.failIfEqual(factory, None)

        gen = factory.createGridGenerator()
        gen.regular(3)

        for i in xrange(factory.getStorage().size()):
            srcLeaf.append(factory.getStorage().get(i).isLeaf())

        str = factory.serialize()
        self.assert_(len(str) > 0)
        
        newfac = Grid.unserialize(str)
        self.failIfEqual(newfac, None)
        
        self.assertEqual(factory.getStorage().size(), newfac.getStorage().size())
        
        for i in xrange(factory.getStorage().size()):
            self.failUnlessEqual(newfac.getStorage().get(i).isLeaf(), srcLeaf[i])
Exemplo n.º 15
0
 def setUp(self):
     self.grid = Grid.createModLinearGrid(2)  # a simple 2D grid
     self.grid.createGridGenerator().regular(3)  # max level 3 => 17 points
     self.grid_storage = self.grid.getStorage()
Exemplo n.º 16
0
    def createGrid(self):
        """
        Creates the specified grid
        """
        grid = None
        if self.__file is not None and os.path.exists(self.__file):
            gridFormatter = GridFormatter()
            grid = gridFormatter.deserializeFromFile(self.__file)
        else:
            if self.__grid is not None:
                self.__dim = self.__grid.getStorage().dim()

            if (self.__dim is None
                    or self.level is None) and self.__grid is None:
                raise AttributeError("Not all attributes assigned to create\
                                     grid")
            if self.__border is not None:
                if self.__border == BorderTypes.TRAPEZOIDBOUNDARY:
                    if self.__deg > 1:
                        grid = Grid.createPolyBoundaryGrid(
                            self.__dim, self.__deg)
                    else:
                        grid = Grid.createLinearBoundaryGrid(self.__dim)
                elif self.__border == BorderTypes.COMPLETEBOUNDARY:
                    if self.__deg > 1:
                        raise NotImplementedError()
                    else:
                        grid = Grid.createLinearBoundaryGrid(self.__dim, 0)
                else:
                    if self.__deg > 1:
                        grid = Grid.createModPolyGrid(self.__dim, self.__deg)
                    else:
                        grid = Grid.createModLinearGrid(self.__dim)
            else:
                # no border points
                if self.__deg > 1:
                    grid = Grid.createPolyGrid(self.__dim, self.__deg)
                else:
                    grid = Grid.createLinearGrid(self.__dim)

            # generate the grid
            if self.level is not None:
                generator = grid.createGridGenerator()
                if not self.__full:
                    generator.regular(self.level)
                else:
                    generator.full(self.level)

            # if there is a grid specified, add all the missing points
            if self.__grid is not None:
                gs = grid.getStorage()
                copygs = self.__grid.getStorage()

                # insert grid points
                for i in xrange(copygs.size()):
                    gp = copygs.get(i)
                    # insert grid point
                    if not gs.has_key(gp):
                        gs.insert(HashGridIndex(gp))
                    if self.__border == BorderTypes.TRAPEZOIDBOUNDARY:
                        insertTruncatedBorder(grid, gp)
                gs.recalcLeafProperty()

        return grid
Exemplo n.º 17
0
 def setUp(self):
     self.grid = Grid.createModLinearGrid(2)  # a simple 2D grid
     self.grid.createGridGenerator().regular(3)  # max level 3 => 17 points
     self.grid_storage = self.grid.getStorage()