Unable to approximate the sine function using a neural network

后端 未结 4 1575
后悔当初
后悔当初 2020-11-30 02:58

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

4条回答
  •  执念已碎
    2020-11-30 03:23

    Use a linear output unit.

    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")
    

    neural net prediction

提交回复
热议问题