Beispiel #1
0
        /// <summary>
        /// TestData is the method used to compare two layers.
        /// It outputs the difference in probability that two layers share attributes to the static varable
        /// <see cref="averageDifference"/>. It does this as the main focus of this application.
        /// </summary>
        /// <param name="reply"> The poorly-named variable of the location of the data point being tested</param>
        /// <param name="testLayer"> The Layer object that has had weights assigned to it using data from inputs with known attributes</param>
        /// <param name="accuracy">The accuracy /1 (100%) the layer needs to have to be considered 'similar' </param>
        public static void TestData(String reply, Layer testLayer, double accuracy)
        {
            averageDifference = 0.0;
            Layer newLayer = new Layer();

            imageBeingSearched = reply;
            Cell cell = new ImageCell((Bitmap)Image.FromFile(reply));

            cell.CopyCell(testLayer.baseCell);
            newLayer.baseCell = cell;
            for (int i = 0; i < 40; i++)
            {
                cell.ReBuild();
                cell.GetCall();
                DebugWrite("Main->Testing() ->", reply + " Got Cell Values", false);                           //Confirm Image can be read and provide values
                newLayer.AddValue(cell);
                DebugWrite("Main->Testing() ->", reply + " Had values added to it's layer, comparing", false); // Confir mLAyer can add values correctly
                CompareLayers(testLayer, newLayer, accuracy, false);
            }
            if (averageDifference < (1.0 - accuracy))
            {
                lastWasApple = true;
                DebugWrite("Main->Testing() ->", reply + " Apparently WAS an apple", true, true);
            }
            else
            {
                lastWasApple = false;
                DebugWrite("Main->Testing() ->", reply + " Apparently WASN'T an apple", true, true);
            }
            DebugWrite("main->Testing->", "Average Difference was " + averageDifference + ", accuracy was " + accuracy, true);
        }
Beispiel #2
0
        /// <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
        }
Beispiel #3
0
        /// <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]);
        }
Beispiel #4
0
 /// <summary>
 /// Changes the root iamge. Should have <see cref="Cell.ReBuild"/> called after so new root values can
 /// be passed up.
 /// </summary>
 /// <param name="c">The Image Cell to change image for</param>
 /// <param name="img">The iamge to change to</param>
 public static void ChangeImage(ImageCell c, Bitmap img)
 {
     c.img = img;
 }