Exemplo n.º 1
0
    def test__sumAllWeights(self):
        smoothingMetadata = dc.Test_DefaultSmoothingOscilationWeightedMean_Metadata(
            test_smoothingEndCheckType='wgsum')

        smoothing = dc.DefaultSmoothingOscilationWeightedMean(
            smoothingMetadata=smoothingMetadata)
        smoothing.__setDictionary__(
            smoothingMetadata=smoothingMetadata,
            dictionary=self.model.getNNModelModule().named_parameters())
        smoothing.countWeights = 1

        smoothing.calcMean(model=self.model,
                           smoothingMetadata=smoothingMetadata)
        sumWg = smoothing._sumAllWeights(smoothingMetadata=smoothingMetadata,
                                         metadata=self.metadata)
        ut.testCmpPandas(sumWg, 'weight_sum', 58.0)
    def test_statistics(self):
        self.timer.start()
        self.timer.end()
        self.timer.timeStart = 1.0
        self.timer.timeEnd = 2.5
        self.timer.addToStatistics()

        self.timer.timeStart = 3.0
        self.timer.timeEnd = 5.5
        self.timer.addToStatistics()

        self.timer.timeStart = 10.0
        self.timer.timeEnd = 25.7
        self.timer.addToStatistics()
        
        ut.testCmpPandas(self.timer.getTimeSum(), "timer_sum", (2.5 - 1.0) + (5.5 - 3.0) + (25.7 - 10.0))
        ut.testCmpPandas(self.timer.getAverage(), "timer_sum", ((2.5 - 1.0) + (5.5 - 3.0) + (25.7 - 10.0)) / 3)
Exemplo n.º 3
0
    def test__smoothingGoodEnoughCheck(self):
        smoothingMetadata = dc.Test_DefaultSmoothingOscilationWeightedMean_Metadata(
            test_softMarginAdditionalLoops=0,
            test_weightsEpsilon=1.0,
            test_smoothingEndCheckType='wgsum')

        smoothing = dc.DefaultSmoothingOscilationWeightedMean(
            smoothingMetadata=smoothingMetadata)
        smoothing.__setDictionary__(
            smoothingMetadata=smoothingMetadata,
            dictionary=self.model.getNNModelModule().named_parameters())
        smoothing.countWeights = 1
        a = 2.0
        b = 1.5

        ut.testCmpPandas(
            smoothing._smoothingGoodEnoughCheck(
                abs(a - b), smoothingMetadata=smoothingMetadata), 'bool',
            False)
        ut.testCmpPandas(
            smoothing._smoothingGoodEnoughCheck(
                abs(a - b), smoothingMetadata=smoothingMetadata), 'bool', True)
        b = 3.1
        ut.testCmpPandas(
            smoothing._smoothingGoodEnoughCheck(
                abs(a - b), smoothingMetadata=smoothingMetadata), 'bool',
            False)
