[Insight-users] itk Gradient Descent Optimizer:

Luis Ibanez luis.ibanez@kitware.com
Wed, 23 Oct 2002 00:47:46 -0400


Hi digvijay


Thanks for sending the code the class you wrote
using the itk::GradientDescent optimizer.


--

The segmentation fault is generated by the
GetValue() method of your cost function.

You are using intermediate values in an
array of size 10000. The computation however,
attempts to access the element # 10003.
(out of bounds).


You can easily track this down using gdb
and/or valgrind.  Or the debugger of VC++
if you are working under windows.


The problem is originated by the following code
in the GetValue() method, around line 570




      for(j = 0 ; Intensity[j] != -1 ; j++)
        {
        temp_one[j] =  Frequency[j] -
           maxfrequency_one*(exp((-1)*pow((Intensity[j] -
           nu_one),2)/pow(sigma_one,2))) - constant_term ;

        if (temp_one[j] < 0)
          temp_one[j] = (-1)*(temp_one[j]);

        if (j != 0)
          temp_one[j] = temp_one[j] + temp_one[j-1];
        }



------------


Also, a couple of minor details,

in your code you are using

      using namespace std;
      using namespace itk;


This is not a good practice. It is like
having very secure doors and leaving them
open. If you open the namespaces all the
types are visible as if they were defined
in the global namespace. This opens the
posibilities for name conflicts.

Please try to use the namespaces with
every type:

like   itk::Image   and   std::cout



---------------


Please let us know if you find further problems


Thanks


    Luis