<commit_before>#ifndef __itkAcceleratedGradientDescentOptimizer_cxx
#define __itkAcceleratedGradientDescentOptimizer_cxx

#include "itkAcceleratedGradientDescentOptimizer.h"
#include "vnl/vnl_math.h"
#include "itkSigmoidImageFilter.h"

namespace itk
{

	/**
	 * ************************* Constructor ************************
	 */

	AcceleratedGradientDescentOptimizer
		::AcceleratedGradientDescentOptimizer()
	{
    this->m_UseCruzAcceleration = false;
    this->m_SigmoidMax = 1.0;
    this->m_SigmoidMin = -0.8;
    this->m_SigmoidScale = 1e-8;
				
	} // end Constructor

 
	/**
	 * ************************** UpdateCurrentTime ********************
	 *
	 * This function computes the input for the Compute_a function.
	 */

  void AcceleratedGradientDescentOptimizer
		::UpdateCurrentTime( void )
  {
    typedef itk::Function::Sigmoid<double, double> SigmoidType;

    if ( this->m_UseCruzAcceleration )
    {
      if ( this->GetCurrentIteration() > 0 )
      {
        /** Make sigmoid function 
         * Compute beta such that sigmoid(0)=0 
         * We assume Max>0, min<0 */
        SigmoidType sigmoid;
        sigmoid.SetOutputMaximum( this->GetSigmoidMax() );
        sigmoid.SetOutputMinimum( this->GetSigmoidMin() );
        sigmoid.SetAlpha( this->GetSigmoidScale() );
        const double beta = this->GetSigmoidScale() *
           vcl_log( - this->GetSigmoidMax() / this->GetSigmoidMin() );
        sigmoid.SetBeta( beta );

        /** Formula (2) in Cruz */
        const double inprod = inner_product(
          this->m_PreviousGradient, this->GetGradient() );
        this->m_CurrentTime += sigmoid(-inprod);
        this->m_CurrentTime = vnl_math_max( 0.0, this->m_CurrentTime );        
      }

      /** Save for next iteration */
      this->m_PreviousGradient = this->GetGradient();
    }
    else
    {
      /** Almost Robbins-Monro: time = time + E_0. 
       * If you want the parameter estimation but no adaptive stuff, 
       * this may be use useful:  */
      this->m_CurrentTime += ( this->GetSigmoidMax() + this->GetSigmoidMin() / 2.0 );
    }

  } // end UpdateCurrentTime
	

} // end namespace itk

#endif // end #ifndef __itkAcceleratedGradientDescentOptimizer_cxx
<commit_msg>SK:<commit_after>#ifndef __itkAcceleratedGradientDescentOptimizer_cxx
#define __itkAcceleratedGradientDescentOptimizer_cxx

#include "itkAcceleratedGradientDescentOptimizer.h"
#include "vnl/vnl_math.h"
#include "itkSigmoidImageFilter.h"

namespace itk
{

	/**
	 * ************************* Constructor ************************
	 */

	AcceleratedGradientDescentOptimizer
		::AcceleratedGradientDescentOptimizer()
	{
    this->m_UseCruzAcceleration = false;
    this->m_SigmoidMax = 1.0;
    this->m_SigmoidMin = -0.8;
    this->m_SigmoidScale = 1e-8;
				
	} // end Constructor

 
	/**
	 * ************************** UpdateCurrentTime ********************
	 *
	 * This function computes the input for the Compute_a function.
	 */

  void AcceleratedGradientDescentOptimizer
		::UpdateCurrentTime( void )
  {
    typedef itk::Function::Sigmoid<double, double> SigmoidType;

    if ( this->m_UseCruzAcceleration )
    {
      if ( this->GetCurrentIteration() > 0 )
      {
        /** Make sigmoid function 
         * Compute beta such that sigmoid(0)=0 
         * We assume Max>0, min<0 */
        SigmoidType sigmoid;
        sigmoid.SetOutputMaximum( this->GetSigmoidMax() );
        sigmoid.SetOutputMinimum( this->GetSigmoidMin() );
        sigmoid.SetAlpha( this->GetSigmoidScale() );
        const double beta = this->GetSigmoidScale() *
           vcl_log( - this->GetSigmoidMax() / this->GetSigmoidMin() );
        sigmoid.SetBeta( beta );

        /** Formula (2) in Cruz */
        const double inprod = inner_product(
          this->m_PreviousGradient, this->GetGradient() );
        this->m_CurrentTime += sigmoid(-inprod);
        this->m_CurrentTime = vnl_math_max( 0.0, this->m_CurrentTime );        
      }

      /** Save for next iteration */
      this->m_PreviousGradient = this->GetGradient();
    }
    else
    {
      /** <NAME>: time = time + E_0. 
       * If you want the parameter estimation but no adaptive stuff, 
       * this may be use useful:  */
      this->m_CurrentTime += ( this->GetSigmoidMax() + this->GetSigmoidMin() ) / 2.0;
    }

  } // end UpdateCurrentTime
	

} // end namespace itk

#endif // end #ifndef __itkAcceleratedGradientDescentOptimizer_cxx

{'fraction_non_alphanumeric': 0.15377657168701944, 'fraction_numerical': 0.007688828584350972, 'mean_word_length': 2.981098109810981, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3146104', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1406, 'n_words': 265}