/*
For histograms
432266
protected List<IntervalFeatureFrequency> getIntervalFeatureFrequencies(Region region, int interval, List<Object[]> objectList,
                                                                           int numFeatures, double maxSnpsInterval) {

        int numIntervals = (region.getEnd() - region.getStart()) / interval + 1;
        List<IntervalFeatureFrequency> intervalFeatureFrequenciesList = new ArrayList<>(numIntervals);

        float maxNormValue = 1;

        if (numFeatures != 0) {
            maxNormValue = (float) maxSnpsInterval / numFeatures;
        }

        int start = region.getStart();
        int end = start + interval;
        for (int i = 0, j = 0; i < numIntervals; i++) {
            if (j < objectList.size() && ((BigInteger) objectList.get(j)[0]).intValue() == i) {
                if (numFeatures != 0) {
                    intervalFeatureFrequenciesList.add(new IntervalFeatureFrequency(start, end,
                            ((BigInteger) objectList.get(j)[0]).intValue(), ((BigInteger) objectList.get(j)[1]).intValue(),
                            (float) Math.log(((BigInteger) objectList.get(j)[1]).doubleValue()) / numFeatures / maxNormValue));
                } else {    // no features for this chromosome
                    intervalFeatureFrequenciesList.add(new IntervalFeatureFrequency(start, end,
                            ((BigInteger) objectList.get(j)[0]).intValue(), ((BigInteger) objectList.get(j)[1]).intValue(), 0));
                }
                j++;
            } else {
                intervalFeatureFrequenciesList.add(new IntervalFeatureFrequency(start, end, i, 0, 0.0f));
            }
            start += interval;
            end += interval;
        }

        return intervalFeatureFrequenciesList;
    }
1096678
void findHistogramPeaks() {
		// reset data structures
		peaks.reset();
		angles.reset();
		peakAngle = 0;

		// identify peaks and find the highest peak
		double largest = 0;
		int largestIndex = -1;
		double before = histogramMag[ histogramMag.length-2 ];
		double current = histogramMag[ histogramMag.length-1 ];
		for(int i = 0; i < histogramMag.length; i++ ) {
			double after = histogramMag[ i ];

			if( current > before && current > after ) {
				int currentIndex = CircularIndex.addOffset(i,-1,histogramMag.length);
				peaks.push(currentIndex);
				if( current > largest ) {
					largest = current;
					largestIndex = currentIndex;
				}
			}
			before = current;
			current = after;
		}

		if( largestIndex < 0 )
			return;

		// see if any of the other peaks are within 80% of the max peak
		double threshold = largest*0.8;
		for( int i = 0; i < peaks.size; i++ ) {
			int index = peaks.data[i];
			current = histogramMag[index];
			if( current >= threshold) {
				double angle = computeAngle(index);

				angles.push( angle );

				if( index == largestIndex )
					peakAngle = angle;
			}
		}
	}
708042
def histogram(data):
    
    ret = {}
    for datum in data:
        if datum in ret:
            ret[datum] += 1
        else:
            ret[datum] = 1
    return ret
687154
def histogram(fg = 'white', bg = 'black')
      red   = Array.new(HISTOGRAM_COLS, 0)
      green = Array.new(HISTOGRAM_COLS, 0)
      blue  = Array.new(HISTOGRAM_COLS, 0)
      alpha = Array.new(HISTOGRAM_COLS, 0)
      int   = Array.new(HISTOGRAM_COLS, 0)

      rows.times do |row|
        pixels = get_pixels(0, row, columns, 1)
        pixels.each do |pixel|
          red[pixel.red & MAX_QUANTUM] += 1
          green[pixel.green & MAX_QUANTUM] += 1
          blue[pixel.blue & MAX_QUANTUM] += 1

          # Only count opacity channel if some pixels are not opaque.
          alpha[pixel.opacity & MAX_QUANTUM] += 1 unless opaque?
          v = pixel_intensity(pixel)
          int[v] += 1
        end
      end

      # Scale to chart size. When computing the scale, add some "air" between
      # the max frequency and the top of the histogram. This makes a prettier chart.
      # The RGBA and intensity histograms are all drawn to the same scale.

      max = [red.max, green.max, blue.max, alpha.max, int.max].max
      scale = HISTOGRAM_ROWS / (max * AIR_FACTOR)

      charts = ImageList.new

      # Add the thumbnail.
      thumb = copy
      thumb['Label'] = File.basename(filename)
      charts << thumb

      # Compute the channel and intensity histograms.
      channel_hists = channel_histograms(red, green, blue, int, scale, fg, bg)

      # Add the red, green, and blue histograms to the list
      charts << channel_hists.shift
      charts << channel_hists.shift
      charts << channel_hists.shift

      # Add Alpha channel or image stats
      charts << if !opaque?
                  alpha_hist(alpha, scale, fg, bg)
                else
                  info_text(fg, bg)
                end

      # Add the RGB histogram
      charts << channel_hists.shift

      # Add the intensity histogram.
      charts << intensity_hist(channel_hists.shift)

      # Add the color frequency histogram.
      charts << color_hist(fg, bg)

      # Make a montage.
      histogram = charts.montage do
        self.background_color = bg
        self.stroke = 'transparent'
        self.fill = fg
        self.border_width = 1
        self.tile         = '4x2'
        self.geometry     = "#{HISTOGRAM_COLS}x#{HISTOGRAM_ROWS}+10+10"
      end

      histogram
    end
8107
@Override
	public double[][] getHistogram(int numberOfPoints, double standardDeviations) {
		double[] intervalPoints = new double[numberOfPoints];
		double[] anchorPoints	= new double[numberOfPoints+1];
		double center	= getAverage();
		double radius	= standardDeviations * getStandardDeviation();
		double stepSize	= (numberOfPoints-1) / 2.0;
		for(int i=0; i<numberOfPoints;i++) {
			double alpha = (-(double)(numberOfPoints-1) / 2.0 + i) / stepSize;
			intervalPoints[i]	= center + alpha * radius;
			anchorPoints[i]		= center + alpha * radius - radius / (2 * stepSize);
		}
		anchorPoints[numberOfPoints] = center + 1 * radius + radius / (2 * stepSize);

		double[][] result = new double[2][];
		result[0] = anchorPoints;
		result[1] = getHistogram(intervalPoints);

		return result;
	}
173952
function circularHistogram1D(length, init){
        var circularHist1D; 
        if(length instanceof Array){
            circularHist1D = length;
        }else {
            init = typeof init !== 'undefined' ? init : 0;
            circularHist1D = [];
            for(var x = 0; x< length; ++x){
                circularHist1D[x] = init;   
            }
        }
        
        circularHist1D.circularIndex = circularHistogram1DFunctions.circularIndex;
        circularHist1D.max = circularHistogram1DFunctions.max;
        circularHist1D.min = circularHistogram1DFunctions.min;
        circularHist1D.cv = circularHistogram1DFunctions.cv;
        circularHist1D.medianSmoothing = circularHistogram1DFunctions.medianSmoothing;
        circularHist1D.gaussianSmoothing = circularHistogram1DFunctions.gaussianSmoothing;
        circularHist1D.flatten = circularHistogram1DFunctions.flatten;
        circularHist1D.findPeaks = circularHistogram1DFunctions.findPeaks;
        circularHist1D.normalize = circularHistogram1DFunctions.normalize;
        
        return circularHist1D;
    }
562692
public static void histogram( GrayF32 input , float minValue , int histogram[] ) {
		if( BoofConcurrency.USE_CONCURRENT ) {
			ImplImageStatistics_MT.histogram(input,minValue,histogram);
		} else {
			ImplImageStatistics.histogram(input,minValue,histogram);
		}
	}
596283
public static void histogram( GrayS8 input , int minValue , int histogram[] ) {
		if( BoofConcurrency.USE_CONCURRENT ) {
			ImplImageStatistics_MT.histogram(input,minValue,histogram);
		} else {
			ImplImageStatistics.histogram(input,minValue,histogram);
		}
	}
1129187
void addToHistogram(int cellX, int cellY, int orientationIndex, double magnitude) {
		// see if it's being applied to a valid cell in the histogram
		if( cellX < 0 || cellX >= cellsPerBlockX)
			return;
		if( cellY < 0 || cellY >= cellsPerBlockY)
			return;

		int index = (cellY*cellsPerBlockX + cellX)*orientationBins + orientationIndex;
		histogram[index] += magnitude;
	}
699224
@Override
	public double[] getHistogram(double[] intervalPoints)
	{
		double[] histogramValues = new double[intervalPoints.length+1];

		if(isDeterministic()) {
			/*
			 * If the random variable is deterministic we will return an array
			 * consisting of 0's and one and only one 1.
			 */
			java.util.Arrays.fill(histogramValues, 0.0);
			for (int intervalIndex=0; intervalIndex<intervalPoints.length; intervalIndex++)
			{
				if(valueIfNonStochastic > intervalPoints[intervalIndex]) {
					histogramValues[intervalIndex] = 1.0;
					break;
				}
			}
			histogramValues[intervalPoints.length] = 1.0;
		}
		else {
			/*
			 * If the random variable is deterministic we will return an array
			 * representing a density, where the sum of the entries is one.
			 * There is one exception:
			 * If the size of the random variable is 0, all entries will be zero.
			 */
			float[] realizationsSorted = realizations.clone();
			java.util.Arrays.sort(realizationsSorted);

			int sampleIndex=0;
			for (int intervalIndex=0; intervalIndex<intervalPoints.length; intervalIndex++)
			{
				int sampleCount = 0;
				while (sampleIndex < realizationsSorted.length &&
						realizationsSorted[sampleIndex] <= intervalPoints[intervalIndex])
				{
					sampleIndex++;
					sampleCount++;
				}
				histogramValues[intervalIndex] = sampleCount;
			}
			histogramValues[intervalPoints.length] = realizationsSorted.length-sampleIndex;

			// Normalize histogramValues
			if(realizationsSorted.length > 0) {
				for(int i=0; i<histogramValues.length; i++) {
					histogramValues[i] /= realizationsSorted.length;
				}
			}
		}

		return histogramValues;
	}
