【问题标题】:Echo state network?回声状态网络?
【发布时间】:2012-10-19 11:14:18
【问题描述】:

我最近从几个人那里听说,回声状态网络非常适合时间序列建模。所以我觉得值得一试。

http://en.wikipedia.org/wiki/Echo_state_network

这是一种循环网络,只学习输出层的权重,其他权重是随机的。

他们在 R 中的库/包在多大程度上可用于创建回声状态网络?

(注意:有这个问题:Neural net package in R,这可能是相关的,但它要求“递归”网络,而我正在寻找“循环”或“回声状态”网络)。

【问题讨论】:

    标签: r neural-network time-series


    【解决方案1】:

    我知道这个问题很老了,但这可能仍然有用,也许对其他人有用。

    在这里您可以找到工作演示 source code of a minimalistic Echo State Network in R。它不是一个成熟的库,但我希望它易于理解并适应您的应用程序。

    # A minimalistic Echo State Networks demo with Mackey-Glass (delay 17) data 
    # in "plain" R.
    # by Mantas Lukosevicius 2012
    # http://minds.jacobs-university.de/mantas
    
    # load the data
    trainLen = 2000
    testLen = 2000
    initLen = 100
    
    data = as.matrix(read.table('MackeyGlass_t17.txt'))
    
    # plot some of it
    while( dev.cur() != 1 ) dev.off() # close all previous plots
    dev.new()
    plot(data[1:1000],type='l')
    title(main='A sample of data')
    
    # generate the ESN reservoir
    inSize = outSize = 1
    resSize = 1000
    a = 0.3 # leaking rate
    
    set.seed(42)
    Win = matrix(runif(resSize*(1+inSize),-0.5,0.5),resSize)
    W = matrix(runif(resSize*resSize,-0.5,0.5),resSize)
    # Option 1 - direct scaling (quick&dirty, reservoir-specific):
    #W = W * 0.135 
    # Option 2 - normalizing and setting spectral radius (correct, slow):
    cat('Computing spectral radius...')
    rhoW = abs(eigen(W,only.values=TRUE)$values[1])
    print('done.')
    W = W * 1.25 / rhoW
    
    # allocated memory for the design (collected states) matrix
    X = matrix(0,1+inSize+resSize,trainLen-initLen)
    # set the corresponding target matrix directly
    Yt = matrix(data[(initLen+2):(trainLen+1)],1)
    
    # run the reservoir with the data and collect X
    x = rep(0,resSize)
    for (t in 1:trainLen){
        u = data[t]
        x = (1-a)*x + a*tanh( Win %*% rbind(1,u) + W %*% x )
        if (t > initLen)
            X[,t-initLen] = rbind(1,u,x)
    }
    
    # train the output
    reg = 1e-8  # regularization coefficient
    X_T = t(X)
    Wout = Yt %*% X_T %*% solve( X %*% X_T + reg*diag(1+inSize+resSize) )
    
    # run the trained ESN in a generative mode. no need to initialize here, 
    # because x is initialized with training data and we continue from there.
    Y = matrix(0,outSize,testLen)
    u = data[trainLen+1]
    for (t in 1:testLen){
        x = (1-a)*x + a*tanh( Win %*% rbind(1,u) + W %*% x )
        y = Wout %*% rbind(1,u,x)
        Y[,t] = y
        # generative mode:
        u = y
        ## this would be a predictive mode:
        #u = data[trainLen+t+1] 
    }
    
    # compute MSE for the first errorLen time steps
    errorLen = 500
    mse = ( sum( (data[(trainLen+2):(trainLen+errorLen+1)] - Y[1,1:errorLen])^2 )
        / errorLen )
    print( paste( 'MSE = ', mse ) )
    
    # plot some signals
    dev.new() 
    plot( data[(trainLen+1):(trainLen+testLen+1)], type='l', col='green' )
    lines( c(Y), col='blue' )
    title(main=expression(paste('Target and generated signals ', bold(y)(italic(n)), 
        ' starting at ', italic(n)==0 )))
    legend('bottomleft',legend=c('Target signal', 'Free-running predicted signal'), 
        col=c('green','blue'), lty=1, bty='n' )
    
    dev.new()
    matplot( t(X[(1:20),(1:200)]), type='l' )
    title(main=expression(paste('Some reservoir activations ', bold(x)(italic(n)))))
    
    dev.new()
    barplot( Wout )
    title(main=expression(paste('Output weights ', bold(W)^{out})))
    

    【讨论】:

    • 好的,让我们开始吧,因为它确实提供了回声状态实现,并且已经 2.5 年了:-D
    【解决方案2】:

    尽管这并不能回答您关于 R 的问题,但我几乎可以肯定您可以自己轻松实现 ESN(除非您需要更高级/深奥的功能)。

    看看at the definition of the ESN made by Jaeger:您只需要用于内部状态和输出的方程 (1) 和 (2),再加上用于学习的方程 (3) 或 (4)。实现非常简单,只需矩阵乘法、范数和伪逆即可。

    附:实际上,“递归”和“递归”神经网络并不是很不同的东西。术语“递归”通常(但并非总是)指处理图的那些神经网络,而“递归”网络处理序列/时间序列(这是图的一种特殊情况)。 “递归”和“递归”网络在其隐藏层中都有循环,因此它们的内部状态是递归定义的。语言混乱的一部分,关键是您可以尝试使用现有的库并根据您的需要进行调整。

    【讨论】:

    • 考虑发表评论,总结您提供的要点和链接,因为正如您自己观察到的那样,这不是对所提问题的回答。
    • 我很抱歉,但没有办法将我的帖子变成实际答案,因为据我所知,R 中没有 ESN 库。无论如何,ESN 背后的想法是您可以避免使用训练循环网络通常需要的那些复杂算法。 ESN的主要特点是非常简单,所以我的建议是:利用这种简单性,自己实现。寻找库可能会浪费时间,如果该库旨在为循环网络提供支持,则更是如此,因为 ESN 的训练只涉及线性读出。
    • 关于链接,嗯,那个页面包含 ESN 的定义,它是由 ESN 创建者 Herbert Jaeger 编写的。对于 ESN 的工作方式,您找不到更简单或更可靠的描述。我在这里尝试总结它真的有意义吗?如果您对 ESN 感兴趣 - 无论您是否使用库 - 您都应该至少阅读该页面。如果你认为我做的总结没问题……好吧……你错了。
    • 欢迎来到 Stack Overflow!我的评论是指一些 guidelines 关于如何回答关于 SO 的问题。您给出的内容并不是对提问者问题的严格回答,因为它被认为是关于如何使用 R 库来实现 ESN 的问题,而不是关于定义 ESN 的细微差别的问题。最后,您还建议通过尝试现有库,提问者通过提出问题来做某事。
    猜你喜欢
    • 2012-05-14
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多