Python chainer.training.extensions.ExponentialShift() Examples

The following are 5 code examples of chainer.training.extensions.ExponentialShift(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module chainer.training.extensions , or try the search function .
Example #1
Source File: test_exponential_shift.py    From chainer with MIT License 5 votes vote down vote up
def setUp(self):
        self.optimizer = mock.MagicMock()
        self.extension = extensions.ExponentialShift(
            'x', self.rate, self.init, self.target, self.optimizer)

        self.interval = 4
        self.expect = [e for e in self.expect for _ in range(self.interval)]
        self.trigger = util.get_trigger((self.interval, 'iteration'))

        self.trainer = testing.get_trainer_with_mock_updater(self.trigger)
        self.trainer.updater.get_optimizer.return_value = self.optimizer 
Example #2
Source File: test_exponential_shift.py    From chainer with MIT License 5 votes vote down vote up
def test_basic(self):
        self.optimizer.x = 0
        extension = extensions.ExponentialShift(
            'x', self.rate, init=self.init, target=self.target)
        self._run_trainer(extension, self.expect) 
Example #3
Source File: test_exponential_shift.py    From chainer with MIT License 5 votes vote down vote up
def test_without_init(self):
        self.optimizer.x = self.init
        extension = extensions.ExponentialShift(
            'x', self.rate, target=self.target)
        self._run_trainer(extension, self.expect) 
Example #4
Source File: test_exponential_shift.py    From chainer with MIT License 5 votes vote down vote up
def test_with_optimizer(self):
        optimizer = mock.Mock()
        optimizer.x = 0
        extension = extensions.ExponentialShift(
            'x', self.rate, init=self.init, target=self.target,
            optimizer=optimizer)
        self._run_trainer(extension, self.expect, optimizer) 
Example #5
Source File: test_exponential_shift.py    From chainer with MIT License 5 votes vote down vote up
def test_resume(self):
        new_optimizer = mock.Mock()
        new_extension = extensions.ExponentialShift(
            'x', self.rate, self.init, self.target, new_optimizer)

        self.trainer.extend(self.extension)
        self.trainer.run()

        new_trainer = testing.get_trainer_with_mock_updater((3, 'iteration'))
        new_trainer.extend(new_extension)
        testing.save_and_load_npz(self.trainer, new_trainer)

        new_extension.initialize(new_trainer)
        self.assertEqual(new_optimizer.x, self.optimizer.x)
        self.assertIsInstance(new_optimizer.x, float)