Public Member Functions | Public Attributes | Private Attributes

Histogram2D Class Reference

Class to construct histogram of a pair of random variables. More...

#include <ocsHistogram2D.hh>

List of all members.

Public Member Functions

 Histogram2D (string InFileName, float x_min2, float x_max2, float y_min2, float y_max2)
 Constructor.
void InitializeParameters (void)
 Internal method called by constructors.
 Histogram2D (string InFileName)
 Constructor.
 Histogram2D (string InFileName, OptSignal *oOptSignal)
 Constructor to be used when making eye diagram.
 Histogram2D (Histogram2D &OrigHist)
 Copy constructor.
Histogram2Doperator= (Histogram2D &RHSHist)
 Assignment operator.
 ~Histogram2D ()
 Destructor.
void Clear ()
 Sets all dynamic variables to their initial state. For use when want to output multiple independent histograms during course of a simulation.
void SetMaxX (double x_max2)
void SetMaxY (double y_max2)
void SetMinMaxXY (double x_min2, double x_max2, double y_min2, double y_max2)
float GetMaxX (void)
float GetMaxY (void)
float GetMinX (void)
float GetMinY (void)
float GetDeltaX (void)
float GetDeltaY (void)
int GetNumBinsX (void)
int GetNumBinsY (void)
float GetSamplesMaxX (void)
float GetSamplesMaxY (void)
void SetBin (int x_index, int y_index, double value)
 Internal method.
double GetBin (int x_index, int y_index)
double GetBinSquare (int x_index, int y_index)
int GetIndex (int x_index, int y_index)
double Get_pdfConfidence (int x_index, int y_index)
 Internal method.
void ObtainConfidence (void)
int GetQtSamplesBin (int x_index, int y_index)
void IncrementBin (int x_index, int y_index, double LikelihoodRatio)
int GetQtSamples (void)
 Returns total number of samples.
void AddSample (double x, double y)
 Method to add a sample in a standard Monte Carlo simulation.
void AddSample (double x, double y, double LikelihoodRatio)
 Method to add sample in a Monte Carlo simulation with importance sampling.
void WriteFile_pdf2D (string OutFileName)
 Writes out pdf computed by the histogram to a file.
double GetMeanX (void)
 Returns mean of X calculated from samples that are in range.
double GetMeanY (void)
 Returns mean of Y calculated from samples that are in range.
void UpdateEyeDiagram (OptSignal *oOptSignal, Photodetector *oPhotodetector)
 For applications to eye diagrams in Monte Carlo simulations.
void WriteEyeDiagramHistogram (string OutFileName)
void MultipleSelectMaxRelNumHitsImport (string InFileName, int Convert2dB_Scale)
void GetLevelCurvesMultipleSelectMaxRelNumHitsImport (string InFileName, int Convert2dB_Scale, int CosnvertParam2dB_Scale)
void MultipleHeuristicBalanceImport (string InFileName, int Convert2dB_Scale)
 Use this function for merging 2D histograms named in InFileName.
void MergeMultipleConditionalHeuristicBalance (string InFileName, double z_min, double z_max, int Convert2dB_Scale)
void MergeMultipleConditionalHeuristicBalance (string InFileName, double z_min, double z_max, double w_min, double w_max, int Convert2dB_Scale)
void GetLevelCurvesMultipleHeuristicBalanceImport (string InFileName, int Convert2dB_Scale, int ConvertParam2dB_Scale)
void GetLevelCurvesMultipleHeuristicBalanceImportVarianceWeighted (string InFileName, int Convert2dB_Scale, int ConvertParam2dB_Scale)
void ComputePDFfromHistogram (void)
void NormalizePDF (void)
void SetPDF (int x_index, int y_index, double value)
double GetPDF (int x_index, int y_index)
void ComputeXMarginalPDF (void)
void ComputeYMarginalPDF (void)
double ComputeIntegralPDF (void)
double ComputeMeanX_PDF (void)
double ComputeMeanY_PDF (void)
double GetMaxPDF (void)
double SetPDFToZeroBelowThreshold (double Threshold)
void GaussianPDF (double mean_x, double mean_y, double std)
 Analytic formula for Gaussian PDF. For debugging purposes.
