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

标签 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);
            }
        }

我检查了输入的数据,输入和输出的双[][]格式都是正确的。我还检查了原始应用程序:https://github.com/primaryobjects/deep-learning 这非常有效,所以我很难理解仅仅改变输入数据就会造成如此大的困惑。任何帮助将不胜感激。我收到的错误是:

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

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

最佳答案

当然,在发布这个问题后,我立即意识到我的网络必须反射(reflect)输出的数量,并且设置为 10。对于打扰这个出色的社区,我感到非常抱歉。

关于c# - 为什么在使用 Accord.NET 运行 BackPropagation 时出现 OutofRangeException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41025186/

相关文章:

c# - ThreadPool SetMinThreads - 设置它的影响

c# - 错误 : The type 'System.Data.OleDb.OleDbDataReader' has no constructors defined

C#.net 从控制台使用 HTMLDocument?

c# - 如何让 XMLSerializer 将 namespace 添加到嵌套对象中的属性?

tensorflow - 使用新类别重新训练模型

c# - 从 JSON 字符串中提取值 c#

python - 得分为 ='roc_auc' 的 cross_val_score 和 roc_auc_score 有什么区别?

python - 使用Sklearn加载本地文件,尝试显示任何图像返回空

python - sklearn MultinomialNB 仅预测类先验

python - 连续训练 Keras 与单次迭代