【问题标题】:javascript neuralnet back-propagation algorithm failingjavascript 神经网络反向传播算法失败
【发布时间】:2020-02-09 18:29:28
【问题描述】:

我在构建递归函数以正确沿网络传播时遇到问题。

问题:一个叫做单元格的对象数组,有一个函数:

whatIwant(wanted value, bucket array)

每次连接到最后“一代”单元时都会调用自己。

使用(3 代乘 2 顺序)+3 'answer'cells)单元对象计数,我应该得到 27 个递归调用?我的返回数组中有 107200 个项目 - 而不是 27 个。

IF i don't call Flat() in the code: the return array is in a weird recursive pattern:
(34) [{…}, {…}, {…}, {…}, Array(34), {…}, {…}, Array(34), {…}, {…}, Array(34), Array(34), {…}, {…}, {…}, Array(34), {…}, {…}, Array(34), {…}, {…}, Array(34), Array(34), {…}, {…}, {…}, Array(34), {…}, {…}, Array(34), {…}, {…}, Array(34), Array(34)]
where each array of 34 is yet another array of exactly this array.

我认为它应该如何工作如下:(我认为我写的) 大脑对象最后在每个“答案单元格”上调用 whatIWant(),它计算所需的所有调整,然后在它之前的每个层目标上,它调用 objects.whatIwant() 作为值输入——desiredObject。 activation[i] (此单元格将激活的值)和作为数组,对在此函数之外生成的数组的引用 - 开始为空,在所有 answerCell.whatIWant() 之后不断推送应用于脑细胞的 updateobjectcontainer由大脑调用,然后将这些数组相加/平均。

我脑海中的递归路径(使用 3gen:2order){cell.gen3,order0} 调用 {cell.gen2,order0},调用 {cell.gen1.order0} 调用 {cell.gen0. order0),返回到 {cell.gen1.order0},它调用 cell.gen0.order1},它返回到 {cell.gen1.order0},它返回 {cell.gen2.order0},它调用 {cell.gen1.order0 } 其中调用{cell.gen0.order0}。并且它一直持续到它多次遍历矩阵后回到顶部巢穴。

如果我不调用 flat,它会创建一个对象数组 希望有人能简单快速地告诉我为什么我是个白痴。

some quick helper function defs:

Flat() = returns an array that has been recursively flattened;
Sigmoid() maps all input to between 0-1;
ArrayMultiply() takes two arrays and multiplies against index return a number;
brain.cellArray is the bucket for all the cells;

//
//recusion logic
whatIwant:function(answerValue, returnArray)
            {
         //stuff here that calculates an 
         //objects value(represents the desired 
         //change to the real cell above this 
        //abstraction we combine/average duplicates
       //entries formed in this return array
            if(Array.isArray(cell.lastGenerationTargetKeys) && cell.lastGenerationTargetKeys.length)
                {
                cell.lastGenerationTargetKeys.forEach(x=> returnArray.push(brain.cellArray[x].whatIwant(desiredObjectChange.activations[x], returnArray))); 
                return Flat(returnArray);
            }
            else  
                {
                returnArray.push(desiredObjectChange);      
                return Flat(returnArray);
            }


为清晰起见进行编辑/更新。

【问题讨论】:

    标签: javascript arrays recursion tree backpropagation


    【解决方案1】:

    所以用更新鲜的眼光看它,正在发生的事情是:我正确地通过网络,但我没有正确处理数组。

    我正在将 returnArray 的引用推入自身,而数组中的项目是它所在的数组......糟糕的时候。

    更新后的代码是这样的:

    if(Array.isArray(cell.lastGenerationTargetKeys) && cell.lastGenerationTargetKeys.length)
    {               
        let nextActivation = desiredObjectChange.activations[Symbol.iterator]();
        cell.lastGenerationTargetKeys.forEach(x => brain.cellArray[x].whatIwant(nextActivation.next().value, returnArray)); 
        return returnArray;
    }
    else  
    {
        return;     
    }
    

    【讨论】:

    • 很高兴你找到了它。我没有很好地理解这个问题,但我什至没有合理的问题要求澄清。
    猜你喜欢
    • 2017-09-28
    • 2015-03-03
    • 2012-02-21
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-19
    相关资源
    最近更新 更多