softmaxlayer.java

来自「一个纯java写的神经网络源代码」· Java 代码 · 共 40 行

JAVA
40
字号
/* * SoftmaxLayer.java * * Created on 11 January 2006, 22.19 * */package org.joone.engine;/** * The outputs of the Softmax layer must be interpreted as probabilities. * The output of each node, in fact, ranges from 0 and 1, and * the sum of all the nodes is always 1. * Useful to implement the 1 of C classification network. * * @author P.Marrone */public class SoftmaxLayer extends LinearLayer {        private static final long serialVersionUID = 2243109263560495355L;        /** Creates a new instance of SoftmaxLayer */    public SoftmaxLayer() {        super();    }        public void forward(double[] pattern) {        int x;        int n = getRows();        double sum = 0;        for (x = 0; x < n; ++x) {            outs[x] = Math.exp(getBeta() * pattern[x]);            sum += outs[x];        }        for (x = 0; x < n; ++x) {            outs[x] = outs[x] / sum;        }    }}

⌨️ 快捷键说明

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