2017-03-14 55 views
1

我正在使用Neataptic來訓練一個神經網絡,解決與遺傳算法異或。健身定義如下:避免本地optima訓練XOR

// max score = 0 
score -= Math.abs(0 - network.activate([0, 0])) * 5000; 
score -= Math.abs(1 - network.activate([1, 0])) * 5000; 
score -= Math.abs(1 - network.activate([0, 1])) * 5000; 
score -= Math.abs(0 - network.activate([1, 1])) * 5000; 

有時它運行得很好。但我假設它只是幸運的。但很多時候,它甚至不會達到-6000。它將大約掛起-8000

這是我的設置:

GNN = new Evolution({ 
    size: 100, 
    elitism: 10, 
    mutationRate: 0.3, 
    networkSize : [2,3,1], 
    mutationMethod: [ 
     Methods.Mutate.MODIFY_RANDOM_BIAS, 
     Methods.Mutate.MODIFY_RANDOM_WEIGHT, 
     Methods.Mutate.SWAP_BIAS, 
     Methods.Mutate.SWAP_WEIGHT, 
     Methods.Mutate.MODIFY_SQUASH 
    ], 
    crossOverMethod: [ 
     Methods.Crossover.UNIFORM, 
     Methods.Crossover.AVERAGE, 
     Methods.Crossover.SINGLE_POINT, 
     Methods.Crossover.TWO_POINT 
    ], 
    selectionMethod: [ 
     Methods.Selection.FITNESS_PROPORTIONATE 
    ], 
    generationMethod: [ 
     Methods.Generation.POINTS 
    ], 
    fitnessFunction: function(network){ 
     var score = 0; 

     score -= Math.abs(0 - network.activate([0, 0])) * 5000; 
     score -= Math.abs(1 - network.activate([1, 0])) * 5000; 
     score -= Math.abs(1 - network.activate([0, 1])) * 5000; 
     score -= Math.abs(0 - network.activate([1, 1])) * 5000; 

     return Math.round(score); 
    } 
    }); 

(view the JSFiddle here and press train)

你告訴我什麼設置改變? (請提供證明)

P.S.我知道通過反向傳播訓練XOR要容易得多,但這僅僅是爲了實驗目的。

+0

我在過去做這個任務。 GA找到「很好的解決方案」。那麼,如何使用網絡拓撲? – viceriel

+0

我已經改善了它https://wagenaartje.github.io/gynaptic/examples/xor/ –

+0

我不明白爲什麼平均健康狀況會比前一代更糟。你是否使用了一些超大規模的早熟融合限制? – viceriel

回答

1

我改變:

fitnessFunction: function(network){ 
    var score = 0; 

    score -= Math.abs(0 - network.activate([0, 0])) * 5000; 
    score -= Math.abs(1 - network.activate([1, 0])) * 5000; 
    score -= Math.abs(1 - network.activate([0, 1])) * 5000; 
    score -= Math.abs(0 - network.activate([1, 1])) * 5000; 

    return Math.round(score); 
} 

fitnessFunction: function(network){ 
    var score = 0; 

    score -= Methods.Cost.MSE([0], network.activate([0, 0])) * 5000; 
    score -= Methods.Cost.MSE([1], network.activate([1, 0])) * 5000; 
    score -= Methods.Cost.MSE([1], network.activate([0, 1])) * 5000; 
    score -= Methods.Cost.MSE([0], network.activate([1, 1])) * 5000; 

    return Math.round(score); 
} 

在邏輯上,作爲平方誤差有助於增加機會的輸出是完全錯誤的改變。 Read about it here