• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            Levmar:Levenberg-Marquardt非線性最小二乘算法

            eryar@163.com

            Abstract. Levmar is GPL native ANSI C implementations of the Levenberg-Marquardt optimization algorithm.The blog focus on the compilation of levmar on Windows with Visual Studio.

            Key Words. Levmar, C, LM least squares

            1. levmar簡介

            Gauss-Newton算法是一個古老的處理非線性最小二乘問題的方法。該方法在迭代過程中要求矩陣J(x)滿秩。為了克服這個困難,Levenberg(1944)提出了一種新的方法,但未受到重視。后來Marquardt(1963)又重新提出,并在理論上進行了控討,得到Levenberg-Marquardt方法,簡稱LM方法。在此基礎上,Fletcher(1971)對其實現策略進行了改進,得到了Levenberg-Marquardt-Fletcher方法(LMF)。再后來,More(1978)將LM方法與信賴域方法結合,建立了帶信賴域的LM方法。

            LM算法的產生主要是解決曲線最小二乘擬合問題,現在很多軟件使用LM算法來解決通用的曲線擬合問題。

            本文主要介紹GPL開源庫levmar2.6使用Visual Studio在Windows上進行編譯。這個開源庫的官方網站是:http://users.ics.forth.gr/~lourakis/levmar/

            wps_clip_image-24963

            2. 編譯levmar

            下載源碼levmar-2.6解壓,在其README.txt中對levmar的授權GPL、編譯等進行了說明。在Windows操作系統中,可以使用nmake /f Makefile.vc來編譯levmar和一個示例程序。

            從官網介紹可知,levmar有些算法依賴LAPACK庫,一個線性代數計算開源庫。所以如果要使用那些算法,編譯的時候必須包含這個庫。從示例程序的源文件lmdemo.c中可以看出,有些問題的求解是需要LAPACK庫的,相關源碼列出如下:

              /* uncomment the appropriate line below to select a minimization problem */
              problem=
                      //0; // Rosenbrock function
                      //1; // modified Rosenbrock problem
                      //2; // Powell's function
                  //3; // Wood's function
                      4; // Meyer's (reformulated) problem
                      //5; // Osborne's problem
                  //6; // helical valley function
            #ifdef HAVE_LAPACK
                  //7; // Boggs & Tolle's problem 3
                  //8; // Hock - Schittkowski problem 28
                  //9; // Hock - Schittkowski problem 48
                  //10; // Hock - Schittkowski problem 51
            #else // no LAPACK
            #ifdef _MSC_VER
            #pragma message("LAPACK not available, some test problems cannot be used")
            #else
            #warning LAPACK not available, some test problems cannot be used
            #endif // _MSC_VER
            #endif /* HAVE_LAPACK */
                  //11; // Hock - Schittkowski problem 01
                  //12; // Hock - Schittkowski modified problem 21
                  //13; // hatfldb problem
                  //14; // hatfldc problem
                  //15; // equilibrium combustion problem
            #ifdef HAVE_LAPACK
                  //16; // Hock - Schittkowski modified #1 problem 52
                  //17; // Schittkowski modified problem 235
                  //18; // Boggs & Tolle modified problem #7
                  //19; // Hock - Schittkowski modified #2 problem 52
                  //20; // Hock - Schittkowski modified problem #76"
            #endif /* HAVE_LAPACK */
              switch(problem){
              default: fprintf(stderr, "unknown problem specified (#%d)! Note that some minimization problems require LAPACK.\n", problem);
                       exit(1);
                break;

            從上述源碼可知,如果LAPACK庫不可用的時候,示例程序中的問題

            l 7 Boggs & Tolle’s problem 3

            l 8 Hock - Schittkowski problem 28

            l 9 Hock - Schittkowski problem 48

            l 10 Hock - Schittkowski problem 51

            l 16 Hock - Schittkowskit modified #1 problem 52

            l 17 Schittkowski modified problem 235

            l 18 Boggs & Tolle modified problem #7

            l 19 Hock - Schittkowski modified #2 problem 52

            l 20 Hock - Schittkowski modified probem #76

            這些問題的求解功能是不能使用的。從頭文件levmar.h中要以看出,

            #ifdef LM_DBL_PREC
            /* double precision LM, with & without Jacobian */
            /* unconstrained minimization */
            extern int dlevmar_der(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  void (*jacf)(double *p, double *j, int m, int n, void *adata),
                  double *p, double *x, int m, int n, int itmax, double *opts,
                  double *info, double *work, double *covar, void *adata);
            extern int dlevmar_dif(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  double *p, double *x, int m, int n, int itmax, double *opts,
                  double *info, double *work, double *covar, void *adata);
            /* box-constrained minimization */
            extern int dlevmar_bc_der(
                   void (*func)(double *p, double *hx, int m, int n, void *adata),
                   void (*jacf)(double *p, double *j, int m, int n, void *adata),  
                   double *p, double *x, int m, int n, double *lb, double *ub, double *dscl,
                   int itmax, double *opts, double *info, double *work, double *covar, void *adata);
            extern int dlevmar_bc_dif(
                   void (*func)(double *p, double *hx, int m, int n, void *adata),
                   double *p, double *x, int m, int n, double *lb, double *ub, double *dscl,
                   int itmax, double *opts, double *info, double *work, double *covar, void *adata);
            #ifdef HAVE_LAPACK
            /* linear equation constrained minimization */
            extern int dlevmar_lec_der(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  void (*jacf)(double *p, double *j, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *A, double *b, int k,
                  int itmax, double *opts, double *info, double *work, double *covar, void *adata);
            extern int dlevmar_lec_dif(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *A, double *b, int k,
                  int itmax, double *opts, double *info, double *work, double *covar, void *adata);
            /* box & linear equation constrained minimization */
            extern int dlevmar_blec_der(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  void (*jacf)(double *p, double *j, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *lb, double *ub, double *A, double *b, int k, double *wghts,
                  int itmax, double *opts, double *info, double *work, double *covar, void *adata);
            extern int dlevmar_blec_dif(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *lb, double *ub, double *A, double *b, int k, double *wghts,
                  int itmax, double *opts, double *info, double *work, double *covar, void *adata);
            /* box, linear equations & inequalities constrained minimization */
            extern int dlevmar_bleic_der(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  void (*jacf)(double *p, double *j, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *lb, double *ub,
                  double *A, double *b, int k1, double *C, double *d, int k2,
                  int itmax, double *opts, double *info, double *work, double *covar, void *adata);
            extern int dlevmar_bleic_dif(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *lb, double *ub, 
                  double *A, double *b, int k1, double *C, double *d, int k2,
                  int itmax, double *opts, double *info, double *work, double *covar, void *adata);
            /* box & linear inequality constraints */
            extern int dlevmar_blic_der(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  void (*jacf)(double *p, double *j, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *lb, double *ub, double *C, double *d, int k2,
                  int itmax, double opts[4], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
            extern int dlevmar_blic_dif(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *lb, double *ub, double *C, double *d, int k2,
                  int itmax, double opts[5], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
            /* linear equation & inequality constraints */
            extern int dlevmar_leic_der(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  void (*jacf)(double *p, double *j, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *A, double *b, int k1, double *C, double *d, int k2,
                  int itmax, double opts[4], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
            extern int dlevmar_leic_dif(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *A, double *b, int k1, double *C, double *d, int k2,
                  int itmax, double opts[5], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
            /* linear inequality constraints */
            extern int dlevmar_lic_der(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  void (*jacf)(double *p, double *j, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *C, double *d, int k2,
                  int itmax, double opts[4], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
            extern int dlevmar_lic_dif(
                  void (*func)(double *p, double *hx, int m, int n, void *adata),
                  double *p, double *x, int m, int n, double *C, double *d, int k2,
                  int itmax, double opts[5], double info[LM_INFO_SZ], double *work, double *covar, void *adata);
            #endif /* HAVE_LAPACK */
            #endif /* LM_DBL_PREC */

            從頭文件levmar.h中的代碼可以看出,在#ifdef HAVE_LAPACK和#endif /* HAVE_LAPACK */之間的函數都是不可用的。除此之外的函數是可用的,如基本的dlevmar_der和dlevmar_dif等函數是不依賴LAPACK庫的。如果只使用這幾個函數,則可以不用配置LAPACK庫,編譯levmar就很簡單了。

            如果不使用LAPACK庫,可以先在頭文件levmar.h中把#define HAVE_LAPACK 這一行注釋掉:

            wps_clip_image-1378

            然后再修改Makefile.vc文件,在Makefile.vc中可以看到如下圖所示一句注釋,即當不使用LAPACK庫是,把那一行注釋掉(前面加#):

            wps_clip_image-511

            這時就可以啟動Visual Studio的編譯器CL來編譯levmar庫了。配置好編譯環境的命令工具從Visual Studio的菜單來啟動:

            wps_clip_image-31275

            要編譯32位的levmar庫,可以使用x86的命令工具,要編譯64位的levmar,可以使用x64的命令工具。啟動命令工具后,切換到levmar源碼文件夾,并輸入命令

            nmake /f Makefile.vc

            如下圖所示:

            wps_clip_image-5008

            編譯成功生成levmar.lib和lmdemo.exe說明編譯成功了。

            wps_clip_image-7636

            接著在命令窗口中運行lmdemo.exe,測試levmar例子程序。如果lmdemo正常運行,說明levmar已經成功編譯。

            自己的程序如果要使用levmar,就可以像使用其他開源庫一樣,設置頭文件路徑及庫levmar.lib的路徑,就可以使用了。

            wps_clip_image-10013


            為了方便大家在移動端也能看到我的博文和討論交流,現已注冊微信公眾號,歡迎大家掃描下方二維碼關注。
            Shing Liu(eryar@163.com)


            久久国产精品波多野结衣AV| 久久99久久无码毛片一区二区| 久久人人爽人人人人爽AV | 久久国产热精品波多野结衣AV| 亚洲精品无码成人片久久| avtt天堂网久久精品| 国内精品久久久人妻中文字幕| 69久久夜色精品国产69| 久久九九免费高清视频| 人妻无码αv中文字幕久久琪琪布| 国产精品久久久久久久久免费| 久久不见久久见免费影院www日本| 久久99久久99精品免视看动漫| 久久精品九九亚洲精品天堂| 亚洲精品久久久www| 久久久精品免费国产四虎| 久久精品国产99国产精品导航| 97超级碰碰碰碰久久久久| 国产亚洲美女精品久久久2020| 国产成人久久精品二区三区| 国产午夜免费高清久久影院| 久久频这里精品99香蕉久| 狠狠人妻久久久久久综合| 国产精品国色综合久久| 综合人妻久久一区二区精品| 精品久久久久久99人妻| 91超碰碰碰碰久久久久久综合| 亚洲中文字幕无码一久久区| 久久青青草原亚洲av无码| 久久精品国产福利国产琪琪| 日韩欧美亚洲综合久久影院d3| 99久久免费国产精精品| 国产精品久久久久无码av| 亚洲精品高清国产一线久久| 伊人久久一区二区三区无码| 久久精品中文字幕有码| 欧美与黑人午夜性猛交久久久| 国产AⅤ精品一区二区三区久久| 国产美女久久久| 久久久久久免费一区二区三区| 国产精品久久永久免费|