Thursday, March 19, 2009

Install Ocatve on Ubuntu

Update your apt-get first. 
  1. $ sudo apt-get update
  2. $ sudo apt-get install octave
Miss the first step, you may not find octave package when type step 2 command.
After updating, then input command of step 2.
Then system will ask you to agree the download process and upgrade process.
Press "y" and wait.

If you meet a problem, like 
ldconfig deferred processing tkaing place
dpkg: status database area is locked by another process
Just running step 2 again.

At least, I install it successfully.

Thursday, March 12, 2009

Friday, March 6, 2009

Octave and C/C++

Reference for using Octave and C/C++
參考這幾個網站,

Please confirm that Dynamic Linking feature is ont or off.
先確認Octave是否有支援或是開啟Dynamic Linking,
Typing,
輸入
$ octave_config_info ("ENABLE_DYNAMIC_LINKING")
if
ans = true
That means ON.
表示有開啟。

因為Octave要用gcc compiler,所以勢必得換開發環境了。
至少我不知道怎麼用VisualCompiler去使用。

所以我改用Cygwin和Ubuntu,Cygwin因為我缺少了一些packages,所以花了點工夫。請參考HERE
Ubuntu只要安裝好Octave和Octave-header後,就OK了。請參考HERE1 and HERE2

程式要inlcude
然後告訴compile正確的octave library位置,但是通常都會用make來完成compile動作。下載範例Makefile
內容大致如前面連結提供的範例相同,
makefile:
all:test
clean:
-rm test.o test
test: test.o
mkoctfile --link-stand-alone -o test hello.o
test.o: hello.cpp
g++ -c -I /usr/include/octave-3.0.3/ -o hello.o hello.cpp
指令輸入make all,就會完成Makefile裡指定的動作了。

Wednesday, March 4, 2009

The method of solving least-squares problems

Linear least squares problems
  • Newton's Method
Non-Linear least squares problems
  • Gauss-Newton Method
  • Quasi-Newton Method
  • Gauss-Raphson Method
  • Levenberg-Marguardt Method
  • Powell's Dog Leg Method
  • Hybrid Method: L-M and Quasi-Newton
Good references:
  • 1999, Poul E. Frandsen, http://www2.imm.dtu.dk/documents/ftp/publlec/lec2_99.pdf
Descent method
Conjugate Gradient mehod
Newton-based method, included Quasi-Newton
  • 1999, Hans B. Nielsen: http://www2.imm.dtu.dk/documents/ftp/tr99/tr05_99.pdf
Descent method
Gauss-Newton method
Levenberg-Marquardt method
Powell's Dog Leg method
Hybrid: LMA+QN
Newton's Method, NM
Also called Newton-Raphson Method.  It uses the first few terms of the Taylor series (Taylor expansion) of a function  in the vicinity of a suspected root.  
  • http://mathworld.wolfram.com/NewtonsMethod.html
  • http://en.wikipedia.org/wiki/Newton's_method

Relationship between Newton's method, Halley method, and Householder's method.
  • Newton's method is 1st in the class of Householder's method.
  • Halley's method is 2nd in the class of Householder's method.
  • http://en.wikipedia.org/wiki/Householder's_method
  • http://en.wikipedia.org/wiki/Halley's_method

  • Levenberg-Marquardt Algorithm, LMA
  • http://en.wikipedia.org/wiki/Levenberg-Marquardt_algorithm
  • http://mathworld.wolfram.com/Levenberg-MarquardtMethod.html
  • http://homepages.inf.ed.ac.uk/cgi/rbf/CVONLINE/entries.pl?TAG49
  • Nov. 1996, Sam Roweis: http://www.cs.toronto.edu/~roweis/notes/lm.pdf
  • Good Introduction to talk about the LM from Newton's method, modefied by Levenberg, then modefied by Marquardt to become LM algorithm.
1999, Hans B. Nielsen: http://www2.imm.dtu.dk/documents/ftp/tr99/tr05_99.pdf
Apr. 2004, Hans B. Nielsen: http://www.imm.dtu.dk/pubdb/views/edoc_download.php/3215/pdf/imm3215.pdf
  • Above two articles are refered by LEVMAR.
June 2004, Ananth R.: http://www.cc.gatech.edu/~ananth/docs/lmtut.pdf
  • A good article also to talk about the LM from Newton's, Levenberg, and Marquardt to become LMA.
Feb. 2005, Manolis L.: http://www.ics.forth.gr/~lourakis/levmar/levmar.pdf
  • The article talking about source code LEVMAR. A pseudocode provided.
Nov. 2006, Pradit M.: http://cobweb.ecn.purdue.edu/~kak/courses-i-teach/ECE661.08/homework/HW5_LM_handout.pdf
  • Simple example and Matlab code provided.
http://www.cse.ucsd.edu/classes/fa04/cse252c/vrabaud1.pdf
  • Matlab code, thanks for Pradit Mittrapiyanuruk.

Gauss-Newton Method, GNM
  • http://en.wikipedia.org/wiki/Gauss-Newton_algorithm
  • http://reference.wolfram.com/mathematica/tutorial/UnconstrainedOptimizationGaussNewtonMethods.html
  • 1999, Hans B. Nielsen: http://www2.imm.dtu.dk/documents/ftp/tr99/tr05_99.pdf
Gauss-Raphson Method, GRM
Continue..
Quasi-Netwon Method, QNM
  • http://reference.wolfram.com/mathematica/tutorial/UnconstrainedOptimizationQuasiNewtonMethods.html
  • 1999, Poul E. Frandsen, http://www2.imm.dtu.dk/documents/ftp/publlec/lec2_99.pdf
