亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java XOR 神經網絡未正確訓練

Java XOR 神經網絡未正確訓練

慕哥6287543 2022-07-06 16:01:23
我有一個具有 2 個輸入、2 個隱藏神經元和 1 個輸出神經元的神經網絡來解決這個xor問題。0.1我隨機初始化 0 到 1 之間的權重,我使用帶有sigmoid激活函數的學習率。當我只訓練一個選項時,例如目標為 1 的 1 和 0,它可以正常工作并給出適當的猜測。但是,當我嘗試將所有可能的輸入一起訓練時,輸出會收斂到0.5-0.6.我嘗試過改變學習率、隨機初始化權重的范圍以及網絡訓練的次數,但這對最終輸出沒有影響。這是我在GitHub 上的代碼的鏈接。關于如何解決此問題的任何想法?
查看完整描述

1 回答

?
守著星空守著你

TA貢獻1799條經驗 獲得超8個贊

我懷疑反向傳播沒有正確實施。例如http://users.pja.edu.pl/~msyd/wyk-nai/multiLayerNN-en.pdf在第 17 至 20 頁中給出了概述。


- 類的tuneWeigths- 和delta_weights- 方法Output_Neuron被正確實現。但是,在此步驟weightDeltaHidden中,必須確定稍后Hidden_Neuron調整 -class 的權重時需要的數組(參見代碼中的注釋)。


- 類的tuneWeigths- 和delta_weights- 方法Hidden_Neuron似乎沒有正確實現。在這里,除其他外,weightDeltaHidden必須使用先前確定的數組。


在下面的代碼中,我進行了必要的更改,但實際上并未更改代碼的設計。但也許重構是有意義的。


類的變化Output_Neuron:


...


private double[] weightedDeltaHidden;


...


Output_Neuron(int hiddenNeurons) {


    ...


    this.weightedDeltaHidden = new double[hiddenNeurons];

}


...


void tuneWeights(double LR, double[] hidden_output, int target) {

    double delta = (target - output) * f.dSigmoid(output);

    for (int i = 0; i < weights.length; i++) {

        weights[i] += delta_weights(i, LR, delta, hidden_output);

    }

}


double delta_weights(int i, double LR, double delta, double[] hidden_output) {

    weightedDeltaHidden[i] = delta * weights[i]; // weightedDeltaHidden is the product of delta of this output neuron and the weight of the i-th hidden neuron.

                                                 // That value is needed when the weights of the hidden neurons are tuned...

    return LR * delta * hidden_output[i];

}


...


double[] getWeightedDeltaHidden() {

    return weightedDeltaHidden;

}

類的變化Hidden_Neuron:


...


void tuneWeights(double LR, int[] inputs, double weightedDeltaHiddenTotal) {

    for (int i = 0; i < weights.length; i++) {

        weights[i] += delta_weights(LR, inputs[i], weightedDeltaHiddenTotal);

    }

}


private double delta_weights(double LR, double input, double weightedDeltaHiddenTotal) {

    double deltaOutput = f.dSigmoid(output) * weightedDeltaHiddenTotal;

    return LR * deltaOutput * input;

}


...

調整隱藏權重Network的 - 方法內- 類的變化:train


void train(int[] inputs, int target) {


    ...


    //tune Hidden weights

    for (int i = 0; i < numOfHiddenNeurons; i++) {

        double weightedDeltaHiddenTotal = 0;

        for (int j = 0; j < numOfOutputNeurons; j++) {

            weightedDeltaHiddenTotal += output_neurons[j].getWeightedDeltaHidden()[i]; // weightedDeltaHiddenTotal is the sum of the weightedDeltaHidden over all output neurons. Each weightedDeltaHidden

        }                                                                              // is the product of delta of the j-th output neuron and the weight of the i-th hidden neuron.

        hidden_neurons[i].tuneWeights(LR, inputs, weightedDeltaHiddenTotal);

    }

}

通過這些更改,1_000_000 次調用train(2 個隱藏神經元)的典型輸出為


Error: 1.9212e-01 in cycle 0

Error: 8.9284e-03 in cycle 100000

Error: 1.5049e-03 in cycle 200000

Error: 4.7214e-03 in cycle 300000

Error: 4.4727e-03 in cycle 400000

Error: 2.1179e-03 in cycle 500000

Error: 2.9165e-04 in cycle 600000

Error: 2.0655e-03 in cycle 700000

Error: 1.5381e-03 in cycle 800000

Error: 1.0440e-03 in cycle 900000

0 0: 0.0170

1 0: 0.9616

0 1: 0.9612

1 1: 0.0597

以及 100_000_000 次調用train(2 個隱藏神經元)


Error: 2.4755e-01 in cycle 0

Error: 2.7771e-04 in cycle 5000000

Error: 6.8378e-06 in cycle 10000000

Error: 5.4317e-05 in cycle 15000000

Error: 6.8956e-05 in cycle 20000000

Error: 2.1072e-06 in cycle 25000000

Error: 2.6281e-05 in cycle 30000000

Error: 2.1630e-05 in cycle 35000000

Error: 1.1546e-06 in cycle 40000000

Error: 1.7690e-05 in cycle 45000000

Error: 8.6837e-07 in cycle 50000000

Error: 1.3603e-05 in cycle 55000000

Error: 1.2905e-05 in cycle 60000000

Error: 2.1657e-05 in cycle 65000000

Error: 1.1594e-05 in cycle 70000000

Error: 1.9191e-05 in cycle 75000000

Error: 1.7273e-05 in cycle 80000000

Error: 9.1364e-06 in cycle 85000000

Error: 1.5221e-05 in cycle 90000000

Error: 1.4501e-05 in cycle 95000000

0 0: 0.0008

1 0: 0.9961

0 1: 0.9961

1 1: 0.0053

隱藏神經元的增加會提高性能。下面顯示了 1_000_000 次調用train(4 個隱藏神經元)的典型輸出:


Error: 1.2617e-02 in cycle 0

Error: 7.9950e-04 in cycle 100000

Error: 4.2567e-04 in cycle 200000

Error: 1.7279e-04 in cycle 300000

Error: 1.2246e-04 in cycle 400000

Error: 1.0456e-04 in cycle 500000

Error: 6.9140e-05 in cycle 600000

Error: 6.8698e-05 in cycle 700000

Error: 5.1640e-05 in cycle 800000

Error: 4.4534e-05 in cycle 900000

0 0: 0.0092

1 0: 0.9905

0 1: 0.9912

1 1: 0.0089


查看完整回答
反對 回復 2022-07-06
  • 1 回答
  • 0 關注
  • 88 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號