Shapeworks Studio  2.1
Shape analysis software suite
List of all members | Public Types | Public Member Functions | Protected Member Functions
itk::PSMRegressionShapeMatrixAttribute< T, VDimension > Class Template Reference
+ Inheritance diagram for itk::PSMRegressionShapeMatrixAttribute< T, VDimension >:
+ Collaboration diagram for itk::PSMRegressionShapeMatrixAttribute< T, VDimension >:

Public Types

typedef T DataType
 
typedef PSMRegressionShapeMatrixAttribute Self
 
typedef PSMShapeMatrixAttribute< T, VDimension > Superclass
 
typedef SmartPointer< SelfPointer
 
typedef SmartPointer< const SelfConstPointer
 
typedef WeakPointer< const SelfConstWeakPointer
 
- Public Types inherited from itk::PSMShapeMatrixAttribute< T, VDimension >
typedef T DataType
 
typedef PSMShapeMatrixAttribute Self
 
typedef PSMAttribute< VDimension > Superclass
 
typedef SmartPointer< SelfPointer
 
typedef SmartPointer< const SelfConstPointer
 
typedef WeakPointer< const SelfConstWeakPointer
 
- Public Types inherited from itk::PSMAttribute< VDimension >
typedef PSMAttribute Self
 
typedef DataObject Superclass
 
typedef SmartPointer< SelfPointer
 
typedef SmartPointer< const SelfConstPointer
 
typedef WeakPointer< const SelfConstWeakPointer
 

Public Member Functions

 itkNewMacro (Self)
 
 itkTypeMacro (PSMRegressionShapeMatrixAttribute, PSMShapeMatrixAttribute)
 
virtual void UpdateMeanMatrix ()
 
vnl_vector< double > ComputeMean (double k) const
 
void ResizeParameters (unsigned int n)
 
virtual void ResizeMeanMatrix (int rs, int cs)
 
void ResizeExplanatory (unsigned int n)
 
virtual void DomainAddEventCallback (Object *, const EventObject &e)
 
virtual void PositionAddEventCallback (Object *o, const EventObject &e)
 
virtual void PositionSetEventCallback (Object *o, const EventObject &e)
 
virtual void PositionRemoveEventCallback (Object *, const EventObject &)
 
void SetDomainsPerShape (int i)
 
int GetDomainsPerShape () const
 
void SetVariables (const std::vector< double > &v)
 
void SetExplanatory (const std::vector< double > &v)
 
void SetExplanatory (unsigned int i, double q)
 
const vnl_vector< double > & GetVariables () const
 
const vnl_vector< double > & GetExplanatory () const
 
vnl_vector< double > & GetExplanatory ()
 
const double & GetExplanatory (unsigned int i) const
 
double & GetExplanatory (unsigned int i)
 
const vnl_matrix< double > & GetMeanMatrix () const
 
vnl_matrix< double > & GetMeanMatrix ()
 
const vnl_vector< double > & GetSlope () const
 
vnl_vector< double > & GetSlope ()
 
const vnl_vector< double > & GetIntercept () const
 
vnl_vector< double > GetIntercept ()
 
void SetSlope (const std::vector< double > &v)
 
void SetSlope (const vnl_vector< double > &v)
 
void SetIntercept (const std::vector< double > &v)
 
void SetIntercept (const vnl_vector< double > &v)
 
virtual void EstimateParameters ()
 
virtual void Initialize ()
 
virtual void BeforeIteration ()
 
void SetRegressionInterval (int i)
 
int GetRegressionInterval () const
 
- Public Member Functions inherited from itk::PSMShapeMatrixAttribute< T, VDimension >
 itkNewMacro (Self)
 
 itkTypeMacro (PSMShapeMatrixAttribute, PSMAttribute)
 
virtual void ResizeMatrix (int, int)
 
void SetDomainsPerShape (int i)
 
int GetDomainsPerShape () const
 
virtual void AfterIteration ()
 
virtual void SetMatrix (const vnl_matrix< T > &m)
 
- Public Member Functions inherited from itk::PSMAttribute< VDimension >
 itkNewMacro (Self)
 
 itkTypeMacro (PSMAttribute, DataObject)
 
