gpt4 book ai didi

java - 神经病 : Multi Layer Perceptron Backpropagation learning not working

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:10:10 26 4
gpt4 key购买 nike

这个问题与Neuroph有关Java 库。

我有以下程序创建一个多层感知器,其中包含一个包含 20 个节点的隐藏层。正在学习的函数是 x^2。使用反向传播学习规则。但是,从输出中可以明显看出,该程序似乎无法运行。输出一直是1,是不是我的程序出错了?

程序

import org.neuroph.core.NeuralNetwork;
import org.neuroph.core.data.DataSet;
import org.neuroph.nnet.MultiLayerPerceptron;
import org.neuroph.nnet.learning.BackPropagation;
import org.neuroph.util.TransferFunctionType;

public class SquareNeuralNetwork {

public static void main(String[] args) {
NeuralNetwork neuralNetwork = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, 1, 20, 1);
DataSet trainingSet = new DataSet(1, 1);
for (int i = 1; i <= 100; i++) {
trainingSet.addRow(new double[]{i}, new double[]{i * i});
}
BackPropagation backPropagation = new BackPropagation();
backPropagation.setMaxIterations(10);
neuralNetwork.learn(trainingSet, backPropagation);
for (int i = 1; i <= 100; i++) {
neuralNetwork.setInput(i);
neuralNetwork.calculate();
double output = neuralNetwork.getOutput()[0];
System.out.println(i + " - " + output);
}
}
}

输出

1 - 1.0
2 - 1.0
3 - 1.0
4 - 1.0
5 - 1.0
6 - 1.0
7 - 1.0
8 - 1.0
9 - 1.0
10 - 1.0
11 - 1.0
12 - 1.0

最佳答案

乙状结肠

sigmoid 激活函数的输出值在范围内:

enter image description here

您似乎在尝试教 sigmoid 函数输出 1 到 10000 之间的值,这是不可能的。因此,网络可以实现的最佳适应度是始终输出 1。

enter image description here

替代方法

如果您将函数重新建模为 1/x^2 而不是 x^2,您仍然可以教神经网络对指数函数建模,因为这会将输出范围修改为 [0, 1] for x >= 1 . 在训练完成后使用网络时,你必须除以 1/output 才能得到你想要的指数曲线。

我建模了一个包含 20 个隐藏节点和一个隐藏层的网络作为概念验证:

enter image description here

关于java - 神经病 : Multi Layer Perceptron Backpropagation learning not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29998335/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com