void WritePDF (string OutFileName)
 Writes out data in array PDF.
double BilinearInterpolationPDF (double x, double y)
void RotatePDF (double CenterX, double CenterY, double Angle, double *OutData)

Public Attributes

double * PDF
 The 2D PDF array.

Private Attributes

float x_min
 Minimum x value for 2D Histogram of x and y.
float x_max
 Maximum x value for 2D Histogram of x and y.
float y_min
 Minimum y value for 2D Histogram of x and y.
float y_max
 Maximum y value for 2D Histogram of x and y.
float x_window_size
float y_window_size
int NumBinsX
 Number of bins in X variable.
int NumBinsY
 Number of bins in Y variable.
float delta_x
float delta_y
double * Bin
 The 2D Histogram array.
int * qtSamplesBin
double * BinSquare
double * pdfConfidence
bool PreviouslyComputed_pdfConfidenceFlag
double * XData
double * YData
double * XMarginal
double * YMarginal
int NumSamplesTotal
int NumSamplesInRange
int NumSamplesWithOutOfRangeX
int NumSamplesWithOutOfRangeY
float SamplesMinX
 Minimum X value of all samples (even if lie outside Histogram).
float SamplesMaxX
 Maximum X value of all samples (even if lie outside Histogram).
float SamplesMinY
 Minimum Y value of all samples (even if lie outside Histogram).
float SamplesMaxY
 Maximum Y value of all samples (even if lie outside Histogram).
string HistInFileName
 Used by merge algorithms in importance sampling applications.
double MeanX
double MeanY

Detailed Description

Class to construct histogram of a pair of random variables.

For use in computing two-dimensional histograms, particularly in Monte Carlo sampling. The main applications the code was written for include construction of eye diagrams in optical communications systems and quantification of statistics related to random polarization effects using importance sampling. However the class is generic enough to be used in other situations.

For simple applications call as follows:

For applications to eyediagrams call as

The two random variables are refered to as x and y throughout the code.

If we think of x and y as being on a 2D coordinate system as usual then the bins are indexed by a pair of integers that describes the position of the lower left corner of each bin, with the indices starting at (0,0).

So x-index goes from 0 to NumBinsX - 1.

Samples out of range are discarded and their number is tracked.

For importance sampling applications the pdfs for each bias choice are first written to files using WriteFile_pdf2D in one application. Then in a second aplication they are read back in and merged together usually using the balanaced heuristic method by calling a method like MultipleHeuristicBalanceImport. Finally the merged pdf is written out once more using WriteFile_pdf2D


Constructor & Destructor Documentation

Histogram2D::Histogram2D ( string  InFileName,
float  x_min2,
float  x_max2,
float  y_min2,
float  y_max2 
)
Histogram2D::Histogram2D ( string  InFileName  ) 
Histogram2D::Histogram2D ( string  InFileName,
OptSignal oOptSignal 
)
Histogram2D::Histogram2D ( Histogram2D OrigHist  ) 
Histogram2D::~Histogram2D (  ) 

Destructor.

References Bin, BinSquare, pdfConfidence, and qtSamplesBin.

Referenced by ReceiverSubsystem::~ReceiverSubsystem().


Member Function Documentation

void Histogram2D::AddSample ( double  x,
double  y 
)
void Histogram2D::AddSample ( double  x,
double  y,
double  LikelihoodRatio 
)
double Histogram2D::BilinearInterpolationPDF ( double  x,
double  y 
)

If the data of one of the grid points is off the grid then the value at that grid point is set to zero.

References delta_x, delta_y, GetPDF(), x_min, and y_min.

Referenced by RotatePDF().

void Histogram2D::Clear (  ) 
double Histogram2D::ComputeIntegralPDF ( void   ) 
double Histogram2D::ComputeMeanX_PDF ( void   ) 
double Histogram2D::ComputeMeanY_PDF ( void   ) 
void Histogram2D::ComputePDFfromHistogram ( void   ) 

For applications where want to manipulate PDF rather than histogram first call this method to compute PDF from histogram.

PDF data is stored in separate 2D array double * PDF All integrals involving PDF data done using (iterated) Simpson's Rule

References GetBin(), NormalizePDF(), NumBinsX, NumBinsY, and SetPDF().

void Histogram2D::ComputeXMarginalPDF ( void   ) 
void Histogram2D::ComputeYMarginalPDF ( void   ) 
void Histogram2D::GaussianPDF ( double  mean_x,
double  mean_y,
double  std 
)

Analytic formula for Gaussian PDF. For debugging purposes.

References delta_x, delta_y, NumBinsX, NumBinsY, pi, SetPDF(), x_min, and y_min.

double Histogram2D::Get_pdfConfidence ( int  x_index,
int  y_index 
)
double Histogram2D::GetBin ( int  x_index,
int  y_index 
)
double Histogram2D::GetBinSquare ( int  x_index,
int  y_index 
)
float Histogram2D::GetDeltaX ( void   )  [inline]

References delta_x.

float Histogram2D::GetDeltaY ( void   )  [inline]

References delta_y.

int Histogram2D::GetIndex ( int  x_index,
int  y_index 
) [inline]
void Histogram2D::GetLevelCurvesMultipleHeuristicBalanceImport ( string  InFileName,
int  Convert2dB_Scale,
int  ConvertParam2dB_Scale 
)
void Histogram2D::GetLevelCurvesMultipleHeuristicBalanceImportVarianceWeighted ( string  InFileName,
int  Convert2dB_Scale,
int  ConvertParam2dB_Scale 
)
void Histogram2D::GetLevelCurvesMultipleSelectMaxRelNumHitsImport ( string  InFileName,
int  Convert2dB_Scale,
int  CosnvertParam2dB_Scale 
)
double Histogram2D::GetMaxPDF ( void   ) 

Returns the maximum value of the PDF obtained using

See also:
Histogram2D::ComputePDFfromHistogram()

References GetPDF(), NumBinsX, and NumBinsY.

float Histogram2D::GetMaxX ( void   )  [inline]

References x_max.

float Histogram2D::GetMaxY ( void   )  [inline]

References y_max.

double Histogram2D::GetMeanX ( void   ) 

Returns mean of X calculated from samples that are in range.

Warning:
Not correct for importance sampling!

References MeanX, and NumSamplesInRange.

double Histogram2D::GetMeanY ( void   ) 

Returns mean of Y calculated from samples that are in range.

Warning:
Not correct for importance sampling!

References MeanY, and NumSamplesInRange.

float Histogram2D::GetMinX ( void   )  [inline]

References x_min.

float Histogram2D::GetMinY ( void   )  [inline]

References y_min.

int Histogram2D::GetNumBinsX ( void   )  [inline]

References NumBinsX.

int Histogram2D::GetNumBinsY ( void   )  [inline]

References NumBinsX.

double Histogram2D::GetPDF ( int  x_index,
int  y_index 
)
int Histogram2D::GetQtSamples ( void   )  [inline]
int Histogram2D::GetQtSamplesBin ( int  x_index,
int  y_index 
)
float Histogram2D::GetSamplesMaxX ( void   )  [inline]
See also:
SamplesMaxX

References SamplesMaxX.

float Histogram2D::GetSamplesMaxY ( void   )  [inline]
See also:
SamplesMaxY

References SamplesMaxY.

void Histogram2D::IncrementBin ( int  x_index,
int  y_index,
double  LikelihoodRatio 
)

References Bin, BinSquare, NumBinsY, qtSamplesBin, and sq().

Referenced by AddSample().

void Histogram2D::InitializeParameters ( void   ) 
void Histogram2D::MergeMultipleConditionalHeuristicBalance ( string  InFileName,
double  z_min,
double  z_max,
double  w_min,
double  w_max,
int  Convert2dB_Scale 
)

Use this function for merging 2D histograms named in InFileName Computes the 2D probability density function f(X=x,Y=y| z_min < Z < z_max, w_min < W < w_max), Samples of the random variables X,Y,Z,W have been obtained from an importance sampling simulation, and that the names of the files containing the samples are stored in the file InFileName.

