DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkL2RegularizedLeastSquaresSolver.h
Go to the documentation of this file.
1 
18 #ifndef __itkL2RegularizedLeastSquaresSolver_h
19 #define __itkL2RegularizedLeastSquaresSolver_h
20 
21 #include "vnl/vnl_matrix.h"
22 #include "itkSolverBase.h"
23 
24 
25 namespace itk
26 {
27 
42 template <class TPrecision>
43 class ITK_EXPORT L2RegularizedLeastSquaresSolver : public SolverBase<TPrecision>
44 {
45 public:
49  typedef SmartPointer<Self> Pointer;
50  typedef SmartPointer<const Self> ConstPointer;
51 
53  itkNewMacro(Self);
54 
57 
58  typedef typename Superclass::ValueType ValueType;
63 
65 
67  void SetA(const MatrixPointer& mat);
68  itkGetMacro(A, MatrixPointer);
69  void SetLambda(const MatrixPointer& mat);
70  itkGetMacro(Lambda, MatrixPointer);
71  itkSetMacro(b, VectorPointer);
72  itkGetMacro(b, VectorPointer);
73 
74  itkGetMacro(LS, MatrixPointer);
75  itkGetMacro(ConditionNumber, ValueType);
76 
78  {
79  int N = m_A->Columns();
80  utlException(N==0, "wrong size! m_A->Columns()="<<m_A->Columns());
81  return N;
82  }
83 
85  void Clear() ITK_OVERRIDE;
86  void ClearA()
87  {
88  m_A=MatrixPointer(new MatrixType());
89  m_LS=MatrixPointer(new MatrixType());
90  m_ConditionNumber=-1;
91  }
92  void ClearLambda()
93  {
94  m_Lambda=MatrixPointer(new MatrixType());
95  m_LS=MatrixPointer(new MatrixType());
96  m_ConditionNumber=-1;
97  m_IsLambdaSymmetric = true;
98  }
99  void Clearb()
100  {
101  m_b=VectorPointer(new VectorType());
102  }
103 
104  void VerifyInputs() const ITK_OVERRIDE;
105 
106  void Solve(const VectorType& xInitial=VectorType()) ITK_OVERRIDE;
107  void Initialize(const VectorType& xInitial=VectorType()) ITK_OVERRIDE;
108 
109  ValueType EvaluateCostFunction(const VectorType& x=VectorType()) const ITK_OVERRIDE;
110 
111 protected:
114 
115  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
116 
117  virtual typename LightObject::Pointer InternalClone() const ITK_OVERRIDE;
118 
120  MatrixPointer m_A;
122  VectorPointer m_b;
123 
125  MatrixPointer m_Lambda;
126 
128 
129 
130 private:
131  L2RegularizedLeastSquaresSolver(const Self&); //purposely not implemented
132  void operator=(const Self&); //purposely not implemented
133 
135  MatrixPointer m_LS;
136  ValueType m_ConditionNumber;
137 
138 };
139 
140 }
141 
142 #if ITK_TEMPLATE_EXPLICIT
143 # include "Templates/itkL2RegularizedLeastSquaresSolver+-.h"
144 #endif
145 
146 #if !defined(ITK_MANUAL_INSTANTIATION) && !defined(__itkL2RegularizedLeastSquaresSolver_hxx)
148 #endif
149 
150 
151 #endif
NDArray is a N-Dimensional array class (row-major, c version)
Definition: utlFunctors.h:131
TPrecision ValueType
Definition: itkSolverBase.h:51
#define utlException(cond, expout)
Definition: utlCoreMacro.h:548
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
solve least square problem with L2 regularization
utl_shared_ptr< VectorType > VectorPointer
Definition: itkSolverBase.h:57
utl_shared_ptr< MatrixType > MatrixPointer
Definition: itkSolverBase.h:56
Base class for some optimization solvers using primal-dual updates.
Definition: itkSolverBase.h:39
std::vector< ValueType > ValueContainerType
Definition: itkSolverBase.h:58