cancer_data['symmetry_mean'], cancer_data['fractal_dimension_mean'], cancer_data['radius_se'], cancer_data['texture_se'], cancer_data['perimeter_se'], cancer_data['area_se'], cancer_data['smoothness_se'], cancer_data['compactness_se'], cancer_data['concavity_se'], cancer_data['concave_points_se'], cancer_data['symmetry_se'], cancer_data['fractal_dimension_se'], cancer_data['radius_worst'], cancer_data['texture_worst'], cancer_data['perimeter_worst'], cancer_data['area_worst'], cancer_data['smoothness_worst'], cancer_data['compactness_worst'], cancer_data['concavity_worst'], cancer_data['concave_points_worst'], cancer_data['symmetry_worst'], cancer_data['fractal_dimension_worst'])) x = x / np.max(x, axis=0) y = np.array([float(item == b'B') for item in cancer_data['diagnosis']]).reshape(len(x), 1) with utils.OutSplit('breast-cancer'): population_count = 15 population_size = 15 node_cap = 100 generations = 50 target_accuracy = 0.97 r = 0 np.random.seed(r) perm = np.random.permutation(len(x)) #np.random.shuffle(x) #np.random.shuffle(y) x = x[perm] y = y[perm]
import numpy as np import evolutionary_module as evm import utils np.random.seed(62) with utils.OutSplit('multiple_sin') as out_split: x = (np.random.random(50000)*2*np.math.pi).reshape(50000, 1) y = (np.sin(x)+1).reshape(50000, 1) val_x = (np.random.random(1000)*2*np.math.pi).reshape(1000, 1) val_y = (np.sin(val_x)+1).reshape(1000, 1) # Grab input from the user and print it to stdout population_count = int(input('population_count: ')) print('{}'.format(population_count)) population_size = int(input('poplation_size: ')) print('{}'.format(population_size)) node_cap = int(input('node_cap: ')) print('{}'.format(node_cap)) generations = int(input('generations: ')) print('{}'.format(generations)) target_accuracy = float(input('target_accuracy: ')) print('{}%'.format(target_accuracy*100)) r = int(input("random_seed: ")) print(str(r)) for i in range(50): best = evm.evolve_node_count(x, y, val_x, val_y, utils.jit_near_compare, population_count, population_size, node_cap, generations, target_accuracy, i*r+r) with utils.OutSplit('nultiple_cos'.format(d= datetime.datetime.now())):
import numpy as np import evolutionary_module as evm import utils np.random.seed(57) with utils.OutSplit('multiple_xor') as out_split: x = np.array([[1, 0] if rand < 0.25 else [0, 1] if rand < 0.5 else [1, 1] if rand < 0.75 else [0, 0] for rand in np.random.random(60000)], dtype=int) y = np.array([[ 1, ] if np.sum(itm) == 1 else [ 0, ] for itm in x], dtype=int) # Grab input from the user and print it to stdout population_count = int(input('population_count: ')) print('{}'.format(population_count)) population_size = int(input('poplation_size: ')) print('{}'.format(population_size)) node_cap = int(input('node_cap: ')) print('{}'.format(node_cap)) generations = int(input('generations: ')) print('{}'.format(generations)) target_accuracy = float(input('target_accuracy: ')) print('{}%'.format(target_accuracy * 100)) r = int(input("random_seed: ")) print(str(r))
if __name__ == "__main__": np.random.seed(0) x = np.array([[1, 0] if rand < 0.25 else [0, 1] if rand < 0.5 else [1, 1] if rand < 0.75 else [0, 0] for rand in np.random.random(60000)], dtype=int) y = np.array([[ 1, ] if np.sum(itm) == 1 else [ 0, ] for itm in x], dtype=int) with utils.OutSplit('xor_evolution_test'): # network, fitness, accuracy = evolution(x, y, x, y, utils.jit_round_compare, 30, 4, 50) # print(fitness, accuracy, network.validate(x, y, utils.jit_round_compare)) best_xor = evolve_node_count(x, y, x, y, utils.jit_round_compare, population_count=30, population_size=15, node_cap=50, generations=50, target_accuracy=1, r=2) best_xor.predict(np.array([[0, 1], [1, 1], [0, 0], [1, 0]])) utils.display_network(best_xor, 'xor')
import numpy as np import utils import datetime import evolutionary_module np.random.seed(99) with utils.OutSplit('sin-50k'.format(d=datetime.datetime.now())): population_count = int(input('population_count: ')) print(population_count) population_size = int(input('poplation_size: ')) print(population_size) node_cap = int(input('node_cap: ')) print(node_cap) generations = int(input('generations: ')) print(generations) target_accuracy = float(input('target_accuracy: ')) print('{}%'.format(target_accuracy*100)) r = float(input('random_number: ')) print(r) x = (np.random.random(50000)*2*np.math.pi).reshape(50000, 1) y = (np.sin(x)+1).reshape(50000, 1) val_x = (np.random.random(1000)*2*np.math.pi).reshape(1000, 1) val_y = (np.sin(val_x)+1).reshape(1000, 1) network = evolutionary_module.evolve_node_count(x, y, val_x, val_y, utils.jit_near_compare, population_count, population_size, node_cap, generations, target_accuracy, r)
import numpy as np import evolutionary_module as evm import utils np.random.seed(57) with utils.OutSplit('multiple_cancer') as out_split: cancer_data = np.genfromtxt('datasets\\breast-cancer-wisconsin-data.csv', delimiter=',', dtype=[('id', '<i4'), ('diagnosis', 'S1'), ('radius_mean', '<f8'), ('texture_mean', '<f8'), ('perimeter_mean', '<f8'), ('area_mean', '<f8'), ('smoothness_mean', '<f8'), ('compactness_mean', '<f8'), ('concavity_mean', '<f8'), ('concave_points_mean', '<f8'), ('symmetry_mean', '<f8'), ('fractal_dimension_mean', '<f8'), ('radius_se', '<f8'), ('texture_se', '<f8'), ('perimeter_se', '<f8'), ('area_se', '<f8'), ('smoothness_se', '<f8'), ('compactness_se', '<f8'), ('concavity_se', '<f8'), ('concave_points_se', '<f8'), ('symmetry_se', '<f8'), ('fractal_dimension_se', '<f8'), ('radius_worst', '<f8'), ('texture_worst', '<f8'), ('perimeter_worst', '<f8'), ('area_worst', '<f8'), ('smoothness_worst', '<f8'), ('compactness_worst', '<f8'), ('concavity_worst', '<f8'), ('concave_points_worst', '<f8'), ('symmetry_worst', '<f8'), ('fractal_dimension_worst', '<f8')], names=True) x = np.column_stack(( cancer_data['radius_mean'], cancer_data['texture_mean'], cancer_data['perimeter_mean'], cancer_data['area_mean'], cancer_data['smoothness_mean'], cancer_data['compactness_mean'], cancer_data['concavity_mean'], cancer_data['concave_points_mean'], cancer_data['symmetry_mean'], cancer_data['fractal_dimension_mean'], cancer_data['radius_se'], cancer_data['texture_se'], cancer_data['perimeter_se'], cancer_data['area_se'], cancer_data['smoothness_se'], cancer_data['compactness_se'], cancer_data['concavity_se'], cancer_data['concave_points_se'], cancer_data['symmetry_se'], cancer_data['fractal_dimension_se'], cancer_data['radius_worst'], cancer_data['texture_worst'], cancer_data['perimeter_worst'], cancer_data['area_worst'], cancer_data['smoothness_worst'], cancer_data['compactness_worst'], cancer_data['concavity_worst'], cancer_data['concave_points_worst'], cancer_data['symmetry_worst'], cancer_data['fractal_dimension_worst'] )) x = x / np.max(x, axis=0) y = np.array([float(item==b'B') for item in cancer_data['diagnosis']]).reshape(len(x), 1) # Grab input from the user and print it to stdout population_count = int(input('population_count: ')) print('{}'.format(population_count)) population_size = int(input('poplation_size: ')) print('{}'.format(population_size)) node_cap = int(input('node_cap: ')) print('{}'.format(node_cap)) generations = int(input('generations: ')) print('{}'.format(generations)) target_accuracy = float(input('target_accuracy: ')) print('{}%'.format(target_accuracy*100)) r = int(input("random_seed: ")) print(str(r))
train_labels = utils.jit_to_categorical( mnist_io.labels_from_file( os.path.join(dataset, "train-labels-idx1-ubyte\\train-labels.idx1-ubyte"), 60000), 10) test_images = mnist_io.images_from_file( os.path.join(dataset, "t10k-images-idx3-ubyte\\t10k-images.idx3-ubyte"), 10000) test_images = test_images.reshape(10000, 784).astype('float32') test_images /= 255 test_labels = utils.jit_to_categorical( mnist_io.labels_from_file( os.path.join(dataset, "t10k-labels-idx1-ubyte/t10k-labels.idx1-ubyte"), 10000), 10) with utils.OutSplit('mnist_evolution'): evolved_network = evolve_node_count(train_images, train_labels, test_images, test_labels, utils.jit_categorical_compare, population_count=10, population_size=15, node_cap=1500, generations=50, target_accuracy=0.95, r=4) print(evolved_network.connections, "\n", evolved_network.weights, "\n", evolved_network.learning_rate)
import evolutionary_module as evm import numpy as np import mnist_io import utils r = 23 np.random.seed(r) with utils.OutSplit('multiple_mnist'): x = mnist_io.images_from_file( 'datasets\\train-images-idx3-ubyte\\train-images.idx3-ubyte').reshape( 60000, 784).astype('float64') / 255 y = utils.jit_to_categorical( mnist_io.labels_from_file( 'datasets\\train-labels-idx1-ubyte\\train-labels.idx1-ubyte'), 10) val_x = mnist_io.images_from_file( 'datasets\\t10k-images-idx3-ubyte\\t10k-images.idx3-ubyte').reshape( 10000, 784).astype('float64') / 255 val_y = utils.jit_to_categorical( mnist_io.labels_from_file( 'datasets\\t10k-labels-idx1-ubyte\\t10k-labels.idx1-ubyte'), 10) # Grab input from the user and print it to stdout population_count = int(input('population_count: ')) print(population_count) population_size = int(input('poplation_size: ')) print(population_size) node_cap = int(input('node_cap: ')) print(node_cap) generations = int(input('generations: ')) print(generations)