MINT2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
HyperPointSet Class Reference

#include <HyperPointSet.h>

Public Member Functions

const int & getDimension () const
 
bool compatible (const HyperPoint &other, bool printError=true) const
 
const HyperPointat (int i) const
 
HyperPointat (int i)
 
unsigned int size () const
 
void push_back (const HyperPoint &point)
 
void addHyperPointSet (const HyperPointSet &other)
 
void removeDuplicates ()
 
void sort ()
 
double getSumW () const
 
double getSumW2 () const
 
double getCorrelation (int i, int j) const
 
TMatrixD getCorrelationMatrix () const
 
double getCovarience (int i, int j) const
 
TMatrixD getCovarienceMatrix () const
 
HyperPoint getMin () const
 Get a HyperCuboid that surrounds the points. More...
 
HyperPoint getMax () const
 Get a HyperPoint that gives the maximum in each dim. More...
 
HyperPoint mean () const
 
HyperPoint geometricMean () const
 
HyperPoint harmonicMean () const
 
void save (TString path)
 
void load (TString path)
 
void print (std::ostream &os=std::cout) const
 
 HyperPointSet (int dimension)
 
 HyperPointSet (const HyperPoint &point)
 
 HyperPointSet (const HyperPoint &point1, const HyperPoint &point2)
 
 HyperPointSet (const HyperPoint &point1, const HyperPoint &point2, const HyperPoint &point3)
 
 HyperPointSet (int npoints, const HyperPoint &point)
 
 HyperPointSet (TString path)
 
virtual ~HyperPointSet ()
 
bool linearlyIndependant () const
 
HyperPointSet gramSchmidtProcess () const
 
void normalise ()
 

Private Member Functions

void save ()
 

Private Attributes

int _dimension
 
std::vector< HyperPoint_points
 

Detailed Description

HyperPlot, Author: Sam Harnew, sam.h.nosp@m.arne.nosp@m.w@gma.nosp@m.il.c.nosp@m.om , Date: Dec 2015

A vector of HyperPoints

Definition at line 31 of file HyperPointSet.h.

Constructor & Destructor Documentation

◆ HyperPointSet() [1/6]

HyperPointSet::HyperPointSet ( int  dimension)

Standard constuctor where only the dimensionality is given

Definition at line 6 of file HyperPointSet.cpp.

6  :
7  _dimension(dimension)
8 {
9  WELCOME_LOG << "Hello from the HyperPointSet() Constructor";
10 }
#define WELCOME_LOG

◆ HyperPointSet() [2/6]

HyperPointSet::HyperPointSet ( const HyperPoint point)

Constuctor for a HyperPointSet that takes dimensionality from a given HyperPoint and adds that point to the HyperPointSet

Definition at line 35 of file HyperPointSet.cpp.

35  :
36  _dimension(point.getDimension())
37 {
38  push_back(point);
39 }
int getDimension() const
Definition: HyperPoint.h:99
void push_back(const HyperPoint &point)

◆ HyperPointSet() [3/6]

HyperPointSet::HyperPointSet ( const HyperPoint point1,
const HyperPoint point2 
)

Constuctor for a HyperPointSet that takes dimensionality from a given HyperPoint and adds that point and another to the HyperPointSet

Definition at line 43 of file HyperPointSet.cpp.

43  :
44  _dimension(point1.getDimension())
45 {
46  push_back(point1);
47  push_back(point2);
48 }
int getDimension() const
Definition: HyperPoint.h:99
void push_back(const HyperPoint &point)

◆ HyperPointSet() [4/6]

HyperPointSet::HyperPointSet ( const HyperPoint point1,
const HyperPoint point2,
const HyperPoint point3 
)

Constuctor for a HyperPointSet that takes dimensionality from a given HyperPoint and adds that point and another 2 to the HyperPointSet

Definition at line 52 of file HyperPointSet.cpp.

52  :
53  _dimension(point1.getDimension())
54 {
55  push_back(point1);
56  push_back(point2);
57  push_back(point3);
58 }
int getDimension() const
Definition: HyperPoint.h:99
void push_back(const HyperPoint &point)

