Ejemplo n.º 1
0
for p in [0] + [pp for pp in np.logspace(-4, 0, 30)]:
    filepath = os.path.join(os.getcwd(), 'results', 'mnist_5layer_sweep',
                            'trial_p%.06f' % (p))
    os.mkdir(filepath)
    log_file = open(os.path.join(filepath, 'log.txt'), 'a')
    sys.stdout = log_file
    trial['topology']['bypass p'] = float(p)

    per_layer_rates = []
    correction_matrices = []
    training_errors = []
    test_errors = []
    states = []
    n_epochs = trial['number of epochs']
    Network = eqp.Network(trial['topology'], trial['hyperparameters'],
                          trial['configuration'], trial['dataset'])
    initial_W = Network.W.clone().cpu().squeeze().numpy()
    initial_W_mask = Network.W_mask.clone().cpu().squeeze().numpy()

    with open(os.path.join(filepath, 'init.pickle'), 'wb') as F:
        pickle.dump(
            {
                'trial settings': trial,
                'initial weight': initial_W,
                'initial mask': initial_W_mask
            }, F)

    Network.calculate_test_error()
    training_errors.append(Network.test_error)
    test_errors.append(Network.test_error)
    mean_dW = torch.zeros(Network.W.shape).to(trial['configuration']['device'])
Ejemplo n.º 2
0
assert False"""

with open(os.path.join(filepath, 'init.pickle'), 'wb') as F:
    pickle.dump(
        {
            'topology': topology,
            'hyperparameters': hyperparameters,
            'configuration': configuration
        }, F)

per_layer_rates = []
training_errors = []
test_errors = []

n_epochs = 10
Network = eqp.Network(topology, hyperparameters, configuration,
                      datasets.Diabetes)
Network.calculate_test_error()
training_errors.append(Network.test_error)
test_errors.append(Network.test_error)
for epoch_idx in range(n_epochs):
    print('Starting epoch %d.' % (epoch_idx + 1))
    t0 = time.time()
    Network.train_epoch()
    Network.calculate_test_error()
    training_errors.append(Network.training_error)
    test_errors.append(Network.test_error)
    per_layer_rates.append([])
    for i in range(len(Network.interlayer_connections)):
        per_layer_rates[-1].append(
            np.mean([p[i] for p in Network.per_layer_rates]))
    with open(os.path.join(filepath, 'e%d.pickle' % (epoch_idx)), 'wb') as F: