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); }
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); }