/// <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); }
/// <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 (var i = 0; i < this.MaxIterations; i++) { var 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; }
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); }
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); 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); for (int i = 0; i < MaxIterations; i++) { properties.Iteration = i; 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); } var output = String.Format("Run ({0}/{1}): {2}", i, MaxIterations, network.Cost); OnModelChanged(this, ModelEventArgs.Make(model, output)); } return model; }