Exemplo n.º 1
0
        /// <summary>Generate model based on a set of examples.</summary>
        /// <param name="x">The Matrix to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <returns>Model.</returns>
        public override IModel Generate(Matrix x, Vector y)
        {
            // because I said so...
            if (this.MaxIterations == -1)
            {
                this.MaxIterations = x.Rows * 1000;
            }

            var network = Network.Default(this.Descriptor, x, y, this.Activation);
            var model   = new NeuralNetworkModel {
                Descriptor = this.Descriptor, Network = network
            };

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

            for (int i = 0; i < this.MaxIterations; i++)
            {
                int idx = i % x.Rows;
                network.Forward(x[idx, VectorType.Row]);
                //OnModelChanged(this, ModelEventArgs.Make(model, "Forward"));
                network.Back(y[idx], this.LearningRate);
                var output = String.Format("Run ({0}/{1})", i, this.MaxIterations);
                this.OnModelChanged(this, ModelEventArgs.Make(model, output));
            }

            return(model);
        }
Exemplo n.º 2
0
        /// <summary>Generate model based on a set of examples.</summary>
        /// <param name="x">The Matrix to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <returns>Model.</returns>
        public override IModel Generate(Matrix x, Vector y)
        {
            // because I said so...
            if (MaxIterations == -1)
            {
                MaxIterations = x.Rows * 1000;
            }

            var network = Network.Default(Descriptor, x, y, Activation);

            for (int i = 0; i < MaxIterations; i++)
            {
                int idx = i % x.Rows;
                network.Forward(x[idx, VectorType.Row]);
                network.Back(y[idx], LearningRate);
            }

            return(new NeuralNetworkModel {
                Descriptor = Descriptor, Network = network
            });
        }