Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Parameters of the objective function for the nonlinear fitting routine

Cheng_C_
Beginner
398 Views

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.

0 Kudos
2 Replies
mecej4
Honored Contributor III
398 Views

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.

0 Kudos
Cheng_C_
Beginner
398 Views

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_POWELL

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

0 Kudos
Reply