public virtual CNN.Filter Configure(int?outputfieldsize)
            {
                if (outputfieldsize != null)
                {
                    this.outputfieldsize = outputfieldsize.Value;
                }

                // 0.
                int c = 0;

                for (int i = 0; i < sources.Count; i++)
                {
                    c += sources[i].Columns * sources[i].Rows;
                }

                // 1. set target
                target = new fMap();
                target.Configure(c, 1);

                // 2. set target elements
                for (int i = 0; i < c; i++)
                {
                    target.SetElement(i, 0, new Node(new double?[this.outputfieldsize]));
                }

                return(this);
            }
Exemple #2
0
        public override Image Configure(int rows, int cols, double?min, double?max)
        {
            Foundation.Node node;

            // 0. set range
            this.max = (max == null ? +1.0 : max.Value);
            this.min = (min == null ? -1.0 : min.Value);

            this.cols = cols;
            this.rows = rows;

            // 1. set delta
            dq = (max.Value - min.Value) / 255;

            // 2. initialize fmap
            fMap fmap = (fMap) new fMap()
                        .Configure(rows, cols);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    node = new Foundation.Node(new double?[] { null, null });
                    fmap.SetElement(i, j, node);
                }
            }

            fmaps.Add(fmap);

            return(this);
        }
Exemple #3
0
        public override Model.Unit Configure(string configuration)
        {
            base.Configure(configuration);

            Foundation.Node node;

            // 1. set delta
            dq = (max.Value - min.Value) / 255;

            // 2. initialize fmap
            fMap fmap = (fMap) new fMap()
                        .Configure(rows, cols);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    node = new Foundation.Node(new double?[] { null, null });
                    fmap.SetElement(i, j, node);
                }
            }

            fmaps.Add(fmap);

            return(this);
        }
Exemple #4
0
        /// <summary>
        /// configures connected layer
        /// </summary>
        /// <param name="configuration">neu=outputperceptron; act=sigmoid(a=-1, b=2, c=6); nodes=6; fieldsize=2(def:2)</param>
        /// <returns></returns>
        public override Model.Unit Configure(string configuration)
        {
            string cfg = ANN.Global.Parser.RemoveWhiteSpaces(configuration);

            string[] a    = ANN.Global.Parser.Split(cfg, ";"), b;
            int      nofN = ANN.Global.Parser.Extract <int>(a, new string[] { "nodes" }, ANN.Global.Parser.Option.None, out b);
            string   neu  = ANN.Global.Parser.Extract <string>(b, new string[] { "neu", "neuron" }, ANN.Global.Parser.Option.None, out a);

            cfg = ANN.Global.Parser.Build(a, 0, ";");

            neurons = new ANN.Neuron[nofN];

            for (int i = 0; i < nofN; i++)
            {
                switch (neu)
                {
                case "hiddenperceptron":
                    neurons[i] = new ANN.Neurons.Perceptron.Hidden(cfg);
                    break;

                case "outputperceptron":
                    neurons[i] = new ANN.Neurons.Perceptron.Output(cfg);
                    break;
                }

                neurons[i].SetElement(0.0);
            }

            ANN.Neuron n;

            fmaps.Clear();

            fMap sfmap = Input[0];
            fMap tfmap = (fMap) new fMap()
                         .Configure(neurons.Length, 1);

            for (int i = 0; i < neurons.Length; i++)
            {
                n = neurons[i];
                // 1. connect sources
                for (int j = 0; j < sfmap.Rows; j++)
                {
                    n.Source = sfmap.GetElement(j, 0);
                }
                // 2. set target into map
                tfmap.SetElement(i, 0, n.Output);
            }

            fmaps.Add(tfmap);

            return(this);
        }
Exemple #5
0
        public Kernel(fMap source, int?padding, int?size)
            : base(source, padding, size)
        {
            synapse = new Synapse[size.Value, size.Value];

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    synapse[i, j] = new Synapse(null, Math.Daemon.NextGaussianDouble(0.0, 0.004)[0], 0.0);
                }
            }
        }
Exemple #6
0
            public override CNN.Filter Configure(string configuration)
            {
                bias = (fMap) new fMap()
                       .Configure(1, 1);
                bias.SetElement(0, 0, new Foundation.Node(new double?[] { 1.0, null }));

                string cfg = Global.Parser.RemoveWhiteSpaces(configuration);

                string[] a = Global.Parser.Split(cfg, ";"), b;
                padding = Global.Parser.Extract <int?>(a, new string[] { "kernelSize" }, Global.Parser.Option.StripDefaultToken, out b) / 2;

                kernel.Add(new Kernel(bias, 0, 1));
                base.Configure(cfg);

                return(this);
            }
Exemple #7
0
            protected override void ConstructTargetMap()
            {
                int nr = ((rows.Value - kernelSize.Value) / stride.Value) + 1;
                int nc = ((cols.Value - kernelSize.Value) / stride.Value) + 1;

                target = new fMap();
                target.Configure(nr, nc);

                for (int i = 0; i < nr; i++)
                {
                    for (int j = 0; j < nc; j++)
                    {
                        target.SetElement(i, j, new Foundation.Node(new double?[outputfieldSize]));
                    }
                }
            }
Exemple #8
0
            public override CNN.Filter Configure <T>(double?[] funcparams, int kernelSize, int?stride, int?outputfieldSize)
            {
                bias = (fMap) new fMap()
                       .Configure(1, 1);
                bias.SetElement(0, 0, new Foundation.Node(new double?[] { 1.0, null }));

                padding = kernelSize / 2;

                Kernel k = new Kernel(bias, 0, 1);

                k.WeightCorrection = new double?[] { null };
                kernel.Add(k);

                base.Configure <T>(funcparams, kernelSize, stride, outputfieldSize);

                return(this);
            }
