def main(argv): if len(argv) < 3: usage = 'Usage: %s RESULT_FILE.json DATASET_FILE' print(usage % argv[0], file=sys.stderr) return 1 result_file = argv[1] dataset_file = argv[2] with open(result_file, 'r') as file: result = json.loads(file.read()) network = NeuralNetwork(result['lambda'], result['structure']) dataset = Dataset(parsing.parse_dataset_file(dataset_file), normalize=True) batches = dataset.random_folds(NUM_BATCHES) counter = 1 print('Iterations,J_t') for j_t in network.train(batches, **result['training'], skip=SKIP): print('%s,%s' % (counter * SKIP, j_t)) counter += 1 if counter >= MAX_SAMPLES: break else: print('%s,%s' % (counter * SKIP, j_t))
def test_random_folds(): dataset = Dataset([ ([0.], [1., 0.]), ([1.], [1., 0.]), ([2.], [1., 0.]), ([3.], [1., 0.]), ([4.], [0., 1.]), ([5.], [0., 1.]), ([6.], [0., 1.]), ([7.], [0., 1.]), ]) folds = dataset.random_folds(4) assert len(folds) == 4 for fold in folds: assert isinstance(fold, Dataset) assert len(fold) == 2 # cada fold deve ter uma instância de cada classe assert fold.expectations[0].tolist() != fold.expectations[1].tolist()