Beispiel #1
0
        public void BackpropagatesErrors()
        {
            var last   = new Layer(3);
            var middle = new Layer(3, last, new Sigmoid());
            var first  = new Layer(3, middle);

            last.Errors  = Vec.Build.DenseOfArray(new double[] { -0.2, 0.1, 0.5 });
            last.Weights = Matrix.Build.DenseOfArray(new double[3, 3] {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            });
            last.Biases = Vec.Build.Dense(3, 10);

            middle.Weights = Matrix.Build.DenseIdentity(3, 3);
            middle.Biases  = Vec.Build.Dense(3, 0);

            first.Activations = Vec.Build.DenseOfArray(new double[] { 1, 2, 3 });
            middle.Activate();
            var sigmaPrimeOfZs = new Sigmoid().ActivatePrime(Vec.Build.DenseOfArray(new double[] { 1, 2, 3 }));
            var expectedErrors = Vec.Build.DenseOfArray(new double[] { 3.7, 4.1, 4.5 }).PointwiseMultiply(sigmaPrimeOfZs);

            var errors = middle.Backpropagate();

            Assert.Equal(expectedErrors, errors);
        }
Beispiel #2
0
        private void CreateBitmapLocal(int strSize = 221)
        {
            Layers layers = this.app.ActiveDocument.ActivePage.Layers;

            foreach (Layer l in layers)
            {
                if (l.Shapes.Count == 0 && !l.IsSpecialLayer)
                {
                    l.Delete();
                }
            }

            Layer tempLayer = this.app.ActiveDocument.ActivePage.CreateLayer("temp_qrcode");

            tempLayer.Activate();
            BitmapSource imageSource = (BitmapSource)img_render.Source;

            imageRender.SaveTempQrCodeFile(txt_content.Text, this.app.ActivePage.Resolution, strSize);
            StructImportOptions sio = new StructImportOptions();

            sio.MaintainLayers = true;

            ImportFilter importFilter = this.app.ActiveLayer.ImportEx(imageRender.QrCodeFilePath);

            importFilter.Finish();

            //Corel.Interop.VGCore.Clipboard cp = new Corel.Interop.VGCore.Clipboard();

            //System.Windows.Clipboard.SetImage(imageSource);
        }
Beispiel #3
0
        public void GeneralTest()
        {
            var layer1 = new Layer(null, new[] { 0.46246d, 0.56387d, 0.98518d });
            var layer2 = new Layer(null, new[] { 0.84816d, 0.00589d, 0.41893d, 0.31132d }, TanhLayerActivator.Activate, layer1);

            layer2.PreviousToLayerWeights = new[] { 0.57426d, 0.56688d, 0.30634d, 0.62644d, 0.07241d, 0.35078d, 0.62603d, 0.12419d, 0.52969d, 0.78555d, 0.44469d, 0.17940d };
            layer2.Biases = new[] { 0.84816d, 0.00589d, 0.41893d, 0.31132d };

            layer2.Activate();

            layer2.Values.AssertIsApproximately(new[] { 0.690106988761489d, 0.00588993188878884d, 0.396028631872285d, 0.30163747397554d });
        }
Beispiel #4
0
        public void CalculatesZWithoutActivator()
        {
            var last  = new Layer(3);
            var first = new Layer(2, last);

            last.Weights = Matrix.Build.DenseOfArray(new double[3, 2] {
                { 1, 2 },
                { 1.3, 0.1 },
                { 10, -5 },
            });

            last.Biases = Vec.Build.DenseOfArray(new double[] { 100, 200, 300 });

            var input          = Vec.Build.DenseOfArray(new double[] { 1, 10 });
            var expectedResult = Vec.Build.DenseOfArray(new double[] { 121, 202.3, 260 });

            var result = last.Activate(input);

            Assert.Equal(result, expectedResult);
        }
Beispiel #5
0
        public void CalculatesActivationsWithActivator()
        {
            var activator = new Sigmoid();
            var last      = new Layer(3, null, activator);
            var first     = new Layer(2, last);

            last.Weights = Matrix.Build.DenseOfArray(new double[3, 2] {
                { 1, 2 },
                { 1.3, 0.1 },
                { 10, -5 },
            });

            last.Biases = Vec.Build.DenseOfArray(new double[] { 100, 200, 300 });

            var input              = Vec.Build.DenseOfArray(new double[] { 1, 10 });
            var expectedZ          = Vec.Build.DenseOfArray(new double[] { 121, 202.3, 260 });
            var expectedActivation = activator.Activate(expectedZ);

            var result = last.Activate(input);

            Assert.Equal(result, expectedActivation);
        }