1108871
function Histogram( canvas, width, height, left, top ) {

		var graph, data, histogram, edges, axes, annotations, title, text;

		// [1] Instantiate a new graph generator and configure:
		graph = xfig.graph( canvas )
			.width( width )
			.height( height )
			.position({
				'left': left,
				'top': top
			})
			.xMin( 0 )
			.xMax( 1 )
			.yMin( 0 );

		// Create the graph:
		graph.create( 'histogram' );

		// Get data:
		d3.json( 'data/histogram.data.json', function ( error, json ) {

			// [2] Instantiate a new data generator and configure:
			data = xfig.data( json )
				.accessors( 'x', function ( d ) {
					return d[ 0 ];
				})
				.accessors( 'y', function ( d ) {
					return d[ 1 ];
				});

			// Create edges to define our histogram bins:
			edges = xfig.vector.linspace( -0.025, 1.025, 0.05 );
			
			// Format the data and histogram the data:
			data.format( [ 'x', 'y' ] )
				.histc(
					function ( d ) {
						return d[ 1 ];
					},
					edges
				);

			// Bind the data instance to the graph:
			graph.data( data )
				.yMax( data.max( function ( d ) {
					return d[ 1 ];
				}));

			// [3] Instantiate a new histogram generator and configure:
			histogram = xfig.histogram( graph )
				.labels( [ 'data 0' ] );

			// Create the histogram:
			histogram.create();

			// [4] Instantiate a new axes generator and configure:
			axes = xfig.axes( graph )
				.yLabel( 'counts' );

			// Create the axes:
			axes.create();

			// [5] Instantiate a new annotations generator and configure:
			annotations = xfig.annotations( graph );

			// Create the annotations element:
			annotations.create();

			// [5.1] Instantiate a new title instance and configure:
			title = annotations.title()
				.top( -30 )
				.left( 250 );

			// Add a (sub)title:
			title.create( 'Subtitle' );

			// [5.2] Instantiate a new text instance and configure:
			text = annotations.text()
				.width( 200 )
				.height( 100 )
				.top( 50 )
				.left( 310 );

			// Add a text annotation:
			text.create( 'This is another text annotation, which may run multiple lines.' );

		});

	}
