• <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算法是一個(gè)古老的處理非線性最小二乘問題的方法。該方法在迭代過程中要求矩陣J(x)滿秩。為了克服這個(gè)困難,Levenberg(1944)提出了一種新的方法,但未受到重視。后來Marquardt(1963)又重新提出,并在理論上進(jìn)行了控討,得到Levenberg-Marquardt方法,簡稱LM方法。在此基礎(chǔ)上,F(xiàn)letcher(1971)對(duì)其實(shí)現(xiàn)策略進(jìn)行了改進(jìn),得到了Levenberg-Marquardt-Fletcher方法(LMF)。再后來,More(1978)將LM方法與信賴域方法結(jié)合,建立了帶信賴域的LM方法。

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

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

            wps_clip_image-24963

            2. 編譯levmar

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

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

              /* 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庫不可用的時(shí)候,示例程序中的問題

            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庫的。如果只使用這幾個(gè)函數(shù),則可以不用配置LAPACK庫,編譯levmar就很簡單了。

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

            wps_clip_image-1378

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

            wps_clip_image-511

            這時(shí)就可以啟動(dòng)Visual Studio的編譯器CL來編譯levmar庫了。配置好編譯環(huán)境的命令工具從Visual Studio的菜單來啟動(dòng):

            wps_clip_image-31275

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

            nmake /f Makefile.vc

            如下圖所示:

            wps_clip_image-5008

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

            wps_clip_image-7636

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

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

            wps_clip_image-10013


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


            久久综合狠狠综合久久综合88| 亚洲色大成网站www久久九| 亚洲AV无一区二区三区久久| 久久久久99精品成人片| 伊人丁香狠狠色综合久久| 久久国产色AV免费看| 久久天天躁狠狠躁夜夜96流白浆 | 合区精品久久久中文字幕一区 | 久久中文字幕视频、最近更新| 国产精品久久久久久久久免费| 久久综合狠狠综合久久| 久久久久女人精品毛片| 国内精品伊人久久久久AV影院| 久久亚洲私人国产精品| 99久久99这里只有免费费精品| 欧美黑人又粗又大久久久| 久久99国产乱子伦精品免费| 久久99热只有频精品8| 久久99国产精品二区不卡| 成人免费网站久久久| 秋霞久久国产精品电影院| 国产精品无码久久综合网| 久久久久国产亚洲AV麻豆| 欧美伊人久久大香线蕉综合69| 日韩电影久久久被窝网| 亚洲愉拍99热成人精品热久久| 麻豆一区二区99久久久久| 久久九九亚洲精品| 精品无码久久久久久国产| 久久精品国产欧美日韩99热| 伊人久久精品无码av一区| 国产精品禁18久久久夂久| 国产精久久一区二区三区| 精品久久久一二三区| 久久超碰97人人做人人爱| 国产精久久一区二区三区 | 思思久久99热只有频精品66| 欧洲成人午夜精品无码区久久| 97久久超碰国产精品旧版| 国内精品伊人久久久久网站| 日本WV一本一道久久香蕉|