Exemple #9
0
            public virtual Filter Configure <T>(double?[] funcparams, int kernelsize, int?kernelstride, int?kernelpadding,
                                                int?kernelweightfieldsize, int?outputfieldsize)
                where T : Function, new()
            {
                // 0. construct bias
                bias = (fMap) new fMap()
                       .Configure(1, 1);
                bias.SetElement(0, 0, new Foundation.Node(new double?[] { 1.0, null }));
                Kernel kernel = new Kernel();

                kernel.Configure(1, 1, 0, 0, kernelweightfieldsize == null ? 2 : kernelweightfieldsize.Value, true);
                kernel.Source = bias;
                kernels.Add(kernel);

                // 1. construct kernels
                for (int i = 0; i < sources.Count; i++)
                {
                    kernel = new Kernel();
                    kernel.Configure(kernelsize, kernelsize, kernelstride.Value, kernelpadding.Value, kernelweightfieldsize.Value);
                    kernel.Source = sources[i];
                    kernels.Add(kernel);
                }

                // 2. construct function
                function = new T();
                function.Configure(funcparams);
                function.Input = new double[kernels.Count];

                // 3. construct target
                int rows = ((sources[0].Rows - kernel.Rows + (2 * kernel.Padding)) / kernel.Stride) + 1;
                int cols = ((sources[0].Columns - kernel.Columns + (2 * kernel.Padding)) / kernel.Stride) + 1;

                target = new fMap();
                target.Configure <double?>(rows, cols, outputfieldsize == null ? 2 : outputfieldsize.Value);

                grad = new double?[target.Rows][];
                for (int i = 0; i < target.Rows; i++)
                {
                    grad[i] = new double?[target.Columns];
                }

                SetElement(grad);

                return(this);
            }
Exemple #10
0
            public virtual Filter Configure <T>(int kernelsize, int?kernelstride, int?kernelpadding, int?outputfieldsize)
                where T : CNN.Kernel, new()
            {
                Kernel kernel = new T();

                kernel.Configure(kernelsize, kernelsize, kernelstride, kernelpadding);
                kernel.Source = sources[0];
                kernels.Add(kernel);

                this.outputfieldsize = outputfieldsize == null ? 2 : outputfieldsize.Value;

                // size = (((src.Size - kernel.Size) + (2 * kernel.Padding)) / kernel.Stride) + 1;
                int rows = ((sources[0].Rows - kernel.Rows + (2 * kernel.Padding)) / kernel.Stride) + 1;
                int cols = ((sources[0].Columns - kernel.Columns + (2 * kernel.Padding)) / kernel.Stride) + 1;

                target = new fMap();
                target.Configure <double?>(rows, cols, this.outputfieldsize);

                return(this);
            }
Exemple #11
0
            public override CNN.Filter Configure(string configuration)
            {
                string cfg = ANN.Global.Parser.RemoveWhiteSpaces(configuration);

                string[] a = ANN.Global.Parser.Split(cfg, "=");

                switch (a[0])
                {
                case "outputfieldsize":
                    outputfieldsize = int.Parse(a[1]);
                    break;

                case "void":
                    break;

                default:
                    throw new Exception();
                }

                // 0.
                int c = 0;

                for (int i = 0; i < sources.Count; i++)
                {
                    c += sources[i].Columns * sources[i].Rows;
                }

                // 1. set target
                target = new fMap();
                target.Configure(c, 1);

                // 2. set target elements
                for (int i = 0; i < c; i++)
                {
                    target.SetElement(i, 0, new Node(new double?[outputfieldsize]));
                }

                return(this);
            }
Exemple #12
0
            protected override void ConstructTargetMap()
            {
                int nr = ((rows.Value - kernelSize.Value + (2 * padding.Value)) / stride.Value) + 1;
                int nc = ((cols.Value - kernelSize.Value + (2 * padding.Value)) / stride.Value) + 1;

                double?[][] gradient = new double?[nr][];
                for (int i = 0; i < nr; i++)
                {
                    gradient[i] = new double?[nc];
                }

                Gradient = gradient;

                target = new fMap();
                target.Configure(nr, nc);

                for (int i = 0; i < nr; i++)
                {
                    for (int j = 0; j < nc; j++)
                    {
                        target.SetElement(i, j, new Foundation.Node(new double?[outputfieldSize]));
                    }
                }
            }
Exemple #13
0
            public override CNN.Filter Configure(string configuration)
            {
                bias = (fMap) new fMap()
                       .Configure(1, 1);
                bias.SetElement(0, 0, new Foundation.Node(new double?[] { 1.0, null }));
                string cfg = Global.Parser.RemoveWhiteSpaces(configuration);

                string[] a = Global.Parser.Split(cfg, ";");
                cfg = Global.Parser.Extract <string>(a, new string[] { "ker", "kernel" }, ANN.Global.Parser.Option.None, out string[] b);
                a   = Global.Parser.Split(cfg, "(", ")");
                if (a[0].CompareTo("convolution") != 0)
                {
                    throw new Exception();
                }
                a   = Global.Parser.Split(a[1], ",");
                cfg = Global.Parser.Extract <string>(a, new string[] { "weightfieldsize" }, Global.Parser.Option.None, out b);
                Kernel kernel = new Kernel();

                kernel.Configure(1, 1, 0, 0, int.Parse(cfg));
                kernel.Source = bias;
                kernels.Add(kernel);

                base.Configure(configuration);

                function.Input = new double[kernels.Count];

                grad = new double?[target.Rows][];
                for (int i = 0; i < target.Rows; i++)
                {
                    grad[i] = new double?[target.Columns];
                }

                SetElement(grad);

                return(this);
            }