无法使用神经网络逼近正弦函数 [英] Unable to approximate the sine function using a neural network
问题描述
我正在尝试使用我自己编写的神经网络来近似 sine() 函数.我已经在一个简单的 OCR 问题上测试了我的神经网络并且它有效,但是我无法将它应用于近似正弦().我的问题是在训练过程中我的误差恰好收敛到 50%,所以我猜它是完全随机的.
I am trying to approximate the sine() function using a neural network I wrote myself. I have tested my neural network on a simple OCR problem already and it worked, but I am having trouble applying it to approximate sine(). My problem is that during training my error converges on exactly 50%, so I'm guessing it's completely random.
我使用一个输入神经元作为输入(0 到 PI),一个输出神经元作为结果.我有一个隐藏层,我可以在其中改变神经元的数量,但我目前正在尝试 6-10 个左右.
I am using one input neuron for the input (0 to PI), and one output neuron for the result. I have a single hidden layer in which I can vary the number of neurons but I'm currently trying around 6-10.
我有一种感觉,问题是因为我使用的 sigmoid 传递函数(这是我的应用程序中的要求)只输出 0 到 1 之间,而 sine() 的输出介于 -1 和 1 之间.尝试纠正这个我尝试将输出乘以 2 然后减去 1,但这并没有解决问题.我想我必须在某处进行某种转换才能使这项工作有效.
I have a feeling the problem is because I am using the sigmoid transfer function (which is a requirement in my application) which only outputs between 0 and 1, while the output for sine() is between -1 and 1. To try to correct this I tried multiplying the output by 2 and then subtracting 1, but this didn't fix the problem. I'm thinking I have to do some kind of conversion somewhere to make this work.
有什么想法吗?
推荐答案
使用线性输出单元.
这是一个使用 R 的简单示例:
Here is a simple example using R:
set.seed(1405)
x <- sort(10*runif(50))
y <- sin(x) + 0.2*rnorm(x)
library(nnet)
nn <- nnet(x, y, size=6, maxit=40, linout=TRUE)
plot(x, y)
plot(sin, 0, 10, add=TRUE)
x1 <- seq(0, 10, by=0.1)
lines(x1, predict(nn, data.frame(x=x1)), col="green")
这篇关于无法使用神经网络逼近正弦函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!