def testOperationTest_test(self):
        from pysgpp import Grid, DataVector, DataMatrix

        factory = Grid.createLinearTrapezoidBoundaryGrid(1)
        gen = factory.createGridGenerator()
        gen.regular(1)
        
        alpha = DataVector(factory.getStorage().size())        
        
        data = DataMatrix(1,1)
        data.setAll(0.25)
        classes = DataVector(1)
        classes.setAll(1.0)

        testOP = factory.createOperationTest()

        alpha[0] = 0.0
        alpha[1] = 0.0
        alpha[2] = 1.0
        
        c = testOP.test(alpha, data, classes)
        self.failUnless(c > 0.0)
        
        alpha[0] = 0.0
        alpha[1] = 0.0
        alpha[2] = -1.0
        c = testOP.test(alpha, data, classes)
        self.failUnless(c == 0.0)
Beispiel #2
0
    def testOperationTest_test(self):
        from pysgpp import Grid, DataVector, DataMatrix

        factory = Grid.createLinearTrapezoidBoundaryGrid(1)
        gen = factory.createGridGenerator()
        gen.regular(1)

        alpha = DataVector(factory.getStorage().size())

        data = DataMatrix(1, 1)
        data.setAll(0.25)
        classes = DataVector(1)
        classes.setAll(1.0)

        testOP = factory.createOperationTest()

        alpha[0] = 0.0
        alpha[1] = 0.0
        alpha[2] = 1.0

        c = testOP.test(alpha, data, classes)
        self.failUnless(c > 0.0)

        alpha[0] = 0.0
        alpha[1] = 0.0
        alpha[2] = -1.0
        c = testOP.test(alpha, data, classes)
        self.failUnless(c == 0.0)
Beispiel #3
0
    def testSerializationLinearTrapezoidBoudaryBoundingBox(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid

        factory = Grid.createLinearTrapezoidBoundaryGrid(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)
Beispiel #4
0
    def testSerializationLinearTrapezoidBoudaryWithLeaf(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid

        srcLeaf = []
        factory = Grid.createLinearTrapezoidBoundaryGrid(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 testSerializationLinearTrapezoidBoudaryBoundingBox(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        factory = Grid.createLinearTrapezoidBoundaryGrid(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)
 def testOperationB(self):
     from pysgpp import Grid, DataVector, DataMatrix
     factory = Grid.createLinearTrapezoidBoundaryGrid(1)
     gen = factory.createGridGenerator()
     gen.regular(2)
     
     alpha = DataVector(factory.getStorage().size())
     p = DataMatrix(1,1)
     beta = DataVector(1)
     
     
     alpha.setAll(0.0)
     p.set(0,0,0.25)
     beta[0] = 1.0
     
     opb = factory.createOperationB()
     opb.mult(beta, p, alpha)
     
     self.failUnlessAlmostEqual(alpha[0], 0.75)
     self.failUnlessAlmostEqual(alpha[1], 0.25)
     self.failUnlessAlmostEqual(alpha[2], 0.5)
     self.failUnlessAlmostEqual(alpha[3], 1.0)
     self.failUnlessAlmostEqual(alpha[4], 0.0)
     
     alpha.setAll(0.0)
     alpha[2] = 1.0
     
     p.set(0,0, 0.25)
     
     beta[0] = 0.0
     
     opb.multTranspose(alpha, p, beta)
     self.failUnlessAlmostEqual(beta[0], 0.5)
Beispiel #7
0
    def testOperationB(self):
        from pysgpp import Grid, DataVector, DataMatrix
        factory = Grid.createLinearTrapezoidBoundaryGrid(1)
        gen = factory.createGridGenerator()
        gen.regular(2)

        alpha = DataVector(factory.getStorage().size())
        p = DataMatrix(1, 1)
        beta = DataVector(1)

        alpha.setAll(0.0)
        p.set(0, 0, 0.25)
        beta[0] = 1.0

        opb = factory.createOperationB()
        opb.mult(beta, p, alpha)

        self.failUnlessAlmostEqual(alpha[0], 0.75)
        self.failUnlessAlmostEqual(alpha[1], 0.25)
        self.failUnlessAlmostEqual(alpha[2], 0.5)
        self.failUnlessAlmostEqual(alpha[3], 1.0)
        self.failUnlessAlmostEqual(alpha[4], 0.0)

        alpha.setAll(0.0)
        alpha[2] = 1.0

        p.set(0, 0, 0.25)

        beta[0] = 0.0

        opb.multTranspose(alpha, p, beta)
        self.failUnlessAlmostEqual(beta[0], 0.5)
 def testHierarchisationDTrapezoidBoundary(self):
     from pysgpp import Grid
     
     dim = 3
     level = 5
     function = buildParableBoundary(dim)
     grid = Grid.createLinearTrapezoidBoundaryGrid(dim)
     testHierarchisationDehierarchisation(self, grid, level, function)
    def testHierarchisationDTrapezoidBoundary(self):
        from pysgpp import Grid

        dim = 3
        level = 5
        function = buildParableBoundary(dim)
        grid = Grid.createLinearTrapezoidBoundaryGrid(dim)
        testHierarchisationDehierarchisation(self, grid, level, function)
Beispiel #10
0
    def testHatRegulardD_two(self):
        from pysgpp import Grid
        
        factory = Grid.createLinearTrapezoidBoundaryGrid(3)

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

        # compare
        compareStiffnessMatrices(self, m, m_ref)
Beispiel #11
0
    def testGeneration(self):
        from pysgpp import Grid, DataVector
        factory = Grid.createLinearTrapezoidBoundaryGrid(2)
        storage = factory.getStorage()

        gen = factory.createGridGenerator()
        self.failIfEqual(gen, None)

        self.failUnlessEqual(storage.size(), 0)
        gen.regular(3)
        self.failUnlessEqual(storage.size(), 49)

        #This should fail
        self.failUnlessRaises(Exception, gen.regular, 3)
 def testGeneration(self):
     from pysgpp import Grid, DataVector
     factory = Grid.createLinearTrapezoidBoundaryGrid(2)
     storage = factory.getStorage()
     
     gen = factory.createGridGenerator()
     self.failIfEqual(gen, None)
     
     self.failUnlessEqual(storage.size(), 0)
     gen.regular(3)
     self.failUnlessEqual(storage.size(), 49)
     
     #This should fail
     self.failUnlessRaises(Exception, gen.regular, 3)
Beispiel #13
0
    def testHatRegulardD_two(self):
        from pysgpp import Grid
        
        factory = Grid.createLinearTrapezoidBoundaryGrid(3)
        training = buildTrainingVector(readDataVector('data/data_dim_3_nops_512_float.arff.gz'))
        level = 3
        gen = factory.createGridGenerator()
        gen.regular(level)

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

        # compare
        compareBBTMatrices(self, m, m_ref)  
Beispiel #14
0
    def testHatRegulardD_two(self):
        from pysgpp import Grid
        
        factory = Grid.createLinearTrapezoidBoundaryGrid(3)
        training = buildTrainingVector(readDataVector('data/data_dim_3_nops_512_float.arff.gz'))
        level = 3
        gen = factory.createGridGenerator()
        gen.regular(level)

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

        # compare
        compareBTMatrices(self, m, m_ref)  
    def testOperationEval_eval(self):
        from pysgpp import Grid, DataVector

        factory = Grid.createLinearTrapezoidBoundaryGrid(1)
        gen = factory.createGridGenerator()
        gen.regular(1)
        
        alpha = DataVector(factory.getStorage().size())        
        alpha.setAll(1.0)

        p = DataVector(1)
        p.setAll(0.25)
        
        eval = factory.createOperationEval()

        self.failUnlessAlmostEqual(eval.eval(alpha, p), 1.5)
Beispiel #16
0
    def testOperationEval_eval(self):
        from pysgpp import Grid, DataVector

        factory = Grid.createLinearTrapezoidBoundaryGrid(1)
        gen = factory.createGridGenerator()
        gen.regular(1)

        alpha = DataVector(factory.getStorage().size())
        alpha.setAll(1.0)

        p = DataVector(1)
        p.setAll(0.25)

        eval = factory.createOperationEval()

        self.failUnlessAlmostEqual(eval.eval(alpha, p), 1.5)
    def testSerializationLinearTrapezoidBoudary(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        factory = Grid.createLinearTrapezoidBoundaryGrid(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())
Beispiel #18
0
    def testSerializationLinearTrapezoidBoudary(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid

        factory = Grid.createLinearTrapezoidBoundaryGrid(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())
Beispiel #19
0
    def testRefinement3d(self):
        from pysgpp import Grid, DataVector, SurplusRefinementFunctor
        factory = Grid.createLinearTrapezoidBoundaryGrid(3)
        storage = factory.getStorage()

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

        self.failUnlessEqual(storage.size(), 27)
        alpha = DataVector(27)
        for i in xrange(len(alpha)):
            alpha[i] = 0.0

        alpha[26] = 1.0
        func = SurplusRefinementFunctor(alpha)

        gen.refine(func)
        self.failUnlessEqual(storage.size(), 81)
    def testRefinement3d(self):
        from pysgpp import Grid, DataVector, SurplusRefinementFunctor
        factory = Grid.createLinearTrapezoidBoundaryGrid(3)
        storage = factory.getStorage()
        
        gen = factory.createGridGenerator()
        gen.regular(1)
        
        self.failUnlessEqual(storage.size(), 27)
        alpha = DataVector(27)
        for i in xrange(len(alpha)):
             alpha[i] = 0.0

        alpha[26] = 1.0
        func = SurplusRefinementFunctor(alpha)
        
        gen.refine(func)
        self.failUnlessEqual(storage.size(), 81)
Beispiel #21
0
def createGrid(dim, level, borderType, isFull=False):
    from pysgpp.extensions.datadriven.learner.Types import BorderTypes
    if borderType == BorderTypes.NONE:
        grid = Grid.createLinearGrid(dim)
    elif borderType == BorderTypes.TRAPEZOIDBOUNDARY:
        grid = Grid.createLinearTrapezoidBoundaryGrid(dim)
    elif borderType == BorderTypes.COMPLETEBOUNDARY:
        grid = Grid.createLinearBoundaryGrid(dim, 0)
    else:
        raise Exception('Unknown border type')

    # create regular grid of level accLevel
    gridGen = grid.getGenerator()
    if isFull:
        gridGen.full(level)
    else:
        gridGen.regular(level)

    return grid
Beispiel #22
0
def createGrid(dim, level, borderType, isFull=False):
    from pysgpp.extensions.datadriven.learner.Types import BorderTypes
    if borderType == BorderTypes.NONE:
        grid = Grid.createLinearGrid(dim)
    elif borderType == BorderTypes.TRAPEZOIDBOUNDARY:
        grid = Grid.createLinearTrapezoidBoundaryGrid(dim)
    elif borderType == BorderTypes.COMPLETEBOUNDARY:
        grid = Grid.createLinearBoundaryGrid(dim, 0)
    else:
        raise Exception('Unknown border type')

    # create regular grid of level accLevel
    gridGen = grid.createGridGenerator()
    if isFull:
        gridGen.full(level)
    else:
        gridGen.regular(level)

    return grid
 def testRefinement2d(self):
     from pysgpp import Grid, DataVector, SurplusRefinementFunctor
     factory = Grid.createLinearTrapezoidBoundaryGrid(2)
     storage = factory.getStorage()
     
     gen = factory.createGridGenerator()
     gen.regular(1)
     
     self.failUnlessEqual(storage.size(), 9)
     alpha = DataVector(9)
     alpha[0] = 0.0
     alpha[1] = 0.0
     alpha[2] = 0.0
     alpha[3] = 0.0
     alpha[4] = 0.0
     alpha[5] = 0.0
     alpha[6] = 0.0
     alpha[7] = 0.0
     alpha[8] = 1.0
     func = SurplusRefinementFunctor(alpha)
     
     gen.refine(func)
     self.failUnlessEqual(storage.size(), 21)
Beispiel #24
0
    def testRefinement2d(self):
        from pysgpp import Grid, DataVector, SurplusRefinementFunctor
        factory = Grid.createLinearTrapezoidBoundaryGrid(2)
        storage = factory.getStorage()

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

        self.failUnlessEqual(storage.size(), 9)
        alpha = DataVector(9)
        alpha[0] = 0.0
        alpha[1] = 0.0
        alpha[2] = 0.0
        alpha[3] = 0.0
        alpha[4] = 0.0
        alpha[5] = 0.0
        alpha[6] = 0.0
        alpha[7] = 0.0
        alpha[8] = 1.0
        func = SurplusRefinementFunctor(alpha)

        gen.refine(func)
        self.failUnlessEqual(storage.size(), 21)
    def testSerializationLinearTrapezoidBoudaryWithLeaf(self):
        """Uses Linear grid for tests"""
        from pysgpp import Grid
        
        srcLeaf = []
        factory = Grid.createLinearTrapezoidBoundaryGrid(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])