fawda123 / NeuralNetTools

R package of generic neural network tools
https://fawda123.github.io/NeuralNetTools/
Creative Commons Zero v1.0 Universal
71 stars 20 forks source link

plotting error with skip layer models #12

Closed fawda123 closed 9 years ago

fawda123 commented 9 years ago

Hi Marcus,

With the code below, if you set the size = 1+, plotting works fine. But if you change it to 0 with skip connections enabled, I get the error instead:

Error in data.frame(wts, row_nms) :

arguments imply differing number of rows: 3, 13)

library(nnet)

ird <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]),
                  species = factor(c(rep("s",50), rep("c", 50), rep("v", 50))))

ir.nn2 <- nnet(species ~ ., data = ird, size = 0, rang = 0.1,
               decay = 5e-4, maxit = 200, skip = TRUE)

summary(ir.nn2)

library(NeuralNetTools)

plotnet(ir.nn2, nid = TRUE, all_out = TRUE, all_in = TRUE,
        wts_only = FALSE, rel_rsc = 5, circle_cex = 5, node_labs = TRUE,
        var_labs = TRUE, x_lab = NULL, y_lab = NULL, line_stag = NULL,
        cex_val = 1, alpha_val = 1, circle_col = "lightblue",
        pos_col = "black", neg_col = "lightgrey", bord_col = "black",
        max_sp = TRUE)
fawda123 commented 9 years ago

@mngreene, this is not a bug but more of a feature request. I'd have to modify the plot code significantly for the plotnet.nnet method... stay tuned.

mngreene commented 9 years ago

No didn't think it was a bug - rather was just wondering if you had considered to include support for it.

I will be using the package a bit more in the next few weeks - will try to think of any other features that could improve it.

Regards,

Max


From: Marcus W Beck notifications@github.com Sent: 21 August 2015 15:40 To: fawda123/NeuralNetTools Subject: Re: [NeuralNetTools] plotting error with skip layer models (#12)

Ok, this is not a bug but more of a feature request. I'd have to modify the plot code significantly for the plotnet.nnet method... stay tuned.

Reply to this email directly or view it on GitHubhttps://github.com/fawda123/NeuralNetTools/issues/12#issuecomment-133448214.

fawda123 commented 9 years ago

Hi @mngreene, I think I've got a working version that can plot skip layer connections. The plotting function now includes an option to plot the skip layer connections separate from the primary network. This is the default if size = 0 in your example. Here's a snippet with some examples:

# devtools::install_github('fawda123/NeuralNetTools')
library(NeuralNetTools)
library(nnet)

ird <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]),
                  species = factor(c(rep("s",50), rep("c", 50), rep("v", 50))))

# five nodes in hidden layer, no skip
ir.nn1 <- nnet(species ~ ., data = ird, size = 5, rang = 0.1,
               decay = 5e-4, maxit = 200, skip = FALSE)

# five nodes in hidden layer, skip
ir.nn2 <- nnet(species ~ ., data = ird, size = 5, rang = 0.1,
               decay = 5e-4, maxit = 200, skip = TRUE)

# only a skip layer
ir.nn3 <- nnet(species ~ ., data = ird, size = 0, rang = 0.1,
               decay = 5e-4, maxit = 200, skip = TRUE)

# plots
plotnet(ir.nn1)
plotnet(ir.nn2)
plotnet(ir.nn2, skip = TRUE)
plotnet(ir.nn3) 

Let me know if you have any problems.

-Marcus