plt.show() #++++++++++++++++++++++++++ # THE ANN #++++++++++++++++++++++++++ # ann's ingridients from sklearn.metrics import accuracy_score hl1 = 4 hl2 = 4 hl3 = 4 hl4 = 4 hidden_architecture = np.array([[hl1, sigmoid], [hl2, sigmoid], [hl3, sigmoid], [hl4, sigmoid]]) n_weights = X.shape[1] * hl1 * hl2 * hl3 * hl4 * len(set(y)) # create ann ann_i = ANN(hidden_architecture, sigmoid, accuracy_score, (X, y), random_state, 0, (0, 1)) #++++++++++++++++++++++++++ # THE PROBLEM INSTANCE #++++++++++++++++++++++++++ ann_op_i = ANNOP(search_space=(-2, 2, n_weights), fitness_function=uls.parametrized_ann(ann_i), minimization=False) #++++++++++++++++++++++++++ # THE OPTIMIZATION #++++++++++++++++++++++++++ n_gen = 100 ps = 50 p_c = 0.8 p_m = 0.3
# ++++++++++++++++++++++++++ # THE ANN # restrictions: # - 2 h.l. with sigmoid a.f. # - softmax a.f. at output # - 20% for validation # ++++++++++++++++++++++++++ # ann's ingridients hl1 = 10 hl2 = 10 hidden_architecture = np.array([[hl1, sigmoid], [hl2, sigmoid]]) n_weights = X_train.shape[1] * hl1 * hl2 * len(digits.target_names) validation_p = 0.2 # create ann ann_i = ANN(hidden_architecture, softmax, accuracy_score, (X_train, y_train), random_state, validation_p, digits.target_names) # ++++++++++++++++++++++++++ # THE PROBLEM INSTANCE # ++++++++++++++++++++++++++ validation_threshold = 0.07 ann_op_i = ANNOP(search_space=(-2, 2, n_weights), fitness_function=ann_i.stimulate, minimization=False, validation_threshold=validation_threshold) # ++++++++++++++++++++++++++ # THE OPTIMIZATION # restrictions: # - 5000 f.e./run # - 50 f.e./generation
import os import datetime import logging import numpy as np import matplotlib.pyplot as plt from sklearn import datasets from sklearn.metrics import accuracy_score from sklearn.model_selection import train_test_split import utils as uls from problems.ANNOP import ANNOP from ANN.ANN import ANN, softmax, sigmoid from algorithms.genetic_algorithm_Elitism import GeneticAlgorithm # setup logger file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "LogFiles/" + (str(datetime.datetime.now().date()) + "-" + str(datetime.datetime.now().hour) + \ "_" + str(datetime.datetime.now().minute) + "_log.csv")) logging.basicConfig(filename=file_path, level=logging.DEBUG, format='%(name)s,%(message)s') #++++++++++++++++++++++++++ # THE DATA # restrictions: # - MNIST digits (8*8) # - 33% for testing # - flattened input images #++++++++++++++++++++++++++ # import data digits = datasets.load_digits() flat_images = np.array([image.flatten() for image in digits.images]) print(flat_images.shape) print(digits.target_names)