import matplotlib.pyplot as plt
import numpy as np

from mlpy.numberGenerator.bounds import Bounds
from mlpy.neuralNetwork.feedForwardNeuralNetwork import NeuralNetwork
from mlpy.neuralNetwork.structure.layer import Layer

plt.grid(1)
plt.xlabel('Iterations')
plt.ylabel('Error')
plt.ylim([0, 1])
plt.ion()

l_rate = 0.2

bounds = Bounds(-2, 2)

inputLayer = Layer(bounds,
                   size=2,
                   prev=None,
                   l_rate=l_rate,
                   bias=True,
                   label="Input layer")
hiddenLayer = Layer(bounds,
                    size=4,
                    prev=inputLayer,
                    l_rate=l_rate,
                    bias=True,
                    label="Hidden layer")
outputLayer = Layer(bounds,
                    size=1,
from mlpy.neuralNetwork.structure.layer import Layer

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]),
Beispiel #3
0
 def getBounds(self):
     return Bounds(-1.28, 1.28)
Beispiel #4
0
 def getBounds(self):
     return Bounds(-10, 10)
Beispiel #5
0
 def getBounds(self):
     return Bounds(-600, 600)
 def getBounds(self):
     return Bounds(-32.768, 32.768)
import math

import numpy as np

from mlpy.numberGenerator.bounds import Bounds
from mlpy.particleSwarmOptimization.pso import PSO
from mlpy.particleSwarmOptimization.structure.particle import Particle

np.set_printoptions(suppress=True)

errors = []
bounds = Bounds(-10, 10)

# Create the mlpy with the nn weights
num_particles = 7
inertia_weight = 0.729
cognitiveConstant = 1.49
socialConstant = 1.49
num_dimensions = 50
# Configure PSO
pso = PSO()


def error(position):
    err = 0.0
    for i in range(len(position)):
        xi = position[i]
        err += (xi * xi) - (10 * math.cos(2 * math.pi * xi)) + 10
    return err

Beispiel #8
0
print("Original: ")
sequence.printFinalAlignemnt()

pso = BoundaryConstraintPSO()


def fitness(position):
    error, valid = sequence.getFitness(position)
    return (error[0] * sequence.maxlen) + error[1]


from boundaryConstraints import *

pso.boundaryConstraint = bc2

pso.error = fitness
pso.bounds = Bounds(0, sequence.maxlen + 1)
pso.initialPosition = Bounds(0, sequence.maxlen + 1)

pso.num_particles = NUM_PARTICLES
pso.num_dimensions = sequence.size
pso.weight = INERTIA_WEIGHT
pso.cognitiveConstant = COGNITIVE_CONSTANT
pso.socialConstant = SOCIAL_CONSTANT

trainingErrors, trainingError = pso.train(ITERATIONS, ITERATIONS_SAMPLE_SIZE)

sequence.getFitness(pso.group_best_position)
print("Result: ")
sequence.printFinalAlignemnt()
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(-10, 10)
INITIAL_POSITION = Bounds(-5, 5)

DESC = 'Glass'
DATA_SET_FUNC = dataSetTool.getGlassDataSets
DATA_SET_FILE_LOC = '../problems/dataSets/glass/glass.data'
HIDDEN_LAYER_NEURONS = [12]

# DESC = 'Iris'
# DATA_SET_FUNC = dataSetTool.getIrisDataSets
# DATA_SET_FILE_LOC = 'experiments/dataSets/iris/iris.data'
# HIDDEN_LAYER_NEURONS = [8]

# DESC = 'Wine'
# DATA_SET_FUNC = dataSetTool.getWineDataSets
# DATA_SET_FILE_LOC = 'experiments/dataSets/wine/wine.data'