-
Notifications
You must be signed in to change notification settings - Fork 2
/
brnn_test.R
30 lines (26 loc) · 910 Bytes
/
brnn_test.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#modified example from the brnn package
library(brnn)
set.seed(42)
x1=seq(0,0.23,length.out=25)
y1=4*x1+rnorm(25,sd=0.1)
x2=seq(0.25,0.75,length.out=50)
y2=2-4*x2+rnorm(50,sd=0.1)
x3=seq(0.77,1,length.out=25)
y3=4*x3-4+rnorm(25,sd=0.1)
x=c(x1,x2,x3)
y=c(y1,y2,y3)
#With the formula interface
out=brnn(y~x,neurons=2)
#With the default S3 method the call is
#out=brnn(y=y,x=as.matrix(x),neurons=2)
plot(x,y,xlim=c(0,1),ylim=c(-1.5,1.5),
main="Bayesian Regularization for ANN 1-2-1, 2 Neurons")
lines(x,predict(out),col="blue",lty=2)
legend("topright",legend="Fitted model",col="blue",lty=2,bty="n")
out_3=brnn(y~x,neurons=3)
#With the default S3 method the call is
#out=brnn(y=y,x=as.matrix(x),neurons=2)
plot(x,y,xlim=c(0,1),ylim=c(-1.5,1.5),
main="Bayesian Regularization for ANN 1-2-1, 3 Neurons")
lines(x,predict(out_3),col="blue",lty=2)
legend("topright",legend="Fitted model",col="blue",lty=2,bty="n")