views:

527

answers:

4

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.

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.

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.

Any ideas?

+6  A: 
rcs
By linear output unit, do you mean calculating f(net) = net for the output unit? Because I've tried this and am still having the same problem.
MahlerFive
Exactly, a linear function f(x)=a*x
rcs
Minor detail, but your r-project.org hyperlink doesn't work without prepending "www."
Joe Holloway
A: 

Try playing with this cool applet: http://neuron.eng.wayne.edu/bpFunctionApprox/bpFunctionApprox.html

perimosocordiae
When I pick sin function on that site, it doesn't train properly either..
MahlerFive
I'm getting the following result when using the applet: http://img263.imageshack.us/img263/7119/screenshotfq.png
rcs
+2  A: 
Amro
A: 

There is no reason your network shouldn't work, although 6 is definitely on the low side for approximating a sine wave. I'd try at least 10 maybe even 20.

If that doesn't work then I think you need to give more detail about your system. i.e. the learning algorithm (back-propagation?), the learning rate etc.

Mick