def run(self):
     for i in utility.create_progressbar(self.epochs + 1, desc='epoch', stride=1, start=self.start_epoch):
         train_loss = self.train_one_epoch()
         self.log['train_loss'].write('{}'.format(train_loss), debug='Loss Train {}:'.format(i))
         self.save(i)
         self.optimizer(i)
         test_loss, test_accuracy = self.test_one_epoch()
         self.log['test_loss'].write('{}'.format(test_loss), debug='Loss Test {}:'.format(i))
         self.log['test_accuracy'].write('{}'.format(test_accuracy), debug='Loss Accuracy {}:'.format(i))
debug = args.pop('debug')
start = args.pop('start')

model = Net()
optimizer = MomentumSGD(model, 0, 0)
args['model'], args['optimizer'] = model, optimizer
main = MnistTrainer(**args)

if args['gpu'] >= 0:
    main.to_gpu()

if debug is True:
    print(main.test_one_epoch())

for i in utility.create_progressbar(
        main.test_loader.dataset.test_data.shape[0], desc='z_test',
        start=start):
    z_test, t_test = main.test_loader.dataset[i]
    z_test = main.test_loader.collate_fn([z_test])
    t_test = main.test_loader.collate_fn([t_test])
    for ii in utility.create_progressbar(r, desc='r'):
        s_test_vec = s_test(z_test,
                            t_test,
                            model,
                            main.train_loader,
                            gpu=args['gpu'],
                            damp=damp,
                            scale=scale,
                            repeat=t)
        s_test_vec = [s.cpu() for s in s_test_vec]
        torch.save(s_test_vec, '{}/{}_{}.s_test'.format(main.save_path, i, ii))
    parser.add_argument('--start',
                        type=float,
                        default=0,
                        metavar='N',
                        help='index starts from this')

args = parser.parse_args().__dict__
print(args)
debug = args.pop('debug')
start = args.pop('start')

model = Net()
optimizer = MomentumSGD(model, 0, 0)
args['model'], args['optimizer'] = model, optimizer
main = MnistTrainer(**args)

if args['gpu'] >= 0:
    main.to_gpu()

if debug is True:
    print(main.test_one_epoch())

for i in utility.create_progressbar(
        main.train_loader.dataset.train_data.shape[0], desc='z', start=start):
    z, t = main.train_loader.dataset[i]
    z = main.train_loader.collate_fn([z])
    t = main.train_loader.collate_fn([t])
    grad_z_vec = grad_z(z, t, model, gpu=-1)
    grad_z_vec = [g.cpu() for g in grad_z_vec]
    torch.save(grad_z_vec, '{}/{}.grad_z'.format(main.save_path, i))
print(args)

z = utility.remove_slash(args['z'])
s_test = utility.remove_slash(args['s_test'])
s_tests_id = args['s_tests_id']
r = args['r']
n = args['n']
save_figure = args['save_figure']
s_tests = []
for i in six.moves.range(r):
    s_tests.append('{}/{}_{}.s_test'.format(s_test, s_tests_id, i))

grad_z = []
grad_z_iter_len = 60000

for i in utility.create_progressbar(grad_z_iter_len, desc='loading grad_z'):
    grad_z.append(torch.load('{}/{}.grad_z'.format(z, i)))

# take sum
e_s_test = torch.load('{}'.format(s_tests[0]))
for i in utility.create_progressbar(len(s_tests),
                                    desc='loading s_tests',
                                    start=1):
    e_s_test = [
        i + j for i, j in six.moves.zip(e_s_test,
                                        torch.load('{}'.format(s_tests[0])))
    ]
# average
e_s_test = [i / len(s_tests) for i in e_s_test]

influence = []