Create() public static method

Creates a new Network Properties object for use in training a neural network model.
public static Create ( numl.Supervised.NeuralNetwork.Network network, int examples, int features, double learningRate, double lambda, int maxIterations, object parameters = null ) : NetworkTrainingProperties
network numl.Supervised.NeuralNetwork.Network Network being optimized.
examples int Number of training examples.
features int Number of features in the training examples.
learningRate double Learning rate.
lambda double Lambda (weight decay).
maxIterations int Maximum number of iterations.
parameters object Optional parameters object used when training networks. /// Usage: parameters = new { Obj1, Obj2, Obj3... } ///
return NetworkTrainingProperties
示例#1
0
        public virtual ISequenceModel Generate(Matrix X, Matrix Y)
        {
            this.Preprocess(X);
            // because I said so...
            if (MaxIterations == -1)
            {
                MaxIterations = 500;
            }

            var network = Network.New().Create(X.Cols, Y.Cols, Activation, OutputFunction, epsilon: Epsilon);

            INetworkTrainer trainer = new GradientDescentTrainer();

            var model = new NeuralNetworkModel
            {
                Descriptor        = Descriptor,
                NormalizeFeatures = base.NormalizeFeatures,
                FeatureNormalizer = base.FeatureNormalizer,
                FeatureProperties = base.FeatureProperties,
                Network           = network
            };

            OnModelChanged(this, ModelEventArgs.Make(model, "Initialized"));

            NetworkTrainingProperties properties = NetworkTrainingProperties.Create(network, X.Rows, X.Cols, this.LearningRate, this.Lambda, this.MaxIterations);

            Vector loss = Vector.Zeros(this.MaxIterations);

            for (int i = 0; i < MaxIterations; i++)
            {
                properties.Iteration = i;

                network.ResetStates(properties);

                for (int x = 0; x < X.Rows; x++)
                {
                    network.Forward(X[x, VectorType.Row]);
                    //OnModelChanged(this, ModelEventArgs.Make(model, "Forward"));
                    network.Back(Y[x, VectorType.Row], properties, trainer);

                    loss[i] += network.Cost;
                }

                var output = String.Format("Run ({0}/{1}): {2}", i, MaxIterations, network.Cost);
                OnModelChanged(this, ModelEventArgs.Make(model, output));

                if (this.LossMinimized(loss, i))
                {
                    break;
                }
            }

            return(model);
        }
示例#2
0
        public virtual ISequenceModel Generate(Matrix X, Matrix Y)
        {
            Preprocess(X);
            // because I said so...
            if (MaxIterations == -1)
            {
                MaxIterations = 500;
            }

            var network = Network.New().Create(X.Cols, Y.Cols, Activation, OutputFunction, epsilon: Epsilon);

            var model = new NeuralNetworkModel
            {
                Descriptor        = Descriptor,
                NormalizeFeatures = NormalizeFeatures,
                FeatureNormalizer = FeatureNormalizer,
                FeatureProperties = FeatureProperties,
                Network           = network
            };

            OnModelChanged(this, ModelEventArgs.Make(model, "Initialized"));

            var properties = NetworkTrainingProperties.Create(network, X.Rows, X.Cols, LearningRate, Lambda, MaxIterations);

            for (var i = 0; i < MaxIterations; i++)
            {
                properties.Iteration = i;

                for (var x = 0; x < X.Rows; x++)
                {
                    network.Forward(X[x, VectorType.Row]);
                    //OnModelChanged(this, ModelEventArgs.Make(model, "Forward"));
                    network.Back(Y[x, VectorType.Row], properties);
                }

                var output = string.Format("Run ({0}/{1}): {2}", i, MaxIterations, network.Cost);
                OnModelChanged(this, ModelEventArgs.Make(model, output));
            }

            return(model);
        }