virtual void EventCallback (Object *, const EventObject &)
 
virtual void EventWithIndexCallback (Object *, const EventObject &)
 
virtual void TransformSetEventCallback (Object *, const EventObject &)
 
virtual void PrefixTransformSetEventCallback (Object *, const EventObject &)
 
virtual void NeighborhoodSetEventCallback (Object *, const EventObject &)
 

Protected Member Functions

void PrintSelf (std::ostream &os, Indent indent) const
 
- Protected Member Functions inherited from itk::PSMShapeMatrixAttribute< T, VDimension >
void PrintSelf (std::ostream &os, Indent indent) const
 
- Protected Member Functions inherited from itk::PSMAttribute< VDimension >
void PrintSelf (std::ostream &os, Indent indent) const
 

Additional Inherited Members

- Public Attributes inherited from itk::PSMAttribute< VDimension >
DefinedCallbacksStruct m_DefinedCallbacks
 
- Protected Attributes inherited from itk::PSMShapeMatrixAttribute< T, VDimension >
int m_DomainsPerShape
 

Detailed Description

template<class T, unsigned int VDimension>
class itk::PSMRegressionShapeMatrixAttribute< T, VDimension >

Definition at line 33 of file itkPSMRegressionShapeMatrixAttribute.h.

Member Typedef Documentation

template<class T , unsigned int VDimension>
typedef T itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::DataType

Standard class typedefs

Definition at line 38 of file itkPSMRegressionShapeMatrixAttribute.h.

Member Function Documentation

template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::BeforeIteration ( )
virtual

Invoked before an iteration of an optimization that depends on this class.

Reimplemented from itk::PSMShapeMatrixAttribute< T, VDimension >.

Definition at line 270 of file itkPSMRegressionShapeMatrixAttribute.hxx.

271 {
272  m_UpdateCounter ++;
273  if (m_UpdateCounter >= m_RegressionInterval)
274  {
275  m_UpdateCounter = 0;
276  this->EstimateParameters();
277  this->UpdateMeanMatrix();
278  }
279 }
template<class T , unsigned int VDimension>
vnl_vector<double> itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::ComputeMean ( double  k) const
inline

Return the mean value for a given explanatory variable.

Definition at line 55 of file itkPSMRegressionShapeMatrixAttribute.h.

56  {
57  return m_Intercept + m_Slope * k;
58  }
template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::DomainAddEventCallback ( Object *  ,
const EventObject &  e 
)
virtual

Callbacks that may be defined by a subclass. If a subclass defines one of these callback methods, the corresponding flag in m_DefinedCallbacks should be set to true so that the PSMParticleSystem will know to register the appropriate event with this method.

Reimplemented from itk::PSMShapeMatrixAttribute< T, VDimension >.

Definition at line 99 of file itkPSMRegressionShapeMatrixAttribute.hxx.

100 {
101  const ParticleDomainAddEvent &event
102  = dynamic_cast<const ParticleDomainAddEvent &>(e);
103  unsigned int d = event.GetDomainIndex();
104 
105  if ( d % this->m_DomainsPerShape == 0 )
106  {
107  this->ResizeMatrix(this->rows(), this->cols()+1);
108  this->ResizeMeanMatrix(this->rows(), this->cols()+1);
109  this->ResizeExplanatory(this->cols());
110  }
111 }
template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::EstimateParameters ( )
virtual

Estimates the linear regression parameters (slope and intercept) in shape space.

Definition at line 211 of file itkPSMRegressionShapeMatrixAttribute.hxx.