◆ HyperPointSet() [5/6]

HyperPointSet::HyperPointSet ( int  npoints,
const HyperPoint point 
)

Constuctor for a HyperPointSet that repeats the same point a total of npoints times.

Definition at line 24 of file HyperPointSet.cpp.

24  :
25  _dimension(point.getDimension())
26 {
27 
28  for (int i = 0; i < npoints; i++) push_back(point);
29 
30 }
int getDimension() const
Definition: HyperPoint.h:99
void push_back(const HyperPoint &point)

◆ HyperPointSet() [6/6]

HyperPointSet::HyperPointSet ( TString  path)

Constuctor for loading exisiting HyperPointSet from a file

Definition at line 14 of file HyperPointSet.cpp.

14  :
15  _dimension(-1)
16 {
17 
18  load(path);
19 
20 }
void load(TString path)

◆ ~HyperPointSet()

HyperPointSet::~HyperPointSet ( )
virtual

Destructor

Definition at line 506 of file HyperPointSet.cpp.

506  {
507  GOODBYE_LOG << "Goodbye from the HyperPointSet() Destructor";
508 }
#define GOODBYE_LOG

Member Function Documentation

◆ addHyperPointSet()

void HyperPointSet::addHyperPointSet ( const HyperPointSet other)

Add all the points from another HyperPointSet to this one.

Definition at line 202 of file HyperPointSet.cpp.

202  {
203 
204  if (_dimension != other._dimension){
205  ERROR_LOG << "Removing all duplicates from the HyperPointSet - did you remember to call sort() first?!?";
206 
207  }
208 
209  for (unsigned int i = 0; i < other.size(); i++){
210  this->push_back(other.at(i));
211  }
212 
213 }
#define ERROR_LOG
const HyperPoint & at(int i) const
unsigned int size() const
void push_back(const HyperPoint &point)

◆ at() [1/2]

const HyperPoint & HyperPointSet::at ( int  i) const

Get a point from the HyperPointSet

Definition at line 72 of file HyperPointSet.cpp.

72  {
73  return _points.at(i);
74 }
std::vector< HyperPoint > _points
Definition: HyperPointSet.h:34

◆ at() [2/2]

HyperPoint & HyperPointSet::at ( int  i)

Get a point from the HyperPointSet

Definition at line 78 of file HyperPointSet.cpp.

78  {
79  return _points.at(i);
80 }
std::vector< HyperPoint > _points
Definition: HyperPointSet.h:34

◆ compatible()

bool HyperPointSet::compatible ( const HyperPoint other,
bool  printError = true 
) const

Is this HyperPoint compatible with this HyperPointSet? (same dimension)

Definition at line 62 of file HyperPointSet.cpp.

62  {
63 
64  if (_dimension == other.getDimension()) return true;
65 
66  if (printError) ERROR_LOG << "This HyperPoint is NOT compatible with this HyperPointSet";
67  return false;
68 }
#define ERROR_LOG
int getDimension() const
Definition: HyperPoint.h:99

◆ geometricMean()

HyperPoint HyperPointSet::geometricMean ( ) const

Get the geometric mean of all points. This does not use the weights.

Definition at line 460 of file HyperPointSet.cpp.

460  {
461 
462  HyperPoint geoMean(getDimension());
463  for (unsigned i = 0; i < size(); i++){
464  HyperPoint temp(getDimension());
465  for (int j= 0; j < getDimension(); j++){
466  temp.at(j) = log( this->at(i).at(j) );
467  }
468  geoMean = geoMean + temp;
469  }
470 
471  geoMean = geoMean/double(size());
472 
473  for (int j= 0; j < getDimension(); j++){
474  geoMean.at(j) = exp( geoMean.at(j) );
475  }
476 
477  return geoMean;
478 
479 }
const HyperPoint & at(int i) const
const int & getDimension() const
Definition: HyperPointSet.h:40
unsigned int size() const

