[Insight-developers] (no subject)

C. Aaron Cois cacst11+ at pitt . edu
Thu, 20 Jun 2002 13:28:10 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_0036_01C2185E.521D0060
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_0037_01C2185E.521D0060"


------=_NextPart_001_0037_01C2185E.521D0060
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

We have run across an error that has stumped us for almost a week.  It =
seems like a good time to see if any other developers have any thoughts =
or similar experiences. =20

We modified itkLevenbergMarquardtOptimizerTest.cxx to operate on our
particular cost function.  The major modifications were:
1. GetValue() modified
2. GetDerivative() modified
3. Added ERF function
4. Changed Max_Iterations to 100

And a few other changes like prints and const. We used data generated =
with
known parameters from excel and the test will fit the parameters almost
perfectly:

----------------
vnl_levenberg_marquardt: 13 iterations, 66 evaluations, 5 residuals.  =
RMS
error
start/end 60.749/0.000208907
End condition   =3D  Failed X Tolerance too small
Number of iters =3D 13
Number of evals =3D 66

Solution        =3D (31.9992,255.022,4.0002,2.00008)
Test passed.
----------------

After this solutions is printed out, we get a crash as the smart pointer =
for the cost function goes out of scope...some kind of crash on cleanup. =
 =20

I've included the source file (replace
itkLevenbergMarquardtOptimizerTest.cxx and hit 4 when running) and a =
screen
capture of the error.

Any ideas?

Thanks


------=_NextPart_001_0037_01C2185E.521D0060
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>We have run across an error that has =
stumped us for=20
almost a week.&nbsp; It seems like a good time to see if any other =
developers=20
have any thoughts or similar experiences.&nbsp; </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>We modified =
itkLevenbergMarquardtOptimizerTest.cxx=20
to operate on our<BR>particular cost function.&nbsp; The major =
modifications=20
were:<BR>1. GetValue() modified<BR>2. GetDerivative() modified<BR>3. =
Added ERF=20
function<BR>4. Changed Max_Iterations to 100<BR><BR>And a few other =
changes like=20
prints and const. We used data generated with<BR>known parameters from =
excel and=20
the test will fit the parameters=20
almost<BR>perfectly:<BR><BR>----------------<BR>vnl_levenberg_marquardt: =
13=20
iterations, 66 evaluations, 5 residuals.&nbsp; RMS<BR>error<BR>start/end =

60.749/0.000208907<BR>End condition&nbsp;&nbsp; =3D&nbsp; Failed X =
Tolerance too=20
small<BR>Number of iters =3D 13<BR>Number of evals =3D=20
66<BR><BR>Solution&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D=20
(31.9992,255.022,4.0002,2.00008)<BR>Test=20
passed.<BR>----------------<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>After this solutions is printed out, we =
get a crash=20
as the smart pointer for the cost function goes out of scope...some kind =
of=20
crash on cleanup.&nbsp;  </FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR>I've included the source file=20
(replace<BR>itkLevenbergMarquardtOptimizerTest.cxx and hit 4 when =
running) and a=20
screen<BR>capture of the error.<BR><BR>Any=20
ideas?<BR><BR>Thanks<BR></DIV></FONT></BODY></HTML>

------=_NextPart_001_0037_01C2185E.521D0060--

------=_NextPart_000_0036_01C2185E.521D0060
Content-Type: application/octet-stream;
	name="itkLevenbergMarquardtOptimizer.cxx"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="itkLevenbergMarquardtOptimizer.cxx"

/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkLevenbergMarquardtOptimizer.cxx,v $
  Language:  C++
  Date:      $Date: 2002/03/01 18:31:57 $
  Version:   $Revision: 1.14 $

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for =
details.

     This software is distributed WITHOUT ANY WARRANTY; without even=20
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR =

     PURPOSE.  See the above copyright notices for more information.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
#ifndef _itkLevenbergMarquardtOptimizer_txx
#define _itkLevenbergMarquardtOptimizer_txx

#include "itkLevenbergMarquardtOptimizer.h"

namespace itk
{

/**
 * Constructor
 */
LevenbergMarquardtOptimizer
::LevenbergMarquardtOptimizer()
{
  m_OptimizerInitialized    =3D false;
  m_VnlOptimizer            =3D 0;
}


/**
 * Destructor
 */
LevenbergMarquardtOptimizer
::~LevenbergMarquardtOptimizer()
{
  delete m_VnlOptimizer;
}



/**
 * Connect a Cost Function
 */
void
LevenbergMarquardtOptimizer
::SetCostFunction( MultipleValuedCostFunction * costFunction )
{


  const unsigned int numberOfParameters =3D=20
                        costFunction->GetNumberOfParameters();

  const unsigned int numberOfValues =3D=20
                        costFunction->GetNumberOfValues();

  CostFunctionAdaptorType * adaptor =3D=20
        new CostFunctionAdaptorType( numberOfParameters, numberOfValues =
);
      =20
  adaptor->SetCostFunction( costFunction );

  if( m_OptimizerInitialized )
    {=20
    delete m_VnlOptimizer;
    }
   =20
  this->SetCostFunctionAdaptor( adaptor );

  m_VnlOptimizer =3D new vnl_levenberg_marquardt( *adaptor );

  ScalesType scales( numberOfParameters );
  scales.Fill( 1.0f );
  SetScales( scales );

  m_OptimizerInitialized =3D true;

}



/**
 * Start the optimization
 */
void
LevenbergMarquardtOptimizer
::StartOptimization( void )
{
 =20
  ParametersType initialPosition =3D GetInitialPosition();

  InternalParametersType parameters( initialPosition.Size() );

  CostFunctionAdaptorType::ConvertExternalToInternalParameters(=20
                                            GetInitialPosition(),=20
                                            parameters     );

  m_VnlOptimizer->minimize( parameters );
  // InternalParametersType is different than ParametersType....
  ParametersType p(parameters.size());
  for(unsigned int i=3D0; i < parameters.size(); ++i)
    {
    p[i] =3D parameters[i];
    }
  this->SetCurrentPosition( p );
     =20

}




/**
 * Get the Optimizer
 */
vnl_levenberg_marquardt *=20
LevenbergMarquardtOptimizer
::GetOptimizer()
{
  return m_VnlOptimizer;
}




} // end namespace itk

#endif

------=_NextPart_000_0036_01C2185E.521D0060
Content-Type: image/gif;
	name="error.gif"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="error.gif"

R0lGODdhvAG/APcAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwMDcwKbK8EAgAGAgAIAgAKAgAMAg
AOAgAABAACBAAEBAAGBAAIBAAKBAAMBAAOBAAABgACBgAEBgAGBgAIBgAKBgAMBgAOBgAACAACCA
AECAAGCAAICAAKCAAMCAAOCAAACgACCgAECgAGCgAICgAKCgAMCgAOCgAADAACDAAEDAAGDAAIDA
AKDAAMDAAODAAADgACDgAEDgAGDgAIDgAKDgAMDgAODgAAAAQCAAQEAAQGAAQIAAQKAAQMAAQOAA
QAAgQCAgQEAgQGAgQIAgQKAgQMAgQOAgQABAQCBAQEBAQGBAQIBAQKBAQMBAQOBAQABgQCBgQEBg
QGBgQIBgQKBgQMBgQOBgQACAQCCAQECAQGCAQICAQKCAQMCAQO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