212 {
213  const double tol = 1.0e-12;
214  vnl_matrix<double> X = *this + m_MeanMatrix;
215 
216  // Number of samples
217  double n = (double)(X.cols());
218 
219  vnl_vector<double> sumtx = m_Explanatory[0] * X.get_column(0);
220  vnl_vector<double> sumx = X.get_column(0);
221  double sumt = m_Explanatory[0];
222  double sumt2 = m_Explanatory[0] * m_Explanatory[0];
223  for (unsigned int k = 1; k < X.cols(); k++) // k is the sample number
224  {
225  sumtx += m_Explanatory[k] * X.get_column(k);
226  sumx += X.get_column(k);
227  sumt += m_Explanatory[k];
228  sumt2 += m_Explanatory[k] * m_Explanatory[k];
229  }
230 
231  m_Slope = (n * sumtx - (sumx * sumt)) / ((n * sumt2 - (sumt*sumt)) + tol);
232 
233  vnl_vector<double> sumbt = m_Slope * m_Explanatory[0];
234  for (unsigned int k = 1; k < X.cols(); k++)
235  {
236  sumbt += m_Slope * m_Explanatory[k];
237  }
238 
239  m_Intercept = (sumx - sumbt) / n;
240 }
template<class T , unsigned int VDimension>
const vnl_vector<double>& itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::GetIntercept ( ) const
inline

Returns the intercept (in shape space) of the regression line.

Definition at line 127 of file itkPSMRegressionShapeMatrixAttribute.h.

128  { return m_Intercept; }
template<class T , unsigned int VDimension>
const vnl_vector<double>& itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::GetSlope ( ) const
inline

Returns the slope (in shape space) of the regression line.

Definition at line 121 of file itkPSMRegressionShapeMatrixAttribute.h.

122  { return m_Slope; }
template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::Initialize ( )
virtual

Initialize some parameters. This method should be invoked before any optimization is run that depends on this class.

Reimplemented from itk::PSMShapeMatrixAttribute< T, VDimension >.

Definition at line 244 of file itkPSMRegressionShapeMatrixAttribute.hxx.

245 {
246  // if (m_Explanatory.size() != this->columns())
247  // {
248  // itkExceptionMacro("The number of columns (shapes) does not match the number of explanatory variables -- or no explanatory variables have been set.");
249  // }
250  // Check that the paramters are not all equal. This is likely
251  // because the user did not set the parameters. In any case, it
252  // will result in undefined results (nan) for the slope and
253  // intercept.
254  bool ok = false;
255  for (unsigned int i = 1; i < m_Explanatory.size(); i++)
256  {
257  if (m_Explanatory[i] != m_Explanatory[0]) ok = true;
258  }
259  if (!ok)
260  {
261  itkExceptionMacro("All explanatory variables are the same value. Please set these values before running the filter.");
262  }
263  m_Intercept.fill(0.0);
264  m_Slope.fill(0.0);
265  m_MeanMatrix.fill(0.0);
266 }
template<class T , unsigned int VDimension>
itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::itkNewMacro ( Self  )

Method for creation through the object factory.

template<class T , unsigned int VDimension>
itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::itkTypeMacro ( PSMRegressionShapeMatrixAttribute< T, VDimension >  ,
PSMShapeMatrixAttribute   
)

Run-time type information (and related methods).

template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::PositionAddEventCallback ( Object *  o,
const EventObject &  e 
)
virtual

Callback defining actions when a position is added to a ParticleSystem. This method will likely be called from itkParticleSystem with the event ParticleAddEvent.

Reimplemented from itk::PSMShapeMatrixAttribute< T, VDimension >.

Definition at line 115 of file itkPSMRegressionShapeMatrixAttribute.hxx.

116 {
117  const ParticlePositionAddEvent &event
118  = dynamic_cast<const ParticlePositionAddEvent &>(e);
119  const PSMParticleSystem<VDimension> *ps
120  = dynamic_cast<const PSMParticleSystem<VDimension> *>(o);
121  const int d = event.GetDomainIndex();
122  const unsigned int idx = event.GetPositionIndex();
124  = ps->GetTransformedPosition(idx, d);
125 
126  const unsigned int PointsPerDomain = ps ->GetNumberOfParticles(d);
127 
128  // Make sure we have enough rows.
129  if ((ps->GetNumberOfParticles(d) * VDimension * this->m_DomainsPerShape)
130  > this->rows())
131  {
132  this->ResizeParameters(PointsPerDomain * VDimension * this->m_DomainsPerShape);
133  this->ResizeMatrix(PointsPerDomain * VDimension * this->m_DomainsPerShape,
134  this->cols());
135  this->ResizeMeanMatrix(PointsPerDomain * VDimension * this->m_DomainsPerShape,
136  this->cols());
137  }
138 
139  // ! CANNOT ADD POSITION INFO UNTIL ALL POINTS PER DOMAIN IS KNOWN !
140  // Add position info to the matrix
141  unsigned int k = ((d % this->m_DomainsPerShape) * PointsPerDomain * VDimension)
142  + (idx * VDimension);
143  for (unsigned int i = 0; i < VDimension; i++)
144  {
145  this->operator()(i+k, d / this->m_DomainsPerShape) = pos[i];
146  }
147 }
Point< double, VDimension > PointType
template<class T , unsigned int VDimension>
virtual void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::PositionRemoveEventCallback ( Object *  ,
const EventObject &   
)
inlinevirtual

