/// <summary> /// AddWeightsPreTest is used to modify a Layer with a seires of inputs, training it to either be /// biased towards inputs with similar values, or opposed to inputs with simialr values /// </summary> /// <param name="size">The size of the input arrays</param> /// <param name="tag">The tag that <see cref="DebugWrite"/> method will use as it's 'tag'</param> /// <param name="imageLocation">The File loation of the data to be checked (.png)</param> /// <param name="isCorrect">Whether the Layer will be trained up to bias or anti-bias the inputs' values</param> /// <param name="testLayer">The 'Layer' class that is being trained</param> /// <param name="testAmmounts">How many itterations of training will be performed</param> private static void AddWeightsPreTest(int size, String tag, String imageLocation, bool isCorrect, Layer testLayer, int testAmmounts) { Bitmap[] inputs = new Bitmap[size]; String[] inputstrings = new String[size]; for (int i = 0; i < inputs.Length; i++) { inputstrings[i] = imageLocation + "/Image" + (i + 1) + ".png"; DebugWrite(tag, " Loading Image " + inputstrings[i], true);// Confirm Image Loaded inputs[i] = (Bitmap)Image.FromFile(inputstrings[i]); } imageBeingSearched = inputstrings[0]; DebugWrite(tag, " Image 0 height is " + inputs[0].Height, true); // Confirm Images are valid testLayer.baseCell = new ImageCell(inputs[0]); DebugWrite(tag, " Begining Loop to Test Cells", true); // Section Definition for (int i = 0; i < inputs.Length; i++) { for (int r = 0; r < testAmmounts; r++) { DateTime nowTime = DateTime.Now; imageBeingSearched = inputstrings[i]; DebugWrite(tag, " Testing & Rewarding Image " + inputstrings[i], true); // State Which image is being actioned ImageCell.ChangeImage((ImageCell)testLayer.baseCell, inputs[i]); DebugWrite(tag, " Rebuilding Image " + inputstrings[i], true); // State that image has changed correctly testLayer.baseCell.ReBuild(); DebugWrite(tag, " Getting Call of Image " + inputstrings[i], true); // State that 'GetCall()' Method is running successfully ValueClass debugValueClass = testLayer.baseCell.GetCall(); // DebugWrite(tag, " Image Call was " + debugValueClass.value + "," + debugValueClass.weight, false); // Get the value Class of the training for (int xAxis = 0; xAxis < 2; xAxis++) { for (int yAxis = 0; yAxis < 2; yAxis++) { if (isCorrect) { testLayer.AddValue(testLayer.baseCell); testLayer.baseCell.Reward(); } else { testLayer.baseCell.TellOff(); } } } averageCellTime += DateTime.Now.Subtract(nowTime); double averageCellTimeMili = averageCellTime.TotalMilliseconds; averageCellTime = TimeSpan.FromMilliseconds(averageCellTimeMili / 2); } } DebugWrite(tag, " Average Time Per Cell is " + averageCellTime, true, true); //Optimize time of calculation }
/// <summary> /// CreateSubCell uses <see cref="Bitmap"/> functions to segregate the root image and fill the /// 'subCell' array with he relevant subsections of the root image. /// </summary> /// <param name="i">The X co-ord of the subsection to create</param> /// <param name="f">he Y co-ord of the subsection ot create</param> /// <returns>The created subcell made from the specified sub-image of the root image</returns> public override Cell CreateSubCell(int i, int f) { Bitmap subImage = new Bitmap(img.Width / 2, img.Height / 2); NeuralNet.DebugWrite("ImageCell->Cell()->", String.Format("Image Width/Height is {0},{1}", img.Width, img.Height), false); // Create new subImage for (int z = 0; z < subImage.Height; z++) { for (int x = 0; x < subImage.Height; x++) { subImage.SetPixel(z, x, img.GetPixel((img.Width / 2 * i) + z, (img.Width / 2 * f) + x)); } } if (subCells[i, f] != null) { ImageCell.ChangeImage((ImageCell)subCells[i, f], subImage); } else { subCells[i, f] = new ImageCell(subImage); } return(subCells[i, f]); }