# NOT RUN {
####################
# train.ratio = 0.6 ## 60% of data is used for training
# batch.size = 10
# total.iter = 100
# hiddenlayer=c(20,10) ## Use two hidden layers
# arrange=TRUE #### Use "arrange" option
# activations = c("Relu","SoftPlus") ### Use Relu and SoftPlus
# optim = "Nesterov" ### Use the "Nesterov" method for the optimization.
# type = Classification
# rand.eff = TRUE #### Add some random effect
# distr="Normal" #### The random effect is a normal random variable
# disp = TRUE #### Display intemeidate results during iterations.
data(iris)
lst = TrainBuddle("Species~Sepal.Width+Petal.Width", iris, train.ratio=0.6,
arrange=TRUE, batch.size=10, total.iter = 100, hiddenlayer=c(20, 10),
batch.norm=TRUE, drop=TRUE, drop.ratio=0.1, lr=0.1, init.weight=0.1,
activation=c("Relu","SoftPlus"), optim="Nesterov",
type = "Classification", rand.eff=TRUE, distr = "Normal", disp=TRUE)
lW = lst$lW
lb = lst$lb
lParam = lst$lParam
confusion.matrix = lst$confusion.matrix
precision = lst$precision
confusion.matrix
precision
### Another classification example
### Using mnist data
data(mnist_data)
Img_Mat = mnist_data$Images
Img_Label = mnist_data$Labels
##### Use 100 images
X = Img_Mat ### X: 100 x 784 matrix
Y = Img_Label ### Y: 100 x 1 vector
lst = TrainBuddle(Y, X, train.ratio=0.6, arrange=TRUE, batch.size=10, total.iter = 100,
hiddenlayer=c(20, 10), batch.norm=TRUE, drop=TRUE,
drop.ratio=0.1, lr=0.1, init.weight=0.1,
activation=c("Relu","SoftPlus"), optim="AdaGrad",
type = "Classification", rand.eff=TRUE, distr = "Logistic", disp=TRUE)
confusion.matrix = lst$confusion.matrix
precision = lst$precision
confusion.matrix
precision
############### Regression example
n=100
p=10
X = matrix(rnorm(n*p, 1, 1), n, p) ## X is a 100-by-10 design matrix
b = matrix( rnorm(p, 1, 1), p,1)
e = matrix(rnorm(n, 0, 1), n,1)
Y = X %*% b + e ### Y=X b + e
######### train.ratio=0.7
######### batch.size=20
######### arrange=FALSE
######### total.iter = 100
######### hiddenlayer=c(20)
######### activation = c("Identity")
######### "optim" = "Adam"
######### type = "Regression"
######### rand.eff=FALSE
lst = TrainBuddle(Y, X, train.ratio=0.7, arrange=FALSE, batch.size=20, total.iter = 100,
hiddenlayer=c(20), batch.norm=TRUE, drop=TRUE, drop.ratio=0.1, lr=0.1,
init.weight=0.1, activation=c("Identity"), optim="AdaGrad",
type = "Regression", rand.eff=FALSE, disp=TRUE)
# }
Run the code above in your browser using DataLab