DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Member Functions | Private Attributes
DGtal::AngleLinearMinimizerByGradientDescent Class Reference

#include <AngleLinearMinimizer.h>

Inheritance diagram for DGtal::AngleLinearMinimizerByGradientDescent:
Inheritance graph
[legend]
Collaboration diagram for DGtal::AngleLinearMinimizerByGradientDescent:
Collaboration graph
[legend]

Public Member Functions

 AngleLinearMinimizerByGradientDescent (double step=0.1)
virtual ~AngleLinearMinimizerByGradientDescent ()
virtual double lastDelta () const
virtual void selfDisplay (std::ostream &aStream) const
- Public Member Functions inherited from DGtal::AngleLinearMinimizer
virtual ~AngleLinearMinimizer ()
 AngleLinearMinimizer ()
void reset ()
void init (unsigned int nbMax)
ValueInforw (unsigned int i)
const ValueInforo (unsigned int i) const
unsigned int maxSize () const
unsigned int size () const
void setSize (unsigned int nb)
void setIsCurveOpen (bool is_curve_open=false)
double getEnergy (unsigned int i1, unsigned int i2) const
double getFormerEnergy (unsigned int i1, unsigned int i2) const
std::vector< double > getGradient () const
std::vector< double > getFormerGradient () const
double optimize ()
double optimize (unsigned int i1, unsigned int i2)
double sum () const
double max () const
std::string className () const
bool isValid () const

Protected Member Functions

virtual void oneStep (unsigned int i1, unsigned int i2)

Private Attributes

double myStep

Additional Inherited Members

- Protected Attributes inherited from DGtal::AngleLinearMinimizer
bool myIsCurveOpen
ValueInfomyValues
unsigned int mySize

Detailed Description

Specializes AngleLinearMinimizer to optimize with a gradient descent method.

Definition at line 423 of file AngleLinearMinimizer.h.


Constructor & Destructor Documentation

DGtal::AngleLinearMinimizerByGradientDescent::AngleLinearMinimizerByGradientDescent ( double  aStep = 0.1)
inline

Default constructor. Does nothing.

Definition at line 89 of file AngleLinearMinimizer.ih.

: myStep( aStep )
{}
DGtal::AngleLinearMinimizerByGradientDescent::~AngleLinearMinimizerByGradientDescent ( )
inlinevirtual

Destructor. Does nothing.

Definition at line 98 of file AngleLinearMinimizer.ih.

{}

Member Function Documentation

double DGtal::AngleLinearMinimizerByGradientDescent::lastDelta ( ) const
virtual

Should be used to stop the minimization process. The smaller is this value, the more the optimization is at an end. May have several meanings, like the infinite norm of the last displacement or the infinite norm of the projected gradient.

Returns:
an upper bound on the norm of the last displacement.

Reimplemented from DGtal::AngleLinearMinimizer.

Definition at line 389 of file AngleLinearMinimizer.cpp.

References DGtal::AngleLinearMinimizer::ValueInfo::oldValue, and DGtal::AngleLinearMinimizer::ValueInfo::value.

{
vector<double> grad ( getFormerGradient() );
double ninf = 0.0;
for ( unsigned int i = 0; i < size(); i++ )
{
const ValueInfo & vi = this->ro( i );
if ( vi.value != vi.oldValue )
{
double n = fabs( grad[ i ] );
if ( n > ninf ) ninf = n;
}
}
return ninf;
}
void DGtal::AngleLinearMinimizerByGradientDescent::oneStep ( unsigned int  i1,
unsigned int  i2 
)
protectedvirtual

The method which performs the optimization effectively. Use a relaxation technique. The optimization is performed on values [i1] included to [i2] excluded.

Parameters:
i1the first value to be optimized (between 0 and 'size()-1').
i2the value after the last to be optimized (between 0 and 'size()-1').

Reimplemented from DGtal::AngleLinearMinimizer.

Definition at line 361 of file AngleLinearMinimizer.cpp.

References DGtal::AngleComputer::cast(), DGtal::AngleComputer::less(), DGtal::AngleLinearMinimizer::ValueInfo::max, DGtal::AngleLinearMinimizer::ValueInfo::min, DGtal::ModuloComputer< TInteger >::next(), DGtal::AngleLinearMinimizer::ValueInfo::oldValue, and DGtal::AngleLinearMinimizer::ValueInfo::value.

{
vector<double> grad ( getFormerGradient() );
double mid;
unsigned int i = i1;
do
{
unsigned int inext = mc.next( i );
ValueInfo & vi = this->rw( i );
double val = vi.oldValue;
mid = AngleComputer::cast( val - myStep*grad[ i ] );
if ( AngleComputer::less( mid, vi.min ) ) mid = vi.min;
if ( AngleComputer::less( vi.max, mid ) ) mid = vi.max;
vi.value = mid;
// go to next.
i = inext;
}
while ( i != i2 );
double E1 = getFormerEnergy( i1, i2 );
double E2 = getEnergy( i1, i2 );
cerr << "E1=" << E1 << " E2=" << E2 << " s=" << myStep << endl;
}
void DGtal::AngleLinearMinimizerByGradientDescent::selfDisplay ( std::ostream &  aStream) const
virtual

Writes/Displays the object on an output stream.

Parameters:
aStreamthe output stream where the object is written.

Reimplemented from DGtal::AngleLinearMinimizer.

Definition at line 495 of file AngleLinearMinimizer.cpp.

{
aStream << "[LinearMinimizer::gradient descent " << myStep << "]";
}

Field Documentation

double DGtal::AngleLinearMinimizerByGradientDescent::myStep
private

The step for the gradient descent.

Definition at line 430 of file AngleLinearMinimizer.h.


The documentation for this class was generated from the following files: