用神经网络构建一个简单的生殖对抗网络

时间:2021-10-13 07:17:24

I am trying to reproduce the example given in Goodfellow, I. et al.: Generative Adversarial Nets

我正在复制Goodfellow等人给出的示例:生成性对抗性网络

The pseudocode is given on page 4 as "Algorithm 1". I am trying to rebuild it with the neuralnet package in R:

第4页给出的伪代码为“算法1”。我正在尝试用R中的neuralnet包重建它:

library(neuralnet)

train_iter <- 10
steps <- 1
m <- 100

# initialize D and G
z <- sort(runif(m))
x <- sort(rnorm(m))
data <- cbind(z, x)
D <- neuralnet( , data = data, hidden = 11) # unclear how to define formula
G <- neuralnet(x ~ z, data = data, hidden = 11)

for (i in 1:train_iter) {
  for (k in 1:steps) {
    z <- sort(runif(m))
    x <- sort(rnorm(m))
    data <- cbind(z, x)
    err_fct_d <- function(x, z) {
      -log(compute(D, x)$net.result + log(1 - compute(D, compute(G, z)$net.result)$net.result))
    }
    D <- neuralnet( , data = data, hidden = 11, err.fct = err_fct_d, startweights = D$weights) # unclear how to define formula
  }
  z <- sort(runif(m))
  data <- cbind(z, x)
  err_fct_g <- function(x, z) {
    log(1 - compute(D, compute(G, z)$net.result)$net.result)
  }
  G <- neuralnet(x ~ z, data = data, hidden = 11, err.fct = err_fct_g, startweights = G$weights)
}

My questions
My first question is whether it is possible to use the neuralnet package with these customized error functions in the above way at all.
My second question concerns the discriminator network: I don't know how to train it, i.e. how to define the formula part of the neuralnet function.

我的第一个问题是,是否有可能使用这些自定义的错误函数在上述方法中使用neuralnet包。我的第二个问题与鉴别器网络有关:我不知道如何训练它,即如何定义神经网络函数的公式部分。

1 个解决方案

#1


0  

Unfortunately this does not work out of the box because err.fct has to be an analytically differentiable function and the compute function prevents this.

不幸的是,这并不是开箱即用的,因为出错了。fct必须是一个解析可微函数,而计算函数可以防止这种情况。

#1


0  

Unfortunately this does not work out of the box because err.fct has to be an analytically differentiable function and the compute function prevents this.

不幸的是,这并不是开箱即用的,因为出错了。fct必须是一个解析可微函数,而计算函数可以防止这种情况。