首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在使用Accord.NET运行BackPropagation时会出现OutofRangeException?

为什么在使用Accord.NET运行BackPropagation时会出现OutofRangeException?
EN

Stack Overflow用户
提问于 2016-12-08 02:54:49
回答 1查看 455关注 0票数 2

我正在处理Accord.NET中不同的深度学习算法,我决定用我随处可见的光谱数据来做这件事。我使用Accord的统计工具箱对数据进行PCA变换,以便将其减少到10个数据点。然后严格按照教程进行操作:

代码语言:javascript
复制
// Setup the deep belief network and initialize with random weights.
        DeepBeliefNetwork network = new DeepBeliefNetwork(transformedInputs.First().Length, 10, 10);
        new GaussianWeights(network, 0.1).Randomize();
        network.UpdateVisibleWeights();

        // Setup the learning algorithm.
        DeepBeliefNetworkLearning teacher = new DeepBeliefNetworkLearning(network)
        {
            Algorithm = (h, v, i) => new ContrastiveDivergenceLearning(h, v)
            {
                LearningRate = 0.1,
                Momentum = 0.5,
                Decay = 0.001,
            }
        };

        // Setup batches of input for learning.
        int batchCount = Math.Max(1, transformedInputs.Length / 100);
        // Create mini-batches to speed learning.
        int[] groups = Accord.Statistics.Tools.RandomGroups(transformedInputs.Length, batchCount);
        double[][][] batches = transformedInputs.Subgroups(groups);
        // Learning data for the specified layer.
        double[][][] layerData;

        // Unsupervised learning on each hidden layer, except for the output layer.
        for (int layerIndex = 0; layerIndex < network.Machines.Count - 1; layerIndex++)
        {
            teacher.LayerIndex = layerIndex;
            layerData = teacher.GetLayerInput(batches);
            for (int i = 0; i < 200; i++)
            {
                double error = teacher.RunEpoch(layerData) / transformedInputs.Length;
                if (i % 10 == 0)
                {
                    Console.WriteLine(i + ", Error = " + error);
                }
            }
        }

        // Supervised learning on entire network, to provide output classification.
        var teacher2 = new BackPropagationLearning(network)
        {
            LearningRate = 0.1,
            Momentum = 0.5
        };


        // Run supervised learning.
        for (int i = 0; i < 500; i++)
        {
            double error = teacher2.RunEpoch(transformedInputs, output: outputs);
            if (i % 10 == 0)
            {
                Console.WriteLine(i + ", Error = " + error);
            }
        }

我检查了输入的数据,无论是输入还是输出,都是正确的双格式。我还检查了最初的应用程序:https://github.com/primaryobjects/deep-learning,它工作得很好,所以我很难弄清楚,是什么简单地改变了输入的数据,把事情搞得这么乱。任何帮助都将不胜感激。我得到的错误是:

代码语言:javascript
复制
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Accord.Neuro.dll

附加信息:索引超出了数组的界限。

EN

回答 1

Stack Overflow用户

发布于 2016-12-08 03:02:28

当然,在发布了这个问题后,我立即意识到我的网络必须反映输出的数量,并将其设置为10。我非常抱歉打扰了这个神奇的社区。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41025186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档