Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkImpurityLoss.cpp
Go to the documentation of this file.
1 #ifndef mitkImpurityLoss_cpp
2 #define mitkImpurityLoss_cpp
3 
4 #include <mitkImpurityLoss.h>
5 
6 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
7 template <class T>
9  vigra::ProblemSpec<T> const &ext) :
10  m_UsePointWeights(false),
11  m_Labels(labels),
12  m_Counts(ext.class_count_, 0.0),
13  m_ClassWeights(ext.class_weights_),
14  m_TotalCount(0.0)
15 {
16 }
17 
18 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
19 void
21 {
22  m_Counts.init(0);
23  m_TotalCount = 0.0;
24 }
25 
26 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
27 template <class TDataIterator>
28 double
30 {
31  for (TDataIterator iter = begin; iter != end; ++iter)
32  {
33  double pointProbability = 1.0;
34  if (m_UsePointWeights)
35  {
36  pointProbability = m_PointWeights(*iter,0);
37  }
38  m_Counts[m_Labels(*iter,0)] += pointProbability;
39  m_TotalCount += pointProbability;
40  }
41  return m_LossFunction(m_Counts, m_ClassWeights, m_TotalCount);
42 }
43 
44 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
45 template <class TDataIterator>
46 double
48 {
49  for (TDataIterator iter = begin; iter != end; ++iter)
50  {
51  double pointProbability = 1.0;
52  if (m_UsePointWeights)
53  {
54  pointProbability = m_PointWeights(*iter,0);
55  }
56  m_Counts[m_Labels(*iter,0)] -= pointProbability;
57  m_TotalCount -= pointProbability;
58  }
59  return m_LossFunction(m_Counts, m_ClassWeights, m_TotalCount);
60 }
61 
62 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
63 template <class TArray>
64 double
66 {
67  Reset();
68  std::copy(initCounts.begin(), initCounts.end(), m_Counts.begin());
69  m_TotalCount = std::accumulate(m_Counts.begin(), m_Counts.end(), 0.0);
70  return m_LossFunction(m_Counts, m_ClassWeights, m_TotalCount);
71 }
72 
73 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
74 vigra::ArrayVector<double> const&
76 {
77  return m_Counts;
78 }
79 
80 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
81 void
83 {
84  m_UsePointWeights = useWeights;
85 }
86 
87 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
88 bool
90 {
91  return m_UsePointWeights;
92 }
93 
94 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
95 void
97 {
98  m_PointWeights = weight;
99 }
100 
101 template <class TLossFunction, class TLabelContainer, class TWeightContainer>
104 {
105  return m_PointWeights;
106 }
107 
108 
109 #endif // mitkImpurityLoss_cpp
110 
111 
void UsePointWeights(bool useWeights)
void SetPointWeights(TWeightContainer weight)
double Decrement(TDataIterator begin, TDataIterator end)
vigra::ArrayVector< double > const & Response()
ImpurityLoss(TLabelContainer const &labels, vigra::ProblemSpec< T > const &ext)
double Increment(TDataIterator begin, TDataIterator end)
WeightContainerType GetPointWeights()
double Init(TArray initCounts)
TWeightContainer WeightContainerType