• <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方法。在此基礎上,F(xiàn)letcher(1971)對其實現(xiàn)策略進行了改進,得到了Levenberg-Marquardt-Fletcher方法(LMF)。再后來,More(1978)將LM方法與信賴域方法結合,建立了帶信賴域的LM方法。

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

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

            wps_clip_image-24963

            2. 編譯levmar

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

            從官網(wǎng)介紹可知,levmar有些算法依賴LAPACK庫,一個線性代數(shù)計算開源庫。所以如果要使用那些算法,編譯的時候必須包含這個庫。從示例程序的源文件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 */之間的函數(shù)都是不可用的。除此之外的函數(shù)是可用的,如基本的dlevmar_der和dlevmar_dif等函數(shù)是不依賴LAPACK庫的。如果只使用這幾個函數(shù),則可以不用配置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庫了。配置好編譯環(huán)境的命令工具從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

            接著在命令窗口中運行l(wèi)mdemo.exe,測試levmar例子程序。如果lmdemo正常運行,說明levmar已經(jīng)成功編譯。

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

            wps_clip_image-10013


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


            精品久久一区二区| 亚洲AV无码成人网站久久精品大| 成人免费网站久久久| 91久久精品视频| 久久精品国产精品亚洲精品| 偷偷做久久久久网站| 欧美777精品久久久久网| 亚洲欧洲久久av| 久久国产精品久久| 久久国内免费视频| 欧美亚洲国产精品久久蜜芽| 久久久久久伊人高潮影院| 青青草国产精品久久久久| 污污内射久久一区二区欧美日韩| 狠狠色噜噜色狠狠狠综合久久| 99久久国产热无码精品免费久久久久| 一本色综合久久| 国产L精品国产亚洲区久久 | 欧美午夜精品久久久久免费视| 精品久久久久久| 色狠狠久久AV五月综合| 久久人人超碰精品CAOPOREN| 久久精品成人免费网站| 久久综合九色综合网站| 久久天天躁狠狠躁夜夜不卡 | 日韩欧美亚洲综合久久影院Ds | 国产精品久久久久久久午夜片| 婷婷伊人久久大香线蕉AV| 亚洲国产精品无码久久青草| 久久本道伊人久久| 粉嫩小泬无遮挡久久久久久| 亚洲国产精品久久久天堂 | 亚洲国产精品狼友中文久久久| 亚洲狠狠久久综合一区77777| 久久久久亚洲Av无码专| 久久久久久精品成人免费图片| 亚洲国产综合久久天堂| 欧美久久一级内射wwwwww.| 亚洲精品久久久www| 久久久久久精品免费看SSS| 99久久国产宗和精品1上映|