def prepare_avg_param(filename, param_name, ommit_first=True):
    data = load(filename)
    max_epoch = max(d['epochs'] for d in data['many_results']) + 1
    many_accuracies = [d['test_accuracies'] for d in data['many_results']]
    alligned_many_accuracies = [
        elem + [elem[-1]] * (max_epoch - len(elem)) for elem in many_accuracies
    ]
    avg_accuracies = np.asarray(alligned_many_accuracies).sum(
        axis=0) / len(alligned_many_accuracies)
    if ommit_first:
        # TODO
        avg_accuracies = avg_accuracies[1:].round(4)
        max_epoch -= 1
    elapsed_times = [
        d['elapsed_times'] if 'elapsed_times' in d else None
        for d in data['many_results']
    ]
    avg_times = calc_avg_duration(elapsed_times) if all(
        elapsed_times) else None
    return {
        param_name: data[param_name],
        'avg_accuracies': avg_accuracies,
        'max_epoch': max_epoch,
        'activation': data['activation'] if 'activation' in data else '',
        'avg_times': avg_times,
        'use_adagrad': data['use_adagrad'] if 'use_adagrad' in data else False,
        'draw_type': data['draw_type'] if 'draw_type' in data else 'uniform',
        'momentum_param': data['momentum_param']
    }
Пример #2
0
def test_calc_prediction_accuracy():
    loaded_weights = load(filename='test_once_sigmoid_alpha_0.04_batch_100_draw_range_0.001_hidden_neurones_50_'
                                   'test_accuracy_0.968.pkl')['weights']
    _, _, test_data = load_data_wrapper("../data")
    test_data = add_bias(data=test_data)
    te_in, te_out = test_data
    weights_tested = loaded_weights[0]
    assert(calc_prediction_accuracy(SIGMOID.activation, *weights_tested, te_in, te_out) == 0.101)
    weights_tested = loaded_weights[-1]
    assert(calc_prediction_accuracy(SIGMOID.activation, *weights_tested, te_in, te_out) == 0.9687)
Пример #3
0
def test_mlp():
    loaded_data = load_data_wrapper("../data")
    loaded_result = load(filename='test_once_sigmoid_alpha_0.05_batch_100_draw_range_0.2_hidden_neurones_15_mom_0.5_'
                                   'accuracy_0.7321.pkl')
    np.random.seed(0)
    result = mlp(data=loaded_data, activation=SIGMOID, alpha=0.05, batch_size=100, draw_range=0.2,
                 hidden_neurones=15, worse_result_limit=1, momentum_param=0.5, use_adagrad=False, images_len_divider=250)
    for (w11 , w12), (w21, w22) in zip(loaded_result['weights'], result['weights']):
        assert(np.allclose(a=w11, b=w21))
        assert(np.allclose(a=w12, b=w22))
    assert (len(loaded_result['weights']) == len(result['weights']))
Пример #4
0
def prepare(filename):
    data = load(filename)
    data['activation'] = 'sigmoid'
    str_to_find = '_simulation_'
    index = filename.find(str_to_find) + len(str_to_find)
    new_filename = f'{filename[:index]}sigmoid_{filename[index:]}'
    # data = load(filename)
    # hidden_neurones = 'hidden_neurones'
    # data[hidden_neurones] = 50
    # str_to_find = '_draw_range_'
    # index = filename.find(str_to_find) + len(str_to_find) + 4
    # new_filename = f'{filename[:index]}hidden_neurones_50_{filename[index:]}'
    # save(data=data, filename=new_filename)
    print("'" + new_filename + "',")
Пример #5
0
 def execute(self, inputs=None) -> any:
     return loader.load(self.cu, file=self.file)
Пример #6
0
from loader import loader

if __name__ == "__main__":
    loader.load()
Пример #7
0
def load():
	from loader import loader
	loader.load()
Пример #8
0
    # # goodF = [
    # #     'hidden_neurones_simulation_alpha_0.04_batch_100_draw_range_0.2_hidden_neurones_15_avg_epochs_22.6_times_5.pkl',
    # #     'hidden_neurones_simulation_alpha_0.04_batch_100_draw_range_0.2_hidden_neurones_25_avg_epochs_20.6_times_5.pkl',
    # #     'hidden_neurones_simulation_alpha_0.04_batch_100_draw_range_0.2_hidden_neurones_75_avg_epochs_26.0_times_5.pkl',
    # #     'hidden_neurones_simulation_alpha_0.04_batch_100_draw_range_0.2_hidden_neurones_100_avg_epochs_31.2_times_5.pkl',
    # # ]
    # #
    #
    # for f in files:
    #     prepare(f)

    # print(load('once_relu_alpha_0.003_batch_10_draw_range_0.2_hidden_neurones_50.pkl'))

    print(
        load(
            'hidden_neurones4_simulation_relu_alpha_0.01_batch_5_draw_range_0.2_hidden_neurones_25_avg_epochs_16.0_times_5.pkl'
        ))

    # def calc_avg_times(input):
    #     max_len = max(len(sub_list) for sub_list in input)
    #     result_acc = [0] * max_len
    #     divider_acc = [0] * max_len
    #     for sub_list in input:
    #         for i in range(len(sub_list)):
    #             result_acc[i] += sub_list[i]
    #             divider_acc[i] += 1
    #     return [result_acc[i] / divider_acc[i] for i in range(max_len)]
    #
    # a = [[1, 3], [2, 4, 6, 9], [], [-1]]
    # print(calc_avg_times(a))
Пример #9
0
def load():
    from loader import loader
    loader.load(app.config)