コード例 #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            /******LOAD DATA******/
            List <TrainingItem> trainData =
                MnistReader.ConvertTrainingData(
                    MnistReader.ReadImages("train-images.idx3-ubyte", "train-labels.idx1-ubyte", 60000));

            /***Test form***/

            testForm = new TestingForm();

            /***Graph***/

            graphForm = new Graph();

            /*****Create Network Form*****/

            form = new NetworkForm();

            if (!TryLoadNetwork())
            {
                network = new NeuralNetwork(0.01, 0.9, new int[] { 196, 15, 4 });
            }

            form.DrawNetwork(network);

            form.startTrainingAction += () => network.Train(trainData, (i, cost) =>
            {
                form.SetProgress("Trained for " + TimeSpan.FromMilliseconds(network.TrainedMillis).ToString("c") + " - Gen " + i + " - Cost : " + cost);
                if (graphForm.Visible)
                {
                    graphForm.SetGraphData("Cost", network.Costs);
                }
            }, true, 10000);

            form.stopTrainingAction += network.StopTraining;

            form.toJsonAction += () =>
            {
                File.WriteAllText(networkDataPath, new NetworkInfos(network).GetJSON());
            };

            form.testNetworkAction += TestNetwork;

            form.costGraphAction += () =>
            {
                graphForm.SetGraphData("Cost", network.Costs);
                graphForm.Show();
            };

            form.FormClosed += (object o, FormClosedEventArgs a) => network.StopTraining();

            /*****END*****/

            /***RUN***/
            Application.Run(form);
        }
コード例 #2
0
        private static DbTable <T> _Test <T>(Assembly ca, DbTable <T> node, string title, TestingOption option)
            where T : DbRow
        {
            if (Admin.IsTestingEnvironmentOff(ca) || option == TestingOption.Skip)
            {
                return(node);
            }

            // handle reusability - !
            var node2 = node.RootWithBrokenChain ?? node.Root;

            Chainer query;

            if (node2.IsPureSubject())
            {
                query = new SelectChainer((ISemantic)node2, new Column[] { }, false).Top(Admin.TestSelectTopRows);
            }
            else
            {
                query = new SelectChainer((ISemantic)node2, new Column[] { }, false);
            }

            var connectable = Reader.GetConnectable(ca, query);

            using (var form = new TestingForm(connectable, option, title))
            {
                form.ShowDialog();
            }

            node2.Recover();

            return(node);
        }
コード例 #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (TestingForm tests = new TestingForm())
     {
         tests.ShowDialog();
     }
 }
コード例 #4
0
        /// <summary>
        /// Opens the testing environment window. When closed the execution proceeds. The testing does not affect the data state of the execution.
        /// </summary>
        /// <param name="view">A view object.</param>
        /// <param name="title">A title that will appear in the window.</param>
        /// <param name="option">An option that specifies whether the testing environment window should open, should open and execute, or should be skipped.</param>
        public static View Test(this View view, string title, TestingOption option = TestingOption.OpenAndExecute)
        {
            return(PublicInvoker.Call <View>(Assembly.GetCallingAssembly(), (ca) =>
            {
                var connectable = Reader.GetConnectable(ca, (Chainer)view);
                if (!Admin.IsTestingEnvironmentOff(ca) && option != TestingOption.Skip)
                {
                    using (var form = new TestingForm(connectable, option, title))
                    {
                        form.ShowDialog();
                    }
                }

                return view;
            }));
        }
コード例 #5
0
        /// <summary>
        /// Opens the testing environment window. When closed the execution proceeds. The testing does not affect the data state of the execution.
        /// </summary>
        /// <param name="prev">A predecessor object.</param>
        /// <param name="option">An option that specifies whether the testing environment window should open, should open and execute, or should be skipped.</param>
        public static Connectable Test(this IGo prev, TestingOption option = TestingOption.OpenAndExecute)
        {
            return(PublicInvoker.Call <Connectable>(Assembly.GetCallingAssembly(), (ca) =>
            {
                var connectable = Reader.GetConnectable(ca, (Chainer)prev);
                if (!Admin.IsTestingEnvironmentOff(ca) && option != TestingOption.Skip)
                {
                    using (var form = new TestingForm(connectable, option, null))
                    {
                        form.ShowDialog();
                    }
                }

                return connectable;
            }));
        }
