public Trainer Clone() { Trainer New_Trainer = new Trainer(Setting.Instance().mapSize_Width, Setting.Instance().mapSize_Height, blocksize); New_Trainer.train_setting(); New_Trainer._Genetic = _Genetic.Clone(); return(New_Trainer); } // 사본생산
public void resetFrame() { warms = new Trainer(window_width, window_height, blocksize); warms.train_setting(); Graphics g = CreateGraphics(); FrameUpdate(); g.DrawImage(GDIBuffer.Instance().GetImages, new Point(0, 0)); g.Dispose(); }
public MainForm() { MainForm.mf = this; InitializeComponent(); this.SuspendLayout(); Setting.Instance(); warms = new Trainer(window_width, window_height, blocksize); warms.train_setting(); Load += new EventHandler(MainForm_Load); this.ResumeLayout(false); }
public static List <Trainer> repList(List <Trainer> worm, int Evennum) // 두개의 뉴런값을 섞 { List <Trainer> temp = new List <Trainer>(); // 우월한 유전자들 끼리 섞는 함수 Random r = MainForm.random; int 교배수 = Setting.Instance().교배횟수; for (int k = 0; k < Evennum / 2; k++) { Trainer child1 = new Trainer(Setting.Instance().mapSize_Width, Setting.Instance().mapSize_Height, Setting.Instance().블럭크기); child1.train_setting(); Trainer child2 = new Trainer(Setting.Instance().mapSize_Width, Setting.Instance().mapSize_Height, Setting.Instance().블럭크기); child2.train_setting(); child1._Genetic = worm[k % worm.Count]._Genetic.Clone(); // 부 유전자 child2._Genetic = worm[r.Next(0, worm.Count - 1)]._Genetic.Clone(); // 모 유전자 child1._Genetic.score = 1; child2._Genetic.score = 1; for (int i = 0; i < child1._Genetic.Middle_Neurons.Length; i++) { for (int j = 0; j < child1._Genetic.Middle_Neurons[i].Weighted_value.Length; j++) { if (r.Next(0, 100) < 40) { replaced(ref child1._Genetic.Middle_Neurons[i].Weighted_value[j], ref child2._Genetic.Middle_Neurons[i].Weighted_value[j], 교배수); } } // ref는 사용하기 전에 초기화 replaced(ref child1._Genetic.Middle_Neurons[i].Threshold_value, ref child2._Genetic.Middle_Neurons[i].Threshold_value, 교배수); } for (int i = 0; i < child1._Genetic.Output_Neurons.Length; i++) { for (int j = 0; j < child1._Genetic.Output_Neurons[i].Weighted_value.Length; j++) { if (r.Next(0, 100) < 40) { replaced(ref child1._Genetic.Output_Neurons[i].Weighted_value[j], ref child2._Genetic.Output_Neurons[i].Weighted_value[j], 교배수); } } replaced(ref child1._Genetic.Output_Neurons[i].Threshold_value, ref child2._Genetic.Output_Neurons[i].Threshold_value, 교배수); } temp.Add(child1.Clone()); temp.Add(child2.Clone()); } return(temp); }
public void ReplayStart(Gen[] GData) { FrameCount = 0; rotate = 0; _Generation = 0; trainers.Clear(); for (int i = 0; i < GData.Length; i++) { GData[i].score = 1; warms = new Trainer(window_width, window_height, blocksize); warms.train_setting(); } frameTimer.Enabled = true; }
public void TestStart() { FrameCount = 0; rotate = 0; _Generation = 0; trainers.Clear(); GDIBuffer.Instance(window_width, window_height); for (int i = 0; i < Setting.Instance().모집단; i++) { Trainer t = new Trainer(window_width, window_height, blocksize); t.train_setting(); trainers.Add(t); } frameTimer.Enabled = true; }
private void frameTimer_Tick(object sender, EventArgs e) { FrameCount++; bool endcheck = false; int start, end; if (Setting.Instance().테스트단위 > Setting.Instance().모집단) { start = 0; end = Setting.Instance().모집단; } else { if (rotate < Setting.Instance().모집단 / Setting.Instance().테스트단위) { start = rotate * Setting.Instance().테스트단위; end = Setting.Instance().테스트단위 + Setting.Instance().테스트단위 *rotate; } else { start = rotate * Setting.Instance().테스트단위; end = Setting.Instance().모집단 % Setting.Instance().테스트단위 + Setting.Instance().테스트단위 *rotate; } } for (int i = start; i < end; i++) { trainers[i].FrameUpdate(); } for (int i = start, k = 0; i < end; i++) { if (warms._Genetic.score <= trainers[i]._Genetic.score) { warms = trainers[i]; } if (trainers[i].dead == 1) // 부딪히는 함수 추가필요 { k++; } if (k == Setting.Instance().테스트단위 || k == Setting.Instance().모집단) { endcheck = true; } } if (endcheck) // boolean = true -> 끝값이 수신되면 { rotate = (rotate + 1); FrameCount = 0; warms = new Trainer(window_width, window_height, blocksize); warms.train_setting(); } if (rotate == (Setting.Instance().모집단 / Setting.Instance().테스트단위)) { rotate = 0; // rotate 초기화 trainers.Sort((Trainer x, Trainer y) => y._Genetic.score.CompareTo(x._Genetic.score)); //내림차순 정렬 try { if (_Generation % Setting.Instance().저장간격 == 0) { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(Setting.Instance().저장위치 + @"\BestGeneration[" + _Generation + "].bin", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, Setting.Instance()); for (int i = 0; i < Setting.Instance().저장개체수; i++) { formatter.Serialize(stream, trainers[i]._Genetic); } stream.Close(); } using (StreamWriter w = File.AppendText(Setting.Instance().저장위치 + @"\BestGeneration.txt")) { //w.Write(log); } } catch (Exception ee) { using (StreamWriter w = File.AppendText("BestGeneration.txt")) { // w.Write(log); } } trainers = Generic.check(trainers, Setting.Instance().모집단); // 확률분포리스트를 뽑음 trainers = Generic.repList(trainers, Setting.Instance().모집단); // 교배 및 돌연변이 warms._Genetic.score = 1; // 점수 초기화 _Generation++; // 세대 +1 } FrameUpdate(); FrameRender(); }