예제 #1
0
        /// <summary>Defaults.</summary>
        /// <param name="network">The network.</param>
        /// <param name="d">The Descriptor to process.</param>
        /// <param name="x">The Vector to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <param name="activationFunction">The activation.</param>
        /// <param name="outputFunction">The ouput function for hidden nodes (Optional).</param>
        /// <param name="epsilon">epsilon</param>
        /// <returns>A Network.</returns>
        public static Network Create(
            this Network network,
            Descriptor d,
            Matrix x,
            Vector y,
            IFunction activationFunction,
            IFunction outputFunction = null,
            double epsilon           = double.NaN)
        {
            // set output to number of choices of available
            // 1 if only two choices
            var distinct = y.Distinct().Count();
            var output   = distinct > 2 ? distinct : 1;
            // identity funciton for bias nodes
            IFunction ident = new Ident();

            // set number of hidden units to (Input + Hidden) * 2/3 as basic best guess.
            var hidden = (int)System.Math.Ceiling((x.Cols + output) * 2.0 / 3.0);

            return(network.Create(
                       x.Cols,
                       output,
                       activationFunction,
                       outputFunction,
                       fnNodeInitializer: (l, i) =>
            {
                if (l == 0)
                {
                    return new Neuron(false)
                    {
                        Label = d.ColumnAt(i - 1),
                        ActivationFunction = activationFunction,
                        NodeId = i,
                        LayerId = l
                    }
                }
                ;
                if (l == 2)
                {
                    return new Neuron(false)
                    {
                        Label = Network.GetLabel(i, d),
                        ActivationFunction = activationFunction,
                        NodeId = i,
                        LayerId = l
                    }
                }
                ;
                return new Neuron(false)
                {
                    ActivationFunction = activationFunction, NodeId = i, LayerId = l
                };
            },
                       hiddenLayers: hidden));
        }
예제 #2
0
        /// <summary>Defaults.</summary>
        /// <param name="d">The Descriptor to process.</param>
        /// <param name="x">The Vector to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <param name="activationFunction">The activation.</param>
        /// <param name="outputFunction">The ouput function for hidden nodes (Optional).</param>
        /// <param name="epsilon">epsilon</param>
        /// <returns>A Network.</returns>
        public static Network Create(this Network network, Descriptor d, Matrix x, Vector y, IFunction activationFunction, IFunction outputFunction = null,
                                     double epsilon = double.NaN, ILossFunction lossFunction = null)
        {
            // set output to number of choices of available
            // 1 if only two choices
            int distinct = y.Distinct().Count();
            int output   = distinct > 2 ? distinct : 1;
            // identity funciton for bias nodes
            IFunction ident = new Ident();

            // set number of hidden units to (Input + Hidden) * 2/3 as basic best guess.
            int hidden = (int)System.Math.Ceiling((double)(x.Cols + output) * 2.0 / 3.0);

            return(network.Create(x.Cols, output, activationFunction, outputFunction,
                                  fnNodeInitializer: new Func <int, int, NodeType, Neuron>((l, i, type) =>
            {
                if (type == NodeType.Input)
                {
                    return new Neuron(false)
                    {
                        Label = d.ColumnAt(i - 1), ActivationFunction = activationFunction, NodeId = i, LayerId = l
                    }
                }
                ;
                else if (type == NodeType.Output)
                {
                    return new Neuron(false)
                    {
                        Label = Network.GetLabel(i, d), ActivationFunction = activationFunction, NodeId = i, LayerId = l
                    }
                }
                ;
                else
                {
                    return new Neuron(false)
                    {
                        ActivationFunction = activationFunction, NodeId = i, LayerId = l
                    }
                };
            }), lossFunction: lossFunction, hiddenLayers: hidden));
        }