◆ getCorrelation()

double HyperPointSet::getCorrelation ( int  i,
int  j 
) const

Get the correlation between two variables.

Definition at line 217 of file HyperPointSet.cpp.

217  {
218 
219  WidthFinder statsi;
220  WidthFinder statsj;
221 
222  for (unsigned evt = 0; evt < size(); evt++){
223  statsi.add(at(evt).at(i));
224  statsj.add(at(evt).at(j));
225  }
226 
227  double meani = statsi.mean();
228  double meanj = statsj.mean();
229  double widthi = statsi.width();
230  double widthj = statsj.width();
231 
232  double correlation = 0.0;
233 
234  for (unsigned evt = 0; evt < size(); evt++){
235  correlation += (at(evt).at(i) - meani)*(at(evt).at(j) - meanj);
236  }
237 
238  correlation = correlation / (widthi * widthj * size());
239 
240  return correlation;
241 }
void add(const double &x, const double &weight=1.0)
const HyperPoint & at(int i) const
double width() const
const double & at(int i) const
Definition: HyperPoint.cpp:433
unsigned int size() const
double mean() const

◆ getCorrelationMatrix()

TMatrixD HyperPointSet::getCorrelationMatrix ( ) const

Get the correlation matrix associated with the HyperPointSet.

Definition at line 286 of file HyperPointSet.cpp.

286  {
287 
288  TMatrixD matrix(getDimension(), getDimension());
289 
290  for (int i = 0; i < getDimension(); i++){
291  for (int j = 0; j < getDimension(); j++){
292  matrix(i,j) = getCorrelation(i,j);
293  }
294  }
295 
296  return matrix;
297 }
double getCorrelation(int i, int j) const
const int & getDimension() const
Definition: HyperPointSet.h:40

◆ getCovarience()

double HyperPointSet::getCovarience ( int  i,
int  j 
) const

Get the covarience between two variables.

Definition at line 245 of file HyperPointSet.cpp.

245  {
246 
247  MeanFinder statsi;
248  MeanFinder statsj;
249 
250  for (unsigned evt = 0; evt < size(); evt++){
251  statsi.add(at(evt).at(i));
252  statsj.add(at(evt).at(j));
253  }
254 
255  double meani = statsi.mean();
256  double meanj = statsj.mean();
257 
258  double correlation = 0.0;
259 
260  for (unsigned evt = 0; evt < size(); evt++){
261  correlation += (at(evt).at(i) - meani)*(at(evt).at(j) - meanj);
262  }
263 
264  correlation = correlation / size();
265 
266  return correlation;
267 }
void add(const double &x, const double &weight=1.0)
const HyperPoint & at(int i) const
const double & at(int i) const
Definition: HyperPoint.cpp:433
unsigned int size() const
double mean() const

◆ getCovarienceMatrix()

TMatrixD HyperPointSet::getCovarienceMatrix ( ) const

Get the covarience matrix associated with the HyperPointSet.

Definition at line 271 of file HyperPointSet.cpp.

271  {
272 
273  TMatrixD matrix(getDimension(), getDimension());
274 
275  for (int i = 0; i < getDimension(); i++){
276  for (int j = 0; j < getDimension(); j++){
277  matrix(i,j) = getCovarience(i,j);
278  }
279  }
280 
281  return matrix;
282 }
const int & getDimension() const
Definition: HyperPointSet.h:40
double getCovarience(int i, int j) const

◆ getDimension()

const int& HyperPointSet::getDimension ( ) const
inline

Get the dimensionality of HyperPoints in the HyperPointSet

Definition at line 40 of file HyperPointSet.h.

◆ getMax()

HyperPoint HyperPointSet::getMax ( ) const

Get a HyperPoint that gives the maximum in each dim.

Definition at line 434 of file HyperPointSet.cpp.

