private void RemoveExistingExperiment() { if (_ea != null) { //_ea.Stop(); _ea.Dispose(); } if (_experiment != null) { //_experiment. } _experiment = null; _ea = null; _experimentArgs = null; _hyperneatArgs = null; _harness = null; _harnessArgs = null; _evalArgs = null; _winningBrain = null; }
public AntPos_Evaluator(HarnessArgs harnessArgs, EvaluatorArgs evalArgs) { lock (_lock) { _harnessArgs = harnessArgs; } _evalArgs = evalArgs; }
public void ChangedResolution(int inputSizeXY, int outputSizeXY) { lock (_lock) { _harnessArgs = new HarnessArgs( _harnessArgs.MapSize, _harnessArgs.VisionSize, _harnessArgs.OutputSize, inputSizeXY, outputSizeXY, _harnessArgs.DelayBetweenInstances); } }
public TrackedItemHarness(HarnessArgs args) : this(args.MapSize, args.VisionSize, args.OutputSize, args.InputSizeXY, args.OutputSizeXY, args.DelayBetweenInstances) { }
private void Reset2_Click(object sender, RoutedEventArgs e) { try { // If not hyperneat, just replace with a new net // If hyperneat, compare other args and retain genomes if the only change is input/output resolution string prevGenomeXML = null; if (chkHyperNEAT.IsChecked.Value && _experiment != null && _ea != null) { //_ea.Stop(); // currently, Stop just calls RequestPause, so don't use it. There needs to be a dispose that removes the underlying thread _ea.RequestPauseAndWait(); prevGenomeXML = ExperimentNEATBase.SavePopulation(_ea.GenomeList); } RemoveExistingExperiment(); // My stuff #region harness args _harnessArgs = new HarnessArgs( trkMapSize.Value, trkVisionSize.Value, trkOutputSize.Value, trkInputPixels.Value.ToInt_Round(), trkOutputPixels.Value.ToInt_Round(), trkDelayBetweenInstances.Value); #endregion #region eval args if (chkRandomStartingConditions.IsChecked.Value) { _evalArgs = new EvaluatorArgs( trkEvalIterations.Value.ToInt_Round(), trkDelay.Value, trkEvalElapsedTime.Value, trkMaxSpeed.Value, chkBounceOffWalls.IsChecked.Value, new[] { (TrackedItemType)cboTrackedItemType.SelectedValue }, trkNewItemDuration.Value, trkNewItemErrorMultiplier.Value, (ScoreLeftRightBias)cboErrorBias.SelectedValue); } else { Point position = Math3D.GetRandomVector(_harnessArgs.MapSize / 2).ToPoint2D(); Vector velocity = Math3D.GetRandomVector_Circular(trkMaxSpeed.Value).ToVector2D(); // Don't let the velocity be in the same quadrant as the position (otherwise, you could have something spawn next to a wall, heading // toward the wall). These if statements force it to cross the x,y axiis if (Math.Sign(position.X) == Math.Sign(velocity.X)) { velocity = new Vector(-velocity.X, velocity.Y); } if (Math.Sign(position.Y) == Math.Sign(velocity.Y)) { velocity = new Vector(velocity.X, -velocity.Y); } _evalArgs = new EvaluatorArgs( trkEvalIterations.Value.ToInt_Round(), trkDelay.Value, trkEvalElapsedTime.Value, new[] { Tuple.Create((TrackedItemType)cboTrackedItemType.SelectedValue, position, velocity, chkBounceOffWalls.IsChecked.Value) }, trkNewItemDuration.Value, trkNewItemErrorMultiplier.Value, (ScoreLeftRightBias)cboErrorBias.SelectedValue); } #endregion // SharpNEAT #region experiment args _experimentArgs = new ExperimentInitArgs() { Description = "Input is a pixel array. Output is a pixel array. The NN needs to watch the object and anticipate where it will be at some fixed time in the future", InputCount = _harnessArgs.InputSizeXY * _harnessArgs.InputSizeXY, OutputCount = _harnessArgs.OutputSizeXY * _harnessArgs.OutputSizeXY, IsHyperNEAT = chkHyperNEAT.IsChecked.Value, PopulationSize = trkPopulationSize.Value.ToInt_Round(), SpeciesCount = trkSpeciesCount.Value.ToInt_Round(), Activation = new ExperimentInitArgs_Activation_CyclicFixedTimesteps() { TimestepsPerActivation = trkTimestepsPerActivation.Value.ToInt_Round(), FastFlag = true }, Complexity_RegulationStrategy = ComplexityCeilingType.Absolute, Complexity_Threshold = trkComplexityThreshold.Value.ToInt_Round(), }; #endregion #region hyperneat args _hyperneatArgs = null; if (chkHyperNEAT.IsChecked.Value) { // Use two square sheets var hyperPoints = HyperNEAT_Args.GetSquareSheets(trkVisionSize.Value, trkOutputSize.Value, _harnessArgs.InputSizeXY, _harnessArgs.OutputSizeXY); _hyperneatArgs = new HyperNEAT_Args() { InputPositions = hyperPoints.inputs, OutputPositions = hyperPoints.outputs, }; } #endregion #region create harness _harness = new TrackedItemHarness(_harnessArgs); _harness.ItemRemoved += (s1, e1) => { _harness.SetItem(AntPos_Evaluator.GetNewItem(_harness, _evalArgs)); }; _harness.SetItem(AntPos_Evaluator.GetNewItem(_harness, _evalArgs)); #endregion #region create evaluator AntPos_Evaluator evaluator = new AntPos_Evaluator(_harnessArgs, _evalArgs); //FitnessInfo score = evaluator.Evaluate(new RandomBlackBoxNetwork(_harness.InputSizeXY * _harness.InputSizeXY, _harness.OutputSizeXY * _harness.OutputSizeXY, true)); // this is a good place to unit test the evaluator #endregion #region create experiment _experiment = new ExperimentNEATBase(); _experiment.Initialize("anticipate position", _experimentArgs, evaluator); #endregion #region create evolution algorithm if (prevGenomeXML == null) { if (chkHyperNEAT.IsChecked.Value) { _ea = _experiment.CreateEvolutionAlgorithm(_hyperneatArgs); } else { _ea = _experiment.CreateEvolutionAlgorithm(); } } else { List <NeatGenome> genomeList; if (_hyperneatArgs == null) { genomeList = ExperimentNEATBase.LoadPopulation(prevGenomeXML, _experimentArgs.Activation, _experimentArgs.InputCount, _experimentArgs.OutputCount); } else { genomeList = ExperimentNEATBase.LoadPopulation(prevGenomeXML, _experimentArgs.Activation, _hyperneatArgs); } // The factory is the same for all items, so just grab the first one NeatGenomeFactory genomeFactory = genomeList[0].GenomeFactory; _ea = _experiment.CreateEvolutionAlgorithm(genomeFactory, genomeList, _hyperneatArgs); } _ea.UpdateEvent += EA_UpdateEvent; _ea.PausedEvent += EA_PausedEvent; #endregion ShowBestGenome(); // this ensures the neural viewer is created _winningBrainTime = DateTime.UtcNow - TimeSpan.FromDays(1); // put it way in the past so the first tick will request a new winner _winningBrain = null; //_winningBrain = new RandomBlackBoxNetwork(_harness.InputSizeXY * _harness.InputSizeXY, _harness.OutputSizeXY * _harness.OutputSizeXY, true); _tickCounter = _evalArgs.TotalNumberEvaluations * 2; // force the timer to get the winning NN right away (otherwise it will do a round before refreshing) _ea.StartContinue(); // this needs to be done last } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }