Particle swarm optimization excet

registration
optimization
#1

Hello. I want to use Particle Swarm Optimization (PSO) for Affine image registration. As you see below, I initialized PSO code

optimizer->SetInertiaCoefficient(0.8);
optimizer->SetMaximalNumberOfIterations(1000);
optimizer->SetNumberOfParticles(20);
optimizer->SetGlobalCoefficient(1.5);
optimizer->SetInitializeNormalDistribution(true);
optimizer->SetNumberOfGenerationsWithMinimalImprovement(50);
optimizer->SetPercentageParticlesConverged(0.85);

OptimizerType::ParameterBoundsType bounds;
// bounds.size();

for (int i = 0; i < 9; i++) {
    std::pair < double, double > value;
    value.first = -1;
    value.second = 1;
    bounds.push_back(value);
}

for (int i = 0; i < 3; i++) {
    std::pair < double, double > value;
    value.first = -200;
    value.second = 200;
    bounds.push_back(value);
}
OptimizerType::ParametersType init;
init.set_size(12);
itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer generator =itk::Statistics::MersenneTwisterRandomVariateGenerator::New();

for (int i = 0; i < 9; i++) {
    init(i) = generator->GetUniformVariate(-1, 1);
}

for (int i = 0; i < 3; i++) {
    init(i + 9) = generator->GetUniformVariate(-200, 200);
}
optimizer->SetInitialPosition(init);
optimizer->SetParameterBounds(bounds);
std::cout << optimizer->GetInitialPosition() << std::endl;

std::cout << "Parameter bounds:" << std::endl;
OptimizerType::ParameterBoundsType par = optimizer->GetParameterBounds();
for (int i = 0; i < 12; i++) {
    std::pair<double, double> values = par[i];
    std::cout << values.first << ", " << values.second << std::endl;
}

Althoug the initial position is within the bounds, I always get the exception

itk::ExceptionObject (000000F47353EB48)
Location: “void __cdecl itk::ParticleSwarmOptimizerBase::ValidateSettings(void)”
File: C:\InsightToolkit-4.13.1\Modules\Numerics\Optimizers\src\itkParticleSwarmOptimizerBase.cxx
Line: 369
Description: itk::ERROR: ParticleSwarmOptimizer(000000F475BD3670): initial position is outside specified parameter bounds

How can it be possible?

(Ziv Yaniv) #2

From the code snippet there is nothing that looks clearly wrong. It would be great if you could provide a minimal working example illustrating the problem so that we can reproduce it. Possibly something like the PSOTest2 function found in itkParticleSwarmOptimizerTest.cxx.