Unimplemented. Reserved for future.

Reimplemented from itk::PSMShapeMatrixAttribute< T, VDimension >.

Definition at line 78 of file itkPSMRegressionShapeMatrixAttribute.h.

79  {
80  itkExceptionMacro("Method has not been implemented");
81  }
template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::PositionSetEventCallback ( Object *  o,
const EventObject &  e 
)
virtual

Callback for defining actions when a position value is set – usually from ParticleSystem.

Reimplemented from itk::PSMShapeMatrixAttribute< T, VDimension >.

Definition at line 151 of file itkPSMRegressionShapeMatrixAttribute.hxx.

152 {
153  const ParticlePositionSetEvent &event
154  = dynamic_cast <const ParticlePositionSetEvent &>(e);
155 
156  const PSMParticleSystem<VDimension> *ps
157  = dynamic_cast<const PSMParticleSystem<VDimension> *>(o);
158  const int d = event.GetDomainIndex();
159  const unsigned int idx = event.GetPositionIndex();
160  const typename PSMParticleSystem<VDimension>::PointType pos = ps->GetTransformedPosition(idx, d);
161  const unsigned int PointsPerDomain = ps ->GetNumberOfParticles(d);
162 
163  // Modify matrix info
164  // unsigned int k = VDimension * idx;
165  unsigned int k = ((d % this->m_DomainsPerShape) * PointsPerDomain * VDimension)
166  + (idx * VDimension);
167 
168  for (unsigned int i = 0; i < VDimension; i++)
169  {
170  this->operator()(i+k, d / this->m_DomainsPerShape) =
171  pos[i] - m_MeanMatrix(i+k, d/ this->m_DomainsPerShape);
172  }
173 }
Point< double, VDimension > PointType
template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::SetDomainsPerShape ( int  i)
inline

Set/Get the number of domains per shape. This can only be safely done before shapes are initialized with points!

Definition at line 85 of file itkPSMRegressionShapeMatrixAttribute.h.

86  { this->m_DomainsPerShape = i; }
template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::SetIntercept ( const std::vector< double > &  v)

Sets the intercept (in shape space) of the regression line.

Definition at line 199 of file itkPSMRegressionShapeMatrixAttribute.hxx.

200 {
201  ResizeParameters(v.size());
202  for (unsigned int i = 0; i < v.size(); i++)
203  {
204  m_Intercept[i] = v[i];
205  }
206 
207 }
template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::SetRegressionInterval ( int  i)
inline

Set / Get the interval between estimations of the regression model. The units are number of optimizer iterations. For example, if you are running an optimization in which you only want this class to update every 10 iterations, then you would set this value to 10.

Definition at line 163 of file itkPSMRegressionShapeMatrixAttribute.h.

164  { m_RegressionInterval = i; }
template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::SetSlope ( const std::vector< double > &  v)

Sets the slope (in shape space) of the regression line.

Definition at line 188 of file itkPSMRegressionShapeMatrixAttribute.hxx.

189 {
190  ResizeParameters(v.size());
191  for (unsigned int i = 0; i < v.size(); i++)
192  {
193  m_Slope[i] = v[i];
194  }
195 }
template<class T , unsigned int VDimension>
void itk::PSMRegressionShapeMatrixAttribute< T, VDimension >::SetVariables ( const std::vector< double > &  v)
inline

Set/Get the explanatory variables (e.g. time). There should be one variable per domain.

Definition at line 92 of file itkPSMRegressionShapeMatrixAttribute.h.

93  {
94  this->SetExplanatory(v);
95  }

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