public void RelativeParameterConstructorTest()
        {
            var criteria = new RelativeParameterConvergence(iterations: 0, tolerance: 0.1);

            int progress = 1;

            double[] parameters = { 12345.6, 952.12, 1925.1 };

            do
            {
                // Do some processing...


                // Update current iteration information:
                criteria.NewValues = parameters.Divide(progress++);
            } while (!criteria.HasConverged);


            // The method will converge after reaching the
            // maximum of 11 iterations with a final value
            // of { 1234.56, 95.212, 192.51 }:

            int iterations = criteria.CurrentIteration; // 11
            var v          = criteria.OldValues;        // { 1234.56, 95.212, 192.51 }


            Assert.AreEqual(11, criteria.CurrentIteration);
            Assert.AreEqual(1234.56, criteria.OldValues[0]);
            Assert.AreEqual(95.212, criteria.OldValues[1]);
            Assert.AreEqual(192.51, criteria.OldValues[2]);
        }
 /// <summary>
 ///   Constructs a new Gradient Descent algorithm.
 /// </summary>
 ///
 public LogisticGradientDescent()
 {
     convergence = new RelativeParameterConvergence()
     {
         MaxIterations = 0,
         Tolerance     = 1e-8
     };
 }
Ejemplo n.º 3
0
        /// <summary>
        ///   Constructs a new Newton-Raphson learning algorithm
        ///   for Cox's Proportional Hazards models.
        /// </summary>
        ///
        public ProportionalHazardsNewtonRaphson()
        {
            this.convergence = new RelativeParameterConvergence()
            {
                Iterations = 0,
                Tolerance  = 1e-5
            };

            this.Estimator = HazardEstimator.BreslowNelsonAalen;
            this.Ties      = HazardTiesMethod.Efron;
            this.Lambda    = 0.1;
            this.Token     = new CancellationToken();
        }
        /// <summary>
        ///   Constructs a new Newton-Raphson learning algorithm
        ///   for Cox's Proportional Hazards models.
        /// </summary>
        ///
        /// <param name="hazards">The model to estimate.</param>
        ///
        public ProportionalHazardsNewtonRaphson(ProportionalHazards hazards)
        {
            this.regression     = hazards;
            this.parameterCount = hazards.Coefficients.Length;

            this.hessian  = new double[parameterCount, parameterCount];
            this.gradient = new double[parameterCount];

            this.partialHessian  = new double[parameterCount, parameterCount];
            this.partialGradient = new double[parameterCount];

            this.convergence = new RelativeParameterConvergence()
            {
                Iterations = 0,
                Tolerance  = 1e-5
            };
        }
Ejemplo n.º 5
0
        /// <summary>
        ///   Constructs a new Newton-Raphson learning algorithm
        ///   for Cox's Proportional Hazards models.
        /// </summary>
        ///
        /// <param name="hazards">The model to estimate.</param>
        ///
        public ProportionalHazardsNewtonRaphson(ProportionalHazards hazards)
        {
            this.regression     = hazards;
            this.parameterCount = hazards.Coefficients.Length;

            this.hessian  = new double[parameterCount, parameterCount];
            this.gradient = new double[parameterCount];

            this.partialHessian  = new double[parameterCount, parameterCount];
            this.partialGradient = new double[parameterCount];

            this.convergence = new RelativeParameterConvergence()
            {
                Iterations = 0,
                Tolerance  = 1e-5
            };

            this.Estimator = HazardEstimator.BreslowNelsonAalen;
            this.Ties      = HazardTiesMethod.Efron;
            this.Lambda    = 0.1;
        }
 /// <summary>
 ///   Creates a new <see cref="LowerBoundNewtonRaphson"/>.
 /// </summary>
 ///
 public LowerBoundNewtonRaphson()
 {
     convergence = new RelativeParameterConvergence();
 }