Beispiel #1
0
        /// <summary>
        ///   Get Jacobian matrix of the objective function.
        /// </summary>
        /// <param name = "model">Model function.</param>
        /// <param name = "pointCount">Number of data points.</param>
        /// <param name = "dataX">X-coordinates of the data points.</param>
        /// <param name = "dataY">Y-coordinates of the data points.</param>
        /// <param name = "parameters">Model function parameters.</param>
        /// <param name = "jacobian">Jacobian matrix of the objective function.</param>
        private void GetObjectiveJacobian(PowerModel model, int pointCount, Vector <double> parameters, ref Matrix <double> jacobian)
        {
            int parameterCount = parameters.Count;

            // fill rows of the Jacobian matrix
            // j-th row of a Jacobian is the gradient of model function in j-th measurement
            for (int j = 0; j < pointCount; j++)
            {
                Vector <double> gradient = new DenseVector(parameterCount);

                model.GetGradient(
                    dataX[j],
                    parameters,
                    ref gradient);

                jacobian.SetRow(j, gradient);
            }
        }