private void button1_Click(object sender, EventArgs e) { Settings settings = new Settings(); if (mlp == null) { mlp = new Network.MLP(settings); } else { mlp.Epoch = 0; // trong trường hợp đã có mạng sẵn và nạp lại từ file FileSave.data -- mục đích để cho huấn luyện tiếp nếu Sai số của mạng chưa nhỏ hơn sai số cho phép //mlp.CreateNew_errorEachEpoch_errorOnValidation(); //private List<double> _errorEachEpoch; //private List<double> _errorOnValidation; // còn 2 cái này thì tôi thấy nên cho khởi tạo lại (new List) -- do khi đọc từ file thì _errorEachEpoch _errorOnValidation đc nạp lại => xóa đi để lưu lại cái mới khi cho huấn luyện tiếp } s = new Stopwatch(); Thread thr = new Thread(new ThreadStart(MLPExecute)); thr.IsBackground = true; thr.Start(); System.Windows.Forms.Timer tm = new System.Windows.Forms.Timer(); tm.Interval = 10; tm.Tick += (o, ev) => { UpdateUI(mlp.Error, mlp.Epoch,0/*mlp.ValidationError*/); }; tm.Start(); }
public fTraining() { InitializeComponent(); try { settings = new Settings(); } catch (Exception e) { string s = e.Message; } LoadSettings(); }
public MLP(Settings Configuration) { this.settings = Configuration; layers = new List<Layer>(); try { this.EpochToStop = (int)Configuration["EpochToStop"]; this.ErrorToStop = (double)Configuration["ErrorToStop"]; this.Momentum = (double)Configuration["Momentum"]; this.LerningRateDownStep = (double)Configuration["LearningRateDownStep"]; this.LerningRateUpStep = (double)Configuration["LearningRateUpStep"]; this.ErrorThresholdPercent = (int)Configuration["ErrorThresholdPercent"]; this.EpochPreventOverfitting = (int)Configuration["EpochPreventOverfitting"]; ITransferFunction tranferFunc = (ITransferFunction)Assembly. GetExecutingAssembly().CreateInstance("MLP.Network.TransferFunctions." + Configuration["TransferFunction"]); int NumberOfLayers = (int)Configuration["NumberOfLayers"]; for (int i = 1; i <= NumberOfLayers; i++) { int NumberOfNeurons = (int)Configuration["NeuronsOfLayer[" + i + "]"]; Layer l = new Layer(NumberOfNeurons, tranferFunc); this.layers.Add(l); } for (int i = 0; i < NumberOfLayers - 1; i++) { layers[i].SetRightAdjacentLayer(layers[i + 1]); } Eta = (double)Configuration["LearningRate"];//1.0E-3; //1.0x10^-3 } catch (Exception e) { throw e; } _errorEachEpoch = new List<double>(); _errorOnValidation = new List<double>(); }
private void fSettings_Load(object sender, EventArgs e) { setting = new Settings(); List<string> fucn = Settings.getAllTranferFunctions(); foreach (string f in fucn) { cboxTransferFunction.Items.Add(f); } udLayers.Value = (int)setting["NumberOfLayers"]; txtLearningRate.Text = setting["LearningRate"].ToString(); txtEpochToStop.Text = setting["EpochToStop"] + ""; txtMomentum.Text = setting["Momentum"] + ""; txtErrorToStop.Text = setting["ErrorToStop"] + ""; txtLearningRate.Text = setting["LearningRate"] + ""; txtLearningRateDownStep.Text = setting["LearningRateDownStep"] + ""; txtLearningRateUpStep.Text = setting["LearningRateUpStep"] + ""; txtErrorThresholdPercent.Text = setting["ErrorThresholdPercent"] + ""; cboxTransferFunction.SelectedIndex = cboxTransferFunction.Items.IndexOf(setting["TransferFunction"]); for (int i = 0; i < udLayers.Value; i++) { lstUdLayer[i].Value = (int)setting["NeuronsOfLayer[" + (i+1) + "]"]; } }
public void Save() { String temp = ""; Settings oldsetting = new Settings(); StreamReader config = new StreamReader("Config.ini", Encoding.ASCII); temp = config.ReadToEnd(); config.Close(); // Xóa tất cả về số nơ ron của lớp để nạp lại temp = temp.Remove(temp.IndexOf("NeuronsOfLayer[")); temp = temp.Replace("NumberOfLayers=" + oldsetting["NumberOfLayers"], "NumberOfLayers=" + ConfigData["NumberOfLayers"]); temp = temp.Replace("LearningRate=" + oldsetting["LearningRate"], "LearningRate=" + ConfigData["LearningRate"]); temp = temp.Replace("Momentum=" + oldsetting["Momentum"], "Momentum=" + ConfigData["Momentum"]); temp = temp.Replace("EpochToStop=" + oldsetting["EpochToStop"], "EpochToStop=" + ConfigData["EpochToStop"]); temp = temp.Replace("ErrorToStop=" + oldsetting["ErrorToStop"], "ErrorToStop=" + ConfigData["ErrorToStop"]); temp = temp.Replace("ErrorThresholdPercent=" + oldsetting["ErrorThresholdPercent"], "ErrorThresholdPercent=" + ConfigData["ErrorThresholdPercent"]); temp = temp.Replace("LearningRateUpStep=" + oldsetting["LearningRateUpStep"], "LearningRateUpStep=" + ConfigData["LearningRateUpStep"]); temp = temp.Replace("LearningRateDownStep=" + oldsetting["LearningRateDownStep"], "LearningRateDownStep=" + ConfigData["LearningRateDownStep"]); temp = temp.Replace("TransferFunction=" + oldsetting["TransferFunction"], "TransferFunction=" + ConfigData["TransferFunction"]); // nạp lại nơ ron của lớp foreach (string key in ConfigData.Keys) { if (key.Contains("NeuronsOfLayer[")) temp += key + "=" + ConfigData[key] + Environment.NewLine; } StreamWriter writer = new StreamWriter("Config.ini", false, Encoding.ASCII); writer.Write(temp); writer.Close(); }