コード例 #1
0
 def testDefaultReductionIndex(self):
     """
     Test if all values are preserved if we use the default reduction index of a column
     """
     col = IPETEvaluationColumn(origcolname="D", name="D", reduction="min")
     ev = self.createAndEvaluateColumn(col)
     self.checkEntrySize(ev, 8)
コード例 #2
0
    def testBadReductionIndex(self):
        """
        Test if a suitable error occurs when a non existing column name is used as reduction index
        """
        col = IPETEvaluationColumn(origcolname="D", name="D", reduction="min", reductionindex="E F")

        self.assertRaises(IpetNodeAttributeError, self.createAndEvaluateColumn, col)
コード例 #3
0
 def testColumnAsIndex(self):
     """Add the column to the user columns
     """
     self.ev.addColumn(IPETEvaluationColumn(origcolname="A"))
   
     longtable = self.ev.evaluate(self.ex)[0]
     self.assertTableShape((2,2), longtable)
     self.assertTrue(longtable.index.isin(["A1", "A2"]).all(), 
                     "All index entries of the table should be A1 or A2")
コード例 #4
0
    def test_evalformat(self):
        ex = Experiment()
        ex.addOutputFile(test_out)
        ex.collectData()

        for (index, indexsplit) in ((index, indexsplit) for index in eval_index
                                    for indexsplit in eval_indexsplit):
            for (cols, fgs) in ((cols, fgs) for cols in self.test_cols
                                for fgs in self.test_fgs):
                ev = IPETEvaluation(index=index, indexsplit=indexsplit)
                if cols is not None:
                    for (ind_c, ind_a) in cols:
                        col = IPETEvaluationColumn(**columns[ind_c])
                        if col_filters[ind_c] is not None:
                            colfilter = IPETFilter(**col_filters[ind_c])
                            col.addFilter(colfilter)
                        if ind_a:
                            agg = Aggregation(**aggs[ind_c])
                            col.addAggregation(agg)
                        ev.addColumn(col)
                if fgs is not None:
                    for ind in fgs:
                        fg = IPETFilterGroup(**filtergroups[ind])
                        if filters[ind] is not None:
                            fgfilter = IPETFilter(**filters[ind])
                            fg.addFilter(fgfilter)
                        ev.addFilterGroup(fg)

                try:
                    tab_long, tab_agg = ev.evaluate(ex)
                except AttributeError as e:
                    self.assertTrue((
                        cols is None or fgs is None
                    ), "Either the number of columns or the number of filtergroups should be 0."
                                    )
                    continue

                self.assertEqual(type(tab_long), pd.DataFrame,
                                 "Type of long table wrong.")
                self.assertEqual(type(tab_agg), pd.DataFrame,
                                 "Type of aggregated table wrong.")

                # do not allow rowindex to be empty
                if indexsplit == 0:
                    indexsplit = 1

                rowindex_level = len(index.split()[:indexsplit])
                columns_level = len(index.split()[indexsplit:])

                self.assertEqual(tab_long.columns.nlevels, columns_level + 1,
                                 "Level of columnindex of long table wrong.")
                self.assertEqual(tab_agg.index.nlevels, columns_level + 1,
                                 "Level of rowindex of agg table wrong.")

                self.assertEqual(tab_long.index.nlevels, rowindex_level,
                                 "Level of rowindex of long table wrong.")
コード例 #5
0
ファイル: FilterDataTest.py プロジェクト: stephenjmaher/ipet
    def setUp(self):
        """Set up the evaluation

            The evaluation has only one column
            for the 'Data' key, but applies
            filtering on the 'FilterData' key
        """
        self.ex = HelperExperiment()
        ev = IPETEvaluation(index="Index", indexsplit="1")
        ev.addColumn(IPETEvaluationColumn(origcolname="Data"))
        fg = IPETFilterGroup("TestGroup")
        fi = IPETFilter(expression1="FilterData",
                        expression2=-1.0,
                        operator="eq")
        fg.addFilter(fi)
        ev.addFilterGroup(fg)

        self.ev = ev
コード例 #6
0
 def setUp(self):
     self.ex = HelpExperiment()
     ev = IPETEvaluation(defaultgroup="C1", 
                         index="A C"
                         )
     
     ev.addColumn(IPETEvaluationColumn(origcolname="D"))
     fg = IPETFilterGroup("Test")
     fi = IPETFilter(operator="keep", datakey="A")
     fi.addChild(IPETValue("A1"))
     fg.addFilter(fi)
     fg2 = IPETFilterGroup("Test2")
     fi2 = IPETFilter(operator="keep", datakey="A")
     fi2.addChild(IPETValue("A2"))
     fg2.addFilter(fi2)
     ev.addFilterGroup(fg2)
     ev.addFilterGroup(fg)
     self.ev = ev
     self.fg = fg
コード例 #7
0
ファイル: FillInTest.py プロジェクト: stephenjmaher/ipet
    def setUp(self):
        """
        create an evaluation around a helper experiment
        """
        self.ex = HelpExperiment()
        ev = IPETEvaluation(defaultgroup="C1",
                            index="A B C",
                            fillin=True,
                            indexsplit=3)

        ev.addColumn(
            IPETEvaluationColumn(origcolname="D", alternative="100",
                                 maxval=15))
        fg = IPETFilterGroup("Test")
        fi = IPETFilter(operator="keep", datakey="A")
        fi.addChild(IPETValue("A1"))
        fg.addFilter(fi)
        ev.addFilterGroup(fg)
        self.ev = ev
        self.fg = fg