Exemplo n.º 4
0
 def checkOscilation__isSmoothingGoodEnough__(self, avgLoss, helperEpoch,
                                              avgKLoss, dataMetadata,
                                              smoothing, smoothingMetadata,
                                              helper, model, metadata,
                                              booleanIsGood):
     smoothing(helperEpoch=helperEpoch,
               helper=helper,
               model=model,
               dataMetadata=dataMetadata,
               modelMetadata=None,
               metadata=metadata,
               smoothingMetadata=smoothingMetadata)
     ut.testCmpPandas(smoothing.lossContainer.getAverage(), 'average',
                      avgLoss)
     ut.testCmpPandas(
         smoothing.lossContainer.getAverage(
             smoothingMetadata.lossContainerDelayedStartAt), 'average',
         avgKLoss)
     ut.testCmpPandas(
         smoothing.__isSmoothingGoodEnough__(
             helperEpoch=helperEpoch,
             helper=helper,
             model=model,
             dataMetadata=None,
             modelMetadata=None,
             metadata=metadata,
             smoothingMetadata=smoothingMetadata), 'isSmoothingGoodEnough',
         booleanIsGood)
    def test_pinMemory(self):
        ok = False
        if(torch.cuda.is_available()):
            ok = True

        metadata = sf.Metadata(debugInfo=False)
        model_metadata = sf.Model_Metadata()
        data_metadata = sf.Data_Metadata()
        ut.testCmpPandas(data_metadata.pin_memoryTrain, "pin_memory_train", False)
        ut.testCmpPandas(data_metadata.pin_memoryTest, "pin_memory_test", False)

        data_metadata.tryPinMemoryTrain(metadata, model_metadata)
        ut.testCmpPandas(data_metadata.pin_memoryTrain, "pin_memory_train", ok)

        data_metadata.tryPinMemoryTest(metadata, model_metadata)
        ut.testCmpPandas(data_metadata.pin_memoryTest, "pin_memory_test", ok)
    def test_imprint_2(self):
        state = sf.LoopsState()
        ok = state.decide()
        ut.testCmpPandas(ok, "loopState_loop_here", 0)

        state.imprint(64, True)
        state.imprint(32, True)

        tmp = pickle.dumps(state)
        state = pickle.loads(tmp)

        ok = state.decide()
        ut.testCmpPandas(ok, "loopState_go_next", None)

        ok = state.decide()
        ut.testCmpPandas(ok, "loopState_go_next", None)

        ok = state.decide()
        ut.testCmpPandas(ok, "loopState_loop_here", 0)
    def test_iteration(self):
        inst = sf.CircularList(3)
        inst.pushBack(1)
        inst.pushBack(2)
        inst.pushBack(3)

        i = iter(inst)
        ut.testCmpPandas(i.indexArray, 'array', [2, 1, 0])

        ut.testCmpPandas(next(i), 'iter_next', 3)
        ut.testCmpPandas(next(i), 'iter_next', 2)
        ut.testCmpPandas(next(i), 'iter_next', 1)

        self.assertRaises(StopIteration, lambda : next(i))

        inst.pushBack(4)
        i = iter(inst)
        ut.testCmpPandas(next(i), 'iter_next', 4)
        ut.testCmpPandas(next(i), 'iter_next', 3)
        ut.testCmpPandas(next(i), 'iter_next', 2)
        self.assertRaises(StopIteration, lambda : next(i))

        inst.pushBack(5)
        i = iter(inst)
        ut.testCmpPandas(next(i), 'iter_next', 5)
        ut.testCmpPandas(next(i), 'iter_next', 4)
        ut.testCmpPandas(next(i), 'iter_next', 3)
        self.assertRaises(StopIteration, lambda : next(i))
    def test_getAverage(self):
        inst = sf.CircularList(3)
        ut.testCmpPandas(inst.getAverage(), 'average', 0)
        inst.pushBack(1)
        ut.testCmpPandas(inst.getAverage(), 'average', 1.0)
        inst.pushBack(2)
        ut.testCmpPandas(inst.getAverage(), 'average', 1.5)
        inst.pushBack(3)
        ut.testCmpPandas(inst.getAverage(), 'average', 2.0)
        ut.testCmpPandas(inst.getAverage(startAt=1), 'average', 1.5)
        inst.pushBack(4)
        ut.testCmpPandas(inst.getAverage(), 'average', 3.0)
        inst.pushBack(5)
        ut.testCmpPandas(inst.getAverage(), 'average', 4.0)

        ut.testCmpPandas(inst.getAverage(startAt=1), 'average', 3.5)
        ut.testCmpPandas(inst.getAverage(startAt=2), 'average', 3.0)

        inst.reset()
        ut.testCmpPandas(len(inst.array), 'array_length', 0)
        inst.pushBack(10)
        ut.testCmpPandas(inst.getAverage(), 'average', 10.0)
        ut.testCmpPandas(len(inst.array), 'array_length', 1)

        ut.testCmpPandas(inst.getAverage(startAt=1), 'average', 0)
    def test_pushBack(self):
        inst = sf.CircularList(2)
        inst.pushBack(1)
        ut.testCmpPandas(inst.array[0], 'array_value', 1)
        inst.pushBack(2)
        ut.testCmpPandas(inst.array[0], 'array_value', 1)
        ut.testCmpPandas(inst.array[1], 'array_value', 2)
        inst.pushBack(3)
        ut.testCmpPandas(inst.array[0], 'array_value', 3)
        ut.testCmpPandas(inst.array[1], 'array_value', 2)
        inst.pushBack(4)
        ut.testCmpPandas(inst.array[0], 'array_value', 3)
        ut.testCmpPandas(inst.array[1], 'array_value', 4)

        inst.reset()
        ut.testCmpPandas(len(inst.array), 'array_length', 0)
        inst.pushBack(10)
        ut.testCmpPandas(inst.array[0], 'array_value', 10)
        ut.testCmpPandas(len(inst.array), 'array_length', 1)
Exemplo n.º 10
0
 def test_enterExit(self):
     ut.testCmpPandas(sf.test_mode.isActive(), "test_mode_plain", False)
     with sf.test_mode():
         ut.testCmpPandas(sf.test_mode.isActive(), "test_mode_on", True)
     ut.testCmpPandas(sf.test_mode.isActive(), "test_mode_turn_off", False)
Exemplo n.º 11
0
 def test_onOff(self):
     ut.testCmpPandas(sf.test_mode.isActive(), "test_mode_plain", False)
     sf.StaticData.TEST_MODE = True
     ut.testCmpPandas(sf.test_mode.isActive(), "test_mode_on", True)
     sf.StaticData.TEST_MODE = False
     ut.testCmpPandas(sf.test_mode.isActive(), "test_mode_turn_off", False)
Exemplo n.º 12
0
 def test_sequence_2(self):
     sampler = sf.BaseSampler(dataSize=10, batchSize=2, startIndex=2, seed=988)
     testList = [4, 5, 6, 7, 8, 9]
     random.Random(988).shuffle(testList)
     ut.testCmpPandas(sampler.sequence, "sampler_sequence_2", testList)
Exemplo n.º 13
0
 def test_len(self):
     inst = sf.CircularList(3)
     ut.testCmpPandas(len(inst), 'array_length', 0)
     inst.pushBack(1)
     ut.testCmpPandas(len(inst), 'array_length', 1)
     inst.pushBack(2)
     ut.testCmpPandas(len(inst), 'array_length', 2)
     inst.pushBack(3)
     ut.testCmpPandas(len(inst), 'array_length', 3)
     inst.pushBack(4)
     ut.testCmpPandas(len(inst), 'array_length', 3)
     inst.pushBack(5)
     ut.testCmpPandas(len(inst), 'array_length', 3)