Powell's Dog Leg Method, PDLM
  • 1999, Hans B. Nielsen: http://www2.imm.dtu.dk/documents/ftp/tr99/tr05_99.pdf
Hybrid Method: L-M and Quasi-Newton, H:LM+QN
  • 1999, Hans B. Nielsen: http://www2.imm.dtu.dk/documents/ftp/tr99/tr05_99.pdf
LMA for linear convergence
QN for superlinear convergence
Papers:
  • Yao Jianchao, Chia Tien Chern, COMPARISON OF NEWTON-GAUSS WITH LEVENBERG-MARQUARDT ALGORITHM FOR SPACE RESECTION, Proc. ACRS 2001 - 22nd Asian Conference on Remote Sensing, 5-9 November 2001, Singapore. Vol. 1, pp. 256-261.
  • C. Kanzow, N. Yamashita and M. Fukushima, Levenberg–Marquardt methods with strong local convergence properties for solving nonlinear equations with convex constraints, J. Comput. Appl. Math.172 (2004), pp. 375–397.
  • Kanzow, C., Yamashita, N., and Fukushima, M. 2004. Levenberg-Marquardt methods with strong local convergence properties for solving nonlinear equations with convex constraints. J. Comput. Appl. Math. 172, 2 (Dec. 2004), 375-397. DOI= http://dx.doi.org/10.1016/j.cam.2004.02.013
  • Lourakis, M. I. and Argyros, A. A. 2005. Is Levenberg-Marquardt the Most Efficient Optimization Algorithm for Implementing Bundle Adjustment?. In Proceedings of the Tenth IEEE international Conference on Computer Vision - Volume 2 (October 17 - 20, 2005). ICCV. IEEE Computer Society, Washington, DC, 1526-1531. DOI= http://dx.doi.org/10.1109/ICCV.2005.128

Source codes:
levmar: Levenberg-Marquardt nonlinear least squares algorithms in C/C++
lmfit — a C/C++ routine for Levenberg-Marquardt minimization with wrapper for least-squares curve fitting
lmfit is easy to install it because it is without the dependency problem.
Levenberg-Marquardt for Visual C++ 2005
Levenberg-Marquardt algorithm for multivariate optimization in C#/C++/Delphi/VB6/Zonnon

Continue....

Tuesday, March 3, 2009

Pointer in C

A simple example to using pointer in C.

we claim a pointer in main function, and hope to pass it to subroutin to allocate the memory.
How to use it?
Solution 1, return the address back.
=======================
#include
#include

int array_size =10;


int fill_array( float *ptr)
 {
    int i;
printf("Address %d\n", &ptr);
    ptr = (float *) malloc(array_size *sizeof(float));

    for(i=0; i<>
    {
         
      ptr[i] = (float)i;

    }

    
   for(i=0; i
   {
 printf("In function\n");
 
      printf("%d - %f ", &ptr[i],ptr[i]);
   }
   printf("\n");
   printf("ptr = %d\n", &ptr);
   return(ptr);
 }
main()
{
float *ptr = NULL;
int i;
printf("Address %d\n", &ptr);
ptr=fill_array(&ptr);

printf("Out function\n");
printf("Address %d\n", &ptr);
for(i=0; i
{
printf("Out function\n");
printf("%d - %f ", &ptr[i], ptr[i]);
}
}
=======================
The result will be
-------------------------------------
Address 1245052 //ptr in main( )
Address 1244968 //ptr in fill_array( )
In function
4397824 - 0.000000 In function
4397828 - 1.000000 In function
4397832 - 2.000000 In function
4397836 - 3.000000 In function
4397840 - 4.000000 In function
4397844 - 5.000000 In function
4397848 - 6.000000 In function
4397852 - 7.000000 In function
4397856 - 8.000000 In function
4397860 - 9.000000
ptr = 1244968  //ptr in fill_array( )
Out function
Address 1245052
Out function
4397824 - 0.000000 Out function
4397828 - 1.000000 Out function
4397832 - 2.000000 Out function
4397836 - 3.000000 Out function
4397840 - 4.000000 Out function
4397844 - 5.000000 Out function
4397848 - 6.000000 Out function
4397852 - 7.000000 Out function
4397856 - 8.000000 Out function
4397860 - 9.000000 Press any key to continue
-------------------------------------

Solution 2 , call by address.
=======================
#include
#include

void function(float ** ptrf)
{

int i;
printf("address of *ptrf = %d\n", &*ptrf);
*ptrf = (float *) malloc(5*sizeof(float*));
printf("address of *ptrf = %d\n", &*ptrf);
for(i=0; i<5;>
{
(*ptrf)[i] =i;
}
}

int main()
{
float *ptr=NULL;

int i;
printf("address of *ptr = %d\n", &ptr);
function(&ptr);

for(i=0; i<5;>
{
printf("%f ", ptr[i]);
}
printf("\nAddress ponited to by the ptr out function \nptr=%d, &ptr=%d\n", ptr, &ptr);
}
=======================
The result will be
---------------------------------
address of *ptr = 1245052
address of *ptrf = 1245052
address of *ptrf = 1245052
0.000000 1.000000 2.000000 3.000000 4.000000
Address ponited to by the ptr out function
ptr=4397856, &ptr=1245052
Press any key to continue
---------------------------------

Clicky

Clicky Web Analytics