DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkIterativeSolverBase.hxx
Go to the documentation of this file.
1 
20 #ifndef __itkIterativeSolverBase_hxx
21 #define __itkIterativeSolverBase_hxx
22 
23 #include "itkIterativeSolverBase.h"
24 #include "utl.h"
25 
26 
27 namespace itk
28 {
29 
30 //---------------------------------------------------------
31 template <class TPrecision>
34 {
35  m_EPSOfVaribles = 1e-4;
36  m_MaxNumberOfIterations = 1000;
37  m_NumberOfIterations = 0;
38  m_MinRelativeChangeOfCostFunction = 1e-2;
39  m_MinRelativeChangeOfPrimalResidual = 1e-2;
40  m_MinRelativeChangeOfDualResidual = 1e-2;
41  m_UpdateInformation = NONE;
42  m_NumberOfChangeLessThanThreshold=0;
43  // m_MinRelativeChangeOfSeparateVariable = 1e-2;
44 }
45 
46 template < class TPrecision >
47 void
49 ::Solve ( const VectorType& xInitial)
50 {
51  this->VerifyInputs();
52  Initialize(xInitial);
53 }
54 
55 template < class TPrecision >
56 void
58 ::Initialize ( const VectorType& xInitial)
59 {
60  Superclass::Initialize(xInitial);
61  this->m_CostFunction.clear();
62  this->m_DifferenceNormOfPrimalResidual.clear();
63  this->m_DifferenceNormOfDualResidual.clear();
64 
65  this->m_EPSOfPrimalResidual.clear();
66  this->m_EPSOfDualResidual.clear();
67  m_NumberOfIterations = 0;
68  m_NumberOfChangeLessThanThreshold=0;
69 }
70 
71 template < class TPrecision >
72 void
74 ::Clear ( )
75 {
76  Superclass::Clear();
77  this->m_CostFunction.clear();
78  this->m_DifferenceNormOfPrimalResidual.clear();
79  this->m_DifferenceNormOfDualResidual.clear();
80 
81  this->m_EPSOfPrimalResidual.clear();
82  this->m_EPSOfDualResidual.clear();
83  m_NumberOfIterations = 0;
84  m_UpdateInformation = NONE;
85 }
86 
87 template < class TPrecision >
88 typename LightObject::Pointer
91 {
92  typename LightObject::Pointer loPtr = Superclass::InternalClone();
93  typename Self::Pointer rval = dynamic_cast<Self *>(loPtr.GetPointer());
94  if(rval.IsNull())
95  {
96  itkExceptionMacro(<< "downcast to type " << this->GetNameOfClass()<< " failed.");
97  }
98  rval->m_CostFunction = m_CostFunction;
99  rval->m_DifferenceNormOfPrimalResidual = m_DifferenceNormOfPrimalResidual;
100  rval->m_DifferenceNormOfDualResidual = m_DifferenceNormOfDualResidual;
101  rval->m_EPSOfPrimalResidual = m_EPSOfPrimalResidual;
102  rval->m_EPSOfDualResidual = m_EPSOfDualResidual;
103  rval->m_MaxNumberOfIterations = m_MaxNumberOfIterations;
104  rval->m_NumberOfIterations = m_NumberOfIterations;
105  rval->m_MinRelativeChangeOfCostFunction = m_MinRelativeChangeOfCostFunction;
106  rval->m_MinRelativeChangeOfPrimalResidual = m_MinRelativeChangeOfPrimalResidual;
107  rval->m_MinRelativeChangeOfDualResidual = m_MinRelativeChangeOfDualResidual;
108  rval->m_EPSOfVaribles = m_EPSOfVaribles;
109  rval->m_UpdateInformation = m_UpdateInformation;
110  rval->m_NumberOfChangeLessThanThreshold = m_NumberOfChangeLessThanThreshold;
111  return loPtr;
112 }
113 
114 template <class TPrecision>
115 void
117 ::PrintSelf(std::ostream& os, Indent indent) const
118 {
119  Superclass::PrintSelf(os, indent);
120  PrintVar4(true, m_MaxNumberOfIterations, m_NumberOfIterations, m_EPSOfVaribles, m_UpdateInformation, os<<indent);
121  // PrintVar4(true, m_MinRelativeChangeOfCostFunction, m_MinRelativeChangeOfPrimalResidual,
122  // m_MinRelativeChangeOfDualResidual, m_MinRelativeChangeOfSeparateVariable, os<<indent);
123  PrintVar4(true, m_MinRelativeChangeOfCostFunction, m_MinRelativeChangeOfPrimalResidual,
124  m_MinRelativeChangeOfDualResidual, m_NumberOfChangeLessThanThreshold, os<<indent);
125  utl::PrintVector(m_CostFunction, "m_CostFunction", " ", os<<indent);
126  utl::PrintVector(m_DifferenceNormOfPrimalResidual, "m_DifferenceNormOfPrimalResidual", " ", os<<indent);
127  utl::PrintVector(m_DifferenceNormOfDualResidual, "m_DifferenceNormOfDualResidual", " ", os<<indent);
128  utl::PrintVector(m_EPSOfPrimalResidual, "m_EPSOfPrimalResidual", " ", os<<indent);
129  utl::PrintVector(m_EPSOfDualResidual, "m_EPSOfDualResidual", " ", os<<indent);
130 }
131 
132 } // end namespace itk
133 
134 #endif
135 
Base class for some optimization solvers using primal-dual updates.
virtual void Clear() ITK_OVERRIDE
virtual void Solve(const VectorType &xInitial=VectorType()) ITK_OVERRIDE
helper functions specifically used in dmritool
virtual LightObject::Pointer InternalClone() const ITK_OVERRIDE
void PrintVector(const std::vector< T > &vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
Definition: utlCore.h:1002
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
#define PrintVar4(cond, var1, var2, var3, var4, os)
Definition: utlCoreMacro.h:470
Base class for some optimization solvers using primal-dual updates.
Definition: itkSolverBase.h:39
void Initialize(const VectorType &xInitial=VectorType()) ITK_OVERRIDE
SmartPointer< Self > Pointer