public void MakeLearningProcess(int SpecimenCount, float mutChance, float selectPercent, bool overrideLearningProcess = false) { if (overrideLearningProcess || HiddenLayersSettings == null || NeuronTypesSettings == null) { neuronDefinitionsPanelScript.GetNeuronDefinitions(out HiddenLayersSettings, out NeuronTypesSettings); HiddenLayersSettings.Insert(0, 6); } PercentToSelect = selectPercent; MutationChance = mutChance; config.PercentToSelect = selectPercent; config.MutationChance = mutChance; config.SetParentChoosingMethod(parentChoosingMethod); config.RandOptions.Sigma = sigma; if (overrideLearningProcess || learningProcess == null) { learningProcess = new LearningProcess( SpecimenCount, config, HiddenLayersSettings, NeuronTypesSettings ); } else { Debug.Log("Istniał Learning Process"); //learningProcess.PopulationCount = Specimen.Length; } learningProcess.LearningAlgorithm.Config = config; }
public void ForceSaveInConfigurationMenu(bool overridePrevious) { float mut, sel; PopulationManagerScript popScript = PassValuesToPopulationManager(out mut, out sel); popScript.MakeLearningProcess(NumberOfCarsPanel.NumberOfCars, mut, sel, overridePrevious); if (overridePrevious) { process = null; } using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; switch (sfd.ShowDialog()) { case DialogResult.OK: Debug.Log(sfd.FileName); popScript.SaveLearningProcess(sfd.FileName); break; } } }
public void LoadLearningProcess() { PopulationManagerScript popScript = PopulationManagerObject.GetComponent <PopulationManagerScript>(); process = popScript.LoadLearningProcess(GetOpenFilePath()); if (process != null) { ParentChoosingDropdown.value = (int)process.LearningAlgorithm.Config.ParentMethod; ParentChoosingDropdown.RefreshShownValue(); MutationChanceInputField.text = process.LearningAlgorithm.Config.MutationChance.ToString(); SelectPercentInputField.text = process.LearningAlgorithm.Config.PercentToSelect.ToString(); SigmaInputField.text = process.LearningAlgorithm.Config.RandOptions.Sigma.ToString(); while (NumberOfCarsPanel.NumberOfCars > process.PopulationCount) { NumberOfCarsPanel.LessCars(); } while (NumberOfCarsPanel.NumberOfCars < process.PopulationCount) { NumberOfCarsPanel.MoreCars(); } } }
public void PreviousLearningProcess(LearningProcess process) { learningProcess = process; if (process != null) { foreach (ProcessData data in process.HistoricalData) { UpdatePlots(data); } } //RestartedSimulation(process); }
public Classification() { GeneticAlgorithmConfig config = new GeneticAlgorithmConfig(); config.RandOptions = new RandomizerOptions(-1, 1, 0.2); config.PercentToSelect = 0.5; config.MutationChance = 0.2; config.SetParentChoosingMethod(ParentChoosingMethod.PositionLinear); process = new LearningProcess(populationCount, config, new List <int> { 2, 4, 2 }, new List <Type>() { typeof(TanHNeuron), typeof(StepNeuron) }); }
public Perceptron() { GeneticAlgorithmConfig config = new GeneticAlgorithmConfig(); config.RandOptions = new RandomizerOptions(-1, 1, 0.05); config.PercentToSelect = 0.4; config.MutationChance = 0.005; config.SetParentChoosingMethod(ParentChoosingMethod.Geom); process = new LearningProcess(populationCount, config, new List <int> { 3, 100, 2 }, new List <Type>() { typeof(IdentityNeuron), typeof(IdentityNeuron) }); }
public LearningProcess LoadLearningProcess(string path) { if (path == null || !File.Exists(path)) { return(null); } learningProcess = Serializator.Deserialize(path); if (learningProcess == null) { throw new Exception("Błąd deserializacji!!!"); } config = learningProcess.LearningAlgorithm.Config; parentChoosingMethod = config.ParentMethod; sigma = (float)config.RandOptions.Sigma; PercentToSelect = (float)config.PercentToSelect; MutationChance = (float)config.MutationChance; List <Type> neuronTypes = new List <Type>(); foreach (LayerBase <double> neuron in learningProcess.Population[0].Layers) { neuronTypes.Add(neuron.Neurons[0].GetType()); } Debug.Log(learningProcess.Population[0].Layers[0].Neurons[0]); neuronDefinitionsPanelScript. SetNeuronDefinitions( learningProcess.Population[0].LayersCount, neuronTypes ); //plot.PreviousLearningProcess(learningProcess); plot.RestartedSimulation(learningProcess); ProcessData[] histData = new ProcessData[learningProcess.HistoricalData.Count]; learningProcess.HistoricalData.CopyTo(histData); GenerationList.SetGenerationHistory(new List <ProcessData>(histData)); return(learningProcess); }
public LearningProcess GetLearningProcess() { var result = new LearningProcess() { BestIndex = 1, Generation = 2, HistoricalData = new List <ProcessData>() { GetProcessData() }, LearningAlgorithm = GetGeneticAlgorithm(), Population = new [] { GetNetwork() }, PopulationCount = 3 }; return(result); }
public void RestartedSimulation(LearningProcess process) { MaxY = 0; MinY = 0; foreach (Plot plot in PlotsArray) { plot.Clear(); } foreach (UILineRenderer uiLR in PlotLinesRenderersArray) { uiLR.m_points = null; uiLR.SetVerticesDirty(); } PreviousLearningProcess(process); }
public static LearningProcess Deserialize(string path) { if (string.IsNullOrEmpty(path)) { return(null); } try { LearningProcess result = null; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(path); string xmlString = xmlDocument.OuterXml; using (StringReader read = new StringReader(xmlString)) { XmlSerializer serializer = new XmlSerializer(typeof(LearningProcess)); using (XmlReader reader = new XmlTextReader(read)) { result = (LearningProcess)serializer.Deserialize(reader); reader.Close(); } read.Close(); } if (result != null) { result.LearningAlgorithm.Config.Reinitialize(); } return(result); } catch (Exception e) { Debug.WriteLine("There was an error while deserializing object: " + e.Message); } return(null); }
public static bool Serialize(this LearningProcess process, string path) { try { XmlDocument xmlDocument = new XmlDocument(); XmlSerializer serializer = new XmlSerializer(process.GetType()); using (MemoryStream stream = new MemoryStream()) { serializer.Serialize(stream, process); stream.Position = 0; xmlDocument.Load(stream); xmlDocument.Save(path); stream.Close(); } return(true); } catch (Exception e) { Debug.WriteLine("There was an error while serializing object: " + e.Message); } return(false); }
public void StopSimulation(bool stopForGood = false) { simulationStarted = false; if (!stopForGood) { double[] scores = new double[Specimen.Length]; for (int i = 0; i < Specimen.Length; i++) { scores[i] = (double)(Specimen[i].FinalScore()); } learningProcess.Learn(scores); int temp = learningProcess.HistoricalData.Count; ProcessData tmpData = learningProcess.HistoricalData[temp - 1]; if (OnRoundEnded != null) { OnRoundEnded(tmpData); } Debug.Log( "Generation " + tmpData.GenerationIndex + ", Avg: " + tmpData.AverageScore.ToString("n2") + ", Med: " + tmpData.MedianScore + ", Best: " + tmpData.BestScore + ", Worst: " + tmpData.WorstScore); } else { Specimen = null; learningProcess = null; GenerationList.ResetList(); plot.RestartedSimulation(null); OnRoundEnded(null); } }
public Load() { process = Serializator.Deserialize("leariningtest.xml"); }