Java Code Examples for org.neuroph.core.Layer#getNeuronAt()

The following examples show how to use org.neuroph.core.Layer#getNeuronAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KohonenLearning.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
private void learnPattern(DataSetRow dataSetRow, int neighborhood) {
	neuralNetwork.setInput(dataSetRow.getInput());
	neuralNetwork.calculate();
	Neuron winner = getClosestNeuron();
	if (winner.getOutput() == 0)
		return; // ako je vec istrenirana jedna celija, izadji

	Layer mapLayer = neuralNetwork.getLayerAt(1);
	int winnerIdx = mapLayer.indexOf(winner);
	adjustCellWeights(winner, 0);

	int cellNum = mapLayer.getNeuronsCount();
	for (int p = 0; p < cellNum; p++) {
		if (p == winnerIdx)
			continue;
		if (isNeighbor(winnerIdx, p, neighborhood)) {
			Neuron cell = mapLayer.getNeuronAt(p);
			adjustCellWeights(cell, 1);
		} // if
	} // for

}
 
Example 2
Source File: HopfieldLearning.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates weights for the hopfield net to learn the specified training
 * set
 * 
 * @param trainingSet
 *            training set to learn
 */
public void learn(DataSet trainingSet) {
	int M = trainingSet.size();
	int N = neuralNetwork.getLayerAt(0).getNeuronsCount();
	Layer hopfieldLayer = neuralNetwork.getLayerAt(0);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (j == i)
				continue;
			Neuron ni = hopfieldLayer.getNeuronAt(i);
			Neuron nj = hopfieldLayer.getNeuronAt(j);
			Connection cij = nj.getConnectionFrom(ni);
			Connection cji = ni.getConnectionFrom(nj);
			double w = 0;
			for (int k = 0; k < M; k++) {
				DataSetRow trainingSetRow = trainingSet.getRowAt(k);
				double pki = trainingSetRow.getInput()[i];
				double pkj = trainingSetRow.getInput()[j];
				w = w + pki * pkj;
			} // k
			cij.getWeight().setValue(w);
			cji.getWeight().setValue(w);
		} // j
	} // i

}
 
Example 3
Source File: ConnectionFactory.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Creates full connectivity within layer - each neuron with all other
 * within the same layer
 */
public static void fullConnect(Layer layer) {
	int neuronNum = layer.getNeuronsCount();
	for (int i = 0; i < neuronNum; i++) {
		for (int j = 0; j < neuronNum; j++) {
			if (j == i)
				continue;
			Neuron from = layer.getNeuronAt(i);
			Neuron to = layer.getNeuronAt(j);
			createConnection(from, to);
		} // j
	} // i
}
 
Example 4
Source File: ConnectionFactory.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Creates full connectivity within layer - each neuron with all other
 * within the same layer with the specified weight values for all
 * conections.
 */
public static void fullConnect(Layer layer, double weightVal) {
	int neuronNum = layer.getNeuronsCount();
	for (int i = 0; i < neuronNum; i++) {
		for (int j = 0; j < neuronNum; j++) {
			if (j == i)
				continue;
			Neuron from = layer.getNeuronAt(i);
			Neuron to = layer.getNeuronAt(j);
			createConnection(from, to, weightVal);
		} // j
	} // i
}
 
Example 5
Source File: ConnectionFactory.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Creates full connectivity within layer - each neuron with all other
 * within the same layer with the specified weight and delay values for all
 * conections.
 */
public static void fullConnect(Layer layer, double weightVal, int delay) {
	int neuronNum = layer.getNeuronsCount();
	for (int i = 0; i < neuronNum; i++) {
		for (int j = 0; j < neuronNum; j++) {
			if (j == i)
				continue;
			Neuron from = layer.getNeuronAt(i);
			Neuron to = layer.getNeuronAt(j);
			createConnection(from, to, weightVal, delay);
		} // j
	} // i
}
 
Example 6
Source File: ConnectionFactory.java    From NeurophFramework with Apache License 2.0 3 votes vote down vote up
/**
 * Creates forward connectivity pattern between the specified layers
 * 
 * @param fromLayer
 *            layer to connect
 * @param toLayer
 *            layer to connect to
 */
public static void forwardConnect(Layer fromLayer, Layer toLayer, double weightVal) {
	for(int i=0; i<fromLayer.getNeuronsCount(); i++) {
		Neuron fromNeuron = fromLayer.getNeuronAt(i);
		Neuron toNeuron = toLayer.getNeuronAt(i);
		createConnection(fromNeuron, toNeuron, weightVal);
	}
}
 
Example 7
Source File: ConnectionFactory.java    From NeurophFramework with Apache License 2.0 3 votes vote down vote up
/**
 * Creates forward connection pattern between specified layers
 * 
 * @param fromLayer
 *            layer to connect
 * @param toLayer
 *            layer to connect to
 */
public static void forwardConnect(Layer fromLayer, Layer toLayer) {
	for(int i=0; i<fromLayer.getNeuronsCount(); i++) {
		Neuron fromNeuron = fromLayer.getNeuronAt(i);
		Neuron toNeuron = toLayer.getNeuronAt(i);
		createConnection(fromNeuron, toNeuron, 1);
	}		
}