Computes the 2D probability density function f(X=x,Y=y| z_min < Z < z_max, w_min < W < w_max), Samples of the random variables X,Y,Z,W have been obtained from an importance sampling simulation, and that the names of the files containing the samples are stored in the file InFileName.

The input parameter Convert2dB_Scale converts the pdfs of X and Y to a plus/minus dB scale before adding them to this 2D histogram.

We only add a (X,Y) sample to this 2D histogram if z_min < Z < z_max and w_min < W < w_max

Note: I'm not sure whether or not the Confidence Interval is correctly computed.

By JZ, 23/2/2005 and adapted from code by Ivan T. Lima Jr. and Aurenice O. Lima (7/28/02)

References AddSample(), Clear(), Get_pdfConfidence(), GetIndex(), HistInFileName, Histogram2D(), Linear2dB(), LogFile, NumBinsX, NumBinsY, ObtainConfidence(), pdfConfidence, PreviouslyComputed_pdfConfidenceFlag, sgn(), sq(), and sqrt().

void Histogram2D::MergeMultipleConditionalHeuristicBalance ( string  InFileName,
double  z_min,
double  z_max,
int  Convert2dB_Scale 
)

Use this function for merging 2D histograms named in InFileName Computes the 2D probability density function f(X=x,Y=y| z_min < Z < z_max), the joint probability density for X and Y given that z_min < Z < z_max. It is assumed that samples of the random variables X,Y,Z have been obtained from an importance sampling simulation, and that the names of the files containing the samples are stored in the file InFileName.

Computes the 2D probability density function f(X=x,Y=y| z_min < Z < z_max), the joint probability density for X and Y given that z_min < Z < z_max. It is assumed that samples of the random variables X,Y,Z have been obtained from an importance sampling simulation, and that the names of the files containing the samples are stored in the file InFileName.

The input parameter Convert2dB_Scale converts the pdfs of X and Y to a plus/minus dB scale before adding them to this 2D histogram.

We only add a (X,Y) sample to this 2D histogram if z_min < Z < z_max.

Note: I'm not sure whether or not the Confidence Interval is correctly computed for the case that Prob(z_min < Z < z_max) != 1

By JZ, 15/11/2004, modified 23/2/2005 and adapted from code by Ivan T. Lima Jr. and Aurenice O. Lima (7/28/02)

References AddSample(), Clear(), Get_pdfConfidence(), GetIndex(), HistInFileName, Histogram2D(), Linear2dB(), LogFile, NumBinsX, NumBinsY, ObtainConfidence(), pdfConfidence, PreviouslyComputed_pdfConfidenceFlag, sgn(), sq(), and sqrt().

void Histogram2D::MultipleHeuristicBalanceImport ( string  InFileName,
int  Convert2dB_Scale 
)
void Histogram2D::MultipleSelectMaxRelNumHitsImport ( string  InFileName,
int  Convert2dB_Scale 
)
void Histogram2D::NormalizePDF ( void   ) 

Normalize so integrates to 1. Useful after numerical operations are performed on PDF

References ComputeIntegralPDF(), GetPDF(), NumBinsX, NumBinsY, and SetPDF().

Referenced by ComputePDFfromHistogram(), and SetPDFToZeroBelowThreshold().

void Histogram2D::ObtainConfidence ( void   ) 

Computes width of confidence interval for each bin and stores result in 2D array pdfConfidence

References Get_pdfConfidence(), GetIndex(), NumBinsX, NumBinsY, pdfConfidence, and PreviouslyComputed_pdfConfidenceFlag.

Referenced by MergeMultipleConditionalHeuristicBalance(), and MultipleHeuristicBalanceImport().

Histogram2D & Histogram2D::operator= ( Histogram2D RHSHist  ) 
void Histogram2D::RotatePDF ( double  CenterX,
double  CenterY,
double  Angle,
double *  OutData 
)

Rotates PDF about (CenterX,CenterY) throuhg angle Angle and stores result in OutData.

OutData should be the 1D data array double * PDF from another Histogram2D object. BilinearInterpolationPDF() is used to get a value at ecah rotated point

References BilinearInterpolationPDF(), delta_x, delta_y, NumBinsX, NumBinsY, x_min, and y_min.