434  {
435  HyperPoint val(getDimension());
436 
437  for (int i = 0; i < getDimension(); i++){
438  MinMaxFinder minMax;
439  for (unsigned j = 0; j < size(); j++){
440  minMax.add( this->at(j).at(i) );
441  }
442  val.at(i) = minMax.getMax();
443  }
444  return val;
445 }
void add(const double &x, const double &weight=1.0)
const HyperPoint & at(int i) const
const int & getDimension() const
Definition: HyperPointSet.h:40
unsigned int size() const
const double & getMax() const

◆ getMin()

HyperPoint HyperPointSet::getMin ( ) const

Get a HyperCuboid that surrounds the points.

Get a HyperPoint that gives the minimum in each dim

Definition at line 420 of file HyperPointSet.cpp.

420  {
421  HyperPoint val(getDimension());
422 
423  for (int i = 0; i < getDimension(); i++){
424  MinMaxFinder minMax;
425  for (unsigned j = 0; j < size(); j++){
426  minMax.add( this->at(j).at(i) );
427  }
428  val.at(i) = minMax.getMin();
429  }
430  return val;
431 }
void add(const double &x, const double &weight=1.0)
const double & getMin() const
const HyperPoint & at(int i) const
const int & getDimension() const
Definition: HyperPointSet.h:40
unsigned int size() const

◆ getSumW()

double HyperPointSet::getSumW ( ) const

Find the Sum of weights for all HyperPoints in the HyperPointSet

Definition at line 99 of file HyperPointSet.cpp.

99  {
100 
101  double sumW = 0.0;
102 
103  for(unsigned i = 0; i < size(); i++){
104  sumW += at(i).getWeight();
105  }
106  return sumW;
107 }
const HyperPoint & at(int i) const
unsigned int size() const
double getWeight(int i=0) const
Definition: Weights.cpp:40

◆ getSumW2()

double HyperPointSet::getSumW2 ( ) const

Find the Sum of weights squared for all HyperPoints in the HyperPointSet

Definition at line 111 of file HyperPointSet.cpp.

111  {
112 
113  double sumW2 = 0.0;
114  double w = 0.0;
115  for(unsigned i = 0; i < size(); i++){
116  w = at(i).getWeight();
117  sumW2 += w*w;
118  }
119  return sumW2;
120 
121 }
const HyperPoint & at(int i) const
unsigned int size() const
double getWeight(int i=0) const
Definition: Weights.cpp:40

◆ gramSchmidtProcess()

HyperPointSet HyperPointSet::gramSchmidtProcess ( ) const

Use the gramSchmidtProcess to make the first nDim vectors orthanormal. If there are less than this, only size() vectors will be returned (but they will be orthanormal).

Definition at line 127 of file HyperPointSet.cpp.

127  {
128 
129  int nPoints = size();
130  if ( nPoints > getDimension() ) nPoints = getDimension();
131 
132  if (linearlyIndependant() == 0) {
133  ERROR_LOG << "Trying to perform the Gram Schmidt Process on a set of L.D. vectors";
134  }
135 
136  HyperPointSet orthogonalPoints(at(0));
137 
138  for (int i = 1; i < nPoints; i++){
139  HyperPoint nextPoint = at(i);
140  for (int j = 0; j < i; j++){
141  nextPoint = nextPoint - orthogonalPoints.at(j).project(at(i));
142  }
143  orthogonalPoints.push_back(nextPoint);
144  }
145 
146  orthogonalPoints.normalise();
147  return orthogonalPoints;
148 
149 }
bool linearlyIndependant() const
#define ERROR_LOG
const HyperPoint & at(int i) const
const double & at(int i) const
Definition: HyperPoint.cpp:433
const int & getDimension() const
Definition: HyperPointSet.h:40
unsigned int size() const

◆ harmonicMean()

HyperPoint HyperPointSet::harmonicMean ( ) const

Get the harmonic mean of all points. This does not use the weights.

Definition at line 483 of file HyperPointSet.cpp.

