np.set_printoptions(suppress=True) dataSetTool = DataSetTool() training, generalization, testing = dataSetTool.getIrisDataSets( '../../dataSet/iris/iris.data') plt.grid(1) plt.xlabel('Iterations') plt.ylabel('Error') plt.ylim([0, 1]) plt.ion() l_rate = 0.5 bounds = Bounds(-2, 2) inputLayer = Layer(bounds, size=len(training[0][0]), prev=None, l_rate=l_rate, bias=True, label="Input layer") hiddenLayer = Layer(bounds, size=8, prev=inputLayer, l_rate=l_rate, bias=True, label="Hidden layer") outputLayer = Layer(bounds, size=len(training[0][1]),
from neuralNetwork.structure.layer import Layer from numberGenerator.bounds import Bounds np.set_printoptions(suppress=True) dataSetTool = DataSetTool() fileName = '../../dataSet/pima-indians-diabetes/pima-indians-diabetes.data' training, generalization, testing = dataSetTool.getPrimaIndiansDiabetesSets(fileName) plt.xlabel('Iterations') plt.ylabel('Error') plt.ion() l_rate = 0.1 bounds = Bounds(-1, 1) inputLayer = Layer(bounds, size = len(training[0][0]), prev = None, l_rate = l_rate, bias = True, label = "Input layer") hiddenLayer = Layer(bounds, size = 20, prev = inputLayer, l_rate = l_rate, bias = True, label = "Hidden layer") outputLayer = Layer(bounds, size = len(training[0][1]), prev = hiddenLayer, l_rate = l_rate, bias = False, label = "Output layer") fnn = NeuralNetwork() fnn.appendLayer(inputLayer) fnn.appendLayer(hiddenLayer) fnn.appendLayer(outputLayer) group_training = np.array([input[0] for input in training]) group_target = np.array([output[1] for output in training]) errors = []
[1, 1]]) target = np.array([[0], [1], [1], [0]]) training = [] for x, y in zip(input, target): training.append((x, y)) # Get data set dataSetTool = DataSetTool() psonn.training, psonn.testing = training, training psonn.bounds = Bounds(-5, 5) # Create neural network l_rate = None inputLayer = Layer(psonn.bounds, size = 2, prev = None, l_rate = l_rate, bias = True, label = "Input layer") hiddenLayer = Layer(psonn.bounds, size = 4, prev = inputLayer, l_rate = l_rate, bias = True, label = "Hidden layer") outputLayer = Layer(psonn.bounds, size = 1, prev = hiddenLayer, l_rate = l_rate, bias = False, label = "Output layer") psonn.nn = NeuralNetwork() psonn.nn.appendLayer(inputLayer) psonn.nn.appendLayer(hiddenLayer) psonn.nn.appendLayer(outputLayer) # Create the pso with the nn weights psonn.num_particles = 20 psonn.inertia_weight = 0.729 psonn.cognitiveConstant = 1.49445
cpso_dissipative_errors = [] cpso_dissipative_error = [] cpso_dissipative_generalization_error = [] pso_errors = [] pso_error = [] pso_generalization_error = [] iterations = 5000 samples = 30 NUM_PARTICLES_Y = 5 NUM_PARTICLES_X = 5 INERTIA_WEIGHT = 0.729844 COGNITIVE_CONSTANT = 1.496180 SOCIAL_CONSTANT = 1.496180 BOUNDS = Bounds(-5, 5) # DESC = 'Glass' # DATA_SET_FUNC = dataSetTool.getGlassDataSets # DATA_SET_FILE_LOC = '../../../dataSet/glass/glass.data' # HIDDEN_LAYER_NEURONS = [12] # DESC = 'Iris' # DATA_SET_FUNC = dataSetTool.getIrisDataSets # DATA_SET_FILE_LOC = '../../../dataSet/iris/iris.data' # HIDDEN_LAYER_NEURONS = [8] # DESC = 'Wine' # DATA_SET_FUNC = dataSetTool.getWineDataSets # DATA_SET_FILE_LOC = '../../../dataSet/wine/wine.data' # HIDDEN_LAYER_NEURONS = [10]