void Histogram2D::SetBin ( int  x_index,
int  y_index,
double  value 
)
void Histogram2D::SetMaxX ( double  x_max2  ) 
See also:
x_max
void Histogram2D::SetMaxY ( double  y_max2  ) 
void Histogram2D::SetMinMaxXY ( double  x_min2,
double  x_max2,
double  y_min2,
double  y_max2 
)
void Histogram2D::SetPDF ( int  x_index,
int  y_index,
double  value 
)
double Histogram2D::SetPDFToZeroBelowThreshold ( double  Threshold  ) 

Sets values of PDF that are below the Threshold to zero and renormalizes PDF.

References GetPDF(), NormalizePDF(), NumBinsX, NumBinsY, and SetPDF().

void Histogram2D::UpdateEyeDiagram ( OptSignal oOptSignal,
Photodetector oPhotodetector 
)
void Histogram2D::WriteEyeDiagramHistogram ( string  OutFileName  ) 
void Histogram2D::WriteFile_pdf2D ( string  OutFileName  ) 

Writes out pdf computed by the histogram to a file.

Each line of the files corresponds to a different bin. On each line we have the following entries

  1. x-value of center of bin
  2. y-value of center of bin
  3. pdf value in that bin (ie the mean)
  4. standard deviation in that bin, computed from the pdf of the confidence
  5. standard deviation relative to the mean

References delta_x, delta_y, GetBin(), GetIndex(), LogFile, LogFileSeparator(), NumBinsX, NumBinsY, NumSamplesInRange, NumSamplesTotal, NumSamplesWithOutOfRangeX, NumSamplesWithOutOfRangeY, pdfConfidence, SamplesMaxX, SamplesMaxY, SamplesMinX, SamplesMinY, x_max, x_min, y_max, and y_min.

void Histogram2D::WritePDF ( string  OutFileName  ) 

Writes out data in array PDF.

See also:
Histogram2D::ComputePDFfromHistogram()

References delta_x, delta_y, GetPDF(), NumBinsX, NumBinsY, x_min, and y_min.


Member Data Documentation

double* Histogram2D::Bin [private]
double* Histogram2D::BinSquare [private]
float Histogram2D::delta_x [private]
float Histogram2D::delta_y [private]
string Histogram2D::HistInFileName [private]
double Histogram2D::MeanX [private]
double Histogram2D::MeanY [private]
int Histogram2D::NumBinsX [private]
int Histogram2D::NumBinsY [private]

The 2D PDF array.

Referenced by GetPDF(), InitializeParameters(), and SetPDF().

double* Histogram2D::pdfConfidence [private]
int* Histogram2D::qtSamplesBin [private]
float Histogram2D::SamplesMaxX [private]

Maximum X value of all samples (even if lie outside Histogram).

Referenced by AddSample(), GetSamplesMaxX(), Histogram2D(), operator=(), WriteEyeDiagramHistogram(), and WriteFile_pdf2D().

float Histogram2D::SamplesMaxY [private]

Maximum Y value of all samples (even if lie outside Histogram).

Referenced by AddSample(), GetSamplesMaxY(), Histogram2D(), operator=(), WriteEyeDiagramHistogram(), and WriteFile_pdf2D().

float Histogram2D::SamplesMinX [private]

Minimum X value of all samples (even if lie outside Histogram).

Referenced by AddSample(), Histogram2D(), operator=(), WriteEyeDiagramHistogram(), and WriteFile_pdf2D().

float Histogram2D::SamplesMinY [private]

Minimum Y value of all samples (even if lie outside Histogram).

Referenced by AddSample(), Histogram2D(), operator=(), WriteEyeDiagramHistogram(), and WriteFile_pdf2D().

float Histogram2D::x_max [private]
float Histogram2D::x_min [private]
float Histogram2D::x_window_size [private]
double* Histogram2D::XData [private]
double* Histogram2D::XMarginal [private]
float Histogram2D::y_max [private]
float Histogram2D::y_min [private]
float Histogram2D::y_window_size [private]
double* Histogram2D::YData [private]
double* Histogram2D::YMarginal [private]

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