如何为 Encog 规范化 csv 输出列?
How to just normalize csv ouput coloumn for Encog?
鉴于此 CSV (GoogleSheets)。我想保持数值不变。我怎样才能真正利用这些数据来训练我的前馈网络?
// 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:
"The machine learning method has an input length of 5, but the training data has 0. They must be the same."
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;
}
尝试如下操作。重点是Backward Propagation的数据必须拆分为input和ideal
// 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);
我刚刚将输出列拆分为三个新列 (GoogleSheets)。我所要做的就是像这样加载 CSV:
var trainingSet = EncogUtility.LoadCSV2Memory("trainingData.csv", neuralNet.InputCount, neuralNet.OutputCount, true, CSVFormat.English, false);
鉴于此 CSV (GoogleSheets)。我想保持数值不变。我怎样才能真正利用这些数据来训练我的前馈网络?
// 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: "The machine learning method has an input length of 5, but the training data has 0. They must be the same."
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;
}
尝试如下操作。重点是Backward Propagation的数据必须拆分为input和ideal
// 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);
我刚刚将输出列拆分为三个新列 (GoogleSheets)。我所要做的就是像这样加载 CSV:
var trainingSet = EncogUtility.LoadCSV2Memory("trainingData.csv", neuralNet.InputCount, neuralNet.OutputCount, true, CSVFormat.English, false);