简体   繁体   中英

Tool for drawing neural networks

I am trying to find a tool to replicate the following neural network graph:

在此处输入图像描述

The nodes and edges can be easily drawn with igraph . However, I am not sure whether igraph can be used to replicate the other parts of the figure. Could you please help me?

If you are looking for such a solution like this example: You can find it here: https://hub.packtpub.com/training-and-visualizing-a-neural-network-with-r/

#install.packages("neuralnet")

library(neuralnet)
data(iris)
ind <- sample(2, nrow(iris), replace = TRUE, prob=c(0.7, 0.3))
trainset = iris[ind == 1,] 
testset = iris[ind == 2,]

trainset$setosa = trainset$Species == "setosa"
trainset$virginica = trainset$Species == "virginica"
trainset$versicolor = trainset$Species == "versicolor"

network = neuralnet(versicolor + virginica + setosa~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, trainset, hidden=3)
network
neuralnet(formula = versicolor + virginica + setosa ~ Sepal.Length +     Sepal.Width + Petal.Length + Petal.Width, data = trainset,     hidden = 3)
network$result.matrix
head(network$generalized.weights[[1]])

plot(network)

在此处输入图像描述

I think DiagrammeR can be a nicer variant.

If you want to produce it into R-enviroment. But you need some amount of time to learn this package.

library(DiagrammeR)

grViz("digraph G1 {
  graph [layout=neato overlap = true]     
  I0 [pos='1,3.25!' shape=plaintext label='input layer' fontsize=20]
  I1 [pos='1,2.5!'  style=radial]  
  I2 [pos='1,1!'    style=radial]
  I3 [pos='1,-0.5!' style=radial]
  I7 [pos='0,2.5!'  shape=plaintext label='input 1']
  I8 [pos='0,1!'    shape=plaintext label='input 2']
  I9 [pos='0,-0.5!' shape=plaintext label='input 3']
  H0 [pos='3,3.25!' shape=plaintext label='hidden layer 1' fontsize=20]
  H1 [pos='3,2.5!' style=radial]     
  H2 [pos='3,1!'    style=radial]
  H3 [pos='3,-0.5!' style=radial]
  O0 [pos='5,3.25!' shape=plaintext label='output layer' fontsize=20]
  O1 [pos='5,0!'  style=radial]
  O2 [pos='5,2!'  style=radial] 
  O7 [pos='6,0!' shape=plaintext label='output']
  O8 [pos='6,2!' shape=plaintext label='output']
  
  I7 -> I1 
  I8 -> I2
  I9 -> I3
  I1 -> H1 [label='w=0.8']
  I1 -> {H2 H3}
  I2 -> {H1 H2 H3}
  I3 -> {H1 H2 H3}
  {H1 H2 H3} -> O1
  {H1 H2 H3} -> O2
  O1 -> O7
  O2 -> O8
  
}")

在此处输入图像描述

I don't know how to make a 'vertical arrow to arrows', but I think we can do it via label...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM