/// <summary> /// Normalize a row vector using the hyperbolic tangent (tanh)function. /// </summary> /// <param name="row"></param> /// <param name="properties"></param> /// <returns></returns> public Vector Normalize(Vector row, numl.Math.Summary properties) { if (row == null) { throw new ArgumentNullException("Row was null"); } double[] item = new double[row.Length]; for (int i = 0; i < row.Length; i++) { item[i] = this.Tangent.Compute(row[i]); } return item; }
/// <summary> /// Normalize a row vector using Z-Score normalization on the supplied feature properties. /// </summary> /// <param name="row"></param> /// <param name="properties"></param> /// <returns></returns> public Vector Normalize(Vector row, numl.Math.Summary properties) { if (row == null) { throw new ArgumentNullException("Row was null"); } double[] item = new double[row.Length]; for (int i = 0; i < row.Length; i++) { item[i] = (row[i] - properties.Average[i]) / properties.StandardDeviation[i]; item[i] = (double.IsNaN(item[i]) || double.IsInfinity(item[i]) ? 0d : item[i]); } return item; }
/// <summary> /// Update and return the new Theta value. /// </summary> /// <param name="properties">Properties for the optimization routine.</param> /// <returns></returns> public override Vector UpdateTheta(numl.Math.Optimization.OptimizerProperties properties) { Vector v = (this.Momentum * properties.Theta) - (properties.LearningRate * properties.Gradient); return properties.Theta + this.Momentum * v - properties.LearningRate * properties.Gradient; }