public HistogramAggregator(int nClasses, HistogramData data) { // bins_ = new int[nClasses]; dataHandle_ = data.GetMemory(); sampleCount_ = 0; }
public void Aggregate(IDataPointCollection data, int index, Object userData) { DataPointCollection concreteData = (DataPointCollection)(data); HistogramData histogramData = (HistogramData)(userData); histogramData.Increment(dataHandle_, concreteData.GetIntegerLabel((int)index)); // bins_[concreteData.GetIntegerLabel((int)index)]++; sampleCount_ += 1; }
//public int FindTallestBinIndex() //{ // int maxCount = bins_[0]; // int tallestBinIndex = 0; // for (int i = 1; i < bins_.Length; i++) // { // if (bins_[i] > maxCount) // { // maxCount = bins_[i]; // tallestBinIndex = i; // } // } // return tallestBinIndex; //} #region IStatisticsAggregator implementation public void Clear(Object userData) { HistogramData histogramData = (HistogramData)(userData); histogramData.Clear(dataHandle_); //for (int b = 0; b < bins_.Length; b++) // bins_[b] = 0; sampleCount_ = 0; }
public void Aggregate(HistogramAggregator aggregator, Object userData) { // System.Diagnostics.Debug.Assert(aggregator.bins_.Length == bins_.Length); HistogramData histogramData = (HistogramData)(userData); histogramData.Aggregate(dataHandle_, aggregator.dataHandle_); //for (int b = 0; b < bins_.Length; b++) // bins_[b] += aggregator.bins_[b]; sampleCount_ += aggregator.sampleCount_; }
public double Entropy(HistogramData data) { //if (sampleCount_ == 0) // return 0.0; //double result = 0.0; //for (int b = 0; b < bins_.Length; b++) //{ // double p = (double)bins_[b] / (double)sampleCount_; // result -= p == 0.0 ? 0.0 : p * Math.Log(p, 2.0); //} //return result; return(data.Entropy(dataHandle_, sampleCount_)); }
public float GetProbability(int classIndex, HistogramData data) { // return (float)(bins_[classIndex]) / sampleCount_; return((float)(data.GetBin(dataHandle_, classIndex) / sampleCount_)); }