Jannis (0.1preAlpha) | ||
Frames | No Frames |
1: /* PatternGiver.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 java.io.IOException; 19: 20: import de.webdings.jannis.exceptions.PatternCreateException; 21: import de.webdings.jannis.exceptions.PatternGiverReaderCommunicationException; 22: import de.webdings.tools.files.TextFiles; 23: /** 24: * PatternGiver is used to present a {@link NeuralNet} with 25: * an input {@link Pattern}. 26: * 27: * @author Stefan Thesing<br> 28: * Website: <a href="http://www.webdings.de">http://www.webdings.de</a> 29: * @version 0.1 01.08.2005 30: */ 31: public class PatternGiver { 32: //attributes 33: /** 34: * <code>inputLayer</code> is the input layer of 35: * the {@link NeuralNet} that is presented with 36: * input by this PatternGiver. 37: */ 38: Neuron[] inputLayer; 39: 40: /** 41: * <code>pattern</code> is the the whole of input 42: * {@link Pattern}s the {@link NeuralNet} is presented 43: * with. 44: */ 45: Pattern[] pattern; 46: 47: /** 48: * <code>counter</code> is used to keep track of the 49: * number of patterns the net has already been presented 50: * with. 51: */ 52: private int counter; 53: 54: //constructors 55: /** 56: * @param inputLayer 57: * @param fileName 58: * @throws IOException 59: * @throws PatternCreateException 60: */ 61: public PatternGiver(Neuron[] inputLayer, String fileName) throws IOException, PatternCreateException { 62: this.inputLayer = inputLayer; 63: this.pattern = PatternConverter.strToPattern(TextFiles.readFromFile(fileName), inputLayer.length); 64: this.counter =0; 65: } 66: /** 67: * @param inputLayer 68: * @param pattern 69: */ 70: public PatternGiver(Neuron[] inputLayer, Pattern[] pattern) { 71: this.inputLayer = inputLayer; 72: this.pattern = pattern; 73: this.counter = 0; 74: } 75: 76: //methods 77: /** 78: * Presents the net with the next pattern. 79: * @throws PatternGiverReaderCommunicationException 80: */ 81: public void nextPattern() throws PatternGiverReaderCommunicationException { 82: if(counter >= pattern.length){ 83: throw new PatternGiverReaderCommunicationException("Fehler beim Senden des Musters an die Inputschicht!"); 84: } else { 85: int i; 86: for(i=0; i < inputLayer.length ;++i) { 87: if(pattern[counter].entries[i]) { 88: inputLayer[i].fire(); 89: } 90: } 91: ++counter; 92: } 93: } 94: 95: /** 96: * @return {@link #counter}, i.e. the number of patterns 97: * the net has already been presented with. 98: */ 99: public int numberSent() { 100: return counter; 101: } 102: 103: /** 104: * @return Returns the inputLayer. 105: */ 106: public Neuron[] getInputLayer() { 107: return inputLayer; 108: } 109: /** 110: * @param inputLayer The inputLayer to set. 111: */ 112: public void setInputLayer(Neuron[] inputLayer) { 113: this.inputLayer = inputLayer; 114: } 115: /** 116: * @return Returns the patterns. 117: */ 118: public Pattern[] getPattern() { 119: return pattern; 120: } 121: /** 122: * @param pattern The pattern to set. 123: */ 124: public void setPattern(Pattern[] pattern) { 125: this.pattern = pattern; 126: } 127: }
Jannis (0.1preAlpha) |
© 2005 by Stefan Thesing;
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.