![JAR search and dependency download from the Maven repository](/logo.png)
net.sourceforge.cilib.nn.architecture.Layer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cilib-library Show documentation
Show all versions of cilib-library Show documentation
A library of composable components enabling simpler Computational Intelligence
/** __ __
* _____ _/ /_/ /_ Computational Intelligence Library (CIlib)
* / ___/ / / / __ \ (c) CIRG @ UP
* / /__/ / / / /_/ / http://cilib.net
* \___/_/_/_/_.___/
*/
package net.sourceforge.cilib.nn.architecture;
import java.util.ArrayList;
import net.sourceforge.cilib.nn.components.Neuron;
import net.sourceforge.cilib.type.types.container.Vector;
/**
* Class represents a layer in a neural network, therefore it simply extends
* an ArrayList . It also implements the {@link NeuralInputSource}
* interface and can therefore be used as input for a neuron.
*/
public class Layer extends ArrayList implements NeuralInputSource {
protected boolean bias;
/**
* Gets the neural input of this layer by getting the activation of the
* neuron at the relevant index.
* @param index {@inheritDoc }
* @return the activation of the neuron at the given index.
*/
@Override
public double getNeuralInput(int index) {
return this.get(index).getActivation();
}
/**
* Gets the activations of the neurons in this layer as a {@link Vector}
* @return the activations of the neurons in this layer.
*/
public Vector getActivations() {
Vector.Builder v = Vector.newBuilder();
for (Neuron neuron : this) {
v.add(neuron.getActivation());
}
return v.build();
}
/**
* Whether the layer has a bias neuron.
* @return whether the layer has a bias neuron.
*/
public boolean isBias() {
return bias;
}
/**
* Sets whether the layer has a bias neuron.
* @param bias whether the layer has a bias neuron.
*/
public void setBias(boolean bias) {
this.bias = bias;
}
/**
* {@inheritDoc }
*/
@Override
public Neuron getNeuron(int index) {
return this.get(index);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy