Direct Graphical Models  v.1.7.0
SamplesAccumulator.cpp
1 #include "SamplesAccumulator.h"
2 #include "random.h"
3 #include "macroses.h"
4 
5 namespace DirectGraphicalModels
6 {
8  {
9  for (Mat &acc : m_vSamplesAcc) acc.release();
10  std::fill(m_vNumInputSamples.begin(), m_vNumInputSamples.end(), 0);
11  }
12 
13  void CSamplesAccumulator::addSample(const Mat &featureVector, byte state)
14  {
15  // Assertions:
16  DGM_ASSERT_MSG(state < m_vSamplesAcc.size(), "The groundtruth value %d is out of range %zu", state, m_vSamplesAcc.size());
17 
18  if (m_vSamplesAcc[state].rows < m_maxSamples) {
19  m_vSamplesAcc[state].push_back(featureVector.t());
20  }
21  else {
22  int k = random::u(0, m_vNumInputSamples[state]);
23  if (k < m_maxSamples)
24  m_vSamplesAcc[state].row(k) = featureVector.t();
25  }
26  m_vNumInputSamples[state]++;
27  }
28 
29  int CSamplesAccumulator::getNumSamples(byte state) const
30  {
31  DGM_ASSERT_MSG(state < m_vSamplesAcc.size(), "The groundtruth value %d is out of range %zu", state, m_vSamplesAcc.size());
32  return m_vSamplesAcc[state].rows;
33  }
34 
36  {
37  DGM_ASSERT_MSG(state < m_vNumInputSamples.size(), "The groundtruth value %d is out of range %zu", state, m_vNumInputSamples.size());
38  return m_vNumInputSamples[state];
39  }
40 
42  {
43  m_vNumInputSamples[state] = 0;
44  m_vSamplesAcc[state].release();
45  }
46 
47 }
int getNumSamples(byte state) const
Returns the number of stored samples in container for the state (class) state.
void release(byte state)
Releases memory of container for the state (class) state.
void addSample(const Mat &featureVector, byte state)
Adds new sample to the accumulator.
void reset(void)
Resets the accumulator.
T u(T min, T max)
Returns an integer random number with uniform distribution.
Definition: random.h:29
int getNumInputSamples(byte state) const
Returns the number of input samples in container for the state (class) state.