- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

I want to conduct a nonlinear least square fitting using MKL. However, I don't know how I can introduce some additional parameters for the objective function. Does anybody have some ideas?

This is the introduction of the routine: https://software.intel.com/en-us/node/471086

This is one example code for the routine: https://software.intel.com/en-us/node/471540

How can I past some parameters for the objective function (the f(x) function in the introduction or the extendet_powell() function in the example code)? Thanks very much.

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

One way is to add an array containing the parameters to the argument list of the vector function that is being optimized. You declare and initialize the array in the caller of the optimizer routine, and take care to modify the DJACOBI routine if you are using numerical evaluation of the Jacobian.

Alternatively, in Fortran, put your parameters declarations and initializations into a module, and USE that module in the callback subroutine. For example:

MODULE PARAMETERS IMPLICIT NONE DOUBLE PRECISION :: P(5) = [ 10.D0, 2.2360679774998D0, -2.D0, & 3.1622776601684D0, -1D0 ] END MODULE PARAMETERS SUBROUTINE EXTENDED_POWELL (M, N, X, F) USE PARAMETERS IMPLICIT NONE INTEGER M, N DOUBLE PRECISION X (*), F (*) INTEGER I DO I = 1, N/4 F (4*I-3) = X(4*I - 3) + P(1) * X(4*I - 2) F (4*I-2) = P(2)*(X(4*I-1) - X(4*I)) F (4*I-1) = (X(4*I-2) + P(3)*X(4*I-1))**2 F (4*I) = P(4)*(X(4*I-3) +P(5)* X(4*I))**2 ENDDO END SUBROUTINE EXTENDED_POWELL

Similarly, in C, you can use global variables to contain the parameter values.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Thank you for the suggestions! I'd like to try both ways.

mecej4 wrote:

One way is to add an array containing the parameters to the argument list of the vector function that is being optimized. You declare and initialize the array in the caller of the optimizer routine, and take care to modify the DJACOBI routine if you are using numerical evaluation of the Jacobian.

Alternatively, in Fortran, put your parameters declarations and initializations into a module, and USE that module in the callback subroutine. For example:

MODULE PARAMETERS IMPLICIT NONE DOUBLE PRECISION :: P(5) = [ 10.D0, 2.2360679774998D0, -2.D0, & 3.1622776601684D0, -1D0 ] END MODULE PARAMETERS SUBROUTINE EXTENDED_POWELL (M, N, X, F) USE PARAMETERS IMPLICIT NONE INTEGER M, N DOUBLE PRECISION X (*), F (*) INTEGER I DO I = 1, N/4 F (4*I-3) = X(4*I - 3) + P(1) * X(4*I - 2) F (4*I-2) = P(2)*(X(4*I-1) - X(4*I)) F (4*I-1) = (X(4*I-2) + P(3)*X(4*I-1))**2 F (4*I) = P(4)*(X(4*I-3) +P(5)* X(4*I))**2 ENDDO END SUBROUTINE EXTENDED_POWELLSimilarly, in C, you can use global variables to contain the parameter values.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page