<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkOnePlusOneEvolutionaryOptimizer.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  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 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef _itkOnePlusOneEvolutionaryOptimizer_cxx
#define _itkOnePlusOneEvolutionaryOptimizer_cxx

#include "itkOnePlusOneEvolutionaryOptimizer.h"
#include "vcl/vcl_cmath.h"
#include "vnl/vnl_matrix.h"

namespace itk
{

OnePlusOneEvolutionaryOptimizer
::OnePlusOneEvolutionaryOptimizer()
{
  m_Maximize = false;
  m_Initialized = false ;
  m_Epsilon = (double) 1.5e-4  ; 
  m_RandomGenerator = 0 ;
}

OnePlusOneEvolutionaryOptimizer
::~OnePlusOneEvolutionaryOptimizer() 
{
}

void 
OnePlusOneEvolutionaryOptimizer
::SetNormalVariateGenerator(NormalVariateGeneratorType* generator)
{
  if ( m_RandomGenerator != generator )
    {
      m_RandomGenerator = generator ;
      this->Modified() ;
    }
}

void 
OnePlusOneEvolutionaryOptimizer
::Initialize(double initialRadius, double grow, double shrink) 
{
  m_MaximumIteration = 20 ;
  m_InitialRadius = initialRadius ;

  if (grow == -1)
    m_GrowthFactor = 1.05 ;
  else
    m_GrowthFactor = grow ;

  if (shrink == -1)
    m_ShrinkFactor = pow(m_GrowthFactor, -0.25) ;
  else
    m_ShrinkFactor = shrink ;

  m_Initialized = true ;
}

void
OnePlusOneEvolutionaryOptimizer
::StartOptimization()
{
  
  if( m_CostFunction == 0 || !m_Initialized )
    {
      return ;
    }

  this->InvokeEvent( StartEvent() );
  m_Stop = false ;
  double pvalue, cvalue, adjust ;
  double fro_norm ;

  const unsigned int spaceDimension = m_CostFunction->GetNumberOfParameters();

  vnl_matrix<double> A(spaceDimension, spaceDimension, 0);
  vnl_vector<double> parent(this->GetInitialPosition()); 

  vnl_vector<double> f_norm(spaceDimension);
  vnl_vector<double> child(spaceDimension);
  vnl_vector<double> delta(spaceDimension);

  for(unsigned int i = 0  ; i < spaceDimension ; i++) 
    {
      A(i,i) = m_InitialRadius ;<commit_msg>FIX: VC7 warning fixed by introducing IsNull() method in SmartPointers.<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkOnePlusOneEvolutionaryOptimizer.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  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 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef _itkOnePlusOneEvolutionaryOptimizer_cxx
#define _itkOnePlusOneEvolutionaryOptimizer_cxx

#include "itkOnePlusOneEvolutionaryOptimizer.h"
#include "vcl/vcl_cmath.h"
#include "vnl/vnl_matrix.h"

namespace itk
{

OnePlusOneEvolutionaryOptimizer
::OnePlusOneEvolutionaryOptimizer()
{
  m_Maximize = false;
  m_Initialized = false ;
  m_Epsilon = (double) 1.5e-4  ; 
  m_RandomGenerator = 0 ;
}

OnePlusOneEvolutionaryOptimizer
::~OnePlusOneEvolutionaryOptimizer() 
{
}

void 
OnePlusOneEvolutionaryOptimizer
::SetNormalVariateGenerator(NormalVariateGeneratorType* generator)
{
  if ( m_RandomGenerator != generator )
    {
      m_RandomGenerator = generator ;
      this->Modified() ;
    }
}

void 
OnePlusOneEvolutionaryOptimizer
::Initialize(double initialRadius, double grow, double shrink) 
{
  m_MaximumIteration = 20 ;
  m_InitialRadius = initialRadius ;

  if (grow == -1)
    m_GrowthFactor = 1.05 ;
  else
    m_GrowthFactor = grow ;

  if (shrink == -1)
    m_ShrinkFactor = pow(m_GrowthFactor, -0.25) ;
  else
    m_ShrinkFactor = shrink ;

  m_Initialized = true ;
}

void
OnePlusOneEvolutionaryOptimizer
::StartOptimization()
{
  
  if( m_CostFunction.IsNull() || !m_Initialized )
    {
      return ;
    }

  this->InvokeEvent( StartEvent() );
  m_Stop = false ;
  double pvalue, cvalue, adjust ;
  double fro_norm ;

  const unsigned int spaceDimension = m_CostFunction->GetNumberOfParameters();

  vnl_matrix<double> A(spaceDimension, spaceDimension, 0);
  vnl_vector<double> parent(this->GetInitialPosition()); 

  vnl_vector<double> f_norm(spaceDimension);
  vnl_vector<double> child(spaceDimension);
  vnl_vector<double> delta(spaceDimension);

  for(unsigned int i = 0  ; i < spaceDimension ; i++) 
    {
      A(i,i) = m_InitialRadius ;
{'fraction_non_alphanumeric': 0.14603365384615385, 'fraction_numerical': 0.008413461538461538, 'mean_word_length': 4.572544642857143, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7553026', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1581, 'n_words': 340}