Beispiel #6
0
        public void CalculatesActivationsFromPreviousLayer()
        {
            var last   = new Layer(3);
            var middle = new Layer(3, last);
            var first  = new Layer(2, middle);

            middle.Weights = Matrix.Build.DenseOfArray(new double[3, 2] {
                { 1, 2 },
                { 1.3, 0.1 },
                { 10, -5 },
            });
            middle.Biases = Vec.Build.DenseOfArray(new double[] { 100, 200, 300 });
            last.Weights  = Matrix.Build.DenseIdentity(3);
            last.Biases   = Vec.Build.Dense(3, 10);

            first.Activations = Vec.Build.DenseOfArray(new double[] { 1, 10 });
            middle.Activate();
            var result = last.Activate();

            var expected = Vec.Build.DenseOfArray(new double[] { 131, 212.3, 270 });

            Assert.Equal(expected, result);
        }
        public override void Execute()
        {
            try
            {
                var DateTimeStart = DateTime.Now;

                DsApp.AbortRunningCommand();

                CommandMessage CmdLine = DsApp.GetCommandMessage();
                if (null == CmdLine)
                {
                    return;
                }

                //==============================================================================
                CmdLine.PrintLine("Calque '0' actif");
                Document     DsDoc = DsApp.GetActiveDocument();
                LayerManager LyMgr = DsDoc.GetLayerManager();
                Layer        L0    = LyMgr.GetLayer("0");
                L0.Activate();

                // Creer les calques de pliage
                Color c;
                dsCreateObjectResult_e Erreur;

                //==============================================================================
                CmdLine.PrintLine("Création du claque 'LIGNES DE PLIAGE'");
                Layer LigneDePliage;
                LyMgr.CreateLayer("LIGNES DE PLIAGE", out LigneDePliage, out Erreur);
                c = LigneDePliage.Color;
                c.SetColorByIndex(252);
                LigneDePliage.Color = c;

                //==============================================================================
                CmdLine.PrintLine("Création du claque 'NOTE DE PLIAGE'");
                Layer NoteDePliage = null;
                LyMgr.CreateLayer("NOTE DE PLIAGE", out NoteDePliage, out Erreur);
                c = NoteDePliage.Color;
                c.SetColorByIndex(126);
                NoteDePliage.Color = c;


                Model            Mdl   = DsDoc.GetModel();
                SketchManager    SkMgr = Mdl.GetSketchManager();
                SelectionManager SlMgr = DsDoc.GetSelectionManager();
                SelectionFilter  SlFilter;

                object   ObjType        = null;
                object   ObjEntites     = null;
                Int32[]  TabTypes       = null;
                object[] TabEntites     = null;
                string[] TabNomsCalques = null;

                //==============================================================================
                CmdLine.PrintLine("Couleur des entité sur 'DuCalque'");
                TabNomsCalques = GetTabNomsCalques(DsDoc);
                SkMgr.GetEntities(null, TabNomsCalques, out ObjType, out ObjEntites);
                TabEntites = (object[])ObjEntites;

                EntityHelper dsEntityHelper = DsApp.GetEntityHelper();

                foreach (object entity in TabEntites)
                {
                    Color ce = dsEntityHelper.GetColor(entity);
                    ce.SetNamedColor(dsNamedColor_e.dsNamedColor_ByLayer);
                    dsEntityHelper.SetColor(entity, ce);
                }

                //==============================================================================
                CmdLine.PrintLine("Transfert des lignes et notes de pliage sur les calques correspondants");
                TabNomsCalques = new string[] { "0" };
                SkMgr.GetEntities(null, TabNomsCalques, out ObjType, out ObjEntites);

                TabTypes   = (Int32[])ObjType;
                TabEntites = (object[])ObjEntites;

                for (int i = 0; i < TabEntites.GetLength(0); i++)
                {
                    dsObjectType_e tpe = (dsObjectType_e)TabTypes[i];

                    if (tpe == dsObjectType_e.dsLineType)
                    {
                        Line L = (Line)TabEntites[i];
                        if (L.LineStyle == "SLD-Center")
                        {
                            L.Layer = LigneDePliage.Name;
                        }
                    }
                    else if (tpe == dsObjectType_e.dsNoteType)
                    {
                        Note N = (Note)TabEntites[i];
                        N.Layer = NoteDePliage.Name;
                    }
                }

                //==============================================================================
                CmdLine.PrintLine("Conversion des textes à graver en lignes");
                SlFilter = SlMgr.GetSelectionFilter();
                SlFilter.Clear();
                SlFilter.AddEntityType(dsObjectType_e.dsNoteType);
                SlFilter.Active = true;

                TabNomsCalques = new string[] { "GRAVURE" };
                SkMgr.GetEntities(SlFilter, TabNomsCalques, out ObjType, out ObjEntites);
                TabTypes   = (Int32[])ObjType;
                TabEntites = ObjEntites as object[];

                if (TabEntites != null && TabEntites.Length > 0)
                {
                    CmdLine.PrintLine(TabEntites.Length + " texte(s) convertis");
                    foreach (var Texte in TabEntites)
                    {
                        SlMgr.ClearSelections(dsSelectionSetType_e.dsSelectionSetType_Current);
                        dsEntityHelper.Select(Texte, true);
                        DsApp.RunCommand("ECLATERTEXTE\n", true);
                    }
                }

                DsApp.RunCommand("_CSICON\nP\n", true);

                //==============================================================================
                CmdLine.PrintLine("Purger le dessin");
                DsApp.RunCommand("_-CLEAN\n_All\n*\n_No\n", true);

                TimeSpan t = DateTime.Now - DateTimeStart;
                CmdLine.PrintLine(String.Format("Executé en {0}", GetSimplestTimeSpan(t)));
            }
            catch (Exception e)
            { Log.Write(e); }
        }