private void SimNext() { //NEXT SIMULATION if (NetMain.ToggleSim.Checked) { SimNew(); NetMain.PanelProgress.AddProgress(NetMain.Worker); } else //FIND MINIMUM { NetInit?.Invoke(Net.PixelWidth, Net.PixelHeight, Net.NodesHidden, Net.NodesOutput, LRbefore, Net.Mode, false); Run best = new Run(null, TimeSpan.MinValue, 0, 0, 0); //LOOP PERFORMANCE LIST foreach (Run run in PerformanceList) { if (run.Performance > best.Performance) { best = run; } } double percent = Mod_Convert.DoubleFormat(best.Performance * 100, 2); NetMain.setConsoleInvoke("Simulation stoppt, best performance: " + percent + " % (LR: " + (best.LearningRate * 100) + " %, E: " + best.Epochs + ")"); //PERFORMANCE PLOT ShowPlot(); } }
private void RecalculateNetwork(NetNeural xNet) { //RECALCULATE NETWORK int nodesInput = xNet.NodesInput; int nodesHidden = xNet.NodesHidden; int nodesOutput = xNet.NodesOutput; //PANEL PanelTop = new int[] { 0, (int)Start * 2, Panel.Height - (int)Start * 2 }; PanelHeight = PanelTop[2] - PanelTop[1]; PanelCenter = PanelHeight / 2 + PanelTop[1]; PanelMax = PanelHeight / NodesHeight; PanelRatio = new float[] { nodesInput / PanelMax, nodesHidden / PanelMax, nodesOutput / PanelMax }; for (int i = 0; i < PanelRatio.Length; i++) { if (PanelRatio[i] < 1) { PanelRatio[i] = 1; } } //NODES Count = new int[] { (int)(nodesInput / PanelRatio[0]), (int)(nodesHidden / PanelRatio[1]), (int)(nodesOutput / PanelRatio[2]) }; float[] space = new float[] { Count[0] * NodesHeight, Count[1] * NodesHeight, Count[2] * NodesHeight }; Area = new float[] { PanelCenter - space[0] / 2, PanelCenter - space[1] / 2, PanelCenter - space[2] / 2 }; //TEXTS Caption = new string[] { "Input Nodes (" + nodesInput + ")", "Hidden Nodes (" + nodesHidden + ")", "Output Nodes (" + nodesOutput + ")" }; Factor = new string[] { Mod_Convert.DoubleFormat(PanelRatio[0], 2) + "x", Mod_Convert.DoubleFormat(PanelRatio[1], 2) + "x", Mod_Convert.DoubleFormat(PanelRatio[2], 2) + "x" }; //LIST PointList = new List <PointF[]>(); }
private void UpdatePosition() { //UPDATE POSITION NetMain.PosiX.Text = Mod_Convert.IntegerToString(Location.X + Width / 2); NetMain.PosiY.Text = Mod_Convert.IntegerToString(Location.Y + Height / 2); getPosition(); }
public static void drawCheck(Image xDraw, params UniPanel[] xPanel) { //CHECK DRAWN BITMAP double[] dblArray = NetMain.Cam.getDoubleArray(); //GET ANSWER int answer = NetMain.neuralNetworkQuery(dblArray, 0.0, true); //ABBRUCH if (xPanel.Length == 0 || answer == int.MinValue) { return; } //TRANSFER IMAGE AND TOOLTIP TO NEXT PANEL for (int i = xPanel.Length - 2; i >= 0; i--) { if (xPanel[i].BackgroundImage != null) { xPanel[i + 1].BackgroundImage = xPanel[i].BackgroundImage; } ; xPanel[i + 1].setToolTip(xPanel[i].getToolTip()); } //SET FIRST PANEL Size size = xPanel[0].Size; xDraw = (Bitmap)Mod_PNG.getScaleImage(xDraw, size, false); Graphics g = Graphics.FromImage(xDraw); g.DrawString(Mod_Convert.IntegerToString(answer), Fonts.getFontCooper(9), new SolidBrush(Color.Red), new Point(size.Width - 14, size.Height - 18)); xPanel[0].BackgroundImage = xDraw; xPanel[0].setToolTip(NetMain.ConsoleBox.Tag.ToString()); }
private void evaluateCurrent() { //ABBRUCH if (!NetMain.Cam.Visible) { return; } //EVALUATE CURRENT newSpecies species = Pool.species[Pool.currentSpecies]; newGenome genome = species.genomes[Pool.currentGenome]; List <double> inputs = Mod_Convert.ArrayToList <double>(NetMain.Cam.getDoubleArray()); //READ INPUTS FROM CAM Controller = genome.network.evaluateNetwork(inputs); //GET OUTPUTS }
public static object[] Invert(object[] xObjectArray) { //INVERT List <object> objList = new List <object>(); foreach (object obj in xObjectArray) { int[] split = Mod_Convert.ObjectArrayToIntegerArray(Mod_Convert.StringSplitToObjectArray(obj, ",")); for (int i = 0; i < split.Length; i++) { split[i] = 255 - split[i]; } object str = String.Join(",", split); objList.Add(str); } return(objList.ToArray()); }
public NetIO(Control xForm, int xLeft, int xTop, int xWidth, int xHeight, BorderStyle xBorderStyle, Color xColorBack, bool xVisible) : base(xForm, xLeft, xTop, xWidth, xHeight, xBorderStyle, xColorBack, xVisible, false, true) { //CREATE NET IO OBJECT WidthHalf = xWidth / 2; WidthQuad = WidthHalf / 2; WidthSpace = WidthHalf - StartLeft * 2; HeightHalf = StartTop + Height / 2; HeightSpace = Height - StartTop * 3; //CALCULATION float[] textWidth = new float[] { Mod_Convert.StringToWidth(DrawText[0], MainFont), Mod_Convert.StringToWidth(DrawText[1], MainFont) }; PointText[0] = new PointF(WidthQuad - textWidth[0] / 2, StartTop / 2); PointText[1] = new PointF(WidthHalf + WidthQuad - textWidth[1] / 2, StartTop / 2); //GRAPHICS Pen = new Pen(Colors.getColor(COLOR.GREY)); //EVENT LISTENER Paint += eventPaint; }
public void Load(object[] xObject) { //LOAD NET TABLE for (int i = 0; i < xObject.Length; i++) { DataGridViewRow row = Rows[i]; object[] split = Mod_Convert.StringSplitToObjectArray(xObject[i]); //COLOR ENEMY row.Cells[(int)TYP.ENEMY].Tag = split[(int)TYP.ENEMY]; row.Cells[(int)TYP.ENEMY].Style.BackColor = Color.FromArgb(Mod_Convert.ObjectToInteger(split[(int)TYP.ENEMY])); //COLOR FRIEND row.Cells[(int)TYP.FRIEND].Tag = split[(int)TYP.FRIEND]; row.Cells[(int)TYP.FRIEND].Style.BackColor = Color.FromArgb(Mod_Convert.ObjectToInteger(split[(int)TYP.FRIEND])); //TRIGGER row.Cells[(int)TYP.TRIGGER].Tag = split[(int)TYP.TRIGGER]; row.Cells[(int)TYP.TRIGGER].Value = split[(int)TYP.TRIGGER]; } }
private void eventTick(object sender, EventArgs e) { //TICK EVENT FpsCounter++; if (Reset && Alive) { Reset = false; setHighscore(); } //RESET AFTER DEAD if (FpsCounter >= Fps / ScoreFactor && Alive) { FpsCounter = 1; NetMain.LabelScore.Text = Mod_Convert.IntegerToString(Score); Score++; } //COUNT SCORE WHILE ALIVE if (Alive) { NetMain.LabelScore.setColorFeedback(Color.Green, null); //ALIVE FEEDBACK } else { NetMain.LabelScore.setColorFeedback(Color.Red, null); Reset = true; } //DEAD FEEDBACK Refresh(); }
public static void drawBackQuery(Panel xBackQueryPanel) { //DRAW NEURAL NETWORK BACK QUERY double[] backQuery = NetMain.Net.QueryBack(NetMain.convertDoubleToMatrix(NetMain.Net.AnswerArray, 1, NetMain.Net.AnswerArray.Length)); //CONVERT TO COLOR for (int i = 0; i < backQuery.Length; i++) { backQuery[i] = backQuery[i] * 255; } int pixel = (int)Math.Sqrt(backQuery.Length); int[] pixelArray = Mod_Convert.DoubleArrayToIntegerArray(backQuery); //ABBRUCH if (pixelArray[0] == int.MinValue) { return; } Bitmap bitmap = new Bitmap(pixel, pixel); int index = 0; for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; ++x) { bitmap.SetPixel(x, y, Color.FromArgb(pixelArray[index], pixelArray[index], pixelArray[index])); index++; } } //SET BACKGROUND IMAGE xBackQueryPanel.BackgroundImage = ScaleUp(bitmap); }
public void Plot(Graphics g) { Pool = Main.Mario.Pool; //ABBRUCH if (Pool == null) { return; } //RECALCULATE NEUROEVOLUTION RecalculateNeuroevolution(Pool); //GET SPCIES LIST List <newSpecies> spciesList = Pool.species; for (int i = 0; i < spciesList.Count; i++) { float width = PanelLeft[2] + getScoreWidth(spciesList[i].topFitness); float average = PanelLeft[2] + getScoreWidth(spciesList[i].averageFitness); float height = PanelTop[0] + i * PenPositive.Width; //DRAW NUMBER g.DrawString((i + 1) + ".", Mod_Convert.FontSize(Fonts.MainFont, PenText.Width), PenText.Brush, new PointF(PanelLeft[1], height - PenPositive.Width / 2)); //DRAW SCORE if (Mod_Check.isEven(i)) { g.DrawLine(PenNegative, new PointF(PanelLeft[2], height), new PointF(width, height)); } else { g.DrawLine(PenPositive, new PointF(PanelLeft[2], height), new PointF(width, height)); } //DRAW STALE for (int l = 0; l < Pool.species[i].staleness; l++) { g.FillEllipse(new SolidBrush(Colors.MainLight), PanelLeft[2] + 1f + l * PenPositive.Width, height, PenPositive.Width / 2, PenPositive.Width / 2); } //DRAW AVERAGE g.DrawLine(new Pen(Colors.MainDominant, 1), new PointF(average, height), new PointF(average, height + PenPositive.Width / 2)); } //INFORMATIONS newSpecies currSpecies = Pool.species[Pool.currentSpecies]; //GET CURRENT SPECIES newGenome currGenome = currSpecies.genomes[Pool.currentGenome]; //GET CURRENT GENOME float left = PanelLeft[0]; Font infoFont = Mod_Convert.FontSize(Fonts.MainFont, 9); g.DrawString("Generation:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString(Pool.generation.ToString(), infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Species:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString((Pool.currentSpecies + 1) + "/" + Pool.species.Count, infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Genome:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString((Pool.currentGenome + 1) + "/" + currSpecies.genomes.Count, infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Stale:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString(currSpecies.staleness + "/" + (NetMario.StaleSpecies - 1), infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Fitness:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString(currGenome.fitness + " (" + Pool.maxFitness + ", " + currSpecies.averageFitness + ")", infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Measure:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString(Pool.measured + " %", infoFont, PenText.Brush, new PointF(left, PanelTop[2])); }
public void Plot(Graphics g) { //PLOT Net = Main.Net; //ABBRUCH if (Net == null) { return; } //RECALCULATE PARAMETERS RecalculateNetwork(Net); //LOOP NODES for (int i = 0; i < Count.Length; i++) { //DRAW CAPTION int strWidth = Mod_Convert.StringToWidth(Caption[i], DrawFont) / 2; g.DrawString(Caption[i], DrawFont, Brush, NodesLeft[i] - strWidth, PanelTop[0]); Current = Area[i]; List <PointF> tempList = new List <PointF>(); //DRAW NODES for (int node = 0; node < Count[i]; node++) { tempList.Add(new PointF(NodesLeft[i], Current)); g.DrawEllipse(PenNode, NodesLeft[i] - Radius, Current - Radius, Radius + Radius, Radius + Radius); Current = Current + NodesNext[i]; } PointList.Add(tempList.ToArray()); //DRAW SCALE strWidth = Mod_Convert.StringToWidth(Factor[i], DrawFont) / 2; g.DrawString(Factor[i], DrawFont, Brush, NodesLeft[i] - strWidth, PanelTop[2]); } double maxInput = getAbsMax(Net.weightInput); double maxOutput = getAbsMax(Net.weightOutput); //DRAW LINES foreach (PointF pt1 in PointList[0]) { foreach (PointF pt2 in PointList[1]) { int x = (int)(Array.IndexOf(PointList[0], pt1) * PanelRatio[0]); int y = (int)(Array.IndexOf(PointList[1], pt2) * PanelRatio[1]); double weight = Math.Abs(Net.weightInput[y, x]); PenLine = getPen(weight / maxInput); if (PenLine.Color.A > Alpha) { g.DrawLine(PenLine, pt1, pt2); //INPUT TO HIDDEN } foreach (PointF pt3 in PointList[2]) { int z = (int)(Array.IndexOf(PointList[2], pt3) * PanelRatio[2]); weight = Math.Abs(Net.weightOutput[z, y]); PenLine = getPen(weight / maxOutput); if (PenLine.Color.A > Alpha) { g.DrawLine(PenLine, pt2, pt3); //HIDDEN TO OUTPUT } } } } }
public static MODE getMode(int xIndex) { //GET MODE BY INTEGER object[] ModeList = Mod_Convert.EnumToList(typeof(MODE)); return((MODE)ModeList[xIndex]); }
public void Load() { //LOAD string[] path = Mod_File.FileOpenDialog(false, FILTER.TXT); //ABBRUCH if (path == null) { return; } //START LOADING UniLoad.loadingStart(); //READ TXT FILE string[] file = Mod_TXT.readTXT(path[0]); int x = 0; //GET DURATION Duration = TimeSpan.FromMilliseconds(Mod_Convert.StringToDouble(file[x++])); //GET OUTPUT KEYS OutputKeys = file[x++].Split(' '); //INITIALIZE POOL Initialize(OutputKeys, true); Pool.generation = Mod_Convert.StringToInteger(file[x++]); Pool.maxFitness = Mod_Convert.StringToDouble(file[x++]); int numSpecies = Mod_Convert.StringToInteger(file[x++]); for (int j = 0; j < numSpecies; j++) //SPECIES { newSpecies species = new newSpecies(); Pool.species.Add(species); species.topFitness = Mod_Convert.StringToDouble(file[x++]); species.staleness = Mod_Convert.StringToInteger(file[x++]); int numGenomes = Mod_Convert.StringToInteger(file[x++]); for (int i = 0; i < numGenomes; i++) //GENOME { newGenome genome = new newGenome(); species.genomes.Add(genome); genome.fitness = Mod_Convert.StringToDouble(file[x++]); genome.maxneuron = Mod_Convert.StringToInteger(file[x++]); string line = file[x++]; while (line != "done") { genome.mutationRates[line] = Mod_Convert.StringToDouble(file[x++]); line = file[x++]; } int numGenes = Mod_Convert.StringToInteger(file[x++]); for (int k = 0; k < numGenes; k++) //GENE { newGene gene = new newGene(); genome.genes.Add(gene); string[] split = file[x++].Split(' '); gene.into = Mod_Convert.StringToInteger(split[0]); gene.output = Mod_Convert.StringToInteger(split[1]); gene.weight = Mod_Convert.StringToDouble(split[2]); gene.innovation = Mod_Convert.StringToInteger(split[3]); gene.enabled = Mod_Convert.ObjectToBool(split[4]); } } } //FITNESS ALREADY MEASURED while (fitnessAlreadyMeasured()) { nextGenome(); } initializeRun(); //UPDATE LEARN PANEL NetMain.RoundFinished(0); //END LOADING UniLoad.loadingEnd(); }
public static Bitmap drawAnswer(Bitmap xBitmap, object xAnswer) { //DRAW ANSWER Graphics g = Graphics.FromImage(xBitmap); string answer = xAnswer.ToString(); g.DrawString(answer, BmpFont, new SolidBrush(Color.Red), new Point(NetMain.PanelDraw.Width - Mod_Convert.StringToWidth(answer, BmpFont), 6)); return(xBitmap); }
public string[] getKeys() { //GET TRIGGER KEYS return(Mod_Convert.ObjectArrayToStringArray(getColumnTags(2))); }