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

时间:2016-12-07 18:54:49

标签: c# machine-learning

我在使用Accord.NET中的不同深度学习算法。我决定用我躺着的光谱数据来做这件事。我使用Accord的统计工具箱对PCA进行数据转换,使其减少到10个数据点。然后按照教程写信:

// 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);
            }
        }

我检查了输入的数据,并且输入和输出都是正确的double [] []格式。我还检查了原始应用:https://github.com/primaryobjects/deep-learning 这很有效,所以我很难看到简单地改变输入的数据是如何搞乱的。任何帮助将不胜感激。我得到的错误是:

An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Accord.Neuro.dll

其他信息:索引超出了数组的范围。

1 个答案:

答案 0 :(得分:2)

当然,在发布这个问题之后,我立即意识到我的网络必须反映输出的数量,并且设置为10.我很抱歉打扰这个梦幻般的社区。