private static void SmartChangeNumber(EvolutionInfo EInfo, Equation Eq, Equation BCand, Equation OCand, int[] Indexes) { foreach (int Index in Indexes) { #if DEBUG if (Index >= BCand.AllOperators.Length || Index < 0 || Index >= OCand.AllOperators.Length || Index < 0) { System.Diagnostics.Debugger.Break(); } #endif Operator BCandOper = BCand.AllOperators[Index]; Operator OCandOper = OCand.AllOperators[Index]; if (BCandOper.RandomNumber > OCandOper.RandomNumber) { Eq.AllOperators[Index].RandomNumber = Eq.Randomizer.Next(EInfo.NumberRangeMin, (int)BCandOper.RandomNumber + 1); } else { Eq.AllOperators[Index].RandomNumber = Eq.Randomizer.Next((int)BCandOper.RandomNumber, EInfo.NumberRangeMax); } Eq.AllOperators[Index].OperatorChanged(); } }
public static void EvolveCandidate(EvolutionInfo EInfo, Equation Cand) { int AmountToChange = Cand.Randomizer.Next(1, (int)Math.Max(2, EInfo.MaxChange * Cand.NumberOfAllOperators)); while (AmountToChange > 0 && Cand.OperatorsLeft < Cand.EInfo.MaxSize) { int ToDo = Cand.Randomizer.Next(0, 3); switch (ToDo) { case 0: AmountToChange -= InsertOPS(Cand); break; case 1: AmountToChange -= RemoveOPS(Cand, AmountToChange); break; case 2: AmountToChange -= ChangeOPS(Cand, AmountToChange); break; } #if DEBUG if (Cand.OperatorsLeft < 0) { System.Diagnostics.Debugger.Break(); } #endif } }
public static void EvolveCandidates(EvolutionInfo EInfo, Equation[] Copys, int StartIndex, int Amount) { for (int i = StartIndex; i < StartIndex + Amount; i++) { EvolveCandidate(EInfo, Copys[i]); Copys[i].CalcTotalOffSet(); } }
public void StartSetup(SpecieEnviromentBase <FamilyGenome> SE, GeneralInfo G, EvolutionInfo E) { SpecEnviroment = SE; GInfo = G; EInfo = E; child = new Equation(EInfo, Randomizer); BestCandidate = new Equation(EInfo, Randomizer); }
private static void SmartChangeNumbers(EvolutionInfo EInfo, Equation[] Copys, Equation BCand, Equation OCand, int[] Indexes, int StartIndex, int Amount) { for (int i = StartIndex; i < StartIndex + Amount; i++) { SmartChangeNumber(EInfo, Copys[i], BCand, OCand, Indexes); Copys[i].CalcTotalOffSet(); } }
private static void StupidChangeNumbers(EvolutionInfo EInfo, Equation[] Copys, int StartIndex, int Amount) { for (int i = StartIndex; i < StartIndex + Amount; i++) { StupidChangeNumber(EInfo, Copys[i]); Copys[i].CalcTotalOffSet(); } }
public static void SmartifyCandidate(EvolutionInfo EInfo, Equation ToSmartify, Equation BCand, Equation OCand, int[] Indexes) { if (Indexes != null) { SmartChangeNumber(EInfo, ToSmartify, BCand, OCand, Indexes); } else { StupidChangeNumber(EInfo, ToSmartify); } }
public static void SmartifyCandidates(EvolutionInfo EInfo, Equation[] Copys, Equation BCand, Equation OCand, int StartIndex, int Amount) { int[] Indexes = CanSmartChangeNumbers(BCand, OCand); if (Indexes != null) { SmartChangeNumbers(EInfo, Copys, BCand, OCand, Indexes, StartIndex, Amount); } else { StupidChangeNumbers(EInfo, Copys, StartIndex, Amount); } }
public override GeneralInfo SetupEviroment(EvolutionInfo einfo) { EInfo = einfo; Species = new FamilyGenome[EInfo.SpeciesAmount]; GInfo = new GeneralInfo(); for (int i = 0; i < EInfo.SpeciesAmount; i++) { Species[i] = new T(); Species[i].StartSetup(this, GInfo, EInfo); DoSubscribeEvent(Species[i]); } return(GInfo); }
//public readonly string parameterNames; public Equation(EvolutionInfo einfo, SynchronizedRandom Rand) : base(einfo.MaxSize) { Randomizer = Rand; EInfo = einfo; Holders = new List <OperatorHolder>(EInfo.MaxSize); AllOperators = new Operator[EInfo.MaxSize]; OPStorage = new Stack <Operator>(EInfo.MaxSize); for (int i = 0; i < EInfo.MaxSize; i++) { OPStorage.Push(new Operator(this)); } Holders.Add(this); Results = new float[EInfo.coordInfo.expectedResults.Length]; }
private static void StupidChangeNumber(EvolutionInfo EInfo, Equation Eq) { if (Eq.NumberOfAllOperators == 0) { return; } int AmountToChange = Eq.Randomizer.Next(1, (int)Math.Max(2, EInfo.MaxChange * Eq.NumberOfAllOperators)); for (int i = 0; i < AmountToChange; i++) { int Index = Eq.GetRandomOperatorIndexFromAllOperators(); Eq.AllOperators[Index].RandomNumber = Eq.Randomizer.Next(EInfo.NumberRangeMin, EInfo.NumberRangeMax); Eq.AllOperators[Index].OperatorChanged(); } }
public Family(EvolutionInfo eInfo, int parentCount) { parents = new Equation[parentCount]; children = new Equation[parentCount]; SynchronizedRandom random = new SynchronizedRandom(); for (int i = 0; i < parents.Length; i++) { parents[i] = new Equation(eInfo, random); children[i] = new Equation(eInfo, random); RandomCand.MakeValidRandomEquation(parents[i]); parents[i].CalcTotalOffSet(); } }
public static void SmartifyCandidate(EvolutionInfo EInfo, Equation ToSmartify, Equation BCand, Equation OCand) { int[] Indexes = CanSmartChangeNumbers(BCand, OCand); SmartifyCandidate(EInfo, ToSmartify, BCand, OCand, Indexes); }
/// <summary> /// prepares the enviroment with its evolution parameters /// </summary> /// <param name="EInfo">evolution parameters</param> /// <returns>shared info about species</returns> public abstract GeneralInfo SetupEviroment(EvolutionInfo EInfo);
private void FindFunctionWithSpecies() { try { //MessageBox.Show(Vector<double>.Count.ToString()); //const string SequenceX = "x = {1,2,3,4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, 25}"; //const string SequenceY = "2,3,5,7,11,13,17,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101"; //const string SequenceX = "x = {1,2,3,4, 5, 6, 7, 8, 9,10}"; //const string SequenceY = "2,3,5,7,11,13,17,19,23,29"; //const string SequenceX = "x = { 1, 2, 3, 4, 5,6, 7,8, 9,10}"; //const string SequenceY = "432,4567,987,23,765,2,678,9,34,23"; //const string SequenceX = "x = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54}"; //const string SequenceY = " 1,0,1,0,1,0,0,0,1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1"; //const string SequenceX = " 2, 3, 4"; //const string SequenceY = "182014,364572,495989"; //const string SequenceX = "x = {1,2,3, 4, 5, 6, 7, 8, 9,10}"; //const string SequenceY = "2,4,6,2342238,10,23432,14,12232116,18,20"; const string SequenceX = "x = { 1, 2, 3, 4, 5, 6,7, 8, 9, 10}"; const string SequenceY = "74,143,34,243,23,52,9,253,224,231"; //const string SequenceX = "x = {384, 357, 221, 9, 18, 357, 221, 6}, y = {18, 357, 221, 6, 384, 357, 221, 9}"; //const string SequenceY = " 6, 1, 17, 3, 6, 1, 17, 3"; //const string SequenceX = "x = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}"; //const string SequenceY = " 1, 3, 8, 21, 55, 144, 377, 987, 2584, 6765, 17711"; //const string SequenceX = "x = {1,2,3,4,5,6, 7, 8, 9,10,11}"; //const string SequenceY = " 1,1,2,3,5,8,13,21,34,55,89"; //const string SequenceX = "x = {1.1,1.5,2,2.1,10.8,200.8}"; //const string SequenceY = " 1, 2,2, 2, 11, 201"; //const string SequenceX = "x = {86, 86, 86, 86, 76, 76, 76, 76, 123, 123, 123, 123}, y = {1, 0.5, 0.25, 0.125, 1, 0.5, 0.25, 0.125, 1, 0.5, 0.25, 0.125}"; //const string SequenceY = " 86, 76, 66, 56, 76, 66, 56, 46, 123, 113, 103, 93"; //List<string> xx = new List<string>(); //List<string> yy = new List<string>(); //for (double i = -Math.PI; i < Math.PI; i += 0.2) //{ // xx.Add(i.ToString("N6", CultureInfo.InvariantCulture)); // yy.Add(Math.Sin(i).ToString("N6", CultureInfo.InvariantCulture)); //} //string SequenceX = "x = {" + String.Join(", ", xx) + "}"; //string SequenceY = String.Join(", ", yy); //const string SequenceX = "x = {2,3,4, 5, 6, 7, 8, 9,10,11}"; //const string SequenceY = " 1,3,6,10,15,21,28,36,45,55"; //const string SequenceX = "x = {1, 4, 3}, y = {1, 1, 3}, z = {1, 2, 3}"; //const string SequenceY = "3,2,1"; //const string SequenceX = "x = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}"; //const string SequenceY = " 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377"; //const string SequenceX = "x = {0.0,0.1,0.2,0.7,0.8,0.9,1.0,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.9,3.0}"; //const string SequenceY = " 0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0"; //const string SequenceX = "0.0,0.1,0.2,0.7,0.8,0.9,1.0,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.9,3.0"; //const string SequenceY = "0.0,0.1,0.2,0.7,0.8,0.9,0.0,0.6,0.7,0.8,0.9,0.0,0.1,0.2,0.3,0.9,0.0"; //const string SequenceX = "x = {0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.999,1.0,1.001,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,1.999,2.0,2.001,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,4.0,5.0,5.0,6.0}"; //const string SequenceY = " 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 0.0,1.0, 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0, 1.0,0.0, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0"; //const string SequenceX = "x = {0.0,0.1,0.2,0.7,0.8,0.9,1.0,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.9,3.0}"; //const string SequenceY = " 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0"; //const string SequenceX = "x = {0.0,0.1,0.2,0.7,0.8,0.9,1.0,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.9,3.0,3.1,3.2,3.7,3.8,3.9,4.0,4.6,4.7,4.8,4.9,5.0,5.1,5.2,5.3,5.9,6.0,6.1,6.2,6.3,6.9,7.0,7.1,7.2,7.7,7.8,7.9,8.0}"; //const string SequenceY = " 0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0"; //const string SequenceX = " 1"; //const string SequenceY = "276"; //string str = "Math Memes"; //byte[] bytes = Encoding.ASCII.GetBytes(str); //byte[] bytes = new byte[str.Length * sizeof(char)]; //System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); //string SequenceX = "x = {" + String.Join(", ", Enumerable.Range(0, bytes.Length)) + "}"; //((string SequenceY = String.Join(", ", bytes); //List<double> SeqRX = new List<double>(); //List<double> SeqRY = new List<double>(); //for (double i = -Math.PI; i < Math.PI; i += 0.4) //{ // SeqRX.Add(i); // SeqRY.Add(Math.Sin(i)); //} //string SequenceX = "x = {" + String.Join(", ", SeqRX.Select(x => x.ToString("N2", CultureInfo.GetCultureInfo("en-US")))) + "}"; //string SequenceY = String.Join(", ", SeqRY.Select(x => x.ToString("N2", CultureInfo.GetCultureInfo("en-US")))); //for (double i = -30; i < 150; i += 10) //{ // SeqRX.Add(i); // SeqRY.Add(Math.Exp(i)); //} //VectorPoint[] Seq = GetSequence(SeqRX.ToArray(), SeqRY.ToArray()); CoordInfo Seq = new CoordInfo(SequenceX, SequenceY); MathFunction[] Operators = new MathFunction[] { new Plus(), new Subtract(), new Multiply(), new Divide(), new PowerOf(), new Root(), new Exponent(), new NaturalLog(), new Log(), //new Modulos(), //new Floor(), //new Ceil(), //new Round(), new Sin(), new Cos(), new Tan(), new ASin(), new ACos(), new ATan(), new Parentheses(), //new Constant(), //new Absolute(), //new AND(), //new NAND(), //new OR(), //new NOR(), //new XOR(), //new XNOR(), //new NOT() }; //EvolutionInfo EInfo = new EvolutionInfo( // Seq, // Sequence // 20, // MaxSize // 0.2, // MaxChange // 30000, // CandidatesPerGen // Math.Max(0, GetMaxNumber(Seq)) + 1, // NumberRangeMax // 0, // NumberRangeMin // 6, // SpeciesAmount // 100, // MaxStuckGens // 0.8, // EvolvedCandidatesPerGen // 0, // RandomCandidatesPerGen // 0.2, // SmartCandidatesPerGen // Operators // Operators that can be used in an equation //); //singleSpecieEnviroment = new IndividualSpecieEnviroment<SingleSpecieEvolutionMethod>(); //singleSpecieEnviroment.OnBestEquationChanged += SpecieEnviroment_OnBestEquationChanged; //singleSpecieEnviroment.OnSubscribeToSpecies += SpecieEnviroment_OnSubscribeToSpecies; //GeneralInfo GInfo = singleSpecieEnviroment.SetupEviroment(EInfo); //GeneralInfoControl.InsertInfo(GInfo); //singleSpecieEnviroment.SimulateEnviroment(); EvolutionInfo EInfo = new EvolutionInfo( Seq, // Sequence 20, // MaxSize 0.2, // MaxChange 400, // CandidatesPerGen Math.Max(0, GetMaxNumber(Seq)) + 1, // NumberRangeMax 0, // NumberRangeMin 100, // SpeciesAmount 100, // MaxStuckGens 0.8, // EvolvedCandidatesPerGen 0, // RandomCandidatesPerGen 0.2, // SmartCandidatesPerGen Operators // Operators that can be used in an equation ); familyEnviroment = new FamilyEnviroment <FamilySpecieEvolutionMethod>(); familyEnviroment.OnBestEquationChanged += SpecieEnviroment_OnBestEquationChanged; familyEnviroment.OnSubscribeToSpecies += SpecieEnviroment_OnSubscribeToSpecies; GeneralInfo GInfo = familyEnviroment.SetupEviroment(EInfo); GeneralInfoControl.InsertInfo(GInfo); familyEnviroment.SimulateEnviroment(); } catch (Exception e) { MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace); throw; } MessageBox.Show("Done"); }
public SpecieEnviromentBase <SingleGenome> SpecEnviroment; // this is the enviroment this specie is living in public void StartSetup(SpecieEnviromentBase <SingleGenome> SE, GeneralInfo G, EvolutionInfo E) { SpecEnviroment = SE; GInfo = G; EInfo = E; }