コード例 #8
0
 def setUp(self):
     logger=logging.getLogger()
     logger.setLevel(logging.ERROR)
     self.helper = HelperExperiment()
     self.col = IPETEvaluationColumn(origcolname="D", name="D", reduction="min", reductionindex=2)
     pass
コード例 #9
0
class ReductionIndexTest(unittest.TestCase):


    def setUp(self):
        logger=logging.getLogger()
        logger.setLevel(logging.ERROR)
        self.helper = HelperExperiment()
        self.col = IPETEvaluationColumn(origcolname="D", name="D", reduction="min", reductionindex=2)
        pass


    def tearDown(self):
        pass

    def getPowerSet(self, indexList=list("ABC")):
        from itertools import chain, combinations
        return chain.from_iterable(combinations(indexList,n) for n in range(len(indexList)+1))

    def createAndEvaluateColumn(self, col):
        ev = IPETEvaluation(index="A B C", indexsplit=3)
        ev.addColumn(col)
        ev.evaluate(self.helper)

        return ev

    def checkEntrySize(self, ev, expsize):
        v_counts = ev.getInstanceData()["D"].value_counts()
        gotsize=v_counts.size
        self.assertEqual(gotsize, expsize, "Expecting {} distinct values, have {} in data\n{}\n".format(gotsize, expsize, ev.getInstanceData()))

    def testReductionIndex(self):
        """
        Test all integers between 0 and 4 for the reduction index
        """

        for idx in range(0,4):
            self.col.set_reductionindex(idx)
            ev = self.createAndEvaluateColumn(self.col)
            self.checkEntrySize(ev, 2**idx)


    def testReductionIndexNames(self):
        """
        Test all possible combinations of the index columns A, B, and C as reductionindex
        """
        for s in self.getPowerSet():
            self.col.set_reductionindex(" ".join(s))
            ev = self.createAndEvaluateColumn(self.col)
            self.checkEntrySize(ev, 2**len(s))


    def testDefaultReductionIndex(self):
        """
        Test if all values are preserved if we use the default reduction index of a column
        """
        col = IPETEvaluationColumn(origcolname="D", name="D", reduction="min")
        ev = self.createAndEvaluateColumn(col)
        self.checkEntrySize(ev, 8)

    def testBadReductionIndex(self):
        """
        Test if a suitable error occurs when a non existing column name is used as reduction index
        """
        col = IPETEvaluationColumn(origcolname="D", name="D", reduction="min", reductionindex="E F")

        self.assertRaises(IpetNodeAttributeError, self.createAndEvaluateColumn, col)


    def testReductionResult(self):
        """
        Test the result of a couple of reductions. This also ensures that the shmean shiftby format is recognized.
        """
        reduction2result = {
            "min" : 1.0,
            "max" : 8.0,
            "mean" : 4.5,
            "median" : 4.5,
            "sum" : 36,
            "prod" : 40320,
            "shmean shift. by 1" : 3.9541639,
            "shmean shift. by 10" : 4.3160184,
            "shmean shift. by 100" : 4.4748727,
            "shmean shift. by 1000" : 4.49738675
        }

        for reduction, result in reduction2result.items():
            self.col.set_reduction(reduction)
            self.col.set_reductionindex(0)
            ev = self.createAndEvaluateColumn(self.col)
            self.assertAlmostEqual(ev.getInstanceData()["D"].unique()[0], result, delta=1e-6)
コード例 #10
0
class ReductionIndexTest(unittest.TestCase):


    def setUp(self):
        logger=logging.getLogger()
        logger.setLevel(logging.ERROR)
        self.helper = HelperExperiment()
        self.col = IPETEvaluationColumn(origcolname="D", name="D", reduction="min", reductionindex=2)
        pass


    def tearDown(self):
        pass
    
    def getPowerSet(self, indexList=list("ABC")):
        from itertools import chain, combinations
        return chain.from_iterable(combinations(indexList,n) for n in range(len(indexList)+1))
    
    def createAndEvaluateColumn(self, col):
        ev = IPETEvaluation(index="A B C", indexsplit=3)
        ev.addColumn(col)
        ev.evaluate(self.helper)
        
        return ev
    
    def checkEntrySize(self, ev, expsize):
        v_counts = ev.getInstanceData()["D"].value_counts()
        gotsize=v_counts.size
        self.assertEqual(gotsize, expsize, "Expecting {} distinct values, have {} in data\n{}\n".format(gotsize, expsize, ev.getInstanceData()))

    def testReductionIndex(self):
        """
        Test all integers between 0 and 4 for the reduction index
        """
        
        for idx in range(0,4):
            self.col.set_reductionindex(idx)
            ev = self.createAndEvaluateColumn(self.col)
            self.checkEntrySize(ev, 2**idx)
            
            
    def testReductionIndexNames(self):
        """
        Test all possible combinations of the index columns A, B, and C as reductionindex
        """
        for s in self.getPowerSet():
            self.col.set_reductionindex(" ".join(s))
            ev = self.createAndEvaluateColumn(self.col)
            self.checkEntrySize(ev, 2**len(s))
            
            
    def testDefaultReductionIndex(self):
        """
        Test if all values are preserved if we use the default reduction index of a column
        """
        col = IPETEvaluationColumn(origcolname="D", name="D", reduction="min")
        ev = self.createAndEvaluateColumn(col)
        self.checkEntrySize(ev, 8)
        
    def testBadReductionIndex(self):
        """
        Test if a suitable error occurs when a non existing column name is used as reduction index
        """
        col = IPETEvaluationColumn(origcolname="D", name="D", reduction="min", reductionindex="E F")
        
        self.assertRaises(IpetNodeAttributeError, self.createAndEvaluateColumn, col)