public double ComputePartialDerivative(functionDelegate function, Parameter parameter, int order, double currentFunctionValue)
        {
            int numberOfPoints = _coefficients.Length;
            double result = 0.0;
            double originalValue = parameter;
            double[] points = new double[numberOfPoints];
            double derivativeStepSize = parameter.DerivativeStepSize;
            int centerPoint = (numberOfPoints - 1) / 2;

            for (int i = 0; i < numberOfPoints; i++)
            {
                if (i != centerPoint)
                {
                    parameter.Value = originalValue + ((double)(i - centerPoint)) * derivativeStepSize;
                    points[i] = function();
                }
                else
                {
                    points[i] = currentFunctionValue;
                }
            }
            result = ComputeDerivative(points, order, centerPoint, derivativeStepSize);
            parameter.Value = originalValue;
            return result;
        }
Beispiel #2
0
        public double[] ComputePartialDerivatives(functionDelegate function, Parameter parameter, int[] derivativeOrders, double currentFunctionValue)
        {
            int numberOfPoints = _coefficients.Length;

            double[] result        = new double[derivativeOrders.Length];
            double   originalValue = parameter;

            double[] points             = new double[numberOfPoints];
            double   derivativeStepSize = parameter.DerivativeStepSize;
            int      centerPoint        = (numberOfPoints - 1) / 2;

            for (int i = 0; i < numberOfPoints; i++)
            {
                if (i != centerPoint)
                {
                    parameter.Value = originalValue + ((double)(i - centerPoint)) * derivativeStepSize;
                    points[i]       = function();
                }
                else
                {
                    points[i] = currentFunctionValue;
                }
            }
            for (int i = 0; i < derivativeOrders.Length; i++)
            {
                result[i] = ComputeDerivative(points, derivativeOrders[i], centerPoint, derivativeStepSize);
            }
            parameter.Value = originalValue;
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// 增加控件点击事件
        /// </summary>
        /// <param name="function">函数名</param>
        /// <param name="controlName">控件名</param>
        public void AddContorlClickMethod(functionDelegate function, ControlNames controlName)
        {
            Control control = GetControlByName(controlName);

            if (control == null)
            {
                return;
            }
            control.Click += new EventHandler(function);
        }
        static void Main(string[] args)
        {
            functionDelegate d1 = addNum;
            functionDelegate d2 = mulNum;

            functionDelegate d3 = d1 + d2;

            d3(4, 5);
            Console.ReadKey();
        }
Beispiel #5
0
        public LevenbergMarquardt(functionDelegate regressionFunction, Parameter[] regressionParameters, Parameter[] observedParameters, double[,] data, int numberOfDerivativePoints)
        {
            Debug.Assert(data.GetLength(0) == observedParameters.Length + 1);
            _data = data;
            _observedParameters   = observedParameters;
            _regressionParameters = regressionParameters;
            _regressionFunction   = regressionFunction;
            int numberOfParameters = _regressionParameters.Length;
            int numberOfPoints     = data.GetLength(1);

            _derivatives = new Derivatives(numberOfDerivativePoints);

            _jacobian              = new Matrix(numberOfPoints, numberOfParameters);
            _residuals             = new Matrix(numberOfPoints, 1);
            _regressionParameters0 = new Matrix(numberOfParameters, 1);
        }
        private void Run()
        {
            // Register delegate methods
            functions += ToUpperCase;
            functions += AddSpaces;
            functions += delegate(ref string s) {
                s =  "{" + s + "}";
            };

            //

            string input = "testing";
            functions(ref input); // invoke all registered methods

            Console.WriteLine(input);
        }
        public double ComputePartialDerivative(functionDelegate function, Parameter parameter, int order)
        {
            var numberOfPoints = _coefficients.Length;
            double originalValue = parameter;
            var points = new double[numberOfPoints];
            var derivativeStepSize = parameter.DerivativeStepSize;
            var centerPoint = (numberOfPoints - 1) / 2;

            for (var i = 0; i < numberOfPoints; i++)
            {
                parameter.Value = originalValue + (i - centerPoint) * derivativeStepSize;
                points[i] = function();
            }
            var result = ComputeDerivative(points, order, centerPoint, derivativeStepSize);
            parameter.Value = originalValue;
            return result;
        }
Beispiel #8
0
        public double ComputePartialDerivative(functionDelegate function, Parameter parameter, int order)
        {
            int    numberOfPoints = _coefficients.Length;
            double result         = 0.0;
            double originalValue  = parameter;

            double[] points             = new double[numberOfPoints];
            double   derivativeStepSize = parameter.DerivativeStepSize;
            int      centerPoint        = (numberOfPoints - 1) / 2;

            for (int i = 0; i < numberOfPoints; i++)
            {
                parameter.Value = originalValue + ((double)(i - centerPoint)) * derivativeStepSize;
                points[i]       = function();
            }
            result          = ComputeDerivative(points, order, centerPoint, derivativeStepSize);
            parameter.Value = originalValue;
            return(result);
        }
Beispiel #9
0
 public LevenbergMarquardt(functionDelegate function, Parameter[] regressionParameters, Parameter[] observedParameters, double[,] data) :
     this(function, regressionParameters, observedParameters, data, 3)
 {
 }
Beispiel #10
0
        public void Sort(functionDelegate callback)
        {
            Comparison <Worker> comparison = new Comparison <Worker>(callback);

            listWorker.Sort(comparison);
        }
 public LevenbergMarquardt(functionDelegate function, Parameter[] regressionParameters, Parameter[] observedParameters, double[,] data)
     : this(function, regressionParameters, observedParameters, data, 3)
 {
 }
        public LevenbergMarquardt(functionDelegate regressionFunction, Parameter[] regressionParameters, Parameter[] observedParameters, double[,] data, int numberOfDerivativePoints)
        {
            Debug.Assert(data.GetLength(0) == observedParameters.Length + 1);
            _data = data;
            _observedParameters = observedParameters;
            _regressionParameters = regressionParameters;
            _regressionFunction = regressionFunction;
            int numberOfParameters = _regressionParameters.Length;
            int numberOfPoints = data.GetLength(1);

            _derivatives = new Derivatives(numberOfDerivativePoints);

            _jacobian = new Matrix(numberOfPoints, numberOfParameters);
            _residuals = new Matrix(numberOfPoints, 1);
            _regressionParameters0 = new Matrix(numberOfParameters, 1);
        }
        public double[] ComputePartialDerivatives(functionDelegate function, Parameter parameter, int[] derivativeOrders)
        {
            int numberOfPoints = _coefficients.Length;
            double[] result = new double[derivativeOrders.Length];
            double originalValue = parameter;
            double[] points = new double[numberOfPoints];
            double derivativeStepSize = parameter.DerivativeStepSize;
            int centerPoint = (numberOfPoints - 1) / 2;

            for (int i = 0; i < numberOfPoints; i++)
            {
                parameter.Value = originalValue + ((double)(i - centerPoint)) * derivativeStepSize;
                points[i] = function();
            }
            for (int i = 0; i < derivativeOrders.Length; i++)
            {
                result[i] = ComputeDerivative(points, derivativeOrders[i], centerPoint, derivativeStepSize);
            }
            parameter.Value = originalValue;
            return result;
        }
Beispiel #14
0
 public void SwitchFunction(int functionNumber)
 {
     switch (functionNumber)
     {
         case 0:
             d = new functionDelegate(Helper.RastriginFunction);
             break;
         case 1:
             d = new functionDelegate(Helper.GriewankFunction);
             break;
         case 2:
             d = new functionDelegate(Helper.SchwefelFunction);
             break;
         case 3:
             d = new functionDelegate(Helper.ShubertFunction);
             break;
         case 4:
             d = new functionDelegate(Helper.AckleyFunction);
             break;
         case 5:
             d = new functionDelegate(Helper.MichalewiczFunction);
             break;
         case 6:
             d = new functionDelegate(Helper.CamelbackFunction);
             break;
         case 7:
             d = new functionDelegate(Helper.BecherLagoFunction);
             break;
         case 8:
             d = new functionDelegate(Helper.Scheffer2Function);
             break;
     }
 }
        public double[] ComputePartialDerivatives(functionDelegate function, Parameter parameter, int[] derivativeOrders, double currentFunctionValue)
        {
            var numberOfPoints = _coefficients.Length;
            var result = new double[derivativeOrders.Length];
            double originalValue = parameter;
            var points = new double[numberOfPoints];
            var derivativeStepSize = parameter.DerivativeStepSize;
            var centerPoint = (numberOfPoints - 1) / 2;

            for (var i = 0; i < numberOfPoints; i++)
            {
                if (i != centerPoint)
                {
                    parameter.Value = originalValue + (i - centerPoint) * derivativeStepSize;
                    points[i] = function();
                }
                else
                {
                    points[i] = currentFunctionValue;
                }
            }
            for (var i = 0; i < derivativeOrders.Length; i++)
            {
                result[i] = ComputeDerivative(points, derivativeOrders[i], centerPoint, derivativeStepSize);
            }
            parameter.Value = originalValue;
            return result;
        }