コード例 #1
0
        private static GaussianRandom grnd = new GaussianRandom(); //gausova raspodela za random vrednosti

        /// <summary>
        /// https://en.wikipedia.org/wiki/Artificial_neuron
        /// ulaz1*tezina1
        /// ulaz1*tezina2
        /// bias(+1*tezina)
        /// sve se sabere
        /// provuce se kroz aktivacionu funkciju
        /// </summary>
        /// <param name="n_inputs"></param>
        /// <param name="activation"> String naziv aktivacione funkcije </param>
        public NeuronNode(int n_inputs, string activation)
        {
            this.n_inputs        = n_inputs;
            this.multiplyNodes   = new List <MultiplyNode>();   //for inputs and weights
            this.sumNode         = new SumNode();               //for sum of inputs*weights
            this.previous_deltas = new List <double>();         //vrednost delti u prosloj iteraciji
            this.gradients       = new List <List <double> >(); //lokalni gradijenti
            MultiplyNode mulNode;

            //init inputs
            //collect inputs and corresponding weights
            for (int i = 0; i < this.n_inputs; i++)
            {
                mulNode = new MultiplyNode();
                double b = grnd.NextGaussian(0.3, 0.5);
                mulNode.x = new List <double>()
                {
                    1.0, b
                };
                this.multiplyNodes.Add(mulNode);
                previous_deltas.Add(0.0);
            }

            //init bias node and weight
            mulNode = new MultiplyNode();
            double m = grnd.NextGaussian(0.0, 0.01);

            mulNode.x = new List <double>()
            {
                1.0, m
            };
            this.multiplyNodes.Add(mulNode);
            previous_deltas.Add(0.0);

            // TODO: Ovde dodajem ako dodajem neku drugu aktivacionu funkciju

            /*
             * if else(activation.Equals("TangesHiperbolic").....
             */
            if (activation.Equals("sigmoid"))
            {
                this.activation_node = new SigmoidNode();
            }
            else if (activation.Equals("tanh"))
            {
                this.activation_node = new TanhNode();
            }
            else
            {
                throw new NotImplementedException("Activation function is not supported");
            }
        }
コード例 #2
0
        /// <summary>
        /// https://en.wikipedia.org/wiki/Artificial_neuron
        /// input1*weight1
        /// input1*weight2
        /// bias(+1*weight)
        /// </summary>
        /// <param name="n_inputs"></param>
        /// <param name="activation"></param>
        public NeuronNode(int n_inputs, string activation)
        {
            this.n_inputs        = n_inputs;
            this.multiplyNodes   = new List <MultiplyNode>();   //for inputs and weights
            this.sumNode         = new SumNode();               //for sum of inputs*weights
            this.previous_deltas = new List <double>();         // values of las iteration
            this.gradients       = new List <List <double> >(); //local gradients
            MultiplyNode mulNode;

            //init inputs
            //collect inputs and corresponding weights
            for (int i = 0; i < this.n_inputs; i++)
            {
                mulNode = new MultiplyNode();
                double b = grnd.NextGaussian(0.3, 0.5);
                mulNode.x = new List <double>()
                {
                    1.0, b
                };
                this.multiplyNodes.Add(mulNode);
                previous_deltas.Add(0.0);
            }

            //init bias node and weight
            mulNode = new MultiplyNode();
            double m = grnd.NextGaussian(0.0, 0.01);

            mulNode.x = new List <double>()
            {
                1.0, m
            };
            this.multiplyNodes.Add(mulNode);
            previous_deltas.Add(0.0);

            if (activation.Equals("sigmoid"))
            {
                this.activation_node = new SigmoidNode();
            }
            if (activation.Equals("relu"))
            {
                this.activation_node2 = new RelUNode();
            }
            else
            {
                throw new NotImplementedException("Activation function is not supported");
            }

            this.activation = activation;
        }
コード例 #3
0
        /// <summary>
        /// https://en.wikipedia.org/wiki/Artificial_neuron
        /// ulaz1*tezina1
        /// ulaz1*tezina2
        /// bias(+1*tezina)
        /// sve se sabere
        /// provuce se kroz aktivacionu funkciju
        /// </summary>
        /// <param name="n_inputs"></param>
        /// <param name="activation"></param>
        public NeuronNode(int n_inputs, string activation)
        {
            this.n_inputs        = n_inputs;
            this.multiplyNodes   = new List <MultiplyNode>();   //for inputs and weights
            this.sumNode         = new SumNode();               //for sum of inputs*weights
            this.previous_deltas = new List <double>();         //vrednost delti u prosloj iteraciji
            this.gradients       = new List <List <double> >(); //lokalni gradijenti
            MultiplyNode mulNode;

            //init inputs
            //collect inputs and corresponding weights
            for (int i = 0; i < this.n_inputs; i++)
            {
                mulNode   = new MultiplyNode();
                mulNode.x = new List <double>()
                {
                    1.0, (rnd.NextDouble() - 0.5) / 50.0
                };                                                                      //izemdju -0.1 i 0.1
                this.multiplyNodes.Add(mulNode);
                previous_deltas.Add(0.0);
            }

            //init bias node and weight
            mulNode   = new MultiplyNode();
            mulNode.x = new List <double>()
            {
                1.0, (rnd.NextDouble() - 0.5 / 50.0)
            };                                                                       // -0.01 do 0.01
            this.multiplyNodes.Add(mulNode);
            previous_deltas.Add(0.0);

            if (activation.Equals("sigmoid"))
            {
                this.activation_node = new SigmoidNode();
            }
            else
            {
                throw new NotImplementedException("Activation function is not supported");
            }
        }