22 #ifndef otbGaussianModelComponent_hxx
23 #define otbGaussianModelComponent_hxx
27 #include "itkNumericTraits.h"
36 template <
class TSample>
39 m_CovarianceEstimator =
nullptr;
40 m_GaussianMembershipFunction =
nullptr;
43 template <
class TSample>
46 Superclass::PrintSelf(os, indent);
48 os << indent <<
"Mean Estimator: " << m_CovarianceEstimator << std::endl;
49 os << indent <<
"Covariance Estimator: " << m_CovarianceEstimator << std::endl;
50 os << indent <<
"GaussianMembershipFunction: " << m_GaussianMembershipFunction << std::endl;
53 template <
class TSample>
57 os << indent <<
"Gaussian model component : \n";
58 os << indent <<
"Mean : ";
59 for (i = 0; i < m_Mean.Size(); ++i)
60 os << m_Mean[i] <<
"\t";
61 os <<
"\n" << indent <<
"Covariance : ";
62 for (i = 0; i < m_Mean.Size(); ++i)
64 for (j = 0; j < m_Mean.Size(); ++j)
65 os << m_Covariance(i, j) <<
"\t";
66 os <<
"\n" << indent <<
" ";
71 template <
class TSample>
74 Superclass::SetSample(sample);
76 this->m_Parameters.SetSize(measurementVectorLength * (1 + measurementVectorLength));
79 m_Mean.SetSize(measurementVectorLength);
83 m_Covariance.SetSize(measurementVectorLength, measurementVectorLength);
85 m_CovarianceEstimator = CovarianceEstimatorType::New();
86 m_CovarianceEstimator->SetInput(sample);
87 m_CovarianceEstimator->Update();
89 m_GaussianMembershipFunction = NativeMembershipFunctionType::New();
91 m_GaussianMembershipFunction->SetMeasurementVectorSize(measurementVectorLength);
95 template <
class TSample>
98 Superclass::SetParameters(parameters);
100 unsigned int paramIndex = 0;
105 m_Mean.SetSize(measurementVectorSize);
106 for (i = 0; i < measurementVectorSize; i++)
108 m_Mean[i] = parameters[paramIndex];
112 m_Covariance.SetSize(measurementVectorSize, measurementVectorSize);
113 for (i = 0; i < measurementVectorSize; i++)
114 for (j = 0; j < measurementVectorSize; j++)
116 m_Covariance(i, j) = parameters[paramIndex];
120 this->m_GaussianMembershipFunction->SetMean(m_Mean);
121 this->m_GaussianMembershipFunction->SetCovariance(&m_Covariance);
124 template <
class TSample>
127 if (this->IsSampleModified() == 0)
136 typename CovarianceEstimatorType::MeasurementVectorType meanOutput = m_CovarianceEstimator->GetMean();
138 for (i = 0; i < measurementVectorSize; i++)
140 m_Mean.SetElement(i, meanOutput.GetElement(i));
141 this->m_Parameters[paramIndex] = meanOutput.GetElement(i);
146 const typename CovarianceEstimatorType::MatrixType covariance = m_CovarianceEstimator->GetCovarianceMatrix();
148 for (i = 0; i < measurementVectorSize; i++)
149 for (j = 0; j < measurementVectorSize; j++)
151 this->m_Parameters[paramIndex] = covariance.GetVnlMatrix().get(i, j);
152 m_Covariance(i, j) = covariance.GetVnlMatrix().get(i, j);
156 this->m_GaussianMembershipFunction->SetMean(meanOutput);
157 this->m_GaussianMembershipFunction->SetCovariance(m_Covariance);
159 Superclass::GenerateData();