layer.java

来自「用Java实现的多层BP神经网络」· Java 代码 · 共 65 行

JAVA
65
字号
/*  AI ANN Backpropagation    Copyright (C) 2002-2003  Wim Gillis <d.e.m@gmx.net>    http://sourceforge.net/projects/crap    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program (see COPYING); if not, check out     http://www.gnu.org/licenses/gpl.html    or write to the Free Software Foundation,     Inc., 59 Temple Place, Suite 330, Boston,     MA  02111-1307  USA*/package cx.ma.ai.ann.backprop;import java.io.Serializable;public class Layer implements Serializable{        private Neuron[] neurons;        public Layer(int noOfNeurons, Layer previousLayer, double weightDefaultValue, int activationType) {        neurons = new Neuron[noOfNeurons];         for (int i = 0; i < neurons.length; ++i) {            if (previousLayer != null)                 neurons[i] = new Neuron(previousLayer.getNoOfNeurons(), weightDefaultValue, activationType);               else                    neurons[i] = new Neuron(0, 0, activationType);        }    }        public Layer(Layer layer) {        neurons = new Neuron[layer.getNoOfNeurons()];        for (int i = 0; i < layer.getNoOfNeurons(); ++i) {            neurons[i] = new Neuron (layer.getNeuron (i));        }    }        public int getNoOfNeurons(){        return neurons.length;    }        public Neuron getNeuron(int index){        return neurons[index];    }        public void calculateNets(Layer previousLayer){        for (int i = 0; i < neurons.length; ++i)            neurons[i].calculateNet (previousLayer);    }        public String toString(){        String out = "";        for (int i = 0; i < neurons.length; ++i)            out += "\t\tNeuron " + i + "\n" + neurons[i].toString() + "\n";        return out;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?