2016-06-12 45 views
1

鑑於此CSV(GoogleSheets)。我想保留數值不變。我怎樣才能真正利用這些數據來訓練我的前饋網絡?如何將Encv的csv輸出顏色正常化?

// Load and prepare training data 
var dataSource = new CSVDataSource("trainingData.csv", true, CSVFormat.DecimalPoint); 
var data = new VersatileMLDataSet(dataSource); 
ColumnDefinition outputColumn = data.DefineSourceColumn("Action", ColumnType.Nominal); 
data.DefineSingleOutputOthersInput(outputColumn); 
data.Analyze(); 

// Build neural net 
var neuralNet = BuildNeuralNet(); 

// Train neural net 
var train = new Backpropagation(neuralNet, data); 
int epoch = 1; 

do 
{ 
train.Iteration(); 
Console.WriteLine(@"Epoch #" + epoch + @" Error : " + train.Error); 
epoch++; 
} while (train.Error > errorThreshold); 

這就是EncogError執行過程中出現了: 「機器學習方法具有5輸入長度,但訓練數據爲0。他們必須是相同的。」

private static BasicNetwork BuildNeuralNet() 
{ 
     var net = new BasicNetwork(); 
     net.AddLayer(new BasicLayer(null, true, m_inputNodeCount)); // input layer 
     net.AddLayer(new BasicLayer(new ActivationSigmoid(), true, m_hiddenNodeCount)); // #1 hidden layer 
     net.AddLayer(new BasicLayer(new ActivationSigmoid(), false, m_outputNodeCount)); // output layer 
     net.Structure.FinalizeStructure(); 
     net.Reset(); // initializes the weights of the neural net 
     return net; 
} 
+0

BuildNeuralNet()的內容是什麼? – 2016-06-12 14:49:51

+0

這只是初始化BasicNetwork,添加圖層,完成結構和重新設置權重。輸入節點數指定爲5。 – MarcoMeter

回答

0

我只是把標準輸出列成三個新的(GoogleSheets)。而我所要做的就是像這樣加載CSV:

var trainingSet = EncogUtility.LoadCSV2Memory("trainingData.csv", neuralNet.InputCount, neuralNet.OutputCount, true, CSVFormat.English, false); 
0

嘗試如下所示。主要的一點是,向後傳播的數據必須被分爲輸入和理想

// Load and prepare training data 
    var dataSource = new CSVDataSource(@"C:\dev\SO\learning\encog\SO-Test\trainingData.csv", true, CSVFormat.DecimalPoint); 
    var data = new VersatileMLDataSet(dataSource); 
    data.DefineSourceColumn("EnemyHitPoints", ColumnType.Continuous); 
    data.DefineSourceColumn("EnemyCount", ColumnType.Continuous); 
    data.DefineSourceColumn("FriendlySquadHitPoints", ColumnType.Continuous); 
    data.DefineSourceColumn("FriendlySquadCount", ColumnType.Continuous); 
    data.DefineSourceColumn("LocalHitPoints", ColumnType.Continuous); 
    //EnemyHitPoints,EnemyCount,FriendlySquadHitPoints,FriendlySquadCount,LocalHitPoints,Action 
    ColumnDefinition outputColumn = data.DefineSourceColumn("Action", ColumnType.Nominal); 
    data.DefineSingleOutputOthersInput(outputColumn); 
    data.Analyze(); 

    EncogModel model = new EncogModel(data); 
    model.SelectMethod(data, MLMethodFactory.TypeNEAT); 

    // Now normalize the data. Encog will automatically determine the 
    // correct normalization 
    // type based on the model you chose in the last step. 
    data.Normalize(); 
    model.SelectTrainingType(data); 

    // Build neural net 
    var neuralNet = BuildNeuralNet(); 


    var datainput = data.Select(x => new double[5] { x.Input[0], x.Input[1], x.Input[2], 
    x.Input[3], x.Input[4] }).ToArray(); 
    var dataideal = data.Select(x => new double[1] { x.Ideal[0] }).ToArray(); 

     IMLDataSet trainingData = new BasicMLDataSet(datainput, dataideal); 
     var train = new Backpropagation(neuralNet, trainingData); 
     int epoch = 1; 

     do 
     { 
      train.Iteration(); 
      Console.WriteLine(@"Epoch #" + epoch + @" Error : " + train.Error); 
      epoch++; 
     } while (train.Error > errorThreshold);