483  {
484 
485  HyperPoint geoMean(getDimension());
486  for (unsigned i = 0; i < size(); i++){
487  HyperPoint temp(getDimension());
488  for (int j= 0; j < getDimension(); j++){
489  temp.at(j) = 1.0 / this->at(i).at(j);
490  }
491  geoMean = geoMean + temp;
492  }
493 
494  geoMean = geoMean/double(size());
495 
496  for (int j= 0; j < getDimension(); j++){
497  geoMean.at(j) = 1.0 / geoMean.at(j);
498  }
499 
500  return geoMean;
501 
502 }
const HyperPoint & at(int i) const
const double & at(int i) const
Definition: HyperPoint.cpp:433
const int & getDimension() const
Definition: HyperPointSet.h:40
unsigned int size() const

◆ linearlyIndependant()

bool HyperPointSet::linearlyIndependant ( ) const

Check if the HyperPoints in the HyperPointSet are linearly independent (this isn't implemented yet!!!)

Definition at line 153 of file HyperPointSet.cpp.

153  {
154  //need to implement this...
155  return 1;
156 }

◆ load()

void HyperPointSet::load ( TString  path)

Load exisiting HyperPointSet from a file. HyperPoints are appended to the end of the

Definition at line 362 of file HyperPointSet.cpp.

362  {
363 
364  TFile* file = new TFile(path, "READ");
365  if (file == 0) {
366  ERROR_LOG << "Cannot open file at " << path;
367  return;
368  }
369 
370  TTree* tree = (TTree*)file->Get("HyperPointSet");
371  if (tree == 0) {
372  ERROR_LOG << "Cannot open tree";
373  return;
374  }
375 
376  std::vector<double>* values = 0;
377  std::vector<double>* weights = 0;
378 
379  tree->SetBranchAddress("values" , &values );
380  tree->SetBranchAddress("weights", &weights);
381 
382  int nEntries = tree->GetEntries();
383 
384  for(int i = 0; i < nEntries; i++ ){
385  tree->GetEntry(i);
386 
387  if (_dimension == -1) _dimension = values->size();
388  if ( int(values->size()) != _dimension) ERROR_LOG << "You are loading HyperPoints that do not have the correct dimensionality for this HyperPointSet";
389 
390  HyperPoint point(*values);
391  for(unsigned w = 0; w < weights->size(); w++){
392  point.addWeight(weights->at(w));
393  }
394  this->push_back(point);
395  }
396 
397  tree->ResetBranchAddresses();
398  file->Close();
399 
400 }
#define ERROR_LOG
void push_back(const HyperPoint &point)

◆ mean()

HyperPoint HyperPointSet::mean ( ) const

Get the arithmatic mean of all points. This does not use the weights.

Definition at line 450 of file HyperPointSet.cpp.

450  {
451  HyperPoint temp(getDimension());
452  for (unsigned i = 0; i < size(); i++){
453  temp = temp + at(i);
454  }
455  return temp/double(size());
456 }
const HyperPoint & at(int i) const
const int & getDimension() const
Definition: HyperPointSet.h:40
unsigned int size() const

◆ normalise()

void HyperPointSet::normalise ( )

Normalise all points in the HyperPointSet.

Definition at line 160 of file HyperPointSet.cpp.

160  {
161 
162  for(unsigned i = 0; i < size(); i++){
163  at(i) = at(i)/at(i).norm();
164  }
165 
166 }
const HyperPoint & at(int i) const
unsigned int size() const
double norm() const
Definition: HyperPoint.cpp:131

◆ print()

void HyperPointSet::print ( std::ostream &  os = std::cout) const

Print out the entire HyperPointSet.

Definition at line 301 of file HyperPointSet.cpp.

301  {
302 
303  os << "---------- HyperPointSet ------------" << std::endl;
304  for (unsigned i = 0; i < size(); i++){
305  os << "HyperPoint " << i << ": ";
306  at(i).print(os, 0);
307  os << std::endl;
308  }
309 
310 }
virtual void print(std::ostream &os=std::cout, int endline=1) const
Definition: HyperPoint.cpp:453
const HyperPoint & at(int i) const
unsigned int size() const

◆ push_back()

void HyperPointSet::push_back ( const HyperPoint point)

Add new HyperPoint to the HyperPointSet

Definition at line 91 of file HyperPointSet.cpp.

91  {
92  if (compatible(point) == false) return;
93  _points.push_back(point);
94 }
std::vector< HyperPoint > _points
Definition: HyperPointSet.h:34
bool compatible(const HyperPoint &other, bool printError=true) const

◆ removeDuplicates()

void HyperPointSet::removeDuplicates ( )

Remove all duplicate events. IMPORTANT must be followed by sort()

Definition at line 179 of file HyperPointSet.cpp.

179  {
180 
181  //INFO_LOG << "Removing all duplicates from the HyperPointSet - did you remember to call sort() first?!?";
182 
183  HyperPointSet hyperPointSet(getDimension());
184 
185  HyperPoint currentHyperPoint = _points.at(0);
186  hyperPointSet.push_back(currentHyperPoint);
187 
188  for(unsigned int i = 1; i < size(); i++){
189  if ( _points.at(i) != currentHyperPoint ) {
190  currentHyperPoint = _points.at(i);
191  hyperPointSet.push_back(currentHyperPoint);
192  }
193  }
194 
195  _points.clear();
196  *this = hyperPointSet;
197 
198 }
std::vector< HyperPoint > _points
Definition: HyperPointSet.h:34
const int & getDimension() const
Definition: HyperPointSet.h:40
unsigned int size() const

◆ save() [1/2]

void HyperPointSet::save ( )
private

Save the HyperPointSet to the file currently in scope.

Definition at line 332 of file HyperPointSet.cpp.

332  {
333 
334  TTree* tree = new TTree("HyperPointSet", "HyperPointSet");
335 
336  if (tree == 0) {
337  ERROR_LOG << "Cannot create tree";
338  return;
339  }
340 
341  std::vector<double> values;
342  std::vector<double> weights;
343 
344  tree->Branch("values" , &values );
345  tree->Branch("weights", &weights);
346 
347  for(unsigned i = 0; i < size(); i++ ){
348  weights = at(i).getWeightsVector();
349  values = at(i).getVector();
350  tree->Fill();
351  }
352 
353  tree->ResetBranchAddresses();
354 
355  tree->Write();
356 
357 }
const std::vector< double > & getVector()
Definition: HyperPoint.h:48
#define ERROR_LOG
const std::vector< double > & getWeightsVector()
Definition: Weights.h:36
const HyperPoint & at(int i) const
unsigned int size() const

◆ save() [2/2]

void HyperPointSet::save ( TString  path)

Save the HyperPointSet to a file (opened with RECREATE).

Definition at line 314 of file HyperPointSet.cpp.

314  {
315 
316  TFile* file = new TFile(path, "RECREATE");
317 
318  if (file == 0) {
319  ERROR_LOG << "Cannot open file at " << path;
320  return;
321  }
322 
323  save();
324 
325  file->Write();
326  file->Close();
327 
328 }
#define ERROR_LOG

◆ size()

unsigned int HyperPointSet::size ( ) const

Get the number of points in the HyperPointSet

Definition at line 84 of file HyperPointSet.cpp.

84  {
85  return _points.size();
86 }
std::vector< HyperPoint > _points
Definition: HyperPointSet.h:34

◆ sort()

void HyperPointSet::sort ( )

Sort all the HyperPoints in acending order. First sort by the first element, then by the second etc.

Definition at line 171 of file HyperPointSet.cpp.

171  {
172 
173  std::sort(_points.begin(), _points.end());
174 
175 }
std::vector< HyperPoint > _points
Definition: HyperPointSet.h:34

Member Data Documentation

◆ _dimension

int HyperPointSet::_dimension
private

The dimensionality of HyperPoints in the HyperPointSet

Definition at line 33 of file HyperPointSet.h.

◆ _points

std::vector<HyperPoint> HyperPointSet::_points
private

std::vector containing the HyperPoints

Definition at line 34 of file HyperPointSet.h.


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