[Insight-users] ReceptorMemberCommand
Rupert Brooks
rupe.brooks at gmail.com
Fri Sep 15 15:15:48 EDT 2006
Hi Luis
Thanks - this works, at least in example code. Although i still
havent found where i originally went wrong, that is my coding problem,
not ITKs :-).
For the benefit of anyone else who was interested, or future list
searchers, here are the changes i made to the example
"ImageRegistration3.cxx" to get it to work. Its worth noting that it
failed with rather unhelpful error messages (at least on Visual C++)
due to const-correctness issues until i switched to using the
"GetCachedValue" rather than GetValue method. So if someone tries
this, and it gives you trouble, const issues are a good place to start
looking.
Rupert B.
diff of imageregistration3 to use amoeba and report per iteration information.
----------------------------------------------
66a67
> #include "itkAmoebaOptimizer.h"
163c164
< typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
---
> typedef itk::AmoebaOptimizer OptimizerType;
241c242
< return;
---
> return;
258,260c259,260
< std::cout << optimizer->GetCurrentIteration() << " = ";
< std::cout << optimizer->GetValue() << " : ";
< std::cout << optimizer->GetCurrentPosition() << std::endl;
---
> std::cout << optimizer->GetCachedValue() << " : ";
> std::cout << optimizer->GetCachedCurrentPosition() << std::endl;
276c276,277
< if( argc < 3 )
---
> try {
> if( argc < 3 )
293c294
< typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
---
> typedef itk::AmoebaOptimizer OptimizerType;
345,350c346,356
< optimizer->SetMaximumStepLength( 4.00 );
< optimizer->SetMinimumStepLength( 0.01 );
< optimizer->SetNumberOfIterations( 200 );
<
< optimizer->MaximizeOff();
<
---
> //optimizer->SetMaximumStepLength( 4.00 );
> //optimizer->SetMinimumStepLength( 0.01 );
> //optimizer->SetNumberOfIterations( 200 );
>
> //optimizer->MaximizeOff();
> // Setting up the Amoeba requires different params
> optimizer->SetAutomaticInitialSimplex( 1);
> optimizer->SetParametersConvergenceTolerance(0.01 ); // Was 0.0001 in 3d
> optimizer->SetFunctionConvergenceTolerance( 0.0001 ); // Was 0.0000001 in 3d
> optimizer->SetMaximumNumberOfIterations( 200 );
>
469,470c475,476
< const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
<
---
> //const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
> const unsigned int numberOfIterations = optimizer->GetOptimizer()->get_num_evaluations();
525a532,538
> }
> catch( itk::ExceptionObject & err )
> {
> std::cout << "ExceptionObject caught !" << std::endl;
> std::cout << err << std::endl;
> return -1;
> }
----------------------------------------------
On 9/9/06, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> Hi Rupert
>
> The Amoeba optimizer in ITK is a wrapper around the vnl
> amoeba optimizer. Since VNL does not send any events during
> the iterations of its optimizers, ITK implemented a trick in
> the following way:
>
> itkAmoebaOptimizer wraps vnl_amoeba
>
> SingleValuedVnlCostFunctionAdaptor
> wraps vnl_cost_function
>
>
> vnl_amoeba calls the f() method of the vnl_cost_function,
> that in turn calls the GetValue() method of the ITK
> SingleValuedVnlCostFunctionAdaptor.
>
> The SingleValuedVnlCostFunctionAdaptor sends events that
> are "observed" by the itkAmoebaOptimizer and resent as
> iteration events.
>
> In this way, we get events *per evaluation* of the cost
> function. Note that this is not completely equivalent
> to events per iteration of the amoeba_optimizer,.... but
> it is better than nothing.
>
> as a rule of thumb you could expect that N evaluations of
> the cost_function are equivalent to one iteration of the
> amoeba optimizer, where N is the dimensionality of the
> parametric space of the cost function.
>
>
> For more details, please look at the method:
>
> IterationReport()
>
> in itkSingleValuedNonLiinearVnlOptimizer.cxx, lines 109-116.
>
>
> Note that the receptor command is connected to the cost
> function adaptor in line 70 of the same file.
>
>
> If you connect a normal Command (observer) to the amoeba
> optimizer, you should receive those IterationEvents, that
> correspond to one evaluation of the cost function.
>
>
>
> Regards,
>
>
> Luis
>
>
> ---------------------
> Rupert Brooks wrote:
> > Hi,
> >
> >> From looking in the code, it seems that for VNL optimizers such as the
> >
> > Amoeba, it is possible to get per-iteration callbacks using the
> > ReceptorMemberCommand<type>. I would be interested in doing this, but
> > im having trouble figuring out how it works - my naive approach was to
> > inherit my per-iteration command from ReceptorMemberCommand instead of
> > itk::Command, but this doesn't manage it, at least not with Amoeba.
> >
> > Are there any examples someone could point me to of getting per
> > iteration information from a VNL optimizer?
> >
> > Thanks,
> > Rupert B.
> >
>
>
>
--
--------------------------------------------------------------
Rupert Brooks
McGill Centre for Intelligent Machines (www.cim.mcgill.ca)
Ph.D Program in Intelligent Systems
http://www.cyberus.ca/~rbrooks
More information about the Insight-users
mailing list