示例#1
0
 /// <summary>
 /// Creates an upper triangular array of delegates to calculate portions of each element of the hessian matrix
 /// </summary>
 protected override void CreateHessianDelegates()
 {
     HessianFunctions       = new Delegates.DerivativePortionCalculator[pParameters.Length, pParameters.Length];
     HessianFunctions[0, 0] = new Delegates.DerivativePortionCalculator(CalculateAADerivateComponent);
     HessianFunctions[0, 1] = new Delegates.DerivativePortionCalculator(CalculateABDerivativeComponent);
     HessianFunctions[1, 1] = new Delegates.DerivativePortionCalculator(CalculateBBDerivativeComponent);
 }
示例#2
0
        /// <summary>
        /// Since for sum of squares the method is simply a sum over each of the components, this general method performs the loop
        /// </summary>
        /// <param name="Params"></param>
        /// <param name="calc"></param>
        /// <returns></returns>
        private double EvaluateDerivative(double[] Params, Delegates.DerivativePortionCalculator calc)
        {
            double sum = 0;

            for (int i = 0; i < Params.Length; i++)
            {
                sum += calc(Params, x[i], y[i]);
            }
            return(sum);
        }
示例#3
0
        /// <summary>
        /// Fill in the Hessian matrix for the sum of squares function
        /// </summary>
        /// <param name="Params"></param>
        /// <param name="Hessian"></param>
        private void EvaluateHessian(double[] Params, ref double func, double[] grad, double[,] Hessian, object obj)
        {
            EvaluateSumOfSquaresGradient(Params, ref func, grad, obj);
            int n = Params.Length;

            for (int i = 0; i < n; i++)
            {
                for (int j = i; j < n; j++)
                {
                    Delegates.DerivativePortionCalculator calcDeriv = HessianFunctions[i, j];
                    Hessian[i, j] = EvaluateDerivative(Params, calcDeriv);
                    if (i != j)
                    {
                        Hessian[j, i] = Hessian[i, j];
                    }
                }
            }
        }