405055
def _populateHistogram(self):
        """"""
        try :
            buildHistogram.populate1DHist(self._data, self.histogram,
                self.minValue, self.maxValue, self.binWidth)
        except:
            if ((self._data.max() - self._data.min()) < self.binWidth):
                raise ValueError("In histogram1d class, the binWidth is "
                                 "greater than the data range of the array "
                                 "object.")
            else:
                raise SystemError("An error processing the array object "
                                  "information occured in the buildHistogram "
                                  "module of histogram1d.")
1237713
public Histogram histogram(int[] data, double[] breaks, Color color) {
        return histogram(null, data, breaks, color);
    }
1168167
function _histc( vector, edges ) {
		
		var id, counts = [];

		// Initialize our counts vector: (all zeros)
		for ( var i = -1; i < edges.length; i++ ) {
			counts[ i+1 ] = 0;
		} // end FOR i

		// For each value in the vector, find where the value resides along the edge vector:
		for ( var j = 0; j < vector.length; j++ ) {

			// Perform a binary search to find the index where the value equals or exceeds the corresponding value in the edge vector:
			id = binarysearch( edges, vector[ j ] );

			// Update the counts for a bin:
			counts[ id+1 ] += 1;

		} // end FOR i

		// Return the counts:
		return counts;

	}
662181
@Override
  public SortedMap<String, Histogram> getHistograms(MetricFilter filter) {
    return this.innerMetricContext.getHistograms(filter);
  }
487892
private void combineHistogramSameBuckets(FixedBucketsHistogram otherHistogram)
  {
    long[] otherHistogramArray = otherHistogram.getHistogram();
    for (int i = 0; i < numBuckets; i++) {
      histogram[i] += otherHistogramArray[i];
    }

    count += otherHistogram.getCount();
    max = Math.max(max, otherHistogram.getMax());
    min = Math.min(min, otherHistogram.getMin());

    outlierHandler.handleOutliersForCombineSameBuckets(otherHistogram);
  }
565077
def _histplot_op(ax, data, **kwargs):
    """"""
    bins = get_bins(data)
    ax.hist(data, bins=bins, align="left", density=True, **kwargs)
    return ax