コード例 #6
0
ファイル: Template.cs プロジェクト: ikenni/Layered
        /// <summary>Default constructor.</summary>
        /// <param name="template"><see cref="System.Drawing.Bitmap"/>, that will be used as a template.</param>
        /// <param name="marginMask"><see cref="System.Drawing.Bitmap"/>, that reprensets a map with two colors (transparent and opaque) and used to determine margin (<see cref="System.Windows.Forms.Padding"/>).</param>
        /// <param name="gradientWidth">Minumum width or height of gradient.</param>
        public Template(Bitmap template, Bitmap marginMask = null, int gradientWidth = 20)
        {
            // Basicly, we're cutting each fragment from provided template, then triming each
            // side in order to get rid of empty space. After that, we're drawing onto new
            // bitmap those fragments and creating everything we need to launch the test.

            // Provided bitmap must have specific size, so we could divide it onto three parts
            // horizontally and vertically. A little later, we're checking results...
            var width = template.Width / 3;
            var height = template.Height / 3;

            // ...and throwing exception, if something wrong
            if ((width%1) != 0 || (height%1) != 0) {
                throw new Exception($"Width or height of provided bitmap wrong. Width / 3: {width}; Height / 3: {height}");
            }

            // Here we might ignore it, but when updating layered windows, there might be problems.
            if (template.PixelFormat != PixelFormat.Format32bppArgb) {
                throw new Exception("Pixel format of provided bitmap not equals PixelFormat.Format32bppArgb");
            }

            // Creating fragments of corners for horizontal sides
            var hTopLeft = new Fragment(template, new Rectangle(0, 0, width, height), true);
            var hTopRight = new Fragment(template, new Rectangle(width * 2, 0, width, height), true);
            var hBottomLeft = new Fragment(template, new Rectangle(0, height * 2, width, height), true);
            var hBottomRight = new Fragment(template, new Rectangle(width * 2, height * 2, width, height), true);

            // Creating fragments of corners for vertical sides
            var vTopLeft = new Fragment(template, new Rectangle(0, 0, width, height), true);
            var vTopRight = new Fragment(template, new Rectangle(width * 2, 0, width, height), true);
            var vBottomLeft = new Fragment(template, new Rectangle(0, height * 2, width, height), true);
            var vBottomRight = new Fragment(template, new Rectangle(width * 2, height * 2, width, height), true);

            // Creating fragments of sides
            var left = new Fragment(template, new Rectangle(0, height, width, height), true);
            var right = new Fragment(template, new Rectangle(width * 2, height, width, height), true);
            var top = new Fragment(template, new Rectangle(width, 0, width, height), true);
            var bottom = new Fragment(template, new Rectangle(width, height * 2, width, height), true);

            // You can't move several layered windows simultaniusly, even DeferWindowPos fails.
            // But we could create specific mask, that will cover any delays in movement

            // Generating and applying mask to each corner
            hTopLeft.ApplyMask(MaskType.HTopLeft, gradientWidth);
            hTopRight.ApplyMask(MaskType.HTopRight, gradientWidth);
            hBottomLeft.ApplyMask(MaskType.HBottomLeft, gradientWidth);
            hBottomRight.ApplyMask(MaskType.HBottomRight, gradientWidth);

            // ...
            vTopLeft.ApplyMask(MaskType.VTopLeft, gradientWidth);
            vTopRight.ApplyMask(MaskType.VTopRight, gradientWidth);
            vBottomLeft.ApplyMask(MaskType.VBottomLeft, gradientWidth);
            vBottomRight.ApplyMask(MaskType.VBottomRight, gradientWidth);

            // Calculating maximum size of each side. This will be used during scaling sides and
            // creating inner rectangle. Last thing will be used in order to create Metrics.
            var leftSide = Max(vTopLeft.Width, left.Width, vBottomLeft.Width);
            var topSide = Max(vTopLeft.Height, top.Height, vTopRight.Height);
            var rightSide = Max(vTopRight.Width, right.Width, vBottomRight.Width);
            var bottomSide = Max(vBottomLeft.Height, bottom.Height, vBottomRight.Height);

            // Since we're having two types of corners, we need a place for all of them.
            // So, we could scale sides and store 4 corners inside of square.
            left.Scale(0, topSide + bottomSide);
            right.Scale(0, topSide + bottomSide);
            top.Scale(leftSide + bottomSide, 0);
            bottom.Scale(leftSide + bottomSide, 0);

            // Creating bitmap, that will contain all eight corners and four sides
            Bitmap = new Bitmap((leftSide + rightSide) * 2, (topSide + bottomSide) * 2, PixelFormat.Format32bppArgb);

            // Calculating inner rectangle, that will be used as a parameter for Metrics
            InnerRectangle = new Rectangle {
                X = leftSide,
                Y = topSide,
                Width = leftSide + rightSide,
                Height = topSide + bottomSide
            };

            // Metrics contain information about each fragment on bitmap, and we're
            // creating metrics in order to draw each fragment onto bitmap, simple.
            Metrics = new Metrics(Bitmap.Size, InnerRectangle);

            // ...
            using (var g = Graphics.FromImage(Bitmap)) {

                // Sides
                g.DrawImage(top.Bitmap, Metrics.Top, new Rectangle(Point.Empty, top.Size), GraphicsUnit.Pixel);
                g.DrawImage(bottom.Bitmap, Metrics.Bottom, new Rectangle(Point.Empty, bottom.Size), GraphicsUnit.Pixel);
                g.DrawImage(left.Bitmap, Metrics.Left, new Rectangle(Point.Empty, left.Size), GraphicsUnit.Pixel);
                g.DrawImage(right.Bitmap, Metrics.Right, new Rectangle(Point.Empty, right.Size), GraphicsUnit.Pixel);

                // Corners for vertical sides
                g.DrawImage(vTopLeft.Bitmap, Metrics.Vertical.TopLeft, new Rectangle(Point.Empty, vTopLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(vTopRight.Bitmap, Metrics.Vertical.TopRight, new Rectangle(Point.Empty, vTopRight.Size), GraphicsUnit.Pixel);
                g.DrawImage(vBottomLeft.Bitmap, Metrics.Vertical.BottomLeft, new Rectangle(Point.Empty, vBottomLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(vBottomRight.Bitmap, Metrics.Vertical.BottomRight, new Rectangle(Point.Empty, vBottomRight.Size), GraphicsUnit.Pixel);

                // Corners for horizontal sides
                g.DrawImage(hTopLeft.Bitmap, Metrics.Horizontal.TopLeft, new Rectangle(Point.Empty, vTopLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(hTopRight.Bitmap, Metrics.Horizontal.TopRight, new Rectangle(Point.Empty, vTopRight.Size), GraphicsUnit.Pixel);
                g.DrawImage(hBottomLeft.Bitmap, Metrics.Horizontal.BottomLeft, new Rectangle(Point.Empty, vBottomLeft.Size), GraphicsUnit.Pixel);
                g.DrawImage(hBottomRight.Bitmap, Metrics.Horizontal.BottomRight, new Rectangle(Point.Empty, vBottomRight.Size), GraphicsUnit.Pixel);

            }

            // After we're done with creating result-bitmap, we can dispose from each fragment
            hTopLeft.Dispose();
            hTopRight.Dispose();
            hBottomLeft.Dispose();
            hBottomRight.Dispose();

            // ...
            vTopLeft.Dispose();
            vTopRight.Dispose();
            vBottomLeft.Dispose();
            vBottomRight.Dispose();

            // ...
            left.Dispose();
            right.Dispose();
            top.Dispose();
            bottom.Dispose();

            // Developer could specify margin manually, but it will take time to get it right.
            // So, instead of manual setup, we're using bitmap, that contains two types of pixels:
            // one pixels are fully transparent (Color.A == 0), the other one opaque (Color.A = 255).
            // Using the same class to cut and trim fragments, we can calculate what we need.
            if (marginMask != null) {

                // Creating fragments from sides (top, bottom, left, right)
                var topBitmap = new Fragment(marginMask, new Rectangle(width, 0, width, height), true);
                var bottomBitmap = new Fragment(marginMask, new Rectangle(width, height*2, width, height), true);
                var leftBitmap = new Fragment(marginMask, new Rectangle(0, height, width, height), true);
                var rightBitmap = new Fragment(marginMask, new Rectangle(width*2, height, width, height), true);

                // ...
                Margin = new Padding(-leftBitmap.Width, -topBitmap.Height, -(rightBitmap.Width + 1), -(bottomBitmap.Height + 1));

                // ...
                topBitmap.Dispose();
                bottomBitmap.Dispose();
                leftBitmap.Dispose();
                rightBitmap.Dispose();

            } else {

                // In this case, bitmap wasn't specified, so, margin will be empty. In this case,
                // developer can open testing form and tweak margin on each side manually.
                Margin = Padding.Empty;

            }

            // Final steps, creating theme and form. From now, developer can test generated
            // bitmap and see, what's wrong and what's not.
            Theme = new Theme(Bitmap, Metrics, Margin);
            Form = new TestingForm(this);
        }