static void Main(string[] args) { string[] lines = { "First line", "Second line", "Third line" }; System.IO.File.WriteAllLines(@"C:\Users\anxel\Downloads\NeuralNetwork\NeuralNetwork\WriteLines.txt", lines); // Training Data XmlDocument doc = new XmlDocument(); doc.Load(@"C:\Users\anxel\Downloads\NeuralNetwork\NeuralNetwork\simpleData.xml"); DataSet ds = new DataSet(); ds.Load((XmlElement)doc.DocumentElement.ChildNodes[0]); // Network to train int[] layerSizes = new int[3] { 25, 35, 4 }; TransferFunction[] tFuncs = new TransferFunction[3] { TransferFunction.None, TransferFunction.Sigmoid, TransferFunction.Linear }; BackPropagationNetwork bpn = new BackPropagationNetwork(layerSizes, tFuncs); // Network trainer! NetworkTrainer nt = new NetworkTrainer(bpn, ds); nt.maxError = 0.001; nt.maxIterations = 100000; nt.nudge_window = 500; // Train Console.WriteLine("Training..."); nt.TrainDataSet(); Console.WriteLine("Done!"); // Save the network nt.network.Save(@"C:\Users\anxel\Downloads\NeuralNetwork\NeuralNetwork\simpleData.xml"); // Save the error history double[] error = nt.GetErrorHistory(); string[] filedata = new string[error.Length]; for (int i = 0; i < error.Length; i++) { filedata[i] = i.ToString() + " " + error[i].ToString(); } File.WriteAllLines(@"C:\Users\anxel\Downloads\NeuralNetwork\NeuralNetwork\simple_errors.txt", filedata); // End of program Console.WriteLine("\n\nPress Enter..."); Console.ReadLine(); }
public async Task TrainNetworkAsync() { int[] layerSize = CreateLayersSize(); TransferFunction[] tfunc = AddTransferFunctionToLayers(); BackPropagationNetwork bpn = null; NetworkTrainer nt; if (bpn == null) { bpn = new BackPropagationNetwork(layerSize, tfunc); } await FixInputs(); nt = new NetworkTrainer(bpn, _dataSet); Task.Run(() => { nt.MaxError = MaxError; nt.MaxIterations = MaxIterations; nt.NudgeWindow = NudgeWindow; nt.TrainDataSet(); nt.Network.Save(@"tezine.xml"); double[] error = nt.GetErrorHistory(); string[] filedata = new string[error.Length]; for (int i = 0; i < error.Length; i++) { filedata[i] = i.ToString() + " " + error[i].ToString(); } File.WriteAllLines(@"greske.txt", filedata); NetworkTrained?.Invoke(this, "Završeno treniranje."); }); dynamic settings = SetSettingsForProgressReportPopup(); TrainingNetworkReport.Status = "Treniranje mreže..."; TrainingNetworkReport.Progress = 0; TrainingNetworkReport.MaxIterations = MaxIterations; TrainingNetworkReport.Error = 0; WindowManager window = new WindowManager(); window.ShowDialog(new TrainingNetworkProgresBarViewModel(ref _trainingNetworkReport, settings, this, nt)); }