Infotheory  1.0
InfoTools.h
1 /******************************************************/
2 // A Data handler class that deals with binning and
3 // computing probabilities
4 //
5 // Created - March, 2018 - MCV
6 /******************************************************/
7 
8 #include <iostream>
9 #include <math.h>
10 #include "VectorMatrix.h"
11 
12 #pragma once
13 #define TESTMODE 0
14 #define DOXYGEN_SHOULD_SKIP_THIS
15 
16 class InfoTools{
17  // making everything public to make testing easier
18  #if !TESTMODE
19  private:
20  #else
21  public:
22  #endif
23  int BIN_LIMIT;
24  // numShifts(numDims(numBins))
25  // to allow different number of bins along different dimensions
26  TVector<TVector<TVector<double> > > bins;
27 
28  // one matrix for data binned using one list of bins
29  TVector<TMatrix<double> > binnedData; // XXX matrixShape=(None,numDims+1)
30 
31  // one matrix averaged across all shifts
32  TMatrix<double> avgBinnedData;
33 
34  // one matrix for data binned using one list of bins
35  //TVector<TMatrix<double> > probs; // all combinations of probabilities
36 
37  TVector<int> nBins; // number of bins along each dimension
38 
39  double totalPoints,totalAvgPoints;
40  int nDims, nReps, dataLen;
41  int dataInitedFlag, dataReadyFlag;
42  TVector<int> binningInitedFlag;
43 
44  #if !TESTMODE
45  public:
46  #endif
47  /*******************
48  * Inits
49  *******************/
50  InfoTools(int dims, int nreps=0){
52 
56  BIN_LIMIT = 500;
57 
58  // resetting vars
59  nDims = dims;
60  nReps = nreps*2 + 1;
61  dataLen = 0; // number of non-empty bins, across all shifts
62  totalPoints = totalAvgPoints = 0;
63 
64  bins.SetBounds(1,nReps);
65  for(int r=1; r<=nReps; r++){
66  // bins[r] is all bins for a particular shift
67  bins[r].SetBounds(1,nDims);
68  }
69  binnedData.SetBounds(1,nReps);
70 
71  nBins.SetBounds(1,dims);
72  nBins.FillContents(0.);
73 
74  //cout << "nBins = " << nBins <<endl;
75 
76  // flag set
77  dataInitedFlag = 0;
78  dataReadyFlag = 0;
79  binningInitedFlag.SetBounds(1,nDims);
80  binningInitedFlag.FillContents(0.);
81 
82  //cout << "Total points = " << totalPoints << endl;
83  }
84 
85  ~InfoTools(){};
86 
87  /*******************
88  * Inspection tools
89  *******************/
90 
92  void displayConfig(){
93  cout << "************************ CONFIG ************************" << endl;
94  cout << "Total dimensionality = " << nDims << endl;
95  cout << "Number of shifted bins = " << nReps << endl;
96  cout << "Number of bins in each dimension = " << nBins << endl;
97  cout << "Bin boundaries in each dimension:" << endl;
98  for(int d=1; d<=nDims;d++){
99  cout << "\tFor dimension #" << d << endl;
100  for(int r=1; r<=nReps; r++){
101  cout << "\t\tFor rep #" << r << ":" << bins[r][d] <<endl;
102  }
103  }
104  cout << "********************************************************" << endl;
105  }
106 
109  cout << "************************ SNAPSHOT ************************" << endl;
110  cout << "Number of total datapoints added = " << totalPoints << endl;
111  cout << "Number of populated bins = " << dataLen << endl;
112  if(!dataReadyFlag)
113  cout << "Size of populated bin list = " << binnedData[1].ColumnSize() << endl;
114  cout << "Has data been collapsed across multiple shifted binnings? " << (dataReadyFlag==0 ? "No":"Yes") << endl;
115  if(dataReadyFlag)
116  cout << "Size of average binned data = " << avgBinnedData.ColumnSize() << endl;
117  cout << "**********************************************************" << endl;
118  }
119 
120  /*******************
121  * Binning schemes
122  *******************/
123 
125 
129  void setEqualIntervalBinning(TVector<int>& nbs, TVector<double>& mins, TVector<double>& maxs){
130  if(dataLen > 0){
131  cerr << "ERROR: Cannot set bins after if at least one bin has been populated" << endl;
132  exit(1);
133  }
134  // init bins[r][d] with shifted values from mins[d] to maxs[d] (left margin of bins)
135  if(mins.Size() != nDims){
136  cerr << "ERROR: 'mins' should be a list of length = total dimensionality = " << nDims << endl;
137  exit(1);
138  }
139  if(maxs.Size() != nDims){
140  cerr << "ERROR: 'maxs' should be a list of length = total dimensionality = " << nDims << endl;
141  exit(1);
142  }
143  if(nbs.Size() != nDims){
144  cerr << "ERROR: Bin counts should be a list of length = total dimensionality = " << nDims << endl;
145  exit(1);
146  }
147 
148  int b=nbs.LowerBound(), mi=mins.LowerBound(), ma=maxs.LowerBound();
149  //cout << b << " " << mi << " " << ma << endl;
150  for(int d=1; d<=nDims; d++){
151  TVector<double> boundaries;
152  boundaries.SetBounds(1,nbs[b]-1);
153  for(int bo=1; bo<nbs[b]; bo++){
154  double boundary = mins[mi] + bo*(maxs[ma]-mins[mi])/nbs[b];
155  boundaries[bo] = boundary;
156  }
157  setBinBoundaries(boundaries, d-1);
158  b++;mi++;ma++;
159  }
160  }
161 
163 
166  void setBinBoundaries(TVector<double> boundaries, int dimIndex){
167  if(dataLen > 0){
168  cerr << "ERROR: Cannot set bins after if at least one bin has been populated" << endl;
169  exit(1);
170  }
171  int bLb = boundaries.LowerBound();
172  int bUb = boundaries.UpperBound();
173  dimIndex += 1; // indexing is 1 in this library
174  nBins[dimIndex] = boundaries.Size()+1;
175  int bi = nBins[dimIndex]-1;
176  // if there is more than one rep, create empty bin boundary vecs for shifted binnings
177  for(int r=1; r<=nReps; r++){
178  // set bounds on bin TVecs
179  bins[r][dimIndex].SetBounds(1,bi);
180  }
181 
182  // first setting for 1 rep
183  for(int b=1,b1=bLb; b<=bi; b++,b1++){
184  bins[1][dimIndex][b] = boundaries[b1];
185  }
186 
187  // now for the other reps
188  double offsetWidth, maxLimit;
189  TVector<double> unitOffset, minLimit;
190  unitOffset.SetBounds(1,bi);
191  minLimit.SetBounds(1,bi);
192  for(int b=1,b1=bLb; b<bi; b++,b1++){
193  offsetWidth = (boundaries[b1+1]-boundaries[b1])/2;
194  minLimit[b] = boundaries[b1]-offsetWidth;
195  //maxLimit = boundaries[b1]+offsetWidth;
196  unitOffset[b] = (boundaries[b1] - minLimit[b])/(((nReps-1)/2)+1);
197  }
198  // // setting last bin separately using same offset as last but one
199  minLimit[bi] = boundaries[bUb] - offsetWidth;
200  unitOffset[bi] = (boundaries[bUb] - minLimit[bi])/(((nReps-1)/2)+1);
201 
202  int r;
203  // for each rep to the left of boundaries
204  for(r=2; r<=((nReps-1)/2)+1; r++){
205  // for each bin
206  for(int b=1,b1=bLb; b<=bi; b++,b1++){
207  bins[r][dimIndex][b] = boundaries[b1] - unitOffset[b]*(r-1);
208  //cout << bins[r][d][b] << " ";
209  }
210  }
211  // for each rep to the right of boundaries
212  for(r=((nReps-1)/2)+2; r<=nReps; r++){
213  // for each bin
214  for(int b=1,b1=bLb; b<=bi; b++,b1++){
215  bins[r][dimIndex][b] = boundaries[b1] + unitOffset[b]*(r-1);
216  //cout << bins[r][d][b] << " ";
217  }
218  }
219  binningInitedFlag[dimIndex] = 1;
220  }
221 
223 
225  void setBinBoundaries(TVector<TVector <double> > boundaries){
226  if(boundaries.Size() != nDims){
227  cerr << "ERROR: Boundaries should be a list of length = total dimensionality = " << nDims << endl;
228  exit(1);
229  }
230  int di=1;
231  for(int d=boundaries.LowerBound(); d<=boundaries.UpperBound(); d++){
232  setBinBoundaries(boundaries[d], di-1); // due to 0-indexing of dims in setBinBoundaries
233  di++;
234  }
235  }
236 
237  /*******************
238  * Data Handler
239  *******************/
241 
243  void addDataPoint(TVector<double>& dp){
244  for(int d=1; d<=nDims; d++){
245  if(binningInitedFlag[d] == 0){
246  cerr << "ERROR: binning has not been specified for dimension " << d-1 << " (0-indexing)" << endl;
247  exit(1);
248  }
249  }
250  if(dataReadyFlag){
251  cout << "WARNING: Datapoint is being added after existing collapsing binned data. Previous datapoints will be lost." << endl;
252  cout << "All datapoints need to be added first before using any information theoretic tools" << endl;
253  }
254  if(dp.Size() != nDims){
255  cerr << "ERROR: Each datapoint must be of size = total dimensionality = " << nDims << " *** ";
256  cerr << "Skipping this datapoint" << endl;
257  return;
258  }
259 
260  // renormalizing bounds
261  TVector<double> dataPoint;
262  normalizeBounds(dataPoint, dp);
263 
264  dataReadyFlag = 0;
265  totalPoints++;
266  // locate bin and update counts
267  // may need to do for several bin lists depending on shiftedFlag
268  //cout << "addDataPoint " << endl;
269  //cout << "dataInitedFlag " << dataInitedFlag << endl;
270  if(!dataInitedFlag){
271  //cout << "initing data" << endl;
272  for(int r=1; r<=nReps; r++){
273  binnedData[r].SetBounds(1,BIN_LIMIT,1,nDims+1);
274  binnedData[r].FillContents(0);
275  }
276  dataInitedFlag = 1;
277  }
278 
279  // bin for this dataPoint
280  TVector<double> this_bin;
281  this_bin.SetBounds(1,nDims);
282  this_bin.FillContents(0);
283 
284  //cout << "locating bin " << binSizes << endl;
285  // for each rep
286  for(int r=1; r<=nReps; r++){
287  // for each dimension
288  this_bin.FillContents(0);
289  int valid_dBins=0;
290  for(int d=1; d<=nDims; d++){
291  // for each bin
292  for(int b=1; b<=nBins[d]; b++){
293  //cout << bins[r][d][b] << " " << dataPoint[d] << " " << bins[r][d][b]+binSizes[d] << " " ;
294  //cout << (bins[r][d][b] <= dataPoint[d] && dataPoint[d] < bins[r][d][b]+binSizes[d]) << endl;
295  if(b == 1){
296  // just for the last bin check only right margin
297  if(dataPoint[d] < bins[r][d][1]){
298  // found bin for particular d
299  //cout << "dim" << d << " ";
300  valid_dBins += 1;
301  this_bin[d] = b;
302  break;
303  }
304  }
305  else if(b == nBins[d]){
306  // just for the last bin check only left margin
307  if(dataPoint[d] >= bins[r][d][b-1]){
308  // found bin for particular d
309  //cout << "dim" << d << " ";
310  valid_dBins += 1;
311  this_bin[d] = b;
312  break;
313  }
314  }
315  else{
316  //for all other bins, check both margins
317  if(bins[r][d][b-1] <= dataPoint[d] && dataPoint[d] < bins[r][d][b]){
318  // found bin for particular d
319  //cout << "dim" << d << " ";
320  valid_dBins += 1;
321  this_bin[d] = b;
322  break;
323  }
324  }
325  }
326  }
327  //cout << "valid_dBins=" << valid_dBins << endl;
328  if(valid_dBins == nDims){
329  int added = 0;
330  // increment or insert this_bin at binnedData[r][data_len,:]
331  //cout << "nRep = " << r << endl;
332  added = addOrInsertCoords(this_bin,binnedData[r]);
333  if(added==1){
334  dataLen++;
335  }
336  //cout << added << " " << dataLen << " " << binnedData[r].ColumnSize() << endl;
337  //cout << "Before finishing " << r << endl;
338  }
339  }
340 
341  //cout << "Finished adding point" << endl << endl;
342  //cout << "Data Length = " << dataLen << " Total Points = " << totalPoints << endl;
343  }
344 
346  /* data - TVector with length=number of points, each point being TVector with length=dims
347  */
348  void addData(TVector<TVector<double> >& data){
349  for(int d=1; d<=data.Size(); d++)
350  addDataPoint(data[d]);
351  }
352 
353  /*******************
354  * Information tools
355  *******************/
357 
362  double entropy(TVector<int>& vIDs){
363  if(vIDs.Size() != nDims){
364  cerr << "varIDs argument must be of size = total dimensionality = " << nDims << endl;
365  cerr << "Skipping this call" << endl;
366  return 0.;
367  }
368 
369  TVector<int> varIDs;
370  normalizeBounds(varIDs, vIDs);
371 
372  double entropy = 0.;
373  TVector<double> p_x;
374  computeIndProbs(p_x,varIDs);
375 
376  // iterate over all x values
377  for(int xi=1; xi<=p_x.Size(); xi++){
378  if(p_x[xi] > 0)
379  entropy -= p_x[xi]*log2(p_x[xi]);
380  }
381  return entropy;
382  }
383 
385 
387  double mutualInfo(TVector<int>& vIDs){
388  if(vIDs.Size() != nDims){
389  cerr << "varIDs argument must be of size = total dimensionality = " << nDims << endl;
390  cerr << "Skipping this call" << endl;
391  return 0.;
392  }
393 
394  TVector<int> varIDs;
395  normalizeBounds(varIDs, vIDs);
396 
397  // computer probabilities given the var IDs
398  TMatrix<double> p_xy;
399  computeJointProbs(p_xy,varIDs);
400 
401  //cout << "From mutualInfo"<< endl << p_xy << endl;
402 
403  double mi = 0.0;
404  // parse through each unique data point
405  for (int i = 1; i <= p_xy.ColumnSize(); i++)
406  {
407  mi += p_xy[i][3]*log2(p_xy[i][3]/(p_xy[i][1]*p_xy[i][2]));
408  //cout << "from mi = " << p_xy[i][3]*log2(p_xy[i][3]/(p_xy[i][1]*p_xy[i][2])) << endl;
409  }
410  return mi;
411  }
412 
413  #ifndef DOXYGEN_SHOULD_SKIP_THIS
414  void specificInfo(TVector<double>& si, TVector<int>& varIDs){
415  // specific info for var values identified by varIDs==0, in si
416 
417  // ID 0 is the one we want specific information about
418  TVector<TVector<TVector<double> > > px;
419  //cout << "in specific info " << endl;
420  computeSpecProbs(px, varIDs);
421  //cout << " Back in spec info " << endl;
422 
423  si.SetBounds(1,px.Size());
424 
425  for (int x = 1; x <= px.Size(); x++)
426  {
427  si[x] = 0.0;
428  for (int y = 1; y <= px[x][2].Size(); y++)
429  {
430  si[x] += px[x][3][y] * log2(px[x][3][y] / (px[x][1][1] * px[x][2][y]));
431  //cout << px[x][1][1] << " " << px[x][2][y] << " " << px[x][3][y] << " " << px[x][3][y] * log2( px[x][3][y] / (px[x][1][1] * px[x][2][y])) << endl;
432  }
433  //si[x]=si[x]/px[x][1][1]; //XXX not really specific information
434  }
435  }
436  #endif /* DOXYGEN_SHOULD_SKIP_THIS */
437 
439 
441  double redundantInfo(TVector<int>& vIDs){
442  if(vIDs.Size() != nDims){
443  cerr << "varIDs argument must be of size = total dimensionality = " << nDims << endl;
444  cerr << "Skipping this call" << endl;
445  return 0.;
446  }
447 
448  TVector<int> varIDs;
449  normalizeBounds(varIDs, vIDs);
450 
451  TVector<double> siX1;
452  TVector<double> siX2;
453  TVector<double> p_y;
454 
455  TVector<int> varIDsX1, varIDsX2, varIDsY;
456  varIDsX1.SetBounds(1,varIDs.Size());
457  varIDsX2.SetBounds(1,varIDs.Size());
458  varIDsY.SetBounds(1,varIDs.Size());
459 
460  for(int d=1; d<=varIDs.Size(); d++){
461  // spec Y
462  if(varIDs[d]==0) {
463  varIDsY[d] = 0;
464  varIDsX1[d] = 0;
465  varIDsX2[d] = 0;
466  }
467  // in X1
468  if(varIDs[d]==1) {
469  varIDsY[d] = -1;
470  varIDsX1[d] = 1;
471  varIDsX2[d] = -1;
472  }
473  // in X2
474  if(varIDs[d]==2) {
475  varIDsY[d] = -1;
476  varIDsX1[d] = -1;
477  varIDsX2[d] = 1;
478  }
479  }
480  //cout << "varIDs " << varIDsX1 << "--" << varIDsX2 << endl;
481 
482  computeIndProbs(p_y, varIDsY);
483  specificInfo(siX1,varIDsX1);
484  specificInfo(siX2,varIDsX2);
485 
486  double ri = 0.0;
487 
488  //
489  for (int l = 1; l <= siX1.Size(); l++)
490  {
491  ri += (siX1[l]<siX2[l]?siX1[l]:siX2[l]);
492  }
493  return ri;
494  }
495 
497 
499  double uniqueInfo(TVector<int>& vIDs){
500  if(vIDs.Size() != nDims){
501  cerr << "varIDs argument must be of size = total dimensionality = " << nDims << endl;
502  cerr << "Skipping this call" << endl;
503  return 0.;
504  }
505 
506  TVector<int> varIDs;
507  normalizeBounds(varIDs, vIDs);
508 
509  TVector<int> varIDsX1;
510  varIDsX1.SetBounds(1,varIDs.Size());
511 
512  for(int d=1; d<=varIDs.Size(); d++){
513  // spec Y
514  if(varIDs[d]==0) {
515  varIDsX1[d] = 0;
516  }
517  // in X1
518  if(varIDs[d]==1) {
519  varIDsX1[d] = 1;
520  }
521  // in X2
522  if(varIDs[d]==2) {
523  varIDsX1[d] = -1;
524  }
525  }
526 
527  double infoX1 = mutualInfo(varIDsX1);
528  double redun = redundantInfo(varIDs);
529  //cout << "From unique info" << endl;
530  //cout << "Total info from " << varIDsX1 << " = " << infoX1 << endl;
531  //cout << "Redun info from " << varIDs << " = " << redun << endl;
532 
533  return infoX1 - redun;
534 
535  }
536 
538 
540  double synergy(TVector<int>& vIDs){
541  if(vIDs.Size() != nDims){
542  cerr << "varIDs argument must be of size = total dimensionality = " << nDims << endl;
543  cerr << "Skipping this call" << endl;
544  return 0.;
545  }
546 
547  TVector<int> varIDs;
548  normalizeBounds(varIDs, vIDs);
549 
550  TVector<int> varIDsX1, varIDsX2, varCommon;
551  varIDsX1.SetBounds(1,varIDs.Size());
552  varIDsX2.SetBounds(1,varIDs.Size());
553  varCommon.SetBounds(1,varIDs.Size());
554 
555  for(int d=1; d<=varIDs.Size(); d++){
556  // spec Y
557  if(varIDs[d]==0) {
558  varIDsX1[d] = 0;
559  varIDsX2[d] = 0;
560  varCommon[d] = 0;
561  }
562  // in X1
563  if(varIDs[d]==1) {
564  varIDsX1[d] = 1;
565  varIDsX2[d] = -1;
566  varCommon[d] = 1;
567  }
568  // in X2
569  if(varIDs[d]==2) {
570  varIDsX1[d] = -1;
571  varIDsX2[d] = 1;
572  varCommon[d] = 1;
573  }
574  }
575 
576  double mi = mutualInfo(varCommon);
577  double infoX1 = mutualInfo(varIDsX1);
578  double infoX2 = mutualInfo(varIDsX2);
579  double redun = redundantInfo(varIDs);
580 
581  double synergy = mi - infoX1 - infoX2 + redun;
582  //cout << "mutualInfo = " << mi << endl;
583  //cout << "uniqueInfoX1 = " << infoX1 - redun << endl;
584  //cout << "uniqueInfoX2 = " << infoX2 - redun << endl;
585  //cout << "redundancy = " << redun << endl;
586  //cout << "synergy = " << synergy << endl;
587 
588  return synergy;
589  }
590 
591 
593 
600  void pid(TVector<int>& vIDs, TVector<double>& infos){
601  if(vIDs.Size() != nDims){
602  cerr << "varIDs argument must be of size = total dimensionality = " << nDims << endl;
603  cerr << "Skipping this call" << endl;
604  return;
605  }
606 
607  TVector<int> varIDs;
608  normalizeBounds(varIDs, vIDs);
609 
610  TVector<int> varIDsX1, varIDsX2, varCommon;
611  varIDsX1.SetBounds(1,varIDs.Size());
612  varIDsX2.SetBounds(1,varIDs.Size());
613  varCommon.SetBounds(1,varIDs.Size());
614 
615  for(int d=1; d<=varIDs.Size(); d++){
616  // spec Y
617  if(varIDs[d]==0) {
618  varIDsX1[d] = 0;
619  varIDsX2[d] = 0;
620  varCommon[d] = 1;
621  }
622  // in X1
623  if(varIDs[d]==1) {
624  varIDsX1[d] = 1;
625  varIDsX2[d] = -1;
626  varCommon[d] = 0;
627  }
628  // in X2
629  if(varIDs[d]==2) {
630  varIDsX1[d] = -1;
631  varIDsX2[d] = 1;
632  varCommon[d] = 0;
633  }
634  }
635 
636  double mi = mutualInfo(varCommon);
637  double infoX1 = mutualInfo(varIDsX1);
638  double infoX2 = mutualInfo(varIDsX2);
639  double redun = redundantInfo(varIDs);
640 
641  double synergy = mi - infoX1 - infoX2 + redun; // because redun is subtracted twice
642 
643  infos.SetBounds(1,5);
644  infos[1] = mi;
645  infos[2] = infoX1 - redun; // unique X1
646  infos[3] = infoX2 - redun; // unique X2
647  infos[4] = redun;
648  infos[5] = synergy;
649  }
650 
651  #ifndef DOXYGEN_SHOULD_SKIP_THIS
652  double transfer_entropy_1_delay(TVector<int> varIDs){
653  // one delay transfer entropy from varIDs==0 to varIDs==1
654  double te = 0.;
655 
656  return te;
657  }
658  #endif /* DOXYGEN_SHOULD_SKIP_THIS */
659 
660  /*******************
661  * Utils
662  *******************/
664  void clearAllData(){
665  bins.SetSize(0);
666  binnedData.SetSize(0);
667  avgBinnedData.SetSize(0,0);
668  }
669 
670  #ifndef DOXYGEN_SHOULD_SKIP_THIS
671  void normalizeBounds(TVector<double>& normVec, TVector<double>& vec){
672  normVec.SetBounds(1,vec.Size());
673  int d1=1;
674  for(int d=vec.LowerBound();d<=vec.UpperBound();d++){
675  normVec[d1] = vec[d];
676  d1+=1;
677  }
678  }
679  void normalizeBounds(TVector<int>& normVec, TVector<int>& vec){
680  normVec.SetBounds(1,vec.Size());
681  int d1=1;
682  for(int d=vec.LowerBound();d<=vec.UpperBound();d++){
683  normVec[d1] = vec[d];
684  d1+=1;
685  }
686  }
687 
688  int addOrInsertCoords(TVector<double>& coordinates, TMatrix<double>& intoMatrix){
689  // given bin indices (i.e. bin index along each dim),
690  // if bin is already in the list populated bins i.e. in intoMatrix
691  // add 1 to count of number of points in that bin
692  // else
693  // insert this bin as a new entry to list with number of points = 1
694 
695  int breakFlag, foundFlag, added=0;
696  //cout << "in updateBinnedData " << intoMatrix.ColumnSize() << endl;
697 
698  int dims = intoMatrix.RowSize()-1;
699  int rowLim = intoMatrix.ColumnSize();
700  // check for bins because that might be less likely
701  foundFlag = 0;
702  for(int l=1; l<=intoMatrix.ColumnSize(); l++){
703  breakFlag = 0;
704  //cout << "\t l=" << l << " intoMatrix[l]=" << intoMatrix[l][1] << " " << intoMatrix[l][2] << " coords=" << coordinates << endl;
705  // inserting coordinates - didn't find
706  if(intoMatrix[l][1] == 0){
707  //cout << "inserting coordinates - didn't find - " << coordinates << endl;
708  for(int d=1; d<=dims; d++){
709  intoMatrix[l][d] = coordinates[d];
710  }
711  intoMatrix[l][dims+1] = 1;
712  foundFlag = 1;
713  added = 1;
714  //cout << "inserting at " << l << endl;
715  return 1; // return added
716  }
717  else{
718  breakFlag = 0;
719  //cout << "\t" << intoMatrix[l] << ": " << coordinates << endl;
720  // finding matching coordinate
721  for(int d=1; d<=dims; d++){
722  //cout << intoMatrix[l][d] << " " << coordinates[d] << " " << (intoMatrix[l][d] == coordinates[d]) << endl;
723  if(intoMatrix[l][d] == coordinates[d]){
724  breakFlag += 1;
725  }
726  else{
727  break;
728  }
729  }
730  if(breakFlag==dims){
731  //cout << "match found - increment coordinate" << endl;
732  intoMatrix[l][dims+1] += 1;
733  foundFlag = 1;
734  //cout << "incrementing at " << l << endl;
735  return 0; // return added
736  }
737  }
738  }
739 
740  //if(foundFlag==0){
741  // ran out of space to add new entry - expand bin size
742  //cerr << "********************************** BIN_LIMIT REACHED **********************************" << endl;
743  //exit(0);
744  int l = rowLim+1;
745  TMatrix<double> _intoMatrix;
746  _intoMatrix.SetBounds(1,rowLim,1,dims+1);
747  for(int i=1;i<=rowLim;i++){
748  for(int d=1; d<=dims+1; d++){
749  _intoMatrix[i][d] = intoMatrix[i][d];
750  }
751  }
752  //cout << "expanding BIN_LIMIT" << endl;
753  intoMatrix.SetBounds(1,int(rowLim*1.5),1,dims+1);
754  intoMatrix.FillContents(0.);
755  for(int i=1;i<=rowLim;i++){
756  for(int d=1; d<=dims+1; d++){
757  intoMatrix[i][d] = _intoMatrix[i][d];
758  }
759  }
760 
761  for(int d=1; d<=dims; d++){
762  intoMatrix[l][d] = coordinates[d];
763  }
764  intoMatrix[l][dims+1] = 1;
765  foundFlag = 1;
766  added = 1;
767  //cout << "Expanded intoMatric to - " << intoMatrix.ColumnSize() << endl;
768  //cout << "binned data is now - " << binnedData[1].ColumnSize() << endl;
769  //cout << binnedData[1] << endl;
770  //}
771  //else{
772  //cout << "found/inserted entry for " << coordinates << endl;
773  //}
774  return added;
775 
776  }
777 
778  int indexOf(TMatrix<double>& inWhat, TVector<double>& pattern, TVector<int>& atInds){
779  // if a specific pattern (pattern) exists in a matrix (inWhat) at specific colukmns (atInds)
780  // return its row number
781  // else
782  // return -1
783 
784  for(int l=1; l<=inWhat.ColumnSize(); l++){
785  int matchCount = 0;
786  // for each value in pattern
787  for(int p=1; p<=pattern.Size(); p++){
788  if(inWhat[l][atInds[p]]!=pattern[p]){
789  break;
790  }
791  matchCount++;
792  }
793  if(matchCount == pattern.Size()){
794  // found pattern
795  return l;
796  }
797  }
798  return -1;
799  }
800 
801  double fetchTotalValue(TMatrix<double>& from, TVector<double>& pattern, TVector<int>& atInds, int index){
802  // matches pattern in rows of from at specified atInds columns, and returns the sum of index columns' value of matching row
803  // returns 0 if no match found
804  double totalValue = 0.;
805 
806  //cout << "from.RowSize() " << from.ColumnSize() << " " << pattern.Size() << " ";
807  for(int l=1; l<=from.ColumnSize(); l++){
808  int matchCount = 0;
809  // for each value in pattern
810  for(int p=1; p<=pattern.Size(); p++){
811  if(from[l][atInds[p]]!=pattern[p]){
812  break;
813  }
814  matchCount++;
815  }
816  if(matchCount == pattern.Size()){
817  // found pattern
818  totalValue += from[l][index];
819  }
820  }
821 
822  return totalValue;
823  }
824 
825  void getXYInds(TVector<int>& xInds, TVector<int>& yInds, TVector<int>& xyInds, TVector<int>& xyDims, TVector<int>& varIDs){
826  // given varIDs and references to other lists,
827  // returns
828  // xInds: indices where varIDs == 0
829  // yInds: indices where varIDs == 1
830  // xyInds: indices where varIDs == 0 || varIDs == 1
831  // xyDims: dimensionality of x and y dimensions
832 
833  xyDims.SetBounds(1,2);
834  // Vectors with indices for x and y
835  int xDim=0,yDim=0;
836  for(int d=1; d<=nDims; d++){
837  if(varIDs[d] == 0){
838  xDim++; // xInds.append(d)
839  }
840  else if(varIDs[d] == 1){
841  yDim++;
842  }
843  }
844  xyDims[1] = xDim;
845  xyDims[2] = yDim;
846  xInds.SetBounds(1,xDim);
847  if(yDim>0){
848  yInds.SetBounds(1,yDim);
849  }
850  xyInds.SetBounds(1,xDim+yDim);
851 
852  int xi=1,yi=1,xyi=1;
853  for(int d=1; d<=nDims; d++){
854  if(varIDs[d] == 0){
855  xInds[xi] = d;xi++;
856  xyInds[xyi] = d; xyi++;
857  }
858  if(varIDs[d] == 1 && yDim>0){
859  yInds[yi] = d;yi++;
860  xyInds[xyi] = d; xyi++;
861  }
862  }
863  }
864 
865  void collapseBinnedData(){
866  // After adding all points, before using any infotheory tools,
867  // estimate average shifted bin counts here and
868  // set dataReadyFlag
869 
870  // average across all binnings
871  TMatrix<double> _avgBinnedData;
872  _avgBinnedData.SetBounds(1,dataLen,1,nDims+1);
873 
874  TVector<double> this_bin;
875  this_bin.SetBounds(1,nDims);
876 
877  TVector<int> atInds;
878  atInds.SetBounds(1,nDims);
879 
880  int avgLen = 1;
881  if(nReps>1){
882  for(int r=1; r<=nReps; r++){
883  for(int l=1; l<=binnedData[r].ColumnSize(); l++){
884  if(binnedData[r][l][1] > 0){
885  //cout << "looping " << l << endl;
886  for(int d=1; d<=nDims; d++){
887  this_bin[d] = binnedData[r][l][d];
888  atInds[d] = d;
889  }
890  int binExist = indexOf(_avgBinnedData,this_bin,atInds);
891  //cout << !binExist << " [" << this_bin << "] ";
892  if(binExist == -1){
893  // for each dimension
894  for(int d=1; d<=nDims; d++){
895  //cout << binnedData[r][l][d] << " ";
896  _avgBinnedData[avgLen][d] = binnedData[r][l][d];
897  }
898  _avgBinnedData[avgLen][nDims+1] = 0;
899  for(int r=1; r<=nReps; r++){
900  double counts = fetchTotalValue(binnedData[r],this_bin,atInds,nDims+1);
901  _avgBinnedData[avgLen][nDims+1] += counts;
902  //cout << " (" << counts << ") ";
903  }
904  _avgBinnedData[avgLen][nDims+1] /= nReps;
905  //cout << _avgBinnedData[avgLen][nDims+1];
906  totalAvgPoints += _avgBinnedData[avgLen][nDims+1];
907  avgLen++;
908  }
909  }
910  }
911  }
912  avgLen--;// removing the last unnecessary ++
913  dataLen = avgLen;
914  }
915  else{
916  //cout << "nReps else part - dataLen = " << dataLen << " AvgLEn = " << avgLen << endl;
917  avgLen = dataLen;
918  //cout << "nReps else part - dataLen = " << dataLen << " AvgLEn = " << avgLen << endl;
919  //cout << "_avgBinnedData: " << _avgBinnedData.ColumnSize() << " " << _avgBinnedData.RowSize() << endl;
920  //cout << "binnedData: " << binnedData[1].ColumnSize() << " " << binnedData[1].RowSize() << endl;
921  for(int l=1;l<=dataLen;l++){
922  for(int d=1; d<=nDims+1; d++){
923  _avgBinnedData[l][d] = binnedData[1][l][d];
924  }
925  totalAvgPoints += binnedData[1][l][nDims+1];
926  }
927  //cout << "nReps else part - Done" << endl;
928  }
929 
930  avgBinnedData.SetBounds(1,dataLen,1,nDims+1);
931  //cout << "Done creating _avgBinnedData " << avgLen << endl;
932  for(int l=1;l<=dataLen;l++){
933  for(int d=1; d<=nDims+1; d++){
934  //cout << l << " " << d << " ";
935  //cout << avgBinnedData[l][d] << " " << _avgBinnedData[l][d] << endl;
936  avgBinnedData[l][d] = _avgBinnedData[l][d];
937  }
938  }
939  //cout << "end of collapse " << avgBinnedData.ColumnSize() << " " << avgBinnedData.RowSize() << endl;
940  //cout << "from collapse " << endl << avgBinnedData << endl;
941 
942 
943  // set flag for data ready and delete binnedData
944  dataReadyFlag = 1;
945  binnedData.SetSize(0); // XXX unable to delete
946  //cout << "Done Collapsing data" << endl;
947  }
948  #endif /* DOXYGEN_SHOULD_SKIP_THIS */
949 
950 
951  /*******************
952  * Computing probs
953  *******************/
954  #ifndef DOXYGEN_SHOULD_SKIP_THIS
955  void computeIndProbs(TVector<double>& p_x, TVector<int>& varIDs){
956  // compute individual probabilties for all data dimensions have varIDs==0, in p_x
957 
958  if(dataReadyFlag==0){
959  collapseBinnedData();
960  }
961 
962  TVector<int> xInds, yInds, xyDims, xyInds;
963  getXYInds(xInds,yInds,xyInds,xyDims,varIDs);
964  int xDim = xyDims[1];
965 
966  TVector<double> xpattern;
967  xpattern.SetBounds(1,xDim);
968 
969  int uniqueXCounts=1,added;
970  TVector<double> _p_x;
971  _p_x.SetBounds(1,dataLen);
972  TMatrix<double> trackerVar;
973  trackerVar.SetBounds(1,dataLen,1,xDim+1);
974  trackerVar.FillContents(0.);
975 
976  for(int l=1; l<=dataLen; l++){
977  // construct pattern for x
978  for(int xi=1; xi<=xDim; xi++){
979  xpattern[xi] = avgBinnedData[l][xInds[xi]];
980  }
981  //cout << xpattern << " ";
982  // see if we have already seen this pattern
983  added = addOrInsertCoords(xpattern,trackerVar);
984  if(added==1){
985  //cout << "is new" << endl;
986  // new x pattern
987  _p_x[uniqueXCounts] = fetchTotalValue(avgBinnedData,xpattern,xInds,nDims+1)/totalAvgPoints;
988  uniqueXCounts++;
989  }
990  //else{
991  // cout << "is old" << endl;
992  //}
993  }
994 
995  uniqueXCounts--;
996  // write into actual TVec
997  p_x.SetBounds(1,uniqueXCounts);
998  for(int xi=1; xi<=uniqueXCounts; xi++){
999  p_x[xi] = _p_x[xi];
1000  }
1001  //cout << "p_x " << endl << p_x << endl;
1002  }
1003 
1004  void computeJointProbs(TMatrix<double>& p_xy, TVector<int>& varIDs){
1005  // Compute joint probabilties for data dims given by varIDs==0 and varIDs==1, in p_xy
1006 
1007  if(dataReadyFlag==0){
1008  collapseBinnedData();
1009  }
1010  //cout << "from computeJointProbs " << endl << avgBinnedData << endl;
1011  //cout << "Totals = " << dataLen << " " << totalAvgPoints << endl;
1012 
1013  TVector<int> xInds, yInds, xyDims, xyInds;
1014  getXYInds(xInds,yInds,xyInds,xyDims,varIDs);
1015  int xDim = xyDims[1];
1016  int yDim = xyDims[2];
1017 
1018  //cout << "XYInds " << xInds << "==" << yInds << "==" << xyInds << endl;
1019  TVector<double> xypattern;
1020  xypattern.SetBounds(1,xDim+yDim);
1021  TVector<double> xpattern;
1022  xpattern.SetBounds(1,xDim);
1023  TVector<double> ypattern;
1024  ypattern.SetBounds(1,yDim);
1025 
1026  int uniqueXYcounts=1,added;
1027  TMatrix<double> _p_xy;
1028  _p_xy.SetBounds(1,dataLen,1,3);
1029  TMatrix<double> trackerVar;
1030  trackerVar.SetBounds(1,dataLen,1,xDim+yDim+1);
1031  trackerVar.FillContents(0.);
1032  //cout << "Total points = " << totalPoints << endl;
1033  //cout << "Total Average points = " << totalAvgPoints << endl;
1034  // go through whole list and compute the probs
1035  for(int l=1; l<=avgBinnedData.ColumnSize(); l++){
1036  //for(int d=1; d<=nDims+1; d++)
1037  //cout << avgBinnedData[l][d] << " ";
1038  // construct pattern for x
1039  int xyi=1;
1040  for(int i=1; i<=varIDs.Size(); i++){
1041  if(varIDs[i]==0 || varIDs[i]==1){
1042  xypattern[xyi] = avgBinnedData[l][i];
1043  xyi++;
1044  }
1045  }
1046  //cout << "xypattern = " << xypattern << endl;
1047  // will add this pattern to trackerVar if it already doesnt exist
1048  added = addOrInsertCoords(xypattern,trackerVar);
1049  if(added==1){
1050  // then we haven't looked at this combination xbin and ybin
1051  // so insert it into _p_xy
1052  _p_xy[uniqueXYcounts][3] = fetchTotalValue(avgBinnedData,xypattern,xyInds,nDims+1)/totalAvgPoints;
1053 
1054  // construct pattern for x
1055  for(int xi=1; xi<=xDim; xi++){
1056  xpattern[xi] = avgBinnedData[l][xInds[xi]];
1057  }
1058  _p_xy[uniqueXYcounts][1] = fetchTotalValue(avgBinnedData,xpattern,xInds,nDims+1)/totalAvgPoints;
1059 
1060  // construct pattern for y
1061  for(int yi=1; yi<=yDim; yi++){
1062  ypattern[yi] = avgBinnedData[l][yInds[yi]];
1063  }
1064  _p_xy[uniqueXYcounts][2] = fetchTotalValue(avgBinnedData,ypattern,yInds,nDims+1)/totalAvgPoints;
1065 
1066  uniqueXYcounts++;
1067  }
1068  //cout << _p_xy[l][1] << " " << _p_xy[l][2] << " " << _p_xy[l][3] << endl;
1069  }
1070  //cout << "trackerVar..." << endl << trackerVar << endl;
1071 
1072  uniqueXYcounts--;
1073  p_xy.SetBounds(1,uniqueXYcounts,1,3);
1074  for(int l=1; l<=uniqueXYcounts; l++){
1075  for(int d=1; d<=3; d++)
1076  p_xy[l][d] = _p_xy[l][d];
1077  }
1078 
1079  //cout << "Done" << endl << p_xy <<endl;
1080  }
1081 
1082  void computeSpecProbs(TVector<TVector<TVector<double> > >& p_x, TVector<int>& varIDs){
1083  if(dataReadyFlag==0){
1084  collapseBinnedData();
1085  }
1086  // p_x :TVector: reference to object to populate and return
1087  // varIDs :TVector: identifiers for dims of data
1088  // returns matrix with three columns
1089  // p(x) :double: for each value of x for which specific prob is computed
1090  // p(y) :TVector: for all y, under this value of x, its p(y), NOT p(y\x)
1091  // p(x,y) :TVector: for each X=x, and all y, this is p(X=x,y)
1092 
1093  //cout << "from computeSpecProbs " << endl << avgBinnedData << endl;
1094 
1095  //cout << "in compute probs - " << dataReadyFlag << endl;
1096  TVector<TVector<TVector<double> > > _p_x;
1097  _p_x.SetBounds(1,dataLen);
1098  for(int l=1; l<=dataLen; l++){
1099  _p_x[l].SetBounds(1,3);
1100  _p_x[l][1].SetBounds(1,1);
1101  _p_x[l][2].SetBounds(1,dataLen);
1102  _p_x[l][3].SetBounds(1,dataLen);
1103  _p_x[l][1].FillContents(0.);
1104  _p_x[l][2].FillContents(0.);
1105  _p_x[l][3].FillContents(0.);;
1106  }
1107 
1108  TVector<int> xInds, yInds, xyInds, xyDims;
1109  getXYInds(xInds,yInds,xyInds,xyDims,varIDs);
1110  int xDim = xyDims[1];
1111  int yDim = xyDims[2];
1112  //cout << "XYInds " << xInds << "==" << yInds << "==" << xyInds << endl;
1113 
1114  int uniqueXcounts = 1;
1115  int added, xyAdded;
1116 
1117  TMatrix<double> trackerVar;
1118  trackerVar.SetBounds(1,dataLen,1,xDim+1);
1119  trackerVar.FillContents(0.);
1120 
1121  TMatrix<double> xytrackerVar;
1122  xytrackerVar.SetBounds(1,dataLen,1,xDim+yDim+1);
1123  xytrackerVar.FillContents(0.);
1124 
1125  TVector<int> uniqueXYcounts;
1126  uniqueXYcounts.SetBounds(1,dataLen);
1127  uniqueXYcounts.FillContents(2.); // since it will only be used from idnex of 2 onwards
1128 
1129  TVector<double> this_xbin,this_ybin,this_xybin;
1130  TVector<int> trackDim;
1131  this_xbin.SetBounds(1,xDim);
1132  trackDim.SetBounds(1,xDim);
1133  this_ybin.SetBounds(1,yDim);
1134  this_xybin.SetBounds(1,xDim+yDim);
1135 
1136  //cout << "dataLen = " << dataLen << endl;
1137 
1138  for(int l=1; l<=dataLen; l++){
1139  //cout << "********************** " << l << endl;
1140  // spec x
1141  for(int xi=1; xi<=xDim; xi++){
1142  this_xbin[xi] = avgBinnedData[l][xInds[xi]];
1143  trackDim[xi] = xi;
1144  }
1145  //cout << this_xbin << endl;
1146 
1147  for(int yi=1; yi<=yDim; yi++){
1148  this_ybin[yi] = avgBinnedData[l][yInds[yi]];
1149  }
1150 
1151  int index=1;
1152  for(int i=1; i<=varIDs.Size(); i++){
1153  if(varIDs[i]==0 || varIDs[i]==1){
1154  this_xybin[index] = avgBinnedData[l][i];
1155  index++;
1156  }
1157  }
1158 
1159  //cout << "Sizes - " << this_xbin.Size() << " " << trackerVar.RowSize() << endl;
1160 
1161  // these x coordinates are inserted or added into trackerVar
1162  added = addOrInsertCoords(this_xbin,trackerVar);
1163  //cout << "added = " << added << " unqCounts = " << uniqueXcounts << endl;
1164  if(added==1){
1165  //cout << "new xbin " << this_xbin << endl;
1166  // then this is the first occurence of this bin
1167  // so add it and add the corresponding y
1169  // prob of x
1170  //_p_x[uniqueXcounts][1].SetBounds(1,1);
1171  _p_x[uniqueXcounts][1][1] = fetchTotalValue(avgBinnedData,this_xbin,xInds,nDims+1)/totalAvgPoints;
1172  //cout << "added px " << endl;
1173 
1174  //_p_x[uniqueXcounts][2].SetBounds(1,dataLen);
1175  _p_x[uniqueXcounts][2][1] = fetchTotalValue(avgBinnedData,this_ybin,yInds,nDims+1)/totalAvgPoints;
1176  //cout << "added py " << endl;
1177 
1178  //_p_x[uniqueXcounts][3].SetBounds(1,dataLen);
1179  _p_x[uniqueXcounts][3][1] = fetchTotalValue(avgBinnedData,this_xybin,xyInds,nDims+1)/totalAvgPoints;
1180  //cout << "added pxy " << endl;
1181 
1182  xyAdded = addOrInsertCoords(this_xybin,xytrackerVar);
1183  //cout << "xytrackerVar" << endl << xytrackerVar << endl;
1184  //cout << "*************" << endl;
1185  uniqueXcounts++;
1186  }
1187  else{
1188  //cout << "existing xbin " << this_xybin << " ";
1189  //cout << this_xbin << endl;
1190  //cout << trackerVar << endl;
1191  // this bin has alrady occured before
1192  // find index of where it was
1193  xyAdded = addOrInsertCoords(this_xybin,xytrackerVar);
1194  if(xyAdded==1){
1195  int ind = indexOf(trackerVar,this_xbin,trackDim);
1196  // get its py index
1197  //int pyInd = trackerVar[ind][xDim+1];
1198  //cout << "and also new xybin to be inserted at " << uniqueXYcounts[ind] << " of " << ind << endl;
1199  //cout << ind << " " << pyInd << " " << _p_x.ColumnSize() << " " << _p_x[ind][2].Size() << " " << dataLen << endl;
1200  _p_x[ind][2][uniqueXYcounts[ind]] = fetchTotalValue(avgBinnedData,this_ybin,yInds,nDims+1)/totalAvgPoints;
1201  _p_x[ind][3][uniqueXYcounts[ind]] = fetchTotalValue(avgBinnedData,this_xybin,xyInds,nDims+1)/totalAvgPoints;
1202  uniqueXYcounts[ind]++;
1203  }
1204  else{
1205  //cout << endl;
1206  }
1207  //cout << "xytrackerVar" << endl << xytrackerVar << endl;
1208  //cout << "*************" << endl;
1209  //trackerVar[ind][xDim+1]++; // XXX check this
1210  }
1211  //cout << "********************** " << l << endl << _p_x << endl << "********************** " << endl;
1212  }
1213  uniqueXcounts--;
1214 
1215  // could now shorten all arrays - p_x, p_x[i][2] and p_x[i][3]
1216  p_x.SetBounds(1,uniqueXcounts);
1217  //cout << _p_x[uniqueXcounts][1][1] << endl;
1218  for(int l=1; l<=uniqueXcounts; l++){
1219  p_x[l].SetBounds(1,3);
1220  p_x[l][1].SetBounds(1,1);
1221  p_x[l][1][1] = _p_x[l][1][1];
1222  //cout << "p_x[" << l << "][1][1] = " << _p_x[l][1][1] <<endl;
1223  for(int d=2; d<=3; d++){
1224  p_x[l][d].SetBounds(1,uniqueXYcounts[l]-1);
1225  for(int i=1; i<=uniqueXYcounts[l]-1; i++){
1226  p_x[l][d][i] =_p_x[l][d][i];
1227  }
1228  }
1229  }
1230  }
1231 
1232  /*******************
1233  * Write outs
1234  ******************
1235  void writeBinnedDataOut(){
1236  //cout << "in write binned data" << endl;
1237  //cout << binnedData.Size() << endl;
1238  //cout << binnedData[1][1][1] << endl;
1239 
1240  ofstream binnedDataFile;
1241  binnedDataFile.open("test_binnedData.dat");
1242  for(int r=1; r<=nReps; r++){
1243  for(int l=1; l<=BIN_LIMIT; l++){
1244  if(binnedData[r][l][1] == 0)break;
1245  binnedDataFile << r << " ";
1246  for(int d=1; d<=nDims+1; d++){
1247  binnedDataFile << binnedData[r][l][d] << " ";
1248  }
1249  binnedDataFile << endl;
1250  }
1251  binnedDataFile << endl;
1252  }
1253  binnedDataFile.close();
1254  //cout << "Done writing" << endl;
1255  }
1256 
1257 
1258  void writeOutAvgBinnedData(){
1259  ofstream avgBinnedDataFile;
1260  avgBinnedDataFile.open("./avgBinnedData.dat");
1261 
1262  for(int l=1; l<=dataLen; l++){
1263  for(int d=1; d<=nDims+1; d++){
1264  avgBinnedDataFile << avgBinnedData[l][d] << " ";
1265  }
1266  avgBinnedDataFile << endl;
1267  }
1268 
1269  avgBinnedDataFile.close();
1270  }
1271  */
1272  #endif /* DOXYGEN_SHOULD_SKIP_THIS */
1273 
1274 };
void displayConfig()
Display the config for analyses such as number of bins, dimensionality etc.
Definition: InfoTools.h:92
InfoTools(int dims, int nreps=0)
Definition: InfoTools.h:50
double synergy(TVector< int > &vIDs)
Returns amount of synergistic information about varIDs==0, in varIDs==1 and varIDs==2.
Definition: InfoTools.h:540
void setEqualIntervalBinning(TVector< int > &nbs, TVector< double > &mins, TVector< double > &maxs)
Set bounds on probs depending on max(ids)
Definition: InfoTools.h:129
void displaySnapshot()
Display current status such as number of points added, number of non-empty bins etc.
Definition: InfoTools.h:108
Definition: InfoTools.h:16
void clearAllData()
Clear all data and start over - create another object instead.
Definition: InfoTools.h:664
double entropy(TVector< int > &vIDs)
Returns entropy of var along dims with varIDs==0.
Definition: InfoTools.h:362
void pid(TVector< int > &vIDs, TVector< double > &infos)
Estimates complete info decomposition in infos, returns.
Definition: InfoTools.h:600
void setBinBoundaries(TVector< double > boundaries, int dimIndex)
Set left-boundaries for the binning of specified dimension.
Definition: InfoTools.h:166
void setBinBoundaries(TVector< TVector< double > > boundaries)
Set left-boundaries for the binning of all dimensions.
Definition: InfoTools.h:225
double redundantInfo(TVector< int > &vIDs)
Returns redundant information about varIDs==0, in varIDs==1 and varIDs==2.
Definition: InfoTools.h:441
void addData(TVector< TVector< double > > &data)
Add list of points at a time.
Definition: InfoTools.h:348
double uniqueInfo(TVector< int > &vIDs)
Returns amount of unique information about varIDs==0, from varIDs==1 and not from varIDs==2...
Definition: InfoTools.h:499
double mutualInfo(TVector< int > &vIDs)
Return mutual information between vars along dims varIDs==0 and varIDs==1.
Definition: InfoTools.h:387
void addDataPoint(TVector< double > &dp)
Identify bin for given datapoint and add to count of points in that bin.
Definition: InfoTools.h:243