private Particle createParticle(Vector vector) { Particle particle = new StandardParticle(); particle.getProperties().put(EntityType.CANDIDATE_SOLUTION, vector); particle.getProperties().put(EntityType.Particle.VELOCITY, Vector.of(0.0)); particle.getProperties().put(EntityType.Particle.BEST_POSITION, vector.getClone()); return particle; }
/** {@inheritDoc} */ @Override public Double apply(Vector input) { Vector tmp = input.getClone(); for (int i = 0; i < input.size(); i++) { tmp.setReal(i, (horizontalScale * input.doubleValueOf(i))); } return (verticalScale * function.apply(tmp)); }
/** {@inheritDoc} */ @Override public Double apply(Vector input) { Vector tmp = input.getClone(); if (horizontalReflection) { for (int i = 0; i < input.size(); i++) { tmp.setReal(i, -input.doubleValueOf(i)); } } if (verticalReflection) { return -function.apply(tmp); } return function.apply(tmp); }
/** * Builds a layer by cloning a prototype neuron and adding to it weights such that it is fully * connected to the feeding layer. * * @param layerConfiguration * @param previousLayerAbsoluteSize * @return the built layer. */ @Override public Layer buildLayer(LayerConfiguration layerConfiguration, int previousLayerAbsoluteSize) { prototypeNeuron.setActivationFunction(layerConfiguration.getActivationFunction()); int layerSize = layerConfiguration.getSize(); boolean bias = layerConfiguration.isBias(); // determine correct domain registry DomainRegistry domainRegistry = domainProvider.generateDomain(previousLayerAbsoluteSize); // set domain for prototype neuron prototypeNeuron.setDomain(domainRegistry.getDomainString()); // get prototype weight vector Vector prototypeWeightVector = null; try { prototypeWeightVector = (Vector) domainRegistry.getBuiltRepresentation(); } catch (ClassCastException exception) { throw new UnsupportedOperationException( "The domain string of the neural network weights has to be real valued"); } // add neurons to layer Layer layer = new Layer(); for (int i = 0; i < layerSize; i++) { Neuron newNeuron = prototypeNeuron.getClone(); Vector weights = prototypeWeightVector.getClone(); // TODO: initialisation should be done by training algorithm this.getWeightInitialisationStrategy().initialise(weights); newNeuron.setWeights(weights); layer.add(newNeuron); } if (bias) { layer.add(new BiasNeuron()); layer.setBias(true); } return layer; }