1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* @file SampleSet.h
*
* @author <a href="mailto:mellmann@informatik.hu-berlin.de">Heinrich Mellmann</a>
* Declaration of class SampleSet
*/

#ifndef _SampleSet_h_
#define _SampleSet_h_

#include "Sample.h"
#include <Tools/Math/Moments2.h>
#include <vector>
#include "Tools/Debug/DebugDrawings.h"

class SampleSet
{

public:
  typedef size_t size_type;

  SampleSet(size_t n = 100)
    :
    samples(n)
  {
  }

  ~SampleSet() {}

  /** 
  * sort the particles according to their likelihood
  * with quicksort
  */
  void sort(bool descending = true);

  /** 
  * normalize the likelihoods of patricle so thay sum up to 1
  */
  void normalize(double offset = 0.0);

  /** 
  * reset the likelihoods of patricle to 1/numberOfParticles
  */
  void resetLikelihood();

  /** 
  * set the likelihood to th given value for every particle
  */
  void setLikelihood(double v);

  /**
  * Access operator.
  * @param index The index of the sample to access.
  */
  inline Sample& operator[](int index) {return samples[index];}
  inline Sample& operator[](size_t index) {return samples[index];}

  /**
  * yeah, guess what it does ...
  */
  inline size_t size() const { return samples.size(); }

  /**
   * Constant access operator.
   * @param index The index of the sample to access.
   */
  inline const Sample& operator[](int index) const {return samples[index];}

  const Sample& getMostLikelySample() const;
  Sample meanOfLargestCluster(Moments2<2>& moments) const;
  Sample meanOfCluster(Moments2<2>& moments, int idx) const;

  // TODO: move it out of here
  void drawCluster(DrawingCanvas2D& canvas, unsigned int clusterId) const;
  void drawImportance(DrawingCanvas2D& canvas, bool arrows = true) const;

private:
  std::vector<Sample> samples;

  void quicksort(int d, int low, int high);
};

#endif //_SampleSet_h_