Jannis (0.1preAlpha) | ||
Frames | No Frames |
1: /* NeuronIDFinder.java - Copyright (c) 2005 by Stefan Thesing 2: <p>This file is part of Jannis.</p> 3: <p>Jannis is free software; you can redistribute it and/or modify 4: it under the terms of the GNU General Public License as published by 5: the Free Software Foundation; either version 2 of the License, or 6: (at your option) any later version.</p> 7: <p>Jannis is distributed in the hope that it will be useful, 8: but WITHOUT ANY WARRANTY; without even the implied warranty of 9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10: GNU General Public License for more details.</p> 11: <p>You should have received a copy of the GNU General Public License 12: along with Jannis; if not, write to the<br> 13: Free Software Foundation, Inc.,<br> 14: 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA<br> 15: */ 16: package de.webdings.jannis.neuralnet; 17: 18: import de.webdings.jannis.exceptions.NeuronNotFoundException; 19: /** 20: * NeuronIDFinder is used to find the ID of a given neuron 21: * in a net. It uses the same ID system as NNML.</p> 22: * <p>You should have received a DTD of NNML along with 23: * Jannis. If not, or if you're looking for further info 24: * on NNML, visit the Jannis project Website on Savannah: 25: * <a href="http://www.nongnu.org/jannis/">http://www.nongnu.org/jannis/</a> 26: * 27: * @author Stefan Thesing<br> 28: * Website: <a href="http://www.webdings.de">http://www.webdings.de</a> 29: * @version 0.1 10.08.2005 30: */ 31: public class NeuronIDFinder { 32: //Attribute 33: /** 34: * The layers of the net <code>NeuronIDFinder</code> is searching. 35: */ 36: Neuron[][] layers; 37: //Konstruktor 38: /** 39: * Constructs a <code>NeuronIDFinder</code> that can search the specified {@link 40: * NeuralNet}. 41: * @param net 42: */ 43: public NeuronIDFinder(NeuralNet net) { 44: this(net.getLayers()); 45: } 46: 47: /** 48: * Constructs a <code>NeuronIDFinder</code> that can search the {@link 49: * NeuralNet} specified by its layers.. 50: * @param layers 51: */ 52: public NeuronIDFinder(Neuron[][] layers) { 53: this.layers = layers; 54: } 55: //Methoden 56: /** 57: * @param neuron 58: * @return The ID of the layer the specified neuron resides in. 59: * @throws NeuronNotFoundException 60: */ 61: public int getLayerID(Neuron neuron) throws NeuronNotFoundException { 62: return getIDs(neuron)[0]; 63: } 64: 65: /** 66: * @param neuron 67: * @return The ID of the neuron within the layer it resides in. 68: * @throws NeuronNotFoundException 69: */ 70: public int getNeuronID(Neuron neuron) throws NeuronNotFoundException { 71: return getIDs(neuron)[1]; 72: } 73: 74: /** 75: * @param neuron 76: * @return an array containing two <code>int</code>s. The <code>int</code> at index 0 77: * represents the layerID, the <code>int</code> at index 1 represents the neuronID. 78: * @throws NeuronNotFoundException if the specified neuron does not reside in the 79: * searched net. 80: */ 81: int[] getIDs(Neuron neuron) throws NeuronNotFoundException { 82: int layerID = -1; 83: int neuronID = -1; 84: int i,j; 85: for(i=0;i<layers.length;++i) { 86: for(j=0;j<layers[i].length;++j) { 87: if(neuron == layers[i][j]) { 88: layerID = i; 89: neuronID = j; 90: break; 91: } 92: } 93: } 94: if(layerID == -1 || neuronID == -1) { 95: throw new NeuronNotFoundException("The specified net doesn't contain the neuron searched for!"); 96: } else { 97: int[] rValue = new int[2]; 98: rValue[0] = layerID; 99: rValue[1] = neuronID; 100: return rValue; 101: } 102: } 103: 104: }
Jannis (0.1preAlpha) |
© 2005